:root {
  --ux-touch: 44px;
  --ux-focus: #6ce9f3;
  --ux-sheet-edge: 8px;
  --ux-sheet-bottom: calc(118px + env(safe-area-inset-bottom));
}

:where(button, input, select, textarea, a[href], [tabindex]):focus-visible {
  outline: 2px solid var(--ux-focus) !important;
  outline-offset: 2px !important;
}

body.light-theme {
  --ux-focus: #087c8e;
}

body.light-theme #mapCanvas {
  filter: brightness(1.08) saturate(.96) contrast(1.08) !important;
}

body.buhara-mode:not(.light-theme) #mapCanvas {
  filter: brightness(.84) saturate(1.16) contrast(1.18) !important;
}

body.buhara-mode.light-theme #mapCanvas {
  filter: brightness(.96) saturate(1.02) contrast(1.12) !important;
}

body.light-theme .map-stage {
  background: radial-gradient(circle at 58% 42%, #eaf4f6 0, #cbdde2 52%, #adc5ce 100%) !important;
}

body.light-theme .map-wash {
  background: linear-gradient(90deg, rgba(218, 231, 235, .14), transparent 25%, transparent 76%, rgba(202, 219, 225, .16)), radial-gradient(circle at 55% 46%, transparent 42%, rgba(121, 157, 169, .14) 100%) !important;
}

#mapCanvas:focus-visible {
  outline-offset: -4px !important;
}

.ux-sheet-handle,
.ux-sheet-scrim {
  display: none;
}

.route-panel,
.layer-panel,
.device-card,
.buhara-panel {
  scrollbar-width: thin;
  scrollbar-color: rgba(111, 151, 168, .45) transparent;
}

@media (min-width: 761px) {
  .module-nav {
    min-height: 42px;
    padding: 5px !important;
  }

  .module-nav button {
    min-height: 32px;
    font-size: 10px !important;
    letter-spacing: .1em !important;
  }

  .facility-switch {
    font-size: 11px !important;
  }

  .ops-ticker {
    font-size: 10px !important;
  }

  .route-panel .close-button,
  .layer-title #layerClose,
  .buhara-panel-close,
  .device-card-head button {
    min-width: var(--ux-touch);
    min-height: var(--ux-touch);
  }

  .layer-panel label {
    min-height: 38px;
    box-sizing: border-box;
    font-size: 11px;
  }

  .layer-panel strong,
  .iot-stream b {
    font-size: 10px;
  }
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.mobile-drawer-open {
    touch-action: auto;
  }

  .left-rail {
    z-index: 45 !important;
  }

  .left-rail button {
    min-width: var(--ux-touch);
    min-height: var(--ux-touch);
  }

  .left-rail button::after {
    font-size: 8px !important;
    letter-spacing: .08em !important;
  }

  .ux-sheet-scrim {
    position: fixed;
    z-index: 32;
    inset: 0 0 var(--ux-sheet-bottom);
    display: block;
    border: 0;
    padding: 0;
    background: rgba(2, 6, 12, .42);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    touch-action: none;
    transition: opacity .2s ease, visibility 0s linear .2s;
  }

  body.mobile-drawer-open .ux-sheet-scrim {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
  }

  .route-panel,
  .layer-panel {
    position: fixed !important;
    z-index: 40 !important;
    top: auto !important;
    right: var(--ux-sheet-edge) !important;
    bottom: var(--ux-sheet-bottom) !important;
    left: var(--ux-sheet-edge) !important;
    width: auto !important;
    min-width: 0;
    max-width: none;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 16px 18px !important;
    overflow-x: clip !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
    border: 1px solid rgba(225, 196, 111, .22) !important;
    border-radius: 24px 24px 14px 14px !important;
    background: rgba(7, 12, 22, .985) !important;
    box-shadow: 0 -22px 72px rgba(0, 0, 0, .58), inset 0 1px rgba(255, 255, 255, .04) !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate3d(0, calc(100% + 28px), 0) !important;
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .2s ease, visibility 0s linear .28s !important;
  }

  .route-panel::before,
  .layer-panel::before {
    display: none !important;
  }

  .route-panel.open,
  .layer-panel.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate3d(0, 0, 0) !important;
    transition-delay: 0s !important;
  }

  .route-panel {
    height: min(58dvh, 520px) !important;
    max-height: calc(100dvh - var(--ux-sheet-bottom) - max(72px, env(safe-area-inset-top))) !important;
  }

  .route-panel[data-sheet-state="compact"] {
    height: min(38dvh, 330px) !important;
  }

  .route-panel[data-sheet-state="full"] {
    height: calc(100dvh - var(--ux-sheet-bottom) - max(72px, env(safe-area-inset-top))) !important;
  }

  .layer-panel {
    height: auto !important;
    max-height: min(62dvh, calc(100dvh - var(--ux-sheet-bottom) - max(72px, env(safe-area-inset-top)))) !important;
  }

  .layer-panel[data-sheet-state="full"] {
    height: calc(100dvh - var(--ux-sheet-bottom) - max(72px, env(safe-area-inset-top))) !important;
    max-height: none !important;
  }

  .ux-sheet-handle {
    position: sticky;
    z-index: 6;
    top: -12px;
    display: grid;
    place-items: center;
    width: 100%;
    height: 32px;
    margin: 0 0 3px;
    padding: 0;
    border: 0;
    background: linear-gradient(180deg, rgba(7, 12, 22, .99) 72%, transparent);
    color: #8ba0ad;
    cursor: pointer;
    touch-action: manipulation;
  }

  .ux-sheet-handle::before {
    content: "";
    width: 44px;
    height: 5px;
    border-radius: 99px;
    background: rgba(225, 196, 111, .46);
    box-shadow: 0 0 16px rgba(225, 196, 111, .08);
  }

  .ux-sheet-handle span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .route-head,
  .layer-title {
    position: relative;
    z-index: 5;
  }

  .route-profiles,
  .route-panel .destination-search {
    position: static !important;
  }

  .route-head h2 {
    margin-top: 4px;
    font-size: clamp(20px, 5.6vw, 24px) !important;
    line-height: 1.15;
  }

  .route-head .eyebrow,
  .steps-head h3,
  .layer-title {
    font-size: 11px !important;
  }

  .route-panel .close-button,
  .layer-title #layerClose {
    display: grid !important;
    place-items: center;
    flex: 0 0 var(--ux-touch);
    width: var(--ux-touch) !important;
    height: var(--ux-touch) !important;
    min-width: var(--ux-touch);
    min-height: var(--ux-touch);
    margin: -6px -6px -6px 8px;
    border-radius: 14px !important;
    background: rgba(132, 163, 194, .07) !important;
  }

  .destination-search {
    min-height: 48px;
    height: 48px !important;
    margin: 12px 0 10px !important;
    border-radius: 13px !important;
  }

  .destination-search input,
  .buhara-search {
    min-width: 0;
    font-size: 16px !important;
  }

  .department-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 2px 4px 10px 1px !important;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  }

  .department-chip {
    min-height: 42px;
    padding: 0 14px !important;
    border-radius: 12px !important;
    font-size: 12px !important;
    scroll-snap-align: start;
  }

  .route-profiles,
  .route-summary,
  .route-conditions,
  .safety-actions {
    min-width: 0;
  }

  .route-profiles button,
  .route-conditions button,
  .safety-actions button,
  .start-button,
  .qr-apply {
    min-height: var(--ux-touch) !important;
    border-radius: 13px !important;
    font-size: 12px !important;
  }

  .route-summary {
    margin: 14px 0 !important;
  }

  .route-summary strong {
    font-size: 16px !important;
  }

  .route-summary span,
  .location-card span,
  .steps p,
  .steps small,
  .steps-head span,
  .disclaimer,
  .notice p,
  .safety-actions small {
    font-size: 11px !important;
    line-height: 1.4;
  }

  .location-card {
    width: 100%;
    min-height: 64px;
    height: auto !important;
    box-sizing: border-box;
    grid-template-columns: 12px minmax(0, 1fr) auto !important;
    gap: 10px !important;
    padding: 8px 8px 8px 14px !important;
    border-radius: 13px !important;
  }

  .location-card > div {
    min-width: 0;
  }

  .location-card strong {
    overflow: hidden;
    font-size: 13px !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .location-card button,
  .notice button {
    min-width: var(--ux-touch);
    min-height: var(--ux-touch);
    padding: 0 9px;
    border-radius: 11px;
    font-size: 11px;
  }

  .steps li {
    min-height: 54px;
    box-sizing: border-box;
  }

  .steps strong {
    font-size: 13px !important;
  }

  .layer-title {
    min-height: 44px;
    align-items: center !important;
    margin: 0 !important;
  }

  .layer-panel label {
    min-height: 48px;
    box-sizing: border-box;
    grid-template-columns: 24px 10px minmax(0, 1fr) auto !important;
    gap: 9px !important;
    padding: 6px 4px !important;
    font-size: 13px !important;
  }

  .layer-panel label input {
    width: 20px;
    height: 20px;
    margin: 0;
  }

  .layer-panel strong,
  .iot-stream b {
    font-size: 12px !important;
  }

  .iot-stream span,
  .iot-stream small {
    font-size: 10px !important;
  }

  body.mobile-drawer-open .map-control-dock > *,
  body.mobile-drawer-open .telemetry-card,
  body.mobile-drawer-open .active-floor-hud,
  body.mobile-drawer-open .view-modes,
  body.mobile-drawer-open .block-tabs,
  body.mobile-drawer-open .map-compass {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.light-theme .route-panel,
  body.light-theme .layer-panel {
    background: rgba(249, 252, 253, .99) !important;
    border-color: rgba(53, 83, 99, .2) !important;
    box-shadow: 0 -22px 70px rgba(37, 62, 75, .22), inset 0 1px rgba(255, 255, 255, .9) !important;
  }

  body.light-theme .ux-sheet-handle {
    background: linear-gradient(180deg, rgba(249, 252, 253, .99) 72%, transparent);
  }

  body.light-theme .ux-sheet-scrim {
    background: rgba(48, 72, 84, .22);
  }

  .device-card,
  body.buhara-mode .buhara-panel {
    bottom: var(--ux-sheet-bottom) !important;
  }

  body.mobile-drawer-open #ankaraDeviceMapLabel,
  body.ops-console-open #ankaraDeviceMapLabel {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

/* Operations surfaces share one modal stack and readable control scale. */
.ops-console-backdrop {
  z-index: 70 !important;
}

.ops-console {
  z-index: 71 !important;
}

body.ops-console-open .map-stage {
  isolation: auto !important;
}

.ops-list-tools {
  flex-wrap: wrap;
}

.ops-list-tool-actions {
  flex: 1 1 100%;
  justify-content: flex-start;
  margin-left: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.ops-list-tool-actions::-webkit-scrollbar {
  display: none;
}

.ops-console-heading p,
.ops-kpi span,
.ops-kpi small,
.ops-list-head,
.ops-device-copy small,
.ops-device-state,
.ops-detail-title span,
.ops-detail-field dt,
.ops-section-head span,
.ops-alarm-copy small,
.ops-config-copy small,
.ops-config-field label,
.ops-config-field > span,
.ops-config-status,
.ops-console-footnote {
  font-size: 10px !important;
  letter-spacing: .07em !important;
  line-height: 1.35;
}

.ops-tab,
.ops-search-field input,
.ops-filter-select,
.ops-device-copy span,
.ops-detail-title p,
.ops-detail-field dd,
.ops-alarm-copy span,
.ops-config-copy span,
.ops-config-check,
.ops-config-field input,
.ops-config-field select,
.ops-config-field textarea {
  font-size: 11px !important;
  letter-spacing: .04em !important;
}

.ops-device-copy b,
.ops-alarm-copy b,
.ops-config-copy b,
.ops-detail-title h3 {
  font-size: 12px !important;
}

@media (max-width: 760px) {
  body.ops-console-open .ops-topbar {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.ops-console-open .left-rail {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .ops-console {
    inset: max(82px, calc(72px + env(safe-area-inset-top))) 6px calc(34px + env(safe-area-inset-bottom)) 6px !important;
    max-height: calc(100dvh - max(82px, calc(72px + env(safe-area-inset-top))) - 34px - env(safe-area-inset-bottom));
  }

  .ops-console-heading p {
    font-size: 10px !important;
  }

  .ops-kpi span {
    font-size: 9px !important;
  }

  .ops-tab {
    font-size: 10px !important;
  }
}

@media (pointer: coarse) {
  .ops-console :where(button, input:not([type="checkbox"]), select),
  .ops-schedule-dialog :where(button, input:not([type="checkbox"]), select),
  .cep-dialog :where(button, input:not([type="checkbox"]), select),
  .ops-list-config-dialog :where(button, input:not([type="checkbox"]), select) {
    min-height: var(--ux-touch) !important;
  }

  .ops-console :where(.ops-icon-button, .ops-ack-button, .ops-config-icon),
  .ops-schedule-dialog :where(.ops-schedule-icon-button, .ops-schedule-close),
  .cep-dialog :where(.cep-close, .cep-state-order) {
    min-width: var(--ux-touch) !important;
  }
}

@media (max-width: 760px) and (max-height: 700px) {
  .ops-console {
    top: max(66px, calc(58px + env(safe-area-inset-top))) !important;
  }

  .ops-console-header {
    min-height: 52px !important;
  }

  .ops-console-kpis {
    display: none !important;
  }
}

@media (max-width: 390px) {
  :root {
    --ux-sheet-edge: 6px;
    --ux-sheet-bottom: calc(110px + env(safe-area-inset-bottom));
  }

  .route-panel,
  .layer-panel {
    padding-inline: 13px !important;
  }

  .route-profiles button,
  .route-conditions button {
    padding-inline: 7px !important;
  }
}

@media (max-width: 760px) and (max-height: 700px) {
  :root {
    --ux-sheet-bottom: calc(102px + env(safe-area-inset-bottom));
  }

  .route-panel {
    height: min(62dvh, 430px) !important;
  }

  .route-panel[data-sheet-state="compact"] {
    height: min(42dvh, 290px) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Exterior view is a clean campus presentation, not an indoor workflow.
   Keep the mode switch above projected markers and remove indoor-only UI. */
.view-modes {
  z-index: 16 !important;
}

body.exterior-mode .device-cluster-layer {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.exterior-mode:not(.buhara-mode) :is(.route-launcher, .block-tabs, .floor-picker, .telemetry-card) {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.buhara-mode.exterior-mode :is(.buhara-panel, .buhara-stack, .buhara-panel-open) {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.exterior-mode :is(.legend, .map-scale) {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.exterior-mode :is(#routeToggle, #layerToggle, #cameraToggle, #zonesToggle, #searchToggle) {
  opacity: .28 !important;
  pointer-events: none !important;
}

@media (min-width: 761px) and (max-width: 1050px) {
  .view-modes {
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }
}
