/* SmarterMail Agent — dark theme in the carbonitex.dev visual language:
   oklch colours, near-black gradients, warm-orange accent, soft glows.
   Mobile first; the chat view is a full-height flex column. */

:root {
  --bg-0: oklch(4% 0 0);
  --bg-1: oklch(8% 0.02 15);
  --bg-2: oklch(7% 0.02 15);

  --surface: oklch(12% 0 0);
  --surface-2: oklch(15% 0.01 40);
  --surface-3: oklch(19% 0.01 40);

  --accent: oklch(70% 0.20 45);
  --accent-dim: oklch(55% 0.16 45);
  --accent-soft: oklch(70% 0.20 45 / 0.3);

  --teal: oklch(72% 0.14 175);
  --green: oklch(70% 0.16 150);
  --red: oklch(65% 0.22 25);
  --amber: oklch(80% 0.16 85);

  --text: oklch(92% 0 0);
  --text-dim: oklch(72% 0 0);
  --text-faint: oklch(58% 0 0);

  --border: oklch(70% 0.20 40 / 0.22);
  --border-soft: oklch(100% 0 0 / 0.09);

  --radius: 14px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-0) 50%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .1s ease, box-shadow .18s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, oklch(70% 0.20 45) 0%, oklch(63% 0.22 40) 100%);
  border-color: transparent;
  color: oklch(100% 0 0);
  font-weight: 600;
  box-shadow: 0 4px 15px oklch(70% 0.20 40 / 0.35);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, oklch(74% 0.20 45) 0%, oklch(67% 0.22 40) 100%);
  box-shadow: 0 6px 22px oklch(70% 0.20 40 / 0.5);
}
.btn-stop {
  background: linear-gradient(135deg, oklch(60% 0.22 25) 0%, oklch(52% 0.22 25) 100%);
  border-color: transparent; color: oklch(100% 0 0); font-weight: 600;
}
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-block { display: block; width: 100%; padding: 13px; font-size: 1.05rem; }
.btn-small { padding: 5px 10px; font-size: .85rem; }

/* --------------------------------------------------------- login view */

.login-view {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px 48px;
}

.panel {
  background: linear-gradient(180deg, oklch(12% 0 0) 0%, oklch(6% 0 0) 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 0 70px oklch(65% 0.22 35 / 0.25), 0 18px 40px oklch(0% 0 0 / 0.6);
}

.login-panel { width: 100%; max-width: 520px; padding: 28px 24px 20px; }

.login-header { text-align: center; margin-bottom: 22px; }
.login-icon { font-size: 3rem; filter: drop-shadow(0 4px 12px var(--accent-soft)); }
.login-header h1 {
  font-size: 1.9rem; color: var(--accent); margin-top: 6px;
  text-shadow: 0 2px 12px oklch(70% 0.20 45 / 0.4);
}
.tagline { color: var(--text-dim); font-size: .98rem; margin-top: 6px; }

.field-group { border: none; margin-bottom: 18px; }
.field-group legend {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--accent); margin-bottom: 8px; font-weight: 700;
}

label { display: block; font-size: .88rem; color: var(--text-dim); margin: 12px 0 5px; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: oklch(16% 0 0);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px oklch(70% 0.20 45 / 0.16);
}

.hint { font-size: .8rem; color: var(--text-faint); margin-top: 5px; line-height: 1.45; }
.hint.inline { display: inline; }
.hint code { background: oklch(18% 0 0); padding: 1px 5px; border-radius: 4px; font-size: .95em; }

.checkbox {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 16px; font-size: .9rem; color: var(--text);
  background: oklch(14% 0.01 40); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 12px;
  cursor: pointer;
}
.checkbox input { width: 18px; height: 18px; margin-top: 2px; accent-color: oklch(70% 0.20 45); flex: none; }

.error-line {
  background: oklch(25% 0.10 25);
  border: 1px solid oklch(55% 0.20 25 / 0.6);
  color: oklch(88% 0.06 25);
  border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: .9rem; margin-bottom: 14px;
}

.error-line .error-link {
  display: inline-block;
  margin-top: 6px;
  color: oklch(92% 0.08 25);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.error-line .error-link:hover { color: oklch(100% 0 0); }

.login-footer { margin-top: 20px; text-align: center; color: var(--text-faint); font-size: .78rem; }
.login-footer p + p { margin-top: 8px; }

/* --------------------------------------------------- two-factor view */

.tfa-panel { max-width: 440px; }
.tfa-panel .tagline { margin-top: 10px; }

.code-input {
  display: block;
  width: 100%;
  margin: 4px 0 12px;
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: .42em;
  text-indent: .42em;                 /* re-centres text that letter-spacing pushes left */
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 14px 12px;
  border-radius: var(--radius-sm);
  background: oklch(16% 0 0);
  border: 1px solid var(--border-soft);
  color: var(--text);
}
.code-input::placeholder { color: oklch(32% 0 0); }
.code-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px oklch(70% 0.20 45 / 0.16);
}

.tfa-expiry { text-align: center; margin-bottom: 4px; }
.tfa-attempts {
  text-align: center;
  color: var(--amber);
  margin-bottom: 12px;
}
.tfa-back, .login-cancel { margin-top: 10px; border-color: transparent; }

/* ---------------------------------------------------------- chat view */

.chat-view { display: flex; flex-direction: column; height: 100dvh; }

.chat-header {
  flex: none;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px;
  background: oklch(9% 0 0 / 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.identity { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto; }
.identity-icon { font-size: 1.3rem; flex: none; }
.identity-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.hdr-email { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-host { font-size: .76rem; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  flex: none;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
}
.badge-readonly { background: oklch(30% 0.06 175); color: var(--teal); border: 1px solid oklch(55% 0.12 175 / 0.5); }
.badge-write { background: oklch(30% 0.10 45); color: var(--accent); border: 1px solid var(--accent-soft); }

/* accounts bar: one chip per signed-in account */

.accounts-bar {
  list-style: none;
  display: flex; align-items: center; gap: 8px; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.accounts-bar::-webkit-scrollbar { display: none; }

.acct-chip {
  display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto;
}
.acct-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }

/* Several accounts: each becomes a bordered pill, tinted by role. */
.accounts-bar.many .acct-chip {
  flex: none;
  max-width: 340px;
  padding: 3px 4px 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
}
.accounts-bar.many .acct-chip.role-domain { border-color: oklch(70% 0.14 290 / 0.35); }
.accounts-bar.many .acct-chip.role-sys { border-color: oklch(65% 0.20 25 / 0.4); }
.accounts-bar.many .hdr-email { font-size: .84rem; }
.accounts-bar.many .hdr-host { font-size: .7rem; }

.acct-role {
  flex: none;
  font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  padding: 2px 6px; border-radius: 5px;
  background: oklch(22% 0 0); color: var(--text-dim);
}
.role-domain .acct-role { background: oklch(28% 0.08 290); color: oklch(82% 0.10 290); }
.role-sys .acct-role { background: oklch(28% 0.10 25); color: oklch(84% 0.10 25); }

.acct-remove {
  flex: none;
  font: inherit; font-size: 1.05rem; line-height: 1;
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; color: var(--text-faint);
  border: 1px solid transparent; cursor: pointer;
}
.acct-remove:hover:not(:disabled) { color: var(--text); background: var(--surface-3); border-color: var(--border-soft); }
.acct-remove:disabled { opacity: .35; cursor: not-allowed; }

.add-account { flex: none; border-style: dashed; border-color: var(--border-soft); }

/* margin-left:auto keeps the actions (and the right-anchored Tools popover) on the right when the accounts bar wraps them onto a second row */
.header-actions { display: flex; align-items: center; gap: 6px; flex: none; margin-left: auto; }

/* tools menu */

.tools-menu { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: min(300px, calc(100vw - 20px));
  max-height: min(70dvh, 520px); overflow-y: auto;
  background: linear-gradient(180deg, oklch(13% 0 0) 0%, oklch(9% 0 0) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px oklch(0% 0 0 / 0.6), 0 0 40px oklch(65% 0.22 35 / 0.12);
  padding: 10px 12px;
}
.popover-title { font-size: .78rem; color: var(--text-dim); margin-bottom: 6px; }
.tools-group { border: none; }
.tools-group + .tools-group { margin-top: 8px; border-top: 1px solid var(--border-soft); padding-top: 6px; }
.tools-group legend {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--accent); font-weight: 700; padding: 4px 0 2px;
}
.tools-option {
  display: flex; align-items: center; gap: 9px;
  margin: 0; padding: 5px 4px; border-radius: 6px;
  font-size: .88rem; color: var(--text); cursor: pointer;
}
.tools-option:hover { background: oklch(100% 0 0 / 0.04); }
.tools-option input { width: 16px; height: 16px; accent-color: oklch(70% 0.20 45); flex: none; }
.tools-option span:first-of-type { flex: 1 1 auto; }
.tools-option-count { font-size: .75rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.tools-count { margin-top: 8px; }
.model-select { width: auto; max-width: 190px; padding: 7px 8px; font-size: .82rem; }

/* messages */

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: oklch(25% 0 0); border-radius: 6px; }

.msg { max-width: min(780px, 100%); width: fit-content; }
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, oklch(34% 0.10 45) 0%, oklch(27% 0.09 40) 100%);
  border: 1px solid var(--accent-soft);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  white-space: pre-wrap; word-break: break-word;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px 16px 16px 4px;
  padding: 12px 16px;
  word-break: break-word;
  max-width: min(820px, 100%);
}
.msg.queued { opacity: .6; border-style: dashed; }
.msg.queued::after { content: ' ⏳ queued'; font-size: .72rem; color: var(--text-faint); }

.msg.notice {
  align-self: center; text-align: center;
  font-size: .82rem; color: var(--text-faint);
  background: oklch(14% 0 0); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 5px 14px;
}
.msg.notice.warn { color: var(--amber); border-color: oklch(70% 0.15 85 / 0.35); }
.msg.notice.error {
  color: oklch(85% 0.10 25); background: oklch(22% 0.08 25);
  border-color: oklch(55% 0.20 25 / 0.5); border-radius: var(--radius-sm);
  align-self: flex-start; text-align: left; max-width: 780px; padding: 10px 14px;
}

/* markdown inside assistant bubbles */
.msg.assistant p + p,
.msg.assistant ul, .msg.assistant ol,
.msg.assistant h2, .msg.assistant h3, .msg.assistant h4,
.msg.assistant pre, .msg.assistant blockquote { margin-top: .65em; }
.msg.assistant ul, .msg.assistant ol { padding-left: 1.35em; }
.msg.assistant li { margin: .15em 0; }
.msg.assistant h2 { font-size: 1.18rem; color: var(--accent); }
.msg.assistant h3 { font-size: 1.05rem; color: oklch(80% 0.10 45); }
.msg.assistant h4, .msg.assistant h5, .msg.assistant h6 { font-size: .98rem; color: var(--text-dim); }
.msg.assistant code {
  background: oklch(20% 0 0); padding: 1px 5px; border-radius: 4px; font-size: .9em;
  border: 1px solid var(--border-soft);
}
.msg.assistant pre.code {
  background: oklch(8% 0 0); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; font-size: .85rem;
}
.msg.assistant pre.code code { background: none; border: none; padding: 0; }
.msg.assistant blockquote {
  border-left: 3px solid var(--accent-dim); padding-left: 10px; color: var(--text-dim);
}
.msg.assistant hr { border: none; border-top: 1px solid var(--border-soft); }
.msg.assistant table { border-collapse: collapse; }

.cursor {
  display: inline-block; width: 8px; height: 1.05em; vertical-align: text-bottom;
  background: var(--accent); margin-left: 2px; border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* tool cards */

.tool-card {
  align-self: flex-start;
  width: min(780px, 100%);
  background: oklch(11% 0.01 175);
  border: 1px solid oklch(55% 0.10 175 / 0.3);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: .88rem;
}
.tool-card.error { background: oklch(13% 0.04 25); border-color: oklch(55% 0.18 25 / 0.45); }

.tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px; cursor: pointer; user-select: none;
}
.tool-head:hover { background: oklch(100% 0 0 / 0.04); }
.tool-caret { color: var(--text-faint); transition: transform .15s ease; flex: none; }
.tool-card.open .tool-caret { transform: rotate(90deg); }
.tool-name { font-family: var(--mono); color: var(--teal); font-size: .86rem; }
.tool-card.error .tool-name { color: oklch(78% 0.14 25); }
.tool-account {
  flex: none; max-width: 40%;
  font-size: .72rem; color: var(--text-dim);
  background: oklch(18% 0.02 175); border: 1px solid oklch(55% 0.10 175 / 0.25);
  border-radius: 999px; padding: 1px 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-summary {
  color: var(--text-faint); font-size: .8rem; flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-status { flex: none; font-size: .78rem; color: var(--text-faint); }
.tool-status.running { color: var(--amber); }
.tool-status.ok { color: var(--green); }
.tool-status.err { color: var(--red); }

.tool-body { display: none; border-top: 1px solid var(--border-soft); padding: 10px 11px; }
.tool-card.open .tool-body { display: block; }
.tool-section + .tool-section { margin-top: 10px; }
.tool-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin-bottom: 4px;
}
.tool-pre {
  font-family: var(--mono); font-size: .78rem; line-height: 1.45;
  background: oklch(7% 0 0); border: 1px solid var(--border-soft); border-radius: 6px;
  padding: 8px 10px; max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

.spin { display: inline-block; animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* empty state */

.empty-state { margin: auto 0; text-align: center; padding: 20px 4px; }
.empty-state h2 { font-size: 1.5rem; color: var(--accent); }
.empty-sub { color: var(--text-dim); font-size: .92rem; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip {
  font: inherit; font-size: .86rem;
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border-soft); border-radius: 999px;
  padding: 8px 15px; cursor: pointer; transition: all .18s ease;
}
.chip:hover { color: var(--text); border-color: var(--accent-soft); background: var(--surface-2); }

/* queue bar + composer */

.queue-bar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 14px; font-size: .82rem; color: var(--amber);
  background: oklch(18% 0.05 85 / 0.35); border-top: 1px solid oklch(70% 0.15 85 / 0.25);
}

.composer {
  flex: none;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 14px 6px;
  background: oklch(9% 0 0 / 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
#composer-input {
  flex: 1 1 auto; resize: none; max-height: 180px; min-height: 44px; line-height: 1.45;
}
.composer .btn { min-height: 44px; }
.composer-hint {
  flex: none; text-align: center; font-size: .72rem; color: var(--text-faint);
  padding: 0 14px calc(8px + env(safe-area-inset-bottom));
  background: oklch(9% 0 0 / 0.92);
}

@media (max-width: 600px) {
  .chat-header { padding: 8px 10px; gap: 8px; }
  .model-select { max-width: 130px; }
  .header-actions .btn { padding: 7px 10px; font-size: .85rem; }
  .identity:has(.accounts-bar.many) { flex-basis: 100%; }
  .identity:has(.accounts-bar.many) + .header-actions { flex: 1 1 auto; justify-content: flex-end; }
  .accounts-bar.many .acct-chip { max-width: 220px; }
  .tool-account { max-width: 30%; }
  .messages { padding: 12px 10px 6px; }
  .msg.assistant, .tool-card { width: 100%; max-width: 100%; }
  .composer { padding: 8px 10px 6px; }
  .empty-state h2 { font-size: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
