/* Platform mobile — shared responsive layer */

:root {
  --mobile-nav-h: 3.375rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Bottom site nav (injected by platform-mobile.js) */
.mobile-site-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  height: calc(var(--mobile-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(12, 13, 17, 0.96);
  border-top: 1px solid #1e2128;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mobile-site-nav-inner {
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: var(--mobile-nav-h);
  max-width: 100%;
  margin: 0 auto;
  padding: 0 0.125rem;
}

.mobile-site-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-width: 0;
  padding: 0.25rem 0.125rem;
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #55606e;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-site-nav a .mob-nav-icon {
  display: flex;
  width: 1.25rem;
  height: 1.25rem;
  opacity: 0.85;
}

.mobile-site-nav a .mob-nav-icon svg {
  width: 100%;
  height: 100%;
}

.mobile-site-nav a.active {
  color: #38bdf8;
}

.mobile-site-nav a.active .mob-nav-icon {
  opacity: 1;
}

.mobile-tools-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: var(--header-control-h, 2.125rem);
  min-height: 2.75rem;
  padding: 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #8891a0;
  border-radius: 8px;
  border: 1px solid #1e2128;
  background: #0c0d11;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mobile-tools-toggle--icon {
  flex: 0 0 2.75rem;
  width: 2.75rem;
  padding: 0;
  font-size: 0.9375rem;
}

.mobile-tools-toggle.is-open {
  color: #38bdf8;
  border-color: rgba(14, 165, 233, 0.35);
  background: rgba(14, 165, 233, 0.08);
}

.mobile-tools-toggle svg {
  width: 0.875rem;
  height: 0.875rem;
  transition: transform 0.2s;
}

.mobile-tools-toggle.is-open svg {
  transform: rotate(180deg);
}

@media (max-width: 767px) {
  body.has-mobile-nav {
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
  }

  html.chat-page body.has-mobile-nav {
    height: 100%;
    box-sizing: border-box;
  }

  body.has-mobile-nav .mobile-site-nav {
    display: block;
  }

  /* Hide inline header nav — bottom bar replaces it */
  .header-field:has(> .header-nav),
  .header-field:has(.header-nav),
  .header-field--nav {
    display: none !important;
  }

  .header-wrap {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    gap: 0.5rem 0.625rem !important;
  }

  .header-brand {
    border-right: none !important;
    margin-right: 0 !important;
    padding-right: 0 !important;
  }

  .header-tools {
    gap: 0.5rem !important;
  }

  .header-field {
    min-width: 0;
  }

  .filter-toggle-group {
    max-width: 100%;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .modal-panel {
    width: calc(100vw - 1.5rem) !important;
    max-width: calc(100vw - 1.5rem) !important;
    max-height: calc(100vh - 2rem - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
  }

  .modal-backdrop {
    padding: 0.75rem;
    align-items: flex-end;
  }

  .pf-status-bar,
  .usage-status-bar {
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
  }

  /* Settings */
  .field-row {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    align-items: stretch !important;
  }

  .field-row .field-control {
    width: 100%;
  }

  .settings-actions-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .settings-actions-row .btn-primary,
  .settings-actions-row .btn-ghost {
    width: 100%;
    justify-content: center;
  }

  /* Usage — period chips horizontal scroll */
  #period-group {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    max-width: min(100vw - 2rem, 28rem);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  #period-group::-webkit-scrollbar {
    display: none;
  }

  #custom-range-fields .header-control {
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
  }

  #custom-range-fields .date-input {
    width: 100%;
  }

  .usage-header-tools,
  .dashboard-page .header-tools-right {
    width: 100%;
  }

  /* Chat — mobile layout */
  .mobile-tools-toggle {
    display: inline-flex;
  }

  .chat-header .w-full.px-4 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .chat-header .header-wrap {
    gap: 0.375rem !important;
    padding-bottom: 0.375rem !important;
  }

  .chat-header .chat-header-top {
    width: 100%;
    gap: 0.5rem !important;
  }

  .chat-header .chat-header-top .header-brand {
    flex: 1;
    min-width: 0;
  }

  .chat-header .chat-header-top .header-brand .w-9 {
    width: 2rem;
    height: 2rem;
  }

  .chat-header .chat-header-top .header-brand .w-5 {
    width: 1rem;
    height: 1rem;
  }

  .chat-header .chat-header-top #chat-model-label {
    display: none;
  }

  .chat-header .chat-header-hide-btn {
    width: 2.75rem;
    height: 2.75rem;
    min-height: 2.75rem;
  }

  .chat-header #btn-toggle-sidebar {
    min-height: 2.75rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .chat-header .chat-header-main {
    flex-basis: 100%;
    width: 100%;
    gap: 0.375rem;
    padding-top: 0;
    border-top: none;
  }

  .chat-header-mobile-toolbar {
    display: flex;
    align-items: stretch;
    gap: 0.375rem;
    width: 100%;
  }

  .chat-header-mobile-toolbar .mobile-tools-toggle {
    flex: 1 1 0;
    min-width: 0;
  }

  .chat-header-mobile-toolbar .mobile-tools-toggle--icon {
    flex: 0 0 2.75rem;
  }

  .chat-header-params-panel.is-collapsed,
  .chat-header-tools-panel.is-collapsed {
    display: none !important;
  }

  .chat-header-params-panel:not(.is-collapsed) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    gap: 0.5rem 0.625rem;
    min-height: 0;
    max-height: min(52vh, 26rem);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.625rem;
    border: 1px solid #1e2128;
    border-radius: 10px;
    background: rgba(12, 13, 17, 0.95);
  }

  .chat-header-params-panel:not(.is-collapsed) .header-field {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .chat-header-params-panel:not(.is-collapsed) .header-field--model,
  .chat-header-params-panel:not(.is-collapsed) #chat-orchestration-toggle-field,
  .chat-header-params-panel:not(.is-collapsed) #move-filter-field,
  .chat-header-params-panel:not(.is-collapsed) .header-field:has(.preset-btn) {
    grid-column: 1 / -1;
  }

  .chat-header-params-panel:not(.is-collapsed) .dashboard-select,
  .chat-header-params-panel:not(.is-collapsed) .symbol-picker-trigger,
  .chat-header-params-panel:not(.is-collapsed) .symbol-picker,
  .chat-header-params-panel:not(.is-collapsed) .filter-toggle-group {
    width: 100%;
    max-width: 100%;
  }

  .chat-header-params-panel:not(.is-collapsed) .filter-toggle-group {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-control-h, 2.125rem);
    gap: 0.25rem;
    padding: 0.25rem;
    box-sizing: border-box;
  }

  .chat-header-params-panel:not(.is-collapsed) #move-filter-field .filter-toggle-group {
    flex-wrap: nowrap;
  }

  .chat-header-tools-panel:not(.is-collapsed) {
    width: 100%;
    min-height: 0;
    max-height: min(44vh, 22rem);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem;
    border: 1px solid #1e2128;
    border-radius: 10px;
    background: rgba(12, 13, 17, 0.95);
    box-sizing: border-box;
  }

  .chat-header-tools-panel .chat-header-row--tools {
    gap: 0;
    margin: 0;
  }

  .chat-header-tools-panel .header-field--tools .header-field-label {
    display: none;
  }

  .chat-header-tools-panel .header-field--tools .filter-toggle-group--wrap {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
    gap: 0.375rem;
    padding: 0.125rem;
    height: auto;
    min-height: 0;
  }

  .chat-header-tools-panel .filter-chip input + span {
    width: 100%;
    justify-content: center;
    box-sizing: border-box;
  }

  .chat-header-row--footer {
    display: none !important;
  }

  .chat-status-panel .chat-collapsible-body {
    padding-bottom: 0.5rem !important;
  }

  .chat-status-panel.is-collapsed .chat-status-panel-head {
    padding-bottom: 0.5rem !important;
  }

  .chat-thread-toolbar .chat-collapsible-header {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .chat-thread-toolbar.is-collapsed .thread-toolbar-actions,
  .chat-thread-toolbar.is-collapsed #thread-usage-strip {
    display: none !important;
  }

  .chat-input-area {
    padding: 0.75rem 1rem calc(0.625rem + var(--safe-bottom) * 0.25) !important;
  }

  .chat-input-area .chat-form-row {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 0.5rem;
    align-items: stretch;
  }

  .chat-input-area #btn-prompts {
    order: unset;
    grid-row: 1;
    grid-column: 1;
    min-height: 2.75rem;
    padding-left: 0.625rem;
    padding-right: 0.625rem;
  }

  .chat-input-area #chat-input {
    order: unset;
    grid-row: 1;
    grid-column: 2;
    flex: unset;
    min-width: 0;
    min-height: 2.75rem;
  }

  .chat-input-area #btn-send:not(.hidden),
  .chat-input-area #btn-stop-job:not(.hidden) {
    order: unset;
    grid-row: 2;
    grid-column: 1 / -1;
    flex: unset;
    width: 100%;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .msg-bubble {
    max-width: 100% !important;
  }

  #messages-container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  #chat-active {
    --chat-scroll-gap: 1.5rem;
  }

  .chat-harmonic-chart-inner {
    height: 180px;
  }

  .chat-scenario-chart-actions {
    top: 0.25rem;
    right: 0.25rem;
    gap: 0.25rem;
  }

  .chat-scenario-chart-actions .chat-chart-fs-btn,
  .chat-scenario-chart-actions .chat-scenario-panel-refresh-btn {
    min-height: 2.125rem;
    padding: 0.3rem 0.45rem;
    font-size: 0.5625rem;
  }

  .chat-harmonic-chart-wrap > .chat-chart-fs-btn {
    min-height: 2.75rem;
    min-width: 2.75rem;
    padding: 0.35rem 0.55rem;
  }

  .chat-playbook-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .chat-playbook-label {
    flex: none;
    padding-top: 0;
  }

  .chat-fc-step-body {
    padding: 0.35rem 0.4rem;
  }

  .chat-chart-fs-extras .chat-fs-fc-rail,
  .chat-chart-fs-extras .chat-scenario-watch,
  .chat-chart-fs-extras .chat-scenario-playbook {
    max-width: 100%;
  }

  .chat-harmonic-tab {
    min-height: 2.125rem;
    padding: 0.35rem 0.55rem;
  }

  #settings-modal .modal-panel {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
  }

  #settings-modal .flex.flex-wrap.justify-between {
    flex-direction: column;
    align-items: stretch;
  }

  #prompts-modal .modal-panel,
  #prompt-edit-modal .modal-panel {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    max-height: calc(100vh - 1.5rem - var(--safe-top) - var(--safe-bottom));
    overflow: hidden;
  }

  #prompts-modal .prompts-modal-categories {
    max-height: 4.75rem;
  }

  #prompts-modal .prompts-modal-foot,
  #prompt-edit-modal .prompt-edit-foot {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  #prompts-modal .prompts-modal-foot button,
  #prompt-edit-modal .prompt-edit-foot button {
    width: 100%;
    min-height: 2.75rem;
  }

  #prompts-modal .prompt-card-action {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 0.8125rem;
  }

  #settings-modal #btn-reset-chat-prefs,
  #settings-modal #btn-settings-close {
    width: 100%;
    justify-content: center;
  }

  /* Login safe area */
  body.login-page {
    padding-bottom: var(--safe-bottom);
    padding-top: var(--safe-top);
  }
}

@media (min-width: 768px) {
  .chat-header-mobile-toolbar {
    display: none;
  }

  .chat-header-params-panel {
    display: contents;
  }

  .chat-header-params-panel.is-collapsed {
    display: contents !important;
  }

  .chat-header-tools-panel {
    display: contents;
  }

  .chat-header-tools-panel.is-collapsed {
    display: contents !important;
  }
}

@media (max-width: 1023px) {
  html.dashboard-page,
  html.dashboard-page body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .dashboard-main-row {
    flex-direction: column !important;
    overflow: visible !important;
    min-height: auto !important;
  }

  #dashboard-main {
    overflow: visible !important;
    min-height: auto !important;
  }

  #obs-panel {
    width: 100% !important;
    flex: none !important;
    min-height: auto !important;
    max-height: none !important;
  }

  #obs-panel .table-wrap {
    max-height: none !important;
  }

  .dashboard-page .header-tools-right {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 480px) {
  #platform-stats {
    grid-template-columns: 1fr 1fr !important;
  }

  #llm-stats {
    grid-template-columns: 1fr 1fr !important;
  }

  .cost-analysis-summary-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .header-field-label {
    font-size: 0.5625rem;
  }

  .dashboard-select.select-platform {
    width: 6.5rem;
  }

  .model-picker-trigger,
  .option-picker-trigger {
    min-width: 0;
    max-width: 100%;
  }

  .header-field--model {
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 calc(50% - 0.25rem);
  }
}
