/* ============================================================
   Brylliance Mission Control — shared design system
   Mirrors brylliance.io: warm near-black, teal-400, gold, Inter.
   ============================================================ */

:root[data-theme="dark"] {
  --bg: #0a0a0a;              /* brylliance --color-bg-primary */
  --surface: #121212;         /* --color-bg-secondary */
  --surface-2: #171717;
  --surface-3: #1c1c1c;
  --border: #262626;          /* --color-border */
  --border-strong: #333333;
  --text: #f5f5f7;            /* --color-text-primary */
  --text-2: #9ca0ab;          /* --color-text-secondary */
  --text-3: #6b6b6b;          /* --color-text-tertiary */
  --accent: #2dd4bf;          /* teal-400 */
  --accent-hover: #14b8a6;    /* teal-500 */
  --accent-soft: rgba(45,212,191,0.12);
  --gold: #f5c842;
  --gold-hover: #fad250;
  --gold-text: #0a0a0a;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 12px 40px rgba(0,0,0,0.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --grain-blend: overlay;
  --grain-opacity: 0.04;
  --overlay: rgba(0,0,0,0.62);
  --input-bg: #0f0f0f;
}
:root[data-theme="light"] {
  --bg: #f8f7f5;              /* warm off-white */
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --surface-3: #f2f0ec;
  --border: #e5e5e5;
  --border-strong: #d6d6d6;
  --text: #0a0a0a;
  --text-2: #6b6b6b;
  --text-3: #9a9a9a;
  --accent: #0d9488;          /* teal-600 for contrast on light */
  --accent-hover: #0f766e;
  --accent-soft: rgba(13,148,136,0.10);
  --gold: #f5c842;
  --gold-hover: #e8b62e;
  --gold-text: #0a0a0a;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 12px 40px rgba(0,50,60,0.07);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --grain-blend: multiply;
  --grain-opacity: 0.03;
  --overlay: rgba(20,20,20,0.45);
  --input-bg: #ffffff;
}

/* Agent identity colors (functional) */
:root {
  --agent-main: #c8a8ff;
  --agent-communications: #00e5ff;
  --agent-content: #ff6eb4;
  --agent-operations: #4ade80;
  --agent-research: #fbbf24;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --nav-w: 236px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  transition: background 300ms var(--ease), color 300ms var(--ease);
}
::selection { background: var(--text); color: var(--bg); }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* Grain overlay — brylliance signature */
.grain-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
  opacity: var(--grain-opacity); mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Typography helpers */
.micro { font-size: 11px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); }
.wordmark { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; color: var(--text); line-height: 1; }
.tabular { font-variant-numeric: tabular-nums; }
.h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.h3 { font-size: 16px; font-weight: 600; }
.dim { color: var(--text-2); }
.dimmer { color: var(--text-3); }

/* ── App shell ── */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; overflow: hidden;
}
.side-brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px; }
.side-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.side-brand .sub { font-size: 10px; font-weight: 500; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-3); margin-top: 3px; }
.side-hair { height: 1px; background: linear-gradient(90deg, transparent, var(--gold) 30%, var(--accent) 70%, transparent); opacity: 0.5; }
.nav { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-3); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius);
  color: var(--text-2); font-size: 14px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 200ms var(--ease);
}
.nav-item .ico { width: 18px; text-align: center; opacity: 0.9; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.nav-item.active .ico { filter: drop-shadow(0 0 6px var(--accent)); }
.nav-item .badge { margin-left: auto; }
.side-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; }
.side-foot .who .em { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: 62px; flex-shrink: 0;
  display: flex; align-items: center; gap: 16px; padding: 0 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }
.page { padding: 26px; max-width: 1500px; width: 100%; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius); cursor: pointer;
  font-size: 13px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  transition: all 200ms var(--ease); white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; }
.btn-teal { background: var(--accent); color: #04201d; border-color: transparent; }
.btn-teal:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-icon { width: 34px; height: 34px; padding: 0; }

/* Liquid-gold CTA — brylliance .btn-gold */
.btn-gold {
  position: relative; overflow: hidden; isolation: isolate; border: 1px solid rgba(255,255,255,0.5);
  color: var(--gold-text); font-weight: 700;
  background-image: linear-gradient(110deg,#f5c842 0%,#fbe08a 22%,#e8b62e 48%,#f5c842 72%,#fbe08a 100%);
  background-size: 220% 100%; animation: sheenShift 6s ease-in-out infinite;
  box-shadow: 0 6px 22px rgba(245,200,66,0.30), inset 0 1px 0 rgba(255,255,255,0.55);
}
.btn-gold::before { content:""; position:absolute; inset:0; z-index:0; pointer-events:none;
  background: linear-gradient(180deg, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.08) 40%, transparent 58%); }
.btn-gold > * { position: relative; z-index: 1; }
.btn-gold:hover { transform: translateY(-1px); }
@keyframes sheenShift { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }

/* Theme toggle */
.theme-toggle { position: relative; width: 54px; height: 28px; border-radius: 999px; border: 1px solid var(--border); background: var(--input-bg); cursor: pointer; flex-shrink: 0; }
.theme-toggle .knob { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; background: linear-gradient(135deg, var(--accent-hover), var(--accent)); box-shadow: var(--shadow-sm); transition: transform 300ms var(--ease); }
:root[data-theme="light"] .theme-toggle .knob { transform: translateX(26px); background: linear-gradient(135deg, var(--gold), var(--gold-hover)); }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-hover { transition: border-color 200ms var(--ease), transform 200ms var(--ease), box-shadow 200ms var(--ease); }
.card-hover:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }

.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.section-head { display: flex; align-items: center; gap: 12px; margin: 4px 2px 14px; }
.section-head .micro { flex-shrink: 0; }
.section-head::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Stat tiles */
.stat { padding: 18px 20px; }
.stat .val { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat .lbl { margin-top: 8px; }
.stat.accent .val { color: var(--accent); }
.stat.gold .val { color: var(--gold); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; padding: 3px 9px; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.badge .b-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.st-backlog { color: var(--text-3); }
.badge.st-todo { color: var(--text-2); }
.badge.st-in_progress { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.badge.st-review { color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); border-color: color-mix(in srgb, var(--gold) 30%, transparent); }
.badge.st-done { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge.st-blocked { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* Agent chip */
.agent-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; padding: 3px 10px 3px 8px; border-radius: var(--radius-pill); color: var(--ac, var(--text-2)); background: color-mix(in srgb, var(--ac, var(--text-3)) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ac, var(--text-3)) 30%, transparent); }
.agent-chip .a-ava { width: 18px; height: 18px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; background: color-mix(in srgb, var(--ac, var(--text-3)) 18%, transparent); }

/* ── Character monogram avatar ── */
.ava {
  position: relative; flex-shrink: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; line-height: 1; letter-spacing: -0.02em;
  background:
    radial-gradient(circle at 32% 26%,
      color-mix(in srgb, var(--ac) 45%, #ffffff 30%) 0%,
      color-mix(in srgb, var(--ac) 92%, #000 4%) 52%,
      color-mix(in srgb, var(--ac) 62%, #000 40%) 100%);
  border: 1px solid color-mix(in srgb, var(--ac) 70%, #000 8%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 2px 8px color-mix(in srgb, var(--ac) 34%, transparent);
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  vertical-align: middle;
}
/* rotating "at work" ring + breathing aura */
.ava.working::before {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0%, var(--ac) 25%, #fff 42%, var(--ac) 60%, transparent 78%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: avaSpin 1.05s linear infinite;
}
.ava.working::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  box-shadow: 0 0 18px 2px color-mix(in srgb, var(--ac) 60%, transparent);
  animation: avaAura 1.7s ease-in-out infinite;
}
@keyframes avaSpin { to { transform: rotate(360deg); } }
@keyframes avaAura { 0%,100% { opacity: 0.35; } 50% { opacity: 0.9; } }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; font-family: inherit; font-size: 14px; transition: border-color 200ms, box-shadow 200ms;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%239ca0ab' stroke-width='1.5' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ── Modal ── */
.modal-scrim { position: fixed; inset: 0; z-index: 300; background: var(--overlay); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 24px; opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease); }
.modal-scrim.open { opacity: 1; pointer-events: auto; }
.modal { width: 100%; max-width: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); transform: translateY(10px) scale(0.99); transition: transform 200ms var(--ease); max-height: 88vh; overflow-y: auto; }
.modal-scrim.open .modal { transform: none; }
.modal-head { display: flex; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head .h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); }
.x-btn { width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-3); color: var(--text-2); cursor: pointer; font-size: 15px; }
.x-btn:hover { color: var(--text); }

/* ── Empty ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty .e-ico { font-size: 34px; margin-bottom: 12px; opacity: 0.7; }
.empty .e-title { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }

/* ── Markdown render ── */
.md { font-size: 14px; line-height: 1.68; color: var(--text); }
.md > *:first-child { margin-top: 0; }
.md h1, .md h2, .md h3 { font-weight: 600; letter-spacing: -0.01em; margin: 18px 0 8px; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md p { margin: 10px 0; }
.md ul, .md ol { margin: 10px 0 10px 22px; }
.md li { margin: 4px 0; }
.md code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; background: var(--surface-3); padding: 1px 6px; border-radius: 5px; }
.md pre { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; overflow-x: auto; margin: 12px 0; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text-2); margin: 12px 0; }
.md a { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.md strong { font-weight: 700; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; font-size: 13px; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Toast */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px; animation: toastIn 240ms var(--ease); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
@keyframes toastIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* Animations */
@keyframes riseIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.rise { animation: riseIn 380ms var(--ease) both; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pulse-dot { animation: pulseDot 1.6s ease-in-out infinite; }
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 100; width: 260px; transform: translateX(-100%); transition: transform 240ms var(--ease); }
  .sidebar.open { transform: none; }
  .content { min-height: 100vh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 120ms !important; }
}
