/* ── Fonts (UX-BRAND-07) ──────────────────────────────────────────────── */
@font-face {
  font-family: 'Chronicle Display';
  src: url('/fonts/ChronicleDisplay-Roman.otf') format('opentype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Chronicle Display';
  src: url('/fonts/ChronicleDisplay-Semibold.otf') format('opentype');
  font-weight: 600; font-style: normal; font-display: swap;
}

/* ── Design tokens ────────────────────────────────────────────────────── */
:root {
  /* Brand palette */
  --as-marine:    #075156;
  --as-green:     #2C8248;
  --as-citrus:    #ABDD65;
  --as-navy:      #17232D;
  --as-pale-blue: #E5EEEF;

  /* Font stacks */
  --font-display: 'Chronicle Display', Georgia, 'Times New Roman', serif;
  --font-body:    'Montserrat', 'Helvetica Neue', Arial, sans-serif;
  --font-mono:    'JetBrains Mono', Consolas, 'Courier New', monospace;

  /* Surfaces */
  --bg:   #17232D;
  --bg-2: #1d2b36;
  --bg-3: #253340;
  --bg-4: #2e3e4d;
  --line: #304050;

  /* Text */
  --text:      #E5EEEF;
  --text-dim:  #8fa8b4;
  --text-muted:#5c7582;

  /* Semantic */
  --primary:       #2a7278;
  --primary-hover: #327e84;
  --on-primary:    #FFFFFF;
  --accent:        #ABDD65;
  --on-accent:     #0d1a0a;
  --danger:        #f07680;
  --danger-dim:    rgba(240,118,128,0.15);
  --success:       #4cca70;
  --success-dim:   rgba(76,202,112,0.12);
  --warning:       #f0b429;

  /* Message role colours */
  --msg-user:        #E5EEEF;
  --msg-assistant:   #ABDD65;
  --msg-tool-call:   #cfe6a3;
  --msg-tool-result: #b8b0ff;
  --msg-error:       #f07680;

  /* Radius / spacing */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;

  /* Focus ring */
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── Base ─────────────────────────────────────────────────────────────── */
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }

/* ── Shared button base ───────────────────────────────────────────────── */
button { font-family: var(--font-body); cursor: pointer; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Header ───────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  padding-left:  max(16px, env(safe-area-inset-left,  16px));
  padding-right: max(16px, env(safe-area-inset-right, 16px));
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: relative;
  z-index: 10;
  min-height: 52px;
  flex-shrink: 0;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand .logo { height: 26px; width: auto; display: block; }
.brand .product {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.brand .product .v {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
}
.grow { flex: 1; }

/* ── Status cluster ───────────────────────────────────────────────────── */
.status-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}
.env-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(171,221,101,0.12);
  color: var(--accent);
}
.status-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--font-body);
  background: var(--bg-3);
  color: var(--text-dim);
  border: 1px solid transparent;
  min-height: 32px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.status-trigger:hover,
.status-trigger[aria-expanded="true"] {
  background: var(--bg-4);
  color: var(--text);
  border-color: var(--line);
}
.status-trigger .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-trigger.ok  .dot { background: var(--success); }
.status-trigger.bad .dot { background: var(--danger); }

.status-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 100;
  flex-direction: column;
  overflow: hidden;
}
.status-trigger[aria-expanded="true"] + .status-panel { display: flex; }
.status-panel .p-sect {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.status-panel .p-sect:last-child { border-bottom: none; }
.status-panel h4 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}
.status-panel .p-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 5px;
}
.status-panel .p-row:last-child { margin-bottom: 0; }
.status-panel .p-lbl { color: var(--text-dim); }
.status-panel .p-val { font-family: var(--font-mono); font-size: 12px; }
.status-panel .p-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
.status-panel .p-link:hover { text-decoration: underline; }

/* ── Account / user menu ──────────────────────────────────────────────── */
.account { position: relative; display: flex; align-items: center; }
.user-menu { position: relative; }

.btn-signin {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  min-height: 36px;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-signin:hover  { background: var(--primary-hover); }

.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px 3px 3px;
  color: var(--text);
  font-size: 13px;
  min-height: 36px;
  transition: border-color 0.15s;
}
.user-trigger:hover,
.user-trigger[aria-expanded="true"] { border-color: var(--text-dim); }

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--as-citrus);
  color: var(--as-navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 120;
  padding: 12px;
  flex-direction: column;
  gap: 10px;
}
.user-trigger[aria-expanded="true"] + .user-panel { display: flex; }

.u-ident .u-name  { font-weight: 600; font-size: 14px; }
.u-ident .u-email { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.adv { border-top: 1px solid var(--line); padding-top: 10px; }
.adv summary { cursor: pointer; color: var(--text-dim); font-size: 12px; list-style: none; }
.adv summary::before { content: '▸ '; }
.adv[open] summary::before { content: '▾ '; }
.adv-hint { font-size: 11px; color: var(--text-muted); margin: 6px 0; }
.adv input[type=text] {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.adv input[type=text]:focus { outline: none; box-shadow: var(--focus-ring); }

/* ── Admin gear button ────────────────────────────────────────────────── */
.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 16px;
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.admin-btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg-3); }

/* ── Shared button styles ─────────────────────────────────────────────── */
.btn-primary {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  min-height: 36px;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled)  { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  font-family: var(--font-body);
  font-size: 13px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 14px;
  min-height: 36px;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--bg-3); }

.btn-sm { font-size: 12px; padding: 4px 10px; min-height: 30px; }

.btn-danger {
  font-family: var(--font-body);
  font-size: 12px;
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  min-height: 30px;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(240,118,128,0.25); }

/* ── Main layout ──────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 268px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
aside {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-head-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar-head-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-3);
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-ctrls {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-ctrls-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-ctrls select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  min-height: 38px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238fa8b4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.sidebar-ctrls select:focus { outline: none; box-shadow: var(--focus-ring); border-color: transparent; }

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 9px 12px;
  min-height: 40px;
  transition: filter 0.15s;
}
.btn-new-chat:hover:not(:disabled)  { filter: brightness(1.08); }
.btn-new-chat:disabled { opacity: 0.45; cursor: not-allowed; }

/* Sessions list */
#sessions {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.sessions-empty {
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

.session {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px;
  transition: background 0.12s;
}
.session:hover { background: var(--bg-3); }
.session.active {
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

.session-body { flex: 1; min-width: 0; }
.session-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.session.active .session-title { color: var(--accent); }
.session-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.template-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(171,221,101,0.12);
  color: var(--accent);
  margin-left: 5px;
  font-weight: 600;
  vertical-align: middle;
}

.session-del {
  opacity: 0;
  color: var(--text-muted);
  font-size: 16px;
  background: none;
  border: none;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  align-self: center;
  transition: color 0.12s, opacity 0.12s;
}
.session:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--danger); }

/* ── Workspace ────────────────────────────────────────────────────────── */
section.workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Empty / welcome state */
.workspace-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 32px;
  gap: 16px;
}
.workspace-empty .empty-headline {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 600;
  color: var(--text-dim);
  line-height: 1.2;
}
.workspace-empty .empty-sub {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 380px;
  line-height: 1.6;
}
.workspace-empty .empty-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 11px 22px;
  cursor: pointer;
  margin-top: 8px;
  transition: filter 0.15s;
}
.workspace-empty .empty-cta:hover { filter: brightness(1.08); }

/* Message trail */
#trail {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Message bubbles */
.msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  line-height: 1.6;
  font-size: 15px;
  max-width: 820px;
}
.msg + .msg { margin-top: 4px; }

.msg .role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 5px;
  opacity: 0.75;
}
.msg .body { white-space: pre-wrap; word-break: break-word; }

.msg.user {
  background: rgba(229,238,239,0.04);
  border-left-color: var(--msg-user);
}
.msg.user .role { color: var(--msg-user); }

.msg.assistant {
  background: rgba(171,221,101,0.05);
  border-left-color: var(--msg-assistant);
}
.msg.assistant .role { color: var(--msg-assistant); }

.msg.tool-call {
  background: rgba(207,230,163,0.04);
  border-left-color: var(--msg-tool-call);
}
.msg.tool-call .role { color: var(--msg-tool-call); }
.msg.tool-call .body {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}

.msg.tool-result {
  background: rgba(184,176,255,0.04);
  border-left-color: var(--msg-tool-result);
}
.msg.tool-result .role { color: var(--msg-tool-result); }
.msg.tool-result .body {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}

.msg .footnote {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.msg .template-foot {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* Approval cards (human-in-the-loop) */
.approval-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 8px;
  max-width: 820px;
}
.approval-card .approval-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--warning);
  margin-bottom: 6px;
}
.approval-card .approval-tool {
  font-family: var(--font-mono);
  font-size: 13px;
  margin-bottom: 10px;
  color: var(--text-dim);
}
.approval-card .approval-btns,
.approval-card .approval-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.approval-card .approval-reason { font-size: 13px; margin: 4px 0; }
.approval-card .approval-target {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Tenant / environment chip — shows which external system a tool affects. */
.tenant-chip {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  vertical-align: middle;
  white-space: nowrap;
}
.tenant-chip-safe {
  background: color-mix(in srgb, var(--ok, #2e7d32) 16%, transparent);
  color: var(--ok, #2e7d32);
  border: 1px solid color-mix(in srgb, var(--ok, #2e7d32) 35%, transparent);
}
.tenant-chip-gated {
  background: color-mix(in srgb, var(--warning, #c62828) 16%, transparent);
  color: var(--warning, #c62828);
  border: 1px solid color-mix(in srgb, var(--warning, #c62828) 40%, transparent);
}

/* Thinking indicator */
.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
}
.thinking span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 100% { opacity: 0.25; }
  50%       { opacity: 1; }
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  padding-left:  max(20px, env(safe-area-inset-left,  20px));
  padding-right: max(20px, env(safe-area-inset-right, 20px));
  flex-shrink: 0;
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  overflow-y: auto;
  transition: border-color 0.15s;
  field-sizing: content; /* auto-resize where supported */
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.composer textarea:disabled { opacity: 0.5; }
.composer textarea::placeholder { color: var(--text-muted); }

.composer-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 0 18px;
  height: 44px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: filter 0.15s, opacity 0.15s;
}
.composer-send:hover:not(:disabled)  { filter: brightness(1.08); }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* Signed-out state */
body.signed-out .composer { opacity: 0.5; pointer-events: none; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  right:  max(16px, calc(env(safe-area-inset-right, 0px) + 16px));
  background: var(--bg-4);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 300;
  max-width: min(360px, calc(100vw - 32px));
}
.toast.error { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }

/* ── Admin drawer ─────────────────────────────────────────────────────── */
.admin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  backdrop-filter: blur(2px);
}
.admin-overlay[hidden] { display: none; }

.admin-drawer {
  width: min(520px, 100vw);
  height: 100%;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.45);
  overflow: hidden;
}
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.admin-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.admin-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.admin-close:hover { color: var(--text); background: var(--bg-3); }

.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.admin-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 11px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-tab-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-tab-panel[hidden] { display: none; }

.admin-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.admin-hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.55;
}

.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-row-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.admin-row-name { font-weight: 600; font-size: 13px; flex-shrink: 0; }
.admin-row-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.admin-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.admin-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
}
.admin-badge.active   { background: var(--success-dim); color: var(--success); }
.admin-badge.disabled,
.admin-badge.inactive { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* Admin form */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.2px;
}
.admin-form input[type=text],
.admin-form input[type=url],
.admin-form input[type=number],
.admin-form select,
.admin-form textarea {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
  min-height: 38px;
  transition: border-color 0.15s;
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── PWA / Mobile toggle button ───────────────────────────────────────── */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.sidebar-toggle-btn:hover { background: var(--bg-3); }

/* Sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 140;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.open { display: block; }

/* ── Mobile ≤768px ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { font-size: 15px; }

  .sidebar-toggle-btn { display: inline-flex; }

  /* Collapse header */
  header { gap: 8px; min-height: 48px; }
  header .brand .product { display: none; }
  header .brand .logo { height: 22px; }
  .env-badge { display: none; }
  .health-lbl-text { display: none; }
  .user-name { display: none; }
  .admin-btn { min-width: 40px; min-height: 40px; }

  /* Stack to single column — workspace fills screen */
  main { grid-template-columns: 1fr; }

  /* Sidebar becomes full-height overlay from the left */
  aside {
    position: fixed;
    inset: 0;
    width: min(88vw, 300px);
    right: auto;
    z-index: 145;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  aside.sidebar-open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0,0,0,0.65);
  }

  /* Push sidebar content below the Dynamic Island */
  .sidebar-head {
    padding-top: max(12px, env(safe-area-inset-top, 12px));
  }

  /* Full-width new chat button */
  .btn-new-chat { min-height: 44px; font-size: 14px; }

  /* Larger touch targets */
  .session { min-height: 52px; padding: 12px 10px; }
  .session-del {
    opacity: 1;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Message trail */
  #trail { padding: 14px; }
  .msg { max-width: 100%; font-size: 15px; }
  .workspace-empty { padding: 32px 24px; }
  .workspace-empty .empty-headline { font-size: 26px; }

  /* Status / user panels — keep in viewport */
  .status-panel { width: min(280px, calc(100vw - 16px)); }
  .user-panel   { width: min(260px, calc(100vw - 16px)); }

  /* Composer */
  .composer { padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)); }
  .composer textarea { font-size: 16px; min-height: 44px; max-height: 120px; }
  .composer-hint { display: none; }

  /* Admin drawer full-width */
  .admin-drawer {
    width: 100vw;
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Toast */
  .toast { max-width: calc(100vw - 32px); }
}

/* ── Very small (≤ 390px) ─────────────────────────────────────────────── */
@media (max-width: 390px) {
  .status-trigger { padding: 4px 8px; }
  .admin-btn { padding: 0 6px; }
}

/* ── Landscape on short-screen phones ────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 430px) {
  header { padding-top: 4px; padding-bottom: 4px; min-height: 40px; }
  .composer { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom, 6px)); }
  .composer textarea { min-height: 36px; max-height: 70px; }
  #trail { padding: 8px 12px; }
}
