/* ==========================================================================
   APORTAL — structural styles
   Layout and components only. Colours, radii and decoration come from the
   active theme file (theme-corporate.css / theme-dark.css / theme-aero.css).
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* Fallbacks so the app still renders if a theme file fails to load. */
  --bg: #e9ebee;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --surface-3: #eceef1;
  --border: #d6d9de;
  --border-strong: #b9bec6;
  --text: #1b2430;
  --text-muted: #667080;
  --on-accent: #ffffff;
  --accent: #1f3a63;
  --accent-hover: #27497c;
  --accent-soft: #e8eef8;
  --ok: #2f6f36;
  --ok-soft: #e7f3e8;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --warn: #9a6300;
  --warn-soft: #fdf3e0;
  --radius: 2px;
  --radius-sm: 2px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 18px rgba(16, 24, 40, 0.1);
  --topbar-bg: linear-gradient(180deg, #24466f 0%, #1b3358 100%);
  --topbar-text: #ffffff;
  --topbar-muted: rgba(255, 255, 255, 0.72);
  --topbar-border: rgba(255, 255, 255, 0.14);
  --topbar-hover: rgba(255, 255, 255, 0.14);
  --input-bg: #ffffff;
  --code-bg: #f3f5f8;
  --code-text: #1b2430;
  --user-bubble: #eaf1fb;
  --user-bubble-border: #cfdeef;
  --assistant-bubble: #ffffff;
  --assistant-bubble-border: #dde1e7;
  --font-ui: "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --page-head-bg: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}
a:visited {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

.hidden {
  display: none !important;
}
.inline {
  display: inline;
  margin: 0;
}
.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.small {
  font-size: 12px;
}
.muted {
  color: var(--text-muted);
}
.center {
  text-align: center;
}
.right {
  margin-left: auto;
}
.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ------------------------------------------------------------------- shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Chat pins the shell to the viewport so the page never grows: the transcript
   scrolls inside .messages instead. 100dvh keeps mobile browser chrome honest. */
.app-shell--chat {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.app-shell--chat .page-wrap {
  overflow: hidden;
}
body.is-chat {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 18px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  border-bottom: 1px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 13px;
  line-height: 1;
  border: 1px solid var(--topbar-border);
  border-radius: var(--radius-sm);
  background: var(--topbar-hover);
  color: inherit;
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 22px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar {
  display: none;
}
.nav-link {
  padding: 6px 11px;
  font-size: 13px;
  color: var(--topbar-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0.82;
}
.nav-link:visited {
  color: var(--topbar-text);
}
.nav-link:hover {
  background: var(--topbar-hover);
  opacity: 1;
}
.nav-link.active {
  background: var(--topbar-hover);
  opacity: 1;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.topbar-user {
  font-size: 12.5px;
  color: var(--topbar-muted);
  white-space: nowrap;
}
.nav-btn {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 12px;
  color: var(--topbar-text);
  background: transparent;
  border: 1px solid var(--topbar-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.nav-btn:hover {
  background: var(--topbar-hover);
}

/* --------------------------------------------------------------- page head */
.page-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  animation: pageIn 0.32s cubic-bezier(0.22, 0.7, 0.3, 1) both;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Applied briefly by the page-transition helper before navigating. */
body.page-leaving .app-shell {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.page-head {
  flex: 0 0 auto;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--page-head-bg);
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head-main {
  min-width: 0;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.page-sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}
.page-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.page-note {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding-left: 6px;
}

/* ------------------------------------------------------------------ cards */
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel {
  overflow: hidden;
  scroll-margin-top: 112px;
}
.panel + .panel {
  margin-top: 14px;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.panel-head .spacer {
  margin-left: auto;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
.panel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}
.panel-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ------------------------------------------------------------------- stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 1080px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }
}
.stat {
  position: relative;
  padding: 12px 14px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top: 3px solid var(--accent);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stat-label {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}
.stat-value {
  display: block;
  margin-top: 4px;
  font-size: 23px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat.ok {
  border-top-color: var(--ok);
}
.stat.ok .stat-value {
  color: var(--ok);
}
.stat.danger {
  border-top-color: var(--danger);
}
.stat.danger .stat-value {
  color: var(--danger);
}
.stat.accent {
  border-top-color: var(--accent);
}
.stat.accent .stat-value {
  color: var(--accent);
}
.stat.warn {
  border-top-color: var(--warn);
}
.stat.warn .stat-value {
  color: var(--warn);
}

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  padding: 8px 14px;
  min-height: 32px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:visited {
  color: var(--text);
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-muted);
}
.btn:active {
  background: var(--surface-3);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.btn:disabled {
  color: var(--text-muted);
  background: var(--surface-2);
  border-color: var(--border);
  box-shadow: none;
  cursor: default;
  opacity: 0.75;
}
.btn.primary {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:visited {
  color: var(--on-accent);
}
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn.primary:disabled {
  color: var(--on-accent);
  background: var(--accent);
  opacity: 0.5;
}
.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--surface);
}
.btn.danger:hover {
  background: var(--danger-soft);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.btn.ghost:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.btn.small {
  min-height: 26px;
  padding: 5px 9px;
  font-size: 12px;
}
.btn.wide {
  width: 100%;
}
.file-btn {
  cursor: pointer;
  color: var(--text);
}

/* -------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 52px;
  z-index: 15;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:visited {
  color: var(--text-muted);
}
.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------------ inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.field > span {
  font-weight: 500;
}
.field-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.input,
.select,
textarea.input-area {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  outline: none;
  width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:focus,
.select:focus,
textarea.input-area:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder,
textarea.input-area::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}
.select {
  width: auto;
  min-width: 150px;
  max-width: 260px;
  height: 34px;
  padding: 4px 6px;
}
.input.mini {
  padding: 5px 7px;
  font-size: 12.5px;
}
textarea.input-area {
  resize: vertical;
  min-height: 76px;
  max-height: 260px;
  line-height: 1.55;
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.45;
}
.check input {
  margin: 3px 0 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  align-items: end;
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.form-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.form-box + .hint {
  margin-top: 2px;
}
.rules {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------- tables */
.scroll-x {
  overflow-x: auto;
}
table.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
table.grid th,
table.grid td {
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
}
table.grid th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  white-space: nowrap;
}
table.grid tbody tr:last-child td {
  border-bottom: 0;
}
table.grid tbody tr:hover td {
  background: var(--surface-2);
}
table.grid td.actions {
  white-space: nowrap;
}
table.grid td.actions form {
  display: inline;
  margin: 0;
}

.pill {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill.on {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: var(--ok);
}
.pill.off {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}
.tag {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  vertical-align: middle;
  white-space: nowrap;
}

details.inline-details > summary {
  list-style: none;
  display: inline-flex;
  margin-bottom: 4px;
}
details.inline-details > summary::-webkit-details-marker {
  display: none;
}
details.inline-details[open] > summary {
  background: var(--surface-3);
}

/* ----------------------------------------------------------------- flashes */
.flashes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.flash {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 11px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.flash-mark {
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1.4;
}
.flash.error {
  background: var(--danger-soft);
  border-color: var(--danger);
  border-left-color: var(--danger);
  color: var(--danger);
}
.flash.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  border-left-color: var(--ok);
  color: var(--ok);
}

/* ------------------------------------------------------------------- auth */
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.auth-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 48px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 26px 26px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.auth-brand .mark {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--radius-sm);
}
.auth-brand strong {
  display: block;
  font-size: 15px;
}
.auth-brand small {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.auth-card h1 {
  font-size: 18px;
  margin-bottom: 6px;
}
.auth-card .lead {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.65;
}

/* ---------------------------------------------------------------- chat page */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  overflow: hidden;
}
.sidebar {
  flex: 0 0 250px;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  min-height: 0;
}
.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.panel-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 2px 2px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
  padding-bottom: 6px;
}
.conv-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.empty-note {
  padding: 10px 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.conv-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.conv-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.conv-label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conv-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-x {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
}
.conv-item:hover .conv-x,
.conv-item.active .conv-x {
  opacity: 1;
}
.conv-x:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}
.incognito-flag {
  color: var(--warn);
  margin-right: 4px;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}
.usage-line {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}
.usage-line .mono {
  color: var(--text);
}
.usage-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.usage-note {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.chat-main.drag-over::after {
  content: "Drop files to attach";
  position: absolute;
  inset: 12px 12px 110px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 5;
}
.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.chat-head-title {
  font-size: 13.5px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 14px 0;
  padding: 9px 12px;
  font-size: 12.5px;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  color: var(--text);
  line-height: 1.5;
}
.banner-text {
  flex: 1;
  min-width: 0;
}
.banner.incognito {
  background: var(--surface-3);
  border-color: var(--border-strong);
  border-left-color: var(--warn);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 380px;
  font-size: 13px;
  line-height: 1.7;
}
.empty-logo {
  font-size: 30px;
  color: var(--accent);
  opacity: 0.55;
  margin-bottom: 10px;
}
.empty-state p {
  margin: 0 0 4px;
}
.empty-state strong {
  color: var(--text);
  font-size: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 78%;
}
.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.msg.assistant {
  align-self: flex-start;
}
.msg-meta {
  font-size: 10.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 2px;
}
.msg.streaming .msg-meta::after {
  content: "\2026";
}
.msg-body {
  padding: 10px 13px;
  background: var(--assistant-bubble);
  border: 1px solid var(--assistant-bubble-border);
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.6;
  overflow-wrap: break-word;
  word-break: break-word;
  min-height: 20px;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
}
.msg.user .msg-body {
  background: var(--user-bubble);
  border-color: var(--user-bubble-border);
  white-space: pre-wrap;
}
.msg.error .msg-body {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.msg-body pre.code {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}
.msg-body code {
  padding: 1px 5px;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.msg-body pre.code code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: inherit;
}
.msg-body em {
  font-style: italic;
}

.msg-reasoning {
  max-width: 100%;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.msg-reasoning > summary {
  cursor: pointer;
  padding: 5px 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  user-select: none;
}
.msg-reasoning > summary:hover {
  color: var(--text);
}
.msg-reasoning-body {
  padding: 0 10px 9px;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
}

.stream-warning {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
}
.stream-warning-hint {
  color: var(--text-muted);
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: inherit;
}
.thumb {
  display: block;
  max-width: 180px;
  max-height: 140px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 280px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip:hover {
  background: var(--surface-3);
}

.composer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pending-files:empty {
  display: none;
}
.pending-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  padding: 3px 4px 3px 9px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.pending-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pending-item .drop {
  font: inherit;
  font-size: 13px;
  line-height: 1;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pending-item .drop:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}
.pending-item.uploading {
  color: var(--text-muted);
  font-style: italic;
}
.composer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.composer-spacer {
  flex: 1;
}

.reasoning-toggle {
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.reasoning-toggle:hover {
  background: var(--surface-3);
}
.reasoning-toggle input {
  margin: 0;
  accent-color: var(--accent);
}
.reasoning-toggle:has(input:not(:checked)) {
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ footer */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 18px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.statusbar .cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.led {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: 0 0 auto;
}
.led.busy {
  background: var(--warn);
}
.led.off {
  background: var(--text-muted);
  opacity: 0.5;
}

/* ------------------------------------------------------------- admin layout */
.admin-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 1400px;
  width: 100%;
}

/* ---------------------------------------------------------------- settings */
.settings-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 1000px;
  width: 100%;
}
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.theme-option {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.theme-option:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.theme-option input:focus-visible + .theme-preview {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 92px;
  padding: 7px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.theme-preview .tp-bar {
  display: block;
  height: 12px;
  border-radius: 1px;
}
.theme-preview .tp-body {
  display: flex;
  gap: 4px;
  flex: 1;
}
.theme-preview .tp-side {
  display: block;
  width: 28%;
  border-radius: 1px;
}
.theme-preview .tp-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.theme-preview .tp-card {
  display: block;
  flex: 1;
  border-radius: 1px;
}
.theme-preview .tp-line {
  display: block;
  height: 7px;
  width: 70%;
  border-radius: 1px;
}
.theme-name {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.theme-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}
.theme-saved {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ok);
  border: 1px solid var(--ok);
  background: var(--ok-soft);
  padding: 0 5px;
  border-radius: var(--radius-sm);
}

/* Preview palettes are fixed, so each swatch looks the same in any theme. */
.theme-preview-corporate {
  background: #e9ebee;
}
.theme-preview-corporate .tp-bar {
  background: #1f3a63;
}
.theme-preview-corporate .tp-side {
  background: #ffffff;
  border: 1px solid #d6d9de;
}
.theme-preview-corporate .tp-card {
  background: #ffffff;
  border: 1px solid #d6d9de;
  border-top: 2px solid #2f6f36;
  height: 22px;
  flex: 0 0 auto;
}
.theme-preview-corporate .tp-line {
  background: #cfd4db;
}

.theme-preview-dark {
  background: #0f1319;
}
.theme-preview-dark .tp-bar {
  background: #1b2230;
}
.theme-preview-dark .tp-side {
  background: #171c24;
  border: 1px solid #2a3240;
}
.theme-preview-dark .tp-card {
  background: #171c24;
  border: 1px solid #2a3240;
  border-top: 2px solid #3b82f6;
  height: 22px;
  flex: 0 0 auto;
}
.theme-preview-dark .tp-line {
  background: #39424f;
}

.theme-preview-aero {
  background: linear-gradient(180deg, #a7e0f7 0%, #63b8e8 55%, #2f86c4 100%);
}
.theme-preview-aero .tp-bar {
  background: linear-gradient(180deg, #ffffff 0%, #d8f0fd 50%, #a6d9f4 51%, #c9ebfb 100%);
  border: 1px solid #6fb4d9;
}
.theme-preview-aero .tp-side {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(226, 245, 255, 0.6));
  border: 1px solid rgba(255, 255, 255, 0.9);
}
.theme-preview-aero .tp-card {
  background: linear-gradient(180deg, #ffffff 0%, #eaf8ff 100%);
  border: 1px solid #86c7e6;
  height: 22px;
  flex: 0 0 auto;
}
.theme-preview-aero .tp-line {
  background: rgba(255, 255, 255, 0.85);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.kv {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 8px 12px;
  font-size: 13px;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------- motion */
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(9px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes tokenIn {
  from {
    opacity: 0;
    filter: blur(1px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes blockIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.msg {
  animation: msgIn 0.3s cubic-bezier(0.22, 0.7, 0.3, 1) both;
}

/* Each streamed word fades in with only a whisper of blur, so text arrives
   without smearing. */
.msg-body .tok {
  animation: tokenIn 0.2s ease both;
}

/* Elapsed / estimated generation time, shown in the message meta line. */
.msg-meta .timer {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
.msg.streaming .msg-meta .timer {
  color: var(--accent);
}

.msg.streaming .msg-body::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.18em;
  background: var(--accent);
  opacity: 0.55;
  animation: caretBlink 1s steps(2, start) infinite;
}

@keyframes caretBlink {
  50% {
    opacity: 0;
  }
}

/* Once the reply is formatted, blocks settle in one after another. */
.msg-body.is-formatted {
  animation: formatSettle 0.42s cubic-bezier(0.22, 0.7, 0.3, 1) both;
}

@keyframes formatSettle {
  from {
    opacity: 0.45;
    transform: scale(0.998);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg-body.is-formatted > * {
  animation: blockIn 0.32s cubic-bezier(0.22, 0.7, 0.3, 1) both;
}
.msg-body.is-formatted > *:nth-child(1) {
  animation-delay: 0s;
}
.msg-body.is-formatted > *:nth-child(2) {
  animation-delay: 0.04s;
}
.msg-body.is-formatted > *:nth-child(3) {
  animation-delay: 0.08s;
}
.msg-body.is-formatted > *:nth-child(4) {
  animation-delay: 0.12s;
}
.msg-body.is-formatted > *:nth-child(5) {
  animation-delay: 0.16s;
}
.msg-body.is-formatted > *:nth-child(n + 6) {
  animation-delay: 0.2s;
}

/* Sidebar rows animate out before they are removed from the DOM. */
.conv-item {
  transition: height 0.24s ease, opacity 0.2s ease, transform 0.2s ease,
    background-color 0.12s ease, border-color 0.12s ease, padding 0.24s ease;
}
.conv-item.removing {
  opacity: 0;
  transform: translateX(-14px);
  padding-top: 0;
  padding-bottom: 0;
  border-color: transparent;
  overflow: hidden;
  pointer-events: none;
}

@keyframes convFlash {
  0% {
    background: var(--accent-soft);
  }
  100% {
    background: transparent;
  }
}
.conv-item.just-added {
  animation: convFlash 1.1s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .msg,
  .msg-body .tok,
  .msg-body.is-formatted > *,
  .conv-item.just-added,
  .page-wrap {
    animation: none !important;
  }
  .messages {
    scroll-behavior: auto;
  }
  .conv-item {
    transition: height 0.01s, opacity 0.01s;
  }
}

/* ------------------------------------------------------- drag to reorder */
.conv-grip {
  flex: 0 0 auto;
  width: 16px;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  opacity: 0;
  cursor: grab;
  touch-action: none;
  font-size: 12px;
  line-height: 1;
  letter-spacing: -1px;
  user-select: none;
}
.conv-item:hover .conv-grip,
.conv-item.active .conv-grip {
  opacity: 0.6;
}
.conv-grip:hover {
  opacity: 1;
}
.conv-item.dragging {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.18);
  transform: scale(1.015);
  z-index: 3;
  cursor: grabbing;
  opacity: 0.97;
}
.conv-list.is-reordering {
  user-select: none;
  -webkit-user-select: none;
}
.conv-list.is-reordering .conv-item:not(.dragging) {
  transition: transform 0.18s ease, height 0.24s ease;
}

/* ------------------------------------------------------ drop and paste */
.chat-main.drag-over::after {
  content: "Drop images or documents to attach";
  position: absolute;
  inset: 12px 12px 120px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 5;
  animation: fadeIn 0.15s ease both;
}

.composer {
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.composer.drag-over {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.composer.drag-over .input-area {
  border-color: var(--accent);
}
.composer.drop-hint::before {
  content: "Drop to attach";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 2;
}
.composer {
  position: relative;
}

/* ------------------------------------------------- mobile sidebar drawer */
.sidebar-toggle,
.sidebar-close {
  display: none;
}
.sidebar-toggle {
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  flex: 0 0 auto;
}
.sidebar-close {
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-head .panel-title {
  flex: 1;
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: 0;
}
.scrim {
  display: none;
}

/* --------------------------------------------------------------- scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  /* Chat becomes an app view: header chrome shrinks, sidebar slides in. */
  .app-shell--chat .topbar {
    height: 48px;
    padding: 0 10px;
  }
  .app-shell--chat .brand-name {
    font-size: 14px;
  }
  .app-shell--chat .page-head {
    display: none;
  }
  .app-shell--chat .workspace {
    padding: 8px 8px 0;
    gap: 0;
  }
  .app-shell--chat .chat-main {
    border-radius: var(--radius);
    box-shadow: none;
  }

  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar-close {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 48px;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    flex: none;
    max-height: none;
    z-index: 45;
    border-radius: 0;
    border-left: 0;
    border-top: 0;
    border-bottom: 0;
    transform: translateX(-103%);
    transition: transform 0.26s cubic-bezier(0.22, 0.7, 0.3, 1);
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    box-shadow: 0 0 0 1px var(--border), 14px 0 34px rgba(10, 16, 24, 0.22);
    background: var(--surface);
    overflow: hidden;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .conv-list {
    max-height: none;
  }
  .conv-grip {
    opacity: 0.5;
    width: 22px;
    font-size: 13px;
  }
  .conv-item {
    padding: 9px 8px;
  }

  .scrim {
    display: block;
    position: fixed;
    inset: 48px 0 0 0;
    z-index: 40;
    background: rgba(10, 16, 24, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .scrim.show {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-head {
    padding: 8px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .chat-head-title {
    order: 2;
    flex: 1;
    font-size: 13px;
  }
  .sidebar-toggle {
    order: 1;
  }
  .chat-head-right {
    order: 3;
    width: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .chat-head-right .field-inline > span {
    display: none;
  }
  .chat-head-right .select {
    min-width: 0;
    width: 140px;
    max-width: 40vw;
    height: 32px;
    font-size: 12.5px;
  }
  .chat-head-right .btn {
    padding: 6px 8px;
    min-height: 32px;
  }

  .messages {
    padding: 12px 10px;
    gap: 12px;
  }
  .msg {
    max-width: 94%;
  }
  .msg-body {
    font-size: 14px;
  }

  /* 16px keeps iOS Safari from zooming when the field is focused. */
  textarea.input-area,
  .input-area {
    font-size: 16px;
  }
  .composer {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .composer-row {
    gap: 6px;
    flex-wrap: nowrap;
  }
  .composer-row .hint {
    display: none;
  }
  .composer-row .btn {
    min-height: 38px;
    padding: 8px 12px;
  }
  .composer-row .file-btn {
    flex: 0 0 auto;
  }
  .reasoning-toggle {
    padding: 6px 8px;
    min-height: 38px;
  }
  #send {
    flex: 0 0 auto;
    min-width: 72px;
  }
  .btn.file-btn span.long {
    display: none;
  }

  .statusbar {
    padding: 4px 10px;
    gap: 8px;
    font-size: 10.5px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }
  .statusbar #status-model,
  .statusbar #clock {
    display: none;
  }

  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-nav {
    margin-left: 10px;
  }
  .topbar-user {
    display: none;
  }
  .page-head,
  .admin-body,
  .settings-body {
    padding-left: 12px;
    padding-right: 12px;
  }
  .tabs {
    padding: 0 12px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .kv {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  .kv dt {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
  }
  .kv dd {
    margin-bottom: 8px;
  }
}

@media (max-width: 560px) {
  .nav-link {
    padding: 6px 7px;
    font-size: 12px;
  }
  .brand-name {
    display: none;
  }
  .topbar {
    gap: 6px;
    padding: 0 8px;
  }
  .topbar-nav {
    margin-left: 2px;
  }
  .nav-btn {
    padding: 5px 9px;
    font-size: 12px;
  }
  .page-title {
    font-size: 18px;
  }
  .stat-value {
    font-size: 20px;
  }
  .chat-head-title {
    font-size: 12.5px;
  }
  /* Give the model picker its own row so nothing truncates badly. */
  .chat-head {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .chat-head-right {
    flex: 1 1 100%;
    order: 4;
    justify-content: flex-end;
  }
  .chat-head-right .select {
    flex: 1 1 auto;
    width: auto;
    max-width: none;
  }
  #delete-chat {
    display: none;
  }
  .msg {
    max-width: 97%;
  }
  .statusbar .cell:first-child {
    flex: 1;
    min-width: 0;
  }
}
