/* Outbox TUI — ratatui / xterm surface */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--sz);
  line-height: 1.35;
  overflow: hidden;
}
body { height: 100dvh; min-height: 100dvh; }
button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  margin: 0;
  padding: 0;
}
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
ul, ol, h1, h2, h3, p, dl, dd, dt { margin: 0; padding: 0; }
ul, ol { list-style: none; }
::selection { background: var(--sel-bg); color: var(--sel-fg); }

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

/* ── scanlines (sugar 11) ──────────────────────────────── */
.tui {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 100dvh;
  padding: 6px;
  position: relative;
  isolation: isolate;
}
.tui::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 40;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(255,255,255,0.018) 2px,
    rgba(255,255,255,0.018) 3px
  );
}
@media (prefers-reduced-motion: reduce) {
  .tui::after { display: none; }
}

/* ── status line ───────────────────────────────────────── */
.statusline {
  grid-row: 1;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  min-height: 24px;
  background: var(--bg);
}
.status-cell {
  display: flex;
  align-items: center;
  padding: 2px 10px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
  color: var(--dim);
  font-size: var(--sz-sm);
  gap: 6px;
}
.status-cell:last-child { border-right: none; }
.status-cell.mode {
  background: var(--sel-bg);
  color: var(--sel-fg);
  font-weight: 600;
  letter-spacing: 0.08em;
}
.status-cell.grow {
  flex: 1;
  min-width: 8ch;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-cell.right {
  margin-left: auto;
  border-left: 1px solid var(--line);
  border-right: none;
}
.status-cell[data-tone="signal"] { color: var(--cursor); }
.status-cell[data-tone="agent"]  { color: var(--agent); }
.status-cell[data-tone="alert"]  { color: var(--alert); }
.status-cell[data-tone="err"]    { color: var(--err); }

/* folder tabs (option B — no side rail) */
.tab {
  padding: 2px 10px;
  color: var(--dim);
  font-size: var(--sz-sm);
  border-right: 1px solid var(--line);
  text-transform: lowercase;
}
.tab:hover { background: var(--line); color: var(--fg); }
.tab[aria-current="true"] {
  background: var(--sel-bg);
  color: var(--sel-fg);
}
.tab .n { margin-left: 4px; color: var(--alert); }
.tab[aria-current="true"] .n { color: var(--sel-fg); }
.tab .n[data-flash="true"] { animation: unread-nudge 420ms steps(2, end); }
@keyframes unread-nudge {
  0%, 100% { opacity: 1; }
  40% { opacity: 0.15; background: var(--alert); color: var(--bg); }
}

/* LIVE LED (sugar 7) */
.led {
  width: 7px; height: 7px;
  background: var(--cursor);
  flex-shrink: 0;
}
.led[data-state="live"] { animation: led-pulse 2s ease-in-out infinite; }
.led[data-state="wait"] { background: var(--alert); animation: led-pulse 0.8s ease-in-out infinite; }
.led[data-state="down"] { background: var(--err); animation: none; }
.led[data-state="off"]  { background: var(--faint); animation: none; }
@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .led { animation: none !important; }
}

.clock { font-variant-numeric: tabular-nums; color: var(--faint); }

/* meteor strip (sugar 2) */
.meteor-bar {
  position: relative;
  height: 14px;
  border: 1px solid var(--line);
  border-top: none;
  overflow: hidden;
  background: var(--bg);
  opacity: 0;
}
.meteor-bar[data-on="true"] { opacity: 1; }
.meteor-bar .spark {
  position: absolute;
  top: 2px;
  color: var(--meteor);
  letter-spacing: 0.15em;
  white-space: nowrap;
  text-shadow: 0 0 6px var(--meteor);
}
.meteor-bar[data-on="true"] .spark {
  animation: meteor-streak 700ms linear;
}
@keyframes meteor-streak {
  0% { transform: translateX(-20%); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateX(110%); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .meteor-bar { display: none; }
}

/* ── panes ─────────────────────────────────────────────── */
.panes {
  grid-row: 3;
  display: grid;
  grid-template-columns: minmax(290px, 34%) minmax(0, 1fr);
  min-height: 0;
  border: 1px solid var(--line);
  border-top: none;
  border-bottom: none;
}
.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.pane:last-child { border-right: none; }
.pane[data-focus="true"] .pane-head {
  background: var(--sel-bg);
  color: var(--sel-fg);
}
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 8px;
  font-size: var(--sz-sm);
  color: var(--dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: none;
}
.pane-head .hint { color: var(--faint); letter-spacing: 0.04em; text-transform: none; }
.pane-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.pane-body::-webkit-scrollbar { width: 4px; height: 4px; }
.pane-body::-webkit-scrollbar-thumb { background: var(--line-strong); }

.back-btn {
  display: none;
  width: 100%;
  text-align: left;
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  font-size: var(--sz-sm);
}
.back-btn:hover { background: var(--sel-bg); color: var(--sel-fg); }

/* ── thread list ───────────────────────────────────────── */
.thread {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  text-align: left;
  white-space: normal;
  align-items: baseline;
  position: relative;
}
.thread .sel { color: var(--sel-fg); font-weight: 700; }
.thread .seq { color: var(--faint); font-variant-numeric: tabular-nums; }
.thread .mark { color: var(--dim); }
.thread[data-unread="true"] .mark { color: var(--alert); }
.thread[data-agency="true"] .mark { color: var(--agent); }
.thread[data-unread="true"][data-agency="true"] .mark { color: var(--alert); }
.thread .time { color: var(--dim); font-variant-numeric: tabular-nums; }
.thread .line {
  display: block;
  min-width: 0;
}
.thread .subj {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.5;
  margin-top: 5px;
  color: var(--fg);
}
.thread[data-unread="true"] .subj { color: var(--fg); font-weight: 600; }
.thread .prev {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--dim);
  font-size: var(--sz-sm);
  line-height: 1.5;
  margin-top: 5px;
  overflow-wrap: anywhere;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: var(--sz-sm); }
.thread-sender { min-width: 0; overflow-wrap: anywhere; color: var(--dim); }
.thread .time { flex-shrink: 0; font-size: 10px; }
.thread-status { display: block; margin-top: 6px; color: var(--dim); font-size: 10px; }
.thread[aria-selected="true"] .thread-sender, .thread[aria-selected="true"] .thread-status { color: var(--sel-fg); opacity: .8; }
.reply-footer { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--dim); font-size: var(--sz-sm); line-height: 1.6; overflow-wrap: anywhere; }
.thread:hover:not([aria-selected="true"]) { background: var(--line); }

/* reverse-video selection — no left color bar */
/* dark phosphor selection — not white reverse video */
.thread[aria-selected="true"],
.thread[aria-selected="true"] .sel,
.thread[aria-selected="true"] .seq,
.thread[aria-selected="true"] .mark,
.thread[aria-selected="true"] .time,
.thread[aria-selected="true"] .subj,
.thread[aria-selected="true"] .prev {
  background: var(--sel-bg);
  color: var(--sel-fg);
}
.thread[aria-selected="true"] .prev { color: var(--sel-fg); opacity: 0.7; }

/* sugar 14: row wipe on j/k */
.thread[data-wipe="down"] { animation: wipe-down 140ms steps(4, end); }
.thread[data-wipe="up"] { animation: wipe-up 140ms steps(4, end); }
@keyframes wipe-down {
  0% { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 0 0); }
}
@keyframes wipe-up {
  0% { clip-path: inset(100% 0 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}

/* sugar 4: landing snap */
.thread[data-land="true"] { animation: land-snap 320ms steps(3, end); }
@keyframes land-snap {
  0%, 35% { background: var(--sel-bg); color: var(--sel-fg); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .thread[data-wipe], .thread[data-land] { animation: none !important; }
}

.list-empty {
  display: none;
  padding: 12px 10px;
  color: var(--faint);
  white-space: pre-wrap;
}
.list-empty[data-show="true"] { display: block; }
/* sugar 12: empty rune */
.list-empty .runes {
  color: var(--faint);
  letter-spacing: 0.4em;
  margin-bottom: 8px;
  opacity: 0.55;
}

/* ── message pane ──────────────────────────────────────── */
.msg-wrap {
  display: none;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.msg-wrap[data-show="true"] { display: flex; }
.msg-empty {
  display: none;
  padding: 14px 12px;
  color: var(--dim);
  white-space: pre-wrap;
  line-height: 1.55;
}
.msg-empty[data-show="true"] { display: block; }
.msg-empty .strong { color: var(--cursor); }
.msg-empty h1 { color: var(--fg); font-size: clamp(20px, 3vw, 32px); line-height: 1.2; font-weight: 600; margin-bottom: 20px; }
.msg-empty p { max-width: 56ch; margin-bottom: 18px; white-space: normal; }
.welcome-detail { color: var(--dim); font-size: var(--sz-sm); line-height: 1.6; }

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  font-size: var(--sz-sm);
}
.msg-actions button {
  padding: 2px 10px;
  border-right: 1px solid var(--line);
  color: var(--dim);
}
.msg-actions button:hover:not(:disabled) {
  background: var(--sel-bg);
  color: var(--sel-fg);
}
.msg-actions .spacer {
  flex: 1;
  border-right: 1px solid var(--line);
  min-width: 0;
}
.msg-actions .tag {
  padding: 2px 10px;
  color: var(--agent);
}

.msg-head {
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--line);
  font-size: var(--sz-sm);
  line-height: 1.55;
}
.msg-head .kicker { color: var(--faint); margin-bottom: 4px; }
.msg-head .subject {
  font-size: var(--sz-lg);
  color: var(--fg);
  font-weight: 600;
  margin-bottom: 6px;
  word-break: break-word;
  white-space: normal;
}
.msg-head .meta {
  display: grid;
  grid-template-columns: 5ch 1fr;
  gap: 0 1ch;
}
.msg-head .meta dt { color: var(--faint); }
.msg-head .meta dd { word-break: break-all; }

.msg-body {
  flex: 1;
  overflow: auto;
  padding: 10px 12px 16px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.msg-body::-webkit-scrollbar { width: 4px; }
.msg-body::-webkit-scrollbar-thumb { background: var(--line-strong); }

.prose {
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 78ch;
  line-height: 1.55;
}
.prose .h {
  color: var(--dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 1em 0 0.35em;
}
.prose p + p { margin-top: 0.85em; }
.prose .li { padding-left: 2ch; }
.prose .li::before { content: "· "; color: var(--faint); }
.prose .ol { padding-left: 3ch; }
.prose .quote {
  border-left: 2px solid var(--line-strong);
  padding-left: 1ch;
  color: var(--dim);
  margin: 0.85em 0;
}
.prose .sig {
  margin-top: 1.2em;
  padding-top: 0.6em;
  border-top: 1px solid var(--line);
  color: var(--faint);
}
.prose .summary {
  border: 1px solid var(--line);
  padding: 6px 10px;
  margin: 0 0 1em;
}
.prose .summary .lbl {
  color: var(--agent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: var(--sz-sm);
  margin-bottom: 4px;
}
.prose .attach {
  color: var(--dim);
  margin-top: 0.8em;
}

/* sugar 5: decode reveal */
.prose[data-decode="true"] {
  border-right: 1px solid var(--cursor);
}

/* ── agent prompt (bottom row) ─────────────────────────── */
.agent-wrap {
  grid-row: 4;
  border: 1px solid var(--line);
  position: relative;
}
.agent-wrap[data-unauth="true"] {
  border-color: var(--cursor);
}
.agent-wrap[data-unauth="true"]::before {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid var(--cursor);
  opacity: 0.35;
  animation: ignite 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes ignite {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
  .agent-wrap[data-unauth="true"]::before { animation: none; opacity: 0.4; }
}

.agentline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  min-height: 30px;
}
.mail-controls { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; min-width: 0; }
.mail-controls select { max-width: 100%; background: var(--bg); border: 1px solid var(--line); padding: 3px 5px; }
.mail-controls [hidden], .mail-fields[hidden] { display: none; }
.mail-controls span { flex: 1; min-width: 12ch; color: var(--dim); font-size: var(--sz-sm); overflow-wrap: anywhere; }
.mail-controls button, .dialog-actions button, .verify-link { padding: 5px 8px; border: 1px solid var(--line); color: var(--cursor); }
.mail-fields { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.mail-fields label { color: var(--dim); }
.mail-fields input { min-width: 0; width: 100%; outline-offset: 3px; }
.email-dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; background: var(--bg); color: var(--fg); border: 1px solid var(--cursor); padding: 22px; }
.email-dialog::backdrop { background: #000b; }
.email-dialog h2 { font-size: 18px; margin-bottom: 14px; }
.email-dialog p { margin: 12px 0; line-height: 1.55; }
.email-dialog label { display: block; color: var(--dim); margin-top: 12px; }
.email-dialog input, .email-dialog textarea { display: block; width: 100%; border: 1px solid var(--line); padding: 8px; resize: none; margin: 5px 0 14px; }
.verify-link { display: inline-block; text-decoration: none; }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.agent-field {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 2px;
  position: relative;
}
/* shimmer placeholder — a gray highlight runs across the string */
.agent-shim {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: var(--faint);
  background: linear-gradient(
    100deg,
    var(--faint) 0%,
    var(--faint) 35%,
    var(--fg) 50%,
    var(--faint) 65%,
    var(--faint) 100%
  );
  background-size: 220% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shim-run 2.8s linear infinite;
}
.agent-shim[hidden] { display: none; }
@keyframes shim-run {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .agent-shim {
    animation: none;
    background: none;
    -webkit-text-fill-color: var(--faint);
    color: var(--faint);
  }
}
.agent-ps1 {
  padding: 5px 8px 5px 10px;
  color: var(--cursor);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}
.agent-ps1 .host { color: var(--dim); font-weight: 400; }
.agent-input {
  width: 100%;
  resize: none;
  outline: none;
  padding: 5px 0;
  color: var(--fg);
  background: transparent;
  max-height: 72px;
  overflow-y: auto;
  line-height: 1.35;
  caret-color: var(--cursor);
}
.agent-input::placeholder { color: var(--faint); }
.file-chip {
  flex-shrink: 0;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--agent);
  font-size: var(--sz-sm);
  padding: 0 6px;
  border-left: 1px solid var(--line);
}
.file-chip[hidden] { display: none; }
.art-link {
  margin-right: 1ch;
  color: var(--cursor);
  font-family: inherit;
  font-size: inherit;
}
.art-link:hover { text-decoration: underline; }
.agent-submit {
  padding: 5px 12px;
  color: var(--dim);
  font-size: var(--sz-sm);
  white-space: nowrap;
  border-left: 1px solid var(--line);
}
.agent-submit:hover:not(:disabled) {
  background: var(--sel-bg);
  color: var(--sel-fg);
}

/* green block caret in the agent prompt (sugar: always-on terminal cursor) */
.agent-input {
  caret-color: transparent;
  /* custom cursor drawn as a blinking block after the text when focused/empty */
}
.agent-wrap {
  /* keep wrapper styles above */
}
.agent-line-cursor {
  display: none;
}
.agent-wrap[data-cursor="true"] .agent-line-cursor {
  display: inline-block;
  width: 0.6ch;
  height: 1.1em;
  background: var(--cursor);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: caret-blink 1s steps(1, end) infinite;
}
@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .agent-wrap[data-cursor="true"] .agent-line-cursor {
    animation: none;
    opacity: 1;
  }
}

/* sugar 13: command modal */
.cmd-modal {
  display: none;
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 50;
  width: min(52ch, calc(100% - 24px));
  border: 1px solid var(--line-strong);
  background: var(--bg);
}
.cmd-modal[data-open="true"] { display: block; }
.cmd-modal .cmd-title {
  border-bottom: 1px solid var(--line);
  padding: 2px 10px;
  color: var(--dim);
  font-size: var(--sz-sm);
}
.cmd-modal .cmd-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
}
.cmd-modal .cmd-prefix { color: var(--cursor); }
.cmd-modal input {
  flex: 1;
  outline: none;
  color: var(--fg);
  background: transparent;
  caret-color: var(--cursor);
}
.cmd-modal .cmd-help {
  border-top: 1px solid var(--line);
  padding: 4px 10px;
  color: var(--faint);
  font-size: var(--sz-sm);
}

/* ── responsive ────────────────────────────────────────── */
@media (max-width: 640px) {
  .tui { padding: 4px; }
  .panes {
    grid-template-columns: 1fr;
  }
  .pane-threads[data-mobile-hidden="true"],
  .pane-msg[data-mobile-hidden="true"] {
    display: none;
  }
  .back-btn { display: block; }
  .status-cell.hide-sm { display: none; }
  .agent-ps1 .host { display: none; }
  .meteor-bar { height: 12px; }
}
@media (max-width: 360px) {
  :root { --sz: 11px; --sz-sm: 10px; --sz-lg: 12px; }
}
