/* Shared mobile + header layout after the topbar markup change. */

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "menu title actions"
    ". subtitle subtitle";
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
}
.sidebar-menu { grid-area: menu; }
.title-row { grid-area: title; min-width: 0; }
.topbar-actions { grid-area: actions; }
#headerSubtitle { grid-area: subtitle; margin: 0; }

@media (min-width: 721px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title actions"
      "subtitle actions";
  }
  .search-toggle { display: none !important; }
}

.search-toggle { display: none; }

.md-body { margin: 0; line-height: 1.55; font-size: 13px; overflow-wrap: anywhere; }
.md-body p { margin: 0 0 8px; white-space: normal; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 0 0 8px; line-height: 1.25; }
.md-body h1 { font-size: 16px; }
.md-body h2 { font-size: 15px; }
.md-body h3 { font-size: 14px; }
.md-body ul, .md-body ol { margin: 0 0 8px; padding-left: 1.25em; }
.md-body li { margin: 0 0 4px; }
.md-body li ul, .md-body li ol { margin: 4px 0 0; }
.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(255,255,255,0.06);
  padding: 0 4px;
  border-radius: 4px;
}
.md-body strong { font-weight: 700; }
.assistant-msg .md-body { font-size: inherit; }

.icon-tool {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c5d0e0;
}
.icon-tool:hover { background: rgba(255,255,255,0.06); }
.icon-tool svg { display: block; }

.council-turn { display: grid; gap: 12px; }
.council-turn-q {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}
.council-turn-q small {
  display: block;
  margin-top: 2px;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
}

.council-followup {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  margin-top: 14px;
}
.council-followup[hidden] { display: none !important; }
.council-followup-modes { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.followup-mode { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.followup-mode input { width: 18px; height: 18px; margin: 0; accent-color: #3b82f6; }
.council-followup-costs p { margin: 0; font-size: 13px; font-weight: 600; }
.council-followup-costs .is-selected { color: #93c5fd; }
.council-followup textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  background: #0c1422;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

html, body { max-width: 100%; }
.app-shell, .main { min-width: 0; }

@media (max-width: 720px) {
  .main {
    padding: 12px max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "menu title actions"
      "subtitle subtitle subtitle";
    column-gap: 8px;
    row-gap: 6px;
    margin-bottom: 10px;
  }
  .sidebar-menu,
  .icon-button,
  .bell-button,
  .top-avatar,
  .search-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .search-toggle { display: grid; place-items: center; }
  .title-row h1 {
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #headerSubtitle {
    font-size: 12px;
    line-height: 1.35;
  }
  #searchBar {
    display: none;
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  .topbar.search-open {
    grid-template-areas:
      "menu title actions"
      "search search search";
  }
  .topbar.search-open #searchBar {
    display: flex;
    grid-area: search;
    width: 100%;
  }
  .topbar.search-open #headerSubtitle { display: none; }
  .search input,
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]),
  textarea,
  select,
  .composer-input {
    font-size: 16px !important;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]),
  textarea,
  select,
  .composer-input,
  button,
  .text-tool,
  .nav-item,
  .icon-chip,
  .model-chip,
  .primary-button,
  .ghost-button,
  .collapse-toggle,
  .council-history-item {
    min-height: 44px;
  }
  .toggle input,
  .followup-mode input { min-height: 18px !important; width: 18px; height: 18px; }

  .council-layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .council-main { order: 0; min-width: 0; }
  .council-history {
    order: 1;
    min-height: 0;
    padding: 10px 12px;
  }
  .council-history-list { max-height: 160px; overflow: auto; }
  .council-history-list > .subtle:only-child {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .summary-head { align-items: center; gap: 8px; }
  .summary-head .council-actions { flex: none; flex-wrap: nowrap; }
  .summary-head .text-tool { display: none; }
  .summary-head .icon-tool { display: inline-grid; }

  .assistant-layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .assistant-chat { order: 0; min-width: 0; }
  .assistant-threads {
    order: 1;
    min-height: 0;
    max-height: none;
  }
  .assistant-thread-list { display: none; }
  .assistant-threads.is-open .assistant-thread-list {
    display: block;
    max-height: 220px;
    overflow: auto;
  }
  .assistant-tools { order: 2; }

  .agents-workspace { display: flex; flex-direction: column; gap: 12px; }
  .agent-list-pane { order: 0; max-height: none; }
  #agentEditor { order: 1; min-width: 0; }
  .agent-list-pane .agent-list-search,
  .agent-list-pane .agent-list-scroll { display: none; }
  .agent-list-pane.is-open .agent-list-search { display: flex; }
  .agent-list-pane.is-open .agent-list-scroll {
    display: block;
    max-height: 200px;
    overflow: auto;
  }
  .form-row { grid-template-columns: 1fr; }

  body, .app-shell, .main, .view, .view.is-active, .council-layout, .assistant-layout, .agents-workspace, .ceo-row, #view-dashboard {
    overflow-x: hidden;
    max-width: 100%;
    min-width: 0;
  }
  .org-stage, .org-chart {
    overflow-x: auto;
    max-width: 100%;
    min-width: 0;
  }
  .agent-row { max-width: 100%; }
}


@media (min-width: 721px) {
  .summary-head .icon-tool.icon-tool-mobile { display: none; }
}

@media (max-width: 430px) {
  .title-row .agent-switch { flex: none; }
  #headerSubtitle { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
