/* Design tokens. Every color, radius and shadow comes from here, in light and dark. */
:root {
  --bg: #f6f7fb;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, 0.08), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(14, 165, 233, 0.06), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --sidebar: rgba(255, 255, 255, 0.78);
  --text: #0e1220;
  --text-2: #3b4256;
  --muted: #6b7286;
  --border: #e6e8ef;
  --border-strong: #d6d9e3;
  --hover: #f1f2f8;
  --accent: #5b5bf0;
  --accent-2: #8b5cf6;
  --accent-text: #ffffff;
  --accent-soft: #eeeefe;
  --accent-ink: #3f3fd1;
  --good: #0f9d6b;
  --good-soft: #e3f7ef;
  --warn: #b26b00;
  --warn-soft: #fff3dc;
  --bad: #d63c4a;
  --bad-soft: #fde9eb;
  --info-soft: #e8f2ff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.18);
  --ring: 0 0 0 3px rgba(91, 91, 240, 0.25);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0b10;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(99, 102, 241, 0.14), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(14, 165, 233, 0.08), transparent 60%);
    --surface: #12141c;
    --surface-2: #161924;
    --sidebar: rgba(16, 18, 26, 0.82);
    --text: #eceef6;
    --text-2: #c3c7d6;
    --muted: #8b91a6;
    --border: #232736;
    --border-strong: #2f3446;
    --hover: #1b1f2c;
    --accent: #7c7cff;
    --accent-2: #a78bfa;
    --accent-text: #0b0c14;
    --accent-soft: #1f2040;
    --accent-ink: #b4b4ff;
    --good: #34d399;
    --good-soft: #0f2a21;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #321619;
    --info-soft: #14223a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
    --ring: 0 0 0 3px rgba(124, 124, 255, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14.5px/1.55 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.65rem; line-height: 1.2; font-weight: 650; letter-spacing: -0.025em; margin: 0 0 1.25rem; }
h2 { font-size: 1.02rem; font-weight: 620; letter-spacing: -0.01em; margin: 2rem 0 0.75rem; }
p { margin: 0.4rem 0; }
a { color: var(--accent-ink); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
strong { font-weight: 620; }
pre { margin: 0; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.82rem; overflow-wrap: anywhere; }
::selection { background: var(--accent-soft); color: var(--text); }

/* Icons */
.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* Layout */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
nav.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding: 18px 14px;
  background: var(--sidebar);
  backdrop-filter: saturate(160%) blur(16px);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(91, 91, 240, 0.35);
}
.brand .mark .icon { width: 18px; height: 18px; }
.brand .name { font-weight: 680; letter-spacing: -0.02em; line-height: 1.15; }
.brand .org { font-size: 0.78rem; color: var(--muted); }
nav.side select { margin: 0 0 10px; }
nav.side .links { display: flex; flex-direction: column; gap: 2px; }
nav.side .group { color: var(--muted); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; padding: 16px 10px 6px; }
nav.side .links a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 9px;
  color: var(--text-2); font-weight: 500; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
nav.side .links a .icon { color: var(--muted); transition: color 0.15s; }
nav.side .links a:hover { background: var(--hover); color: var(--text); }
nav.side .links a.active { background: var(--accent-soft); color: var(--accent-ink); }
nav.side .links a.active .icon { color: var(--accent); }
nav.side .count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 0.72rem; font-weight: 650; text-align: center; line-height: 20px; }
.user-card {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 650; font-size: 0.8rem; color: #fff;
  background: linear-gradient(135deg, #0ea5e9, var(--accent));
}
.user-card .who { min-width: 0; flex: 1; }
.user-card .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card .role { font-size: 0.75rem; color: var(--muted); text-transform: capitalize; }
.user-card button { padding: 6px; border: 0; background: transparent; color: var(--muted); box-shadow: none; }
.user-card button:hover { color: var(--bad); background: var(--hover); }
main { padding: 32px 44px 72px; max-width: 1280px; width: 100%; animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Surfaces */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.panel h2:first-child { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.stat:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.stat .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat .l { color: var(--muted); font-size: 0.83rem; font-weight: 500; }
.stat .n { font-size: 1.75rem; font-weight: 680; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.2; }
.stat .tile { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.stat .tile .icon { width: 17px; height: 17px; }
.stat.alert .n { color: var(--bad); }
.stat.alert .tile { background: var(--bad-soft); color: var(--bad); }
.stat.ok .tile { background: var(--good-soft); color: var(--good); }
.section-title { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.75rem; font-weight: 620; letter-spacing: 0.08em; text-transform: uppercase; margin: 26px 0 10px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.hero h1 { margin: 0; }
.hero p { color: var(--muted); margin-top: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow-sm); }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 560; font-size: 0.76rem; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; background: var(--surface-2); }
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child { border-top-right-radius: var(--radius); }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: var(--hover); }
tr.click { cursor: pointer; }

/* Badges: a soft pill with a status dot */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 560; white-space: nowrap; text-transform: capitalize;
  background: var(--hover); color: var(--text-2); border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* Forms and buttons */
form.form { display: grid; gap: 14px; max-width: 540px; }
label { display: grid; gap: 6px; font-size: 0.85rem; font-weight: 550; color: var(--text-2); }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 12px; width: 100%; box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); box-shadow: none; }
textarea { min-height: 6rem; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 0.82rem; min-height: 12rem; }
button {
  font: inherit; font-weight: 560;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
button:hover { background: var(--hover); border-color: var(--border-strong); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black));
  border-color: transparent; color: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.15), 0 4px 12px rgba(91, 91, 240, 0.3);
}
button.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black)); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
button:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: none; box-shadow: var(--ring); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.spread h1, .spread h2 { margin: 0; }
.panel.row { gap: 14px; }

/* Messages to the user */
.notice { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 16px; background: var(--surface); }
.notice.error { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.secret { background: var(--surface-2); border: 1px dashed var(--border-strong); padding: 12px 14px; border-radius: var(--radius-sm); margin: 10px 0; }

/* Sign-in screens */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth .card { width: min(440px, 100%); }
.auth .brand { justify-content: center; padding: 0 0 22px; }
.auth .brand .mark { width: 44px; height: 44px; border-radius: 13px; }
.auth .brand .mark .icon { width: 22px; height: 22px; }
.auth .brand .name { font-size: 1.1rem; }
.auth .panel { margin: 0; padding: 28px; border-radius: 18px; box-shadow: var(--shadow); }
.auth h1 { font-size: 1.35rem; text-align: left; }
.auth form.form { max-width: none; }
.auth button.primary { width: 100%; padding: 10px 14px; }
.auth .foot { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 18px; }

/* Conversations */
.thread { display: grid; gap: 10px; margin-bottom: 8px; }
.msg {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px;
  padding: 11px 14px; max-width: 78%; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-sm);
}
.msg.outbound { justify-self: end; border-radius: 16px 16px 4px 16px; background: var(--accent-soft); border-color: transparent; }
.msg .meta { color: var(--muted); font-size: 0.76rem; white-space: normal; margin-bottom: 4px; }

/* Dialogs */
dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 22px 24px; width: min(580px, calc(100vw - 32px)); max-height: 86vh;
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(10, 12, 20, 0.45); backdrop-filter: blur(4px); }
dialog .spread { margin-bottom: 10px; }
.empty { color: var(--muted); padding: 36px 20px; text-align: center; }
.empty::before { content: ""; display: block; width: 44px; height: 44px; margin: 0 auto 12px; border-radius: 14px; background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Phones and small tablets */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  nav.side { position: sticky; top: 0; z-index: 5; height: auto; padding: 10px 12px 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 2px 4px 8px; }
  nav.side .links { flex-direction: row; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  nav.side .links::-webkit-scrollbar { display: none; }
  nav.side .links a { white-space: nowrap; padding: 7px 10px; }
  nav.side .group, .user-card .who { display: none; }
  .user-card { position: absolute; top: 10px; right: 12px; margin: 0; padding: 4px; border: 0; background: transparent; }
  main { padding: 20px 16px 56px; }
  h1 { font-size: 1.4rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat .n { font-size: 1.45rem; }
  .msg { max-width: 100%; }
}

/* Approval notices */
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(420px, calc(100vw - 32px));
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 14px;
  animation: toast-in 0.2s ease-out; transition: opacity 0.4s, transform 0.4s;
}
.toast .icon { color: var(--accent); flex: none; margin-top: 1px; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Approval requests */
.requests { display: grid; gap: 12px; }
.request {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); display: grid; gap: 10px;
}
.request.pending { border-left: 3px solid var(--warn); }
.request.approved { border-left: 3px solid var(--good); }
.request.rejected, .request.failed { border-left: 3px solid var(--bad); }
.request-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.request-title { font-weight: 600; margin-bottom: 2px; }
.request .quote { padding: 10px 12px; background: var(--hover); border-radius: var(--radius-sm); white-space: pre-wrap; }
.request .row { min-height: 0; }
.votes { display: flex; flex-wrap: wrap; gap: 8px; }
.vote {
  font-size: 12.5px; padding: 4px 10px; border-radius: 999px;
  border: 1px dashed var(--border-strong); color: var(--muted);
}
.vote.yes { border: 1px solid transparent; background: var(--good-soft); color: var(--good); }
.vote.no { border: 1px solid transparent; background: var(--bad-soft); color: var(--bad); }

/* Change log: before and after */
.diff { display: grid; gap: 3px; font-size: 12.5px; min-width: 220px; }
.diff-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.diff-key { color: var(--muted); min-width: 90px; }
.diff-old { font-family: var(--mono); background: var(--bad-soft); color: var(--bad); padding: 0 5px; border-radius: 4px; overflow-wrap: anywhere; }
.diff-new { font-family: var(--mono); background: var(--good-soft); color: var(--good); padding: 0 5px; border-radius: 4px; overflow-wrap: anywhere; }
.diff-old:empty, .diff-new:empty { display: none; }
.diff-arrow { color: var(--muted); }

@media (max-width: 860px) {
  .toast { right: 16px; left: 16px; bottom: 16px; max-width: none; }
  .request-head { flex-direction: column; }
}
