/* internal/console/static/app.css
 *
 * The console's whole visual language. Hand-written, no framework: the
 * surface is small and a build step would cost more than it saves.
 *
 * Layout spine: body is a full-height column, .page takes the rest, and the
 * inbox is a two-pane grid whose panes scroll independently, so the ticket
 * list and the thread keep their own scroll positions like a mail client.
 */

:root {
  --topbar: 56px;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #15181d;
  --ink-soft: #3f4650;
  --muted: #6b7280;
  --line: #e4e6ea;
  --line-soft: #eef0f3;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --note: #b45309;
  --note-soft: #fff7ed;
  --note-line: #fed7aa;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.9em; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 6px; }
h3 { font-size: 0.95rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- top bar ------------------------------------------------------------ */

.topbar {
  display: flex; align-items: center; gap: 18px;
  height: var(--topbar); padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-weight: 700; letter-spacing: -0.02em; color: var(--ink); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; margin-right: auto; }
.nav a {
  color: var(--ink-soft); padding: 6px 10px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); }
.who-name { font-weight: 500; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
}
.avatar.small { width: 28px; height: 28px; font-size: 0.7rem; }
.inline { display: inline; }
.link {
  background: none; border: 0; padding: 0; color: var(--muted);
  font: inherit; cursor: pointer;
}
.link:hover { color: var(--ink); text-decoration: underline; }

/* --- page shell --------------------------------------------------------- */

.page { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.page > .admin, .page > .thread-page, .page > .error-page { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 22px; }

.flash {
  margin: 12px 18px 0; padding: 9px 13px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); font-size: 0.92rem;
  flex: 0 0 auto;
}
.flash.ok { border-color: #bbf7d0; background: var(--ok-soft); color: #14532d; }
.flash.err { border-color: #fecaca; background: var(--danger-soft); color: #7f1d1d; }

.working {
  position: fixed; right: 14px; bottom: 14px; padding: 6px 10px;
  background: var(--ink); color: #fff; border-radius: 8px; font-size: 0.8rem;
  opacity: 0; transition: opacity 0.15s;
}
.htmx-request .working, .htmx-request.working { opacity: 0.85; }

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

body.bare { background: var(--bg); }
.login-wrap { display: flex; align-items: center; justify-content: center; padding: 40px 20px; flex: 1; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.login { width: min(420px, 100%); padding: 26px; }
.brand-lg { font-size: 1.4rem; margin-bottom: 2px; letter-spacing: -0.02em; }

/* --- forms -------------------------------------------------------------- */

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); font: inherit;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent);
}
select { width: auto; min-width: 130px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.note { background: var(--note-soft); border-color: var(--note-line); color: var(--note); }
.btn.note:hover { background: #ffedd5; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.row-form .field { margin-bottom: 0; min-width: 160px; }
.grants { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
.grants legend { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 0 4px; }
.check { display: inline-flex; align-items: center; gap: 5px; margin-right: 12px; font-size: 0.9rem; }
.check input { width: auto; }

/* --- inbox -------------------------------------------------------------- */

.inbox {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 390px 1fr;
}
.pane-list {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.pane-thread { min-height: 0; overflow: auto; background: var(--bg); }
.pane-thread:empty { background: var(--bg); }

.filters { padding: 12px; border-bottom: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; gap: 8px; }
.filter-row .grow { flex: 1; }
.filter-row select { width: 100%; min-width: 0; }

.ticket-list { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; overflow: auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 10px 4px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.tab {
  font-size: 0.8rem; padding: 4px 8px; border-radius: 999px; color: var(--muted);
  border: 1px solid transparent;
}
.tab:hover { background: var(--bg); text-decoration: none; }
.tab.active { background: var(--accent-soft); color: var(--accent); border-color: #dbe6ff; }
.tab .count { opacity: 0.65; font-variant-numeric: tabular-nums; }

.tickets { list-style: none; margin: 0; padding: 0; }
.ticket {
  display: block; padding: 11px 14px; border-bottom: 1px solid var(--line-soft);
  color: inherit; border-left: 3px solid transparent;
}
.ticket:hover { background: #fafbfc; text-decoration: none; }
.ticket.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.ticket-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 0.78rem; }
.ticket-top time { margin-left: auto; }
.ticket-title { font-weight: 600; color: var(--ink); margin-bottom: 4px; line-height: 1.35; }
.ticket-sub { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); }
.ticket-sub .spacer { flex: 1; }
.tickets .empty { padding: 26px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line-soft); }

/* --- thread ------------------------------------------------------------- */

.thread { max-width: 860px; margin: 0 auto; padding: 20px 22px 40px; }
.thread-page .thread { padding-top: 0; }
.thread-head { margin-bottom: 12px; }
.thread-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.thread-head h1 { font-size: 1.3rem; line-height: 1.3; }
.thread-sub { color: var(--muted); font-size: 0.86rem; }
.thread-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px; margin-bottom: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.thread-bar .inline { display: flex; align-items: center; gap: 6px; }

.context { margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.context summary { cursor: pointer; font-size: 0.88rem; font-weight: 600; color: var(--ink-soft); }
.context dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 4px 14px; margin: 10px 0 4px; font-size: 0.85rem; }
.context dt { color: var(--muted); font-family: var(--mono); }
.context dd { margin: 0; word-break: break-word; }

.messages { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.82rem; color: var(--muted); }
.msg-head .who { font-weight: 600; color: var(--ink-soft); }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.msg.customer { border-left: 3px solid #cbd5e1; }
.msg.staff { border-left: 3px solid var(--accent); background: #fbfdff; }
.msg.internal { border-color: var(--note-line); background: var(--note-soft); border-left: 3px solid var(--note); }
.msg.internal .msg-head .who { color: var(--note); }
.sys {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.8rem; color: var(--muted); padding: 0 4px;
}
.sys::before, .sys::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.composer textarea { margin-bottom: 8px; }
.composer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer-actions .hint { margin-left: auto; font-size: 0.78rem; }

.thread-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; padding: 40px; }
.back { margin: 0 0 12px; font-size: 0.88rem; }

/* --- chips and pills ---------------------------------------------------- */

.pill, .chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-soft);
  white-space: nowrap;
}
.chip.internal { background: var(--note-soft); border-color: var(--note-line); color: var(--note); font-weight: 500; }
.chip.assignee { background: var(--accent-soft); border-color: #dbe6ff; color: var(--accent); }
.chip.admin { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; }
.chip.ok { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }
.chip.warn { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }

.pill.status-new { background: var(--accent-soft); border-color: #dbe6ff; color: var(--accent); }
.pill.status-triaged { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; }
.pill.status-in_progress { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.pill.status-resolved { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }
.pill.status-closed { background: var(--bg); color: var(--muted); }
.pill.status-spam { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }

.sev-low { color: var(--muted); }
.sev-medium { color: #0369a1; }
.sev-high { color: #b45309; }
.sev-critical { background: var(--danger-soft) !important; border-color: #fecaca !important; color: var(--danger) !important; }

/* --- admin -------------------------------------------------------------- */

.admin { max-width: 1080px; margin: 0 auto; }
.admin > h1 { margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line);
}
.table td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.operators td:first-child { width: 240px; }
.operators td:last-child { width: 220px; }
.who-cell { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.account-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.account-actions details summary { cursor: pointer; font-size: 0.85rem; color: var(--accent); margin-bottom: 6px; }
.disabled-row { opacity: 0.6; }

/* --- error -------------------------------------------------------------- */

.error-page { max-width: 560px; margin: 60px auto; text-align: center; }
.error-page p { color: var(--muted); }

/* --- narrow screens ----------------------------------------------------- */

@media (max-width: 860px) {
  .inbox { grid-template-columns: 1fr; }
  .pane-list { border-right: 0; }
  .pane-thread { display: none; }
  .inbox.has-thread .pane-list { display: none; }
  .inbox.has-thread .pane-thread { display: block; }
  .grid2 { grid-template-columns: 1fr; }
  .who-name { display: none; }
}
