@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Light-first design system ─────────────────────────────── */
:root {
  --bg-0: #f7f8fa;
  --bg-1: #ffffff;
  --bg-2: #f3f4f6;
  --bg-3: #e9ebf0;
  --bg-hover: #edeef2;
  --border: #e2e5ea;
  --border-hover: #cdd1d9;
  --text-0: #111827;
  --text-1: #374151;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim: rgba(59,130,246,.08);
  --green: #10b981;
  --green-dim: rgba(16,185,129,.08);
  --amber: #f59e0b;
  --amber-dim: rgba(245,158,11,.08);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,.08);
  --purple: #8b5cf6;
  --purple-dim: rgba(139,92,246,.08);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --transition: 150ms ease;
}

/* ─── Dark mode ──────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-0: #0f1117;
  --bg-1: #16181f;
  --bg-2: #1e2028;
  --bg-3: #272a33;
  --bg-hover: #2d303b;
  --border: #2a2d38;
  --border-hover: #3a3e4a;
  --text-0: #f0f1f4;
  --text-1: #b0b6c4;
  --text-2: #6b7180;
  --text-3: #4a4f5c;
  --accent: #5b9bf5;
  --accent-hover: #4a8af4;
  --accent-dim: rgba(91,155,245,.1);
  --green-dim: rgba(16,185,129,.12);
  --amber-dim: rgba(245,158,11,.12);
  --red-dim: rgba(239,68,68,.12);
  --purple-dim: rgba(139,92,246,.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
}

/* ─── Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg-0); color: var(--text-0); line-height: 1.6; -webkit-font-smoothing: antialiased; overflow: hidden; }
::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
textarea { font-family: var(--font); resize: vertical; }

/* ─── Shell ──────────────────────────────────────────────── */
.hub { display: flex; height: 100vh; overflow: hidden; }
.hub-sidebar { width: 220px; background: var(--bg-1); border-right: 1px solid var(--border); display: none; flex-direction: column; flex-shrink: 0; overflow-y: auto; }
.hub-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.hub-topbar { height: 56px; background: var(--bg-1); border-bottom: 1px solid var(--border); display: none; align-items: center; justify-content: space-between; padding: 0 28px; flex-shrink: 0; }
.hub-content { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 32px 40px; }
.hub.authed .hub-sidebar, .hub.authed .hub-topbar { display: flex; }

/* ─── Sidebar ────────────────────────────────────────────── */
.sb-brand { padding: 20px 20px 16px; font-size: 16px; font-weight: 700; letter-spacing: -0.5px; color: var(--text-0); border-bottom: 1px solid var(--border); }
.sb-brand span { color: var(--accent); }
.sb-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.sb-group-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-3); padding: 20px 12px 6px; }
.sb-item { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; font-size: 14px; font-weight: 450; color: var(--text-2); cursor: pointer; border: none; background: none; font-family: var(--font); text-align: left; width: 100%; border-radius: var(--radius); transition: all var(--transition); }
.sb-item:hover { color: var(--text-1); background: var(--bg-2); }
.sb-item.active { color: var(--accent); background: var(--accent-dim); font-weight: 500; }
.sb-item-icon { font-size: 15px; width: 20px; text-align: center; opacity: 0.6; }
.sb-item.active .sb-item-icon { opacity: 1; }
.sb-footer { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-3); text-align: center; }

/* ─── Topbar ─────────────────────────────────────────────── */
.tb-left { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.tb-left span { color: var(--text-0); font-weight: 500; }
.tb-right { display: flex; align-items: center; gap: 14px; }
.tb-user { display: flex; align-items: center; gap: 10px; }
.tb-user-name { font-size: 14px; font-weight: 500; color: var(--text-0); }
.tb-role { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; padding: 3px 8px; border-radius: 4px; background: var(--accent-dim); color: var(--accent); }
.tb-logout { font-size: 13px; color: var(--text-2); cursor: pointer; background: none; border: 1px solid var(--border); padding: 6px 12px; border-radius: var(--radius); font-family: var(--font); transition: all var(--transition); }
.tb-logout:hover { border-color: var(--red); color: var(--red); }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text-2); width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; transition: all var(--transition); }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Login ──────────────────────────────────────────────── */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100%; padding: 32px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-form { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow-md); }
.login-label { font-size: 13px; font-weight: 500; color: var(--text-2); text-align: left; }
.login-select, .login-input { width: 100%; padding: 10px 14px; background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-0); font-size: 14px; font-family: var(--font); transition: border-color var(--transition); }
.login-select:focus, .login-input:focus { outline: none; border-color: var(--accent); }
.login-btn { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: background var(--transition); }
.login-btn:hover { background: var(--accent-hover); }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ─── Cards ──────────────────────────────────────────────── */
.card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; transition: border-color var(--transition); box-shadow: var(--shadow-sm); }
.card:hover { border-color: var(--border-hover); }

/* ─── KPIs ───────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 32px; }
.kpi-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; text-align: center; box-shadow: var(--shadow-sm); }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; margin-bottom: 6px; }
.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-3); }

/* ─── Section headers ────────────────────────────────────── */
.section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-3); margin-bottom: 6px; }
.section-title { font-size: 24px; font-weight: 700; letter-spacing: -0.3px; color: var(--text-0); margin-bottom: 4px; line-height: 1.3; }
.section-sub { font-size: 14px; color: var(--text-2); margin-bottom: 28px; }

/* ─── Tables ─────────────────────────────────────────────── */
.dtable { width: 100%; border-collapse: collapse; }
.dtable thead { border-bottom: 2px solid var(--border); }
.dtable th { padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-3); }
.dtable td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid var(--border); color: var(--text-1); }
.dtable tbody tr { transition: background var(--transition); }
.dtable tbody tr:hover { background: var(--bg-2); }

/* ─── Tags ───────────────────────────────────────────────── */
.tag { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.tag-red { background: var(--red-dim); color: var(--red); }
.tag-amber { background: var(--amber-dim); color: var(--amber); }
.tag-green { background: var(--green-dim); color: var(--green); }
.tag-blue { background: var(--accent-dim); color: var(--accent); }
.tag-purple { background: var(--purple-dim); color: var(--purple); }

/* ─── Progress bars ──────────────────────────────────────── */
.pbar { width: 100%; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.pbar-fill { height: 100%; border-radius: 2px; background: var(--accent); transition: width .5s ease; }
.pbar-fill.green { background: var(--green); }
.pbar-fill.amber { background: var(--amber); }
.pbar-fill.red { background: var(--red); }

/* ─── Tabs ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn { padding: 10px 18px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-2); font-size: 14px; font-weight: 500; font-family: var(--font); cursor: pointer; transition: all var(--transition); }
.tab-btn:hover { color: var(--text-1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: all var(--transition); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--bg-2); color: var(--text-1); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ─── Inputs ─────────────────────────────────────────────── */
.search-input { padding: 9px 14px; background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-0); font-size: 14px; font-family: var(--font); transition: border-color var(--transition); }
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* ─── Toast ──────────────────────────────────────────────── */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); min-width: 260px; box-shadow: var(--shadow-lg); animation: toastIn .3s ease; pointer-events: auto; }
.toast.success { border-left: 3px solid var(--green); }
.toast.warning { border-left: 3px solid var(--amber); }
.toast.error { border-left: 3px solid var(--red); }
.toast-msg { font-size: 14px; color: var(--text-0); }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ─── Modal ──────────────────────────────────────────────── */
#modal-root { position: fixed; inset: 0; z-index: 9000; display: none; background: rgba(0,0,0,.4); backdrop-filter: blur(4px); }
#modal-root.active { display: flex; align-items: center; justify-content: center; animation: fadeIn .2s; }
.modal { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 90%; max-width: 560px; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn .25s ease; }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-2); font-size: 18px; cursor: pointer; padding: 4px; transition: color var(--transition); }
.modal-close:hover { color: var(--text-0); }
.modal-body { padding: 24px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ─── Comments ───────────────────────────────────────────── */
.comment-box { margin-top: 10px; padding: 12px; background: var(--bg-2); border-radius: var(--radius); border-left: 3px solid var(--accent); }
.comment-author { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.comment-text { font-size: 14px; color: var(--text-1); }
.comment-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ─── Feed posts ─────────────────────────────────────────── */
.feed-post { padding: 24px 0; border-bottom: 1px solid var(--border); transition: background var(--transition); }
.feed-post:hover { background: var(--bg-2); }
.feed-post:last-child { border-bottom: none; }

/* ─── Chat bubbles ───────────────────────────────────────── */
.chat-msg { padding: 10px 14px; background: var(--bg-2); border-radius: var(--radius); margin-bottom: 6px; }
.chat-msg-author { font-size: 12px; font-weight: 600; color: var(--purple); margin-bottom: 2px; }
.chat-msg-text { font-size: 14px; color: var(--text-1); }
.chat-msg-time { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ─── Kudos ──────────────────────────────────────────────── */
.kudos-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 10px; border-left: 3px solid var(--amber); }
.kudos-from { font-size: 12px; font-weight: 600; color: var(--amber); }
.kudos-to { font-size: 15px; font-weight: 600; color: var(--text-0); margin: 4px 0; }
.kudos-msg { font-size: 14px; color: var(--text-1); }
.kudos-time { font-size: 11px; color: var(--text-3); margin-top: 6px; }

/* ─── Animations ─────────────────────────────────────────── */
.fade-in { animation: fadeIn .25s ease; }
.stagger > * { opacity: 0; animation: staggerIn .3s ease forwards; }
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .1s; }
.stagger > *:nth-child(3) { animation-delay: .15s; }
.stagger > *:nth-child(4) { animation-delay: .2s; }
.stagger > *:nth-child(5) { animation-delay: .25s; }
.stagger > *:nth-child(6) { animation-delay: .3s; }
@keyframes staggerIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hub { flex-direction: column; }
  .hub-sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; overflow-x: auto; }
  .sb-brand, .sb-footer, .sb-group-label { display: none; }
  .sb-nav { flex-direction: row; padding: 0; gap: 0; }
  .sb-item { border-radius: 0; border-bottom: 2px solid transparent; padding: 12px 16px; white-space: nowrap; height: auto; font-size: 13px; }
  .sb-item.active { border-bottom-color: var(--accent); background: transparent; }
  .hub-content { padding: 20px 16px; }
  .hub-topbar { padding: 0 16px; height: 50px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .section-title { font-size: 20px; }
  .dtable { font-size: 13px; }
  .dtable th, .dtable td { padding: 8px 10px; }
  .btn { padding: 10px 16px; }
  .btn-sm { padding: 8px 12px; }
  #toast-root { bottom: auto; top: 8px; right: 8px; left: 8px; }
  .toast { min-width: auto; }
  .modal { width: 95%; max-height: 90vh; }
}

@media (max-width: 480px) {
  .hub-content { padding: 16px 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .card { padding: 16px; }
}

/* ─── Final Polish: Interaction & Clarity ────────────────── */

/* Clickable rows */
[onclick] { cursor: pointer; }
.dtable tbody tr[onclick]:hover { background: var(--accent-dim); }
.dtable tbody tr[onclick] { cursor: pointer; }

/* Focus items */
.focus-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 6px; background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: all 150ms ease; }
.focus-item:hover { background: var(--accent-dim); border-color: var(--accent); transform: translateX(2px); }
.focus-item:active { transform: translateX(0); }
.focus-item.top-priority { border-left: 3px solid var(--red); }
.focus-item.secondary { opacity: 0.85; }

/* Urgency badges */
.urgency-badge { font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }

/* Activity rows */
.activity-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); transition: background 150ms ease; border-radius: var(--radius); margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
.activity-row[onclick]:hover { background: var(--bg-2); }

/* Metric cards hover */
.kpi-card { transition: border-color 150ms ease, transform 150ms ease; cursor: default; }
.kpi-card:hover { border-color: var(--border-hover); transform: translateY(-1px); }

/* Button refinement */
.btn-primary { box-shadow: 0 1px 3px rgba(59,130,246,.2); }
.btn-primary:hover { box-shadow: 0 2px 6px rgba(59,130,246,.3); }
.btn-ghost { box-shadow: none; }

/* Sidebar active state stronger */
.sb-item.active { font-weight: 600; }

/* Cards clickable indicator */
.card[onclick] { cursor: pointer; }
.card[onclick]:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
