/* UnitOne Triage dashboard — clean professional light theme */
:root {
  --navy: #0f2a5c;
  --navy-dark: #0b2049;
  --navy-light: #1b3a7a;
  --accent: #2f6df6;
  --accent-soft: #e8effe;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #dfe4ee;
  --border-strong: #c6cddc;
  --text: #1a2333;
  --text-muted: #5b657a;
  --text-faint: #8a93a8;
  --success: #157a3d;
  --success-bg: #e4f5ea;
  --warning: #9a5b00;
  --warning-bg: #fdf0d7;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info: #1b5bbf;
  --info-bg: #e8effe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 42, 92, 0.06), 0 4px 16px rgba(15, 42, 92, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.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;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 60px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; color: #fff; flex: none; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }

.nav { display: flex; gap: 4px; }
.nav-btn {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.nav-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.nav-btn.is-active { color: #fff; background: rgba(255, 255, 255, 0.16); }

.stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip strong { font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.user-btn:hover { background: rgba(255, 255, 255, 0.1); }
.user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.caret { width: 14px; height: 14px; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 160px;
  padding: 4px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.menu button:hover { background: var(--accent-soft); }

/* ---------- Buttons / inputs ---------- */
.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: #2459d6; }
.topbar .btn-primary {
  background: #fff;
  color: var(--navy);
  border-color: #fff;
}
.topbar .btn-primary:hover:not(:disabled) { background: #e9eefb; }
.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); background: #f7f9fd; }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #96200f; }
.btn-block { width: 100%; padding: 10px 16px; font-size: 14px; }

.input {
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea.input { resize: vertical; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 12px;
}

/* ---------- Views ---------- */
.view { min-height: calc(100vh - 60px); }

/* Login */
.view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-light) 55%, #27407e 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 400px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-brand .brand-mark { color: var(--navy); width: 32px; height: 32px; }
.login-brand h1 { margin: 0; font-size: 22px; color: var(--navy); }
.login-sub { color: var(--text-muted); margin: 0 0 24px; }

/* Queue layout: two-pane on desktop, stacked on mobile */
.queue-layout {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 32px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 900px) {
  .queue-layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* Queue list pane */
.queue-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 92px);
}
@media (max-width: 900px) {
  .queue-list { position: static; max-height: none; }
}

.queue-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 10px;
}
.tab {
  background: none;
  border: 0;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 7px;
  cursor: pointer;
}
.tab:hover { background: #eef1f7; color: var(--text); }
.tab.is-active { background: var(--navy); color: #fff; }
.filters { display: flex; gap: 8px; }
.filters .input { padding: 7px 10px; font-size: 13px; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}
.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
}
.item:hover { border-color: var(--border-strong); }
.item.is-selected { border: 2px solid var(--accent); padding: 11px 13px; }
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.item-sender { font-weight: 700; font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-subject {
  font-size: 13px;
  color: var(--text);
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
}
.item-meta .spacer { flex: 1; }

.empty-note {
  text-align: center;
  color: var(--text-faint);
  padding: 32px 16px;
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.pager-info { font-size: 12px; color: var(--text-muted); }

/* Category badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-faq { background: #e3f2fd; color: #0d47a1; }
.badge-meeting { background: #e8f5e9; color: #1b5e20; }
.badge-status_update { background: #f3e5f5; color: #6a1b9a; }
.badge-newsletter { background: #fff3e0; color: #e65100; }
.badge-spam { background: #fce4ec; color: #880e4f; }
.badge-sensitive { background: var(--danger-bg); color: var(--danger); }
.badge-ambiguous { background: #fff8e1; color: #8a6d00; }
.badge-other { background: #eceff1; color: #37474f; }

.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-pending { background: var(--warning-bg); color: var(--warning); }
.status-approved { background: var(--info-bg); color: var(--info); }
.status-sent { background: var(--success-bg); color: var(--success); }
.status-rejected { background: var(--danger-bg); color: var(--danger); }
.status-filed { background: #eceff1; color: #37474f; }
.status-escalated { background: #ede7f6; color: #4527a0; }

/* Connectors card */
.connectors { padding: 14px 16px; }
.connector-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.connector-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.connector-name { font-weight: 700; text-transform: capitalize; flex: 1; }
.connector-state { font-size: 12px; color: var(--text-muted); }
.connector-state.is-on { color: var(--success); font-weight: 700; }
.connector-state.is-off { color: var(--warning); }
.connect-link {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  padding: 4px 12px;
  border-radius: 999px;
}
.connect-link:hover { background: var(--accent-soft); }

/* Detail pane */
.queue-detail { min-width: 0; }
.detail-empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 72px 32px;
  text-align: center;
  color: var(--text-muted);
}
.detail-empty-title { font-size: 18px; font-weight: 700; color: var(--text); margin: 0 0 8px; }
.detail-empty-sub { margin: 0; max-width: 420px; margin-left: auto; margin-right: auto; }

.detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.detail-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.btn-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.btn-back:hover { background: #f2f4f9; }
.detail-title { margin: 0; font-size: 18px; color: var(--navy); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fbfcff;
}
.panel h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.msg-line { margin: 0 0 6px; font-size: 13px; }
.msg-line .k { color: var(--text-muted); font-weight: 600; }
.msg-body {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.ai-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.ai-row .k { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; min-width: 90px; }

.conf-bar {
  flex: 1;
  min-width: 120px;
  height: 10px;
  background: #e6eaf2;
  border-radius: 999px;
  overflow: hidden;
}
.conf-fill {
  height: 100%;
  background: linear-gradient(90deg, #f2b035, #2f6df6);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.conf-val { font-size: 13px; font-weight: 700; min-width: 44px; text-align: right; }

.ai-reason {
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 10px;
  color: var(--text);
}
.labels-row { display: flex; gap: 6px; flex-wrap: wrap; }
.label-pill {
  font-size: 11px;
  font-weight: 600;
  background: #eef1f7;
  color: var(--text-muted);
  padding: 2px 10px;
  border-radius: 999px;
}

.draft-section { margin-bottom: 20px; }
.draft-section .field { margin-bottom: 10px; }
.draft-section textarea { min-height: 180px; font-size: 14px; line-height: 1.6; }
.draft-hint { font-size: 12px; color: var(--text-faint); margin: 0 0 12px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions .sep { width: 1px; height: 24px; background: var(--border); }
.reclassify-group { display: flex; gap: 8px; align-items: center; }
.reclassify-group .input { width: auto; padding: 7px 10px; font-size: 13px; }

.kbd-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 14px;
}
kbd {
  font-family: var(--font);
  font-size: 11px;
  background: #eef1f7;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
}

.decision-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.decision-note strong { color: var(--text); }

/* Audit */
.audit-wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px 48px; }
.audit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-title { margin: 0; font-size: 20px; color: var(--navy); }
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th {
  background: #f7f9fd;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
}
.table tr:last-child td { border-bottom: 0; }
.table td.details { max-width: 420px; word-break: break-word; color: var(--text-muted); }
.event-pill {
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--navy);
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 42, 92, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 440px;
}
.modal-title { margin: 0 0 4px; font-size: 18px; color: var(--navy); }
.modal-sub { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Toasts */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  background: var(--navy-dark);
  color: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast.is-error { background: var(--danger); }
.toast.is-success { background: var(--success); }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth toggle links (sign in <-> create workspace) */
.auth-toggle { text-align: center; margin-top: 14px; font-size: 14px; color: #8b93a7; }
.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: #4f7cff; font-size: inherit; text-decoration: underline;
}
.link-btn:hover { color: #3a63d8; }

/* Workspace chip: org name + plan + monthly usage */
.workspace-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid #e2e6f0; border-radius: 999px;
  background: #f7f9fd; font-size: 13px; color: #3c4358; white-space: nowrap;
}
#workspace-name { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.plan-badge {
  background: #e8efff; color: #2f5fe0; border-radius: 999px;
  padding: 2px 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.usage-meter { color: #8b93a7; font-size: 12px; }
