/* ===== TeamWork — "Console" design system =====
   A sharp, dense, data-forward UI. Structure is drawn with 1px hairline borders,
   not shadows. Zero corner radius. Monospace for labels, numbers and metadata.
   Snappy ~80ms transitions, no springs. Class + token names are kept stable so
   every existing template renders against this system unchanged.
   ------------------------------------------------------------------------ */

/* ---------- Design tokens: light ---------- */
:root {
  color-scheme: light;

  /* Brand — overridable per-org via an inline style in the header partial. */
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-2: #6366f1;
  --brand-soft: #e7e9fd;
  --brand-ink: #ffffff;
  --accent: #0891a3;
  --accent-soft: #d8f1f4;

  --bg: #eceef1;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eceef1;
  --border: #d3d8de;
  --border-strong: #aab2bd;
  --grid-line: #e3e7ec;

  --text: #0b0e14;
  --text-soft: #2b323c;
  --muted: #5a6472;
  --muted-2: #8b94a1;

  --green: #0f8a43;  --green-soft: #dcf3e4;
  --amber: #b45c09;  --amber-soft: #fbeccd;
  --red:   #c8352b;  --red-soft:   #fbe3e1;
  --blue:  #2563eb;  --blue-soft:  #dde8fe;

  --sidebar: #0c0e13;
  --sidebar-text: #c2c8d2;
  --sidebar-muted: #6b7480;
  --sidebar-border: #1e222b;
  --sidebar-active-bg: #181c24;

  /* Sharp corners: every radius token resolves to a square. */
  --radius-xs: 0px;
  --radius-sm: 0px;
  --radius: 0px;
  --radius-lg: 0px;

  --shadow-sm: none;
  --shadow: 0 0 0 1px var(--border);
  --shadow-lg: 0 24px 60px -28px rgba(8,11,18,.45);
  --shadow-brand: none;

  --sans: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "IBM Plex Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(.2,0,0,1);
  --ease-out: cubic-bezier(.2,0,0,1);
  --ease-spring: cubic-bezier(.2,0,0,1);

  --t: .08s;

  --sidebar-w: 224px;
  --topbar-h: 50px;
}

/* ---------- Design tokens: dark ---------- */
[data-theme="dark"] {
  color-scheme: dark;

  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --brand-2: #818cf8;
  --brand-soft: #1c1f3a;
  --brand-ink: #ffffff;
  --accent: #22b8cf;
  --accent-soft: #0c343b;

  --bg: #070809;
  --surface: #101216;
  --surface-2: #15181d;
  --surface-3: #1c2027;
  --border: #272c34;
  --border-strong: #3a414c;
  --grid-line: #1a1e24;

  --text: #eef1f5;
  --text-soft: #c2c8d2;
  --muted: #8992a0;
  --muted-2: #5e6772;

  --green: #34c46b;  --green-soft: #0e2a19;
  --amber: #e0962f;  --amber-soft: #2c2008;
  --red:   #f0584c;  --red-soft:   #2e1311;
  --blue:  #5b8dff;  --blue-soft:  #11203c;

  --sidebar: #060708;
  --sidebar-text: #aeb6c1;
  --sidebar-muted: #5b636e;
  --sidebar-border: #181b21;
  --sidebar-active-bg: #14171d;

  --shadow: 0 0 0 1px var(--border);
  --shadow-lg: 0 24px 60px -24px rgba(0,0,0,.8);
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 19px; letter-spacing: -.01em; font-weight: 700; }
h2 { font-size: 16px; letter-spacing: -.005em; font-weight: 700; }
h3 { font-size: 13px; font-weight: 700; letter-spacing: .01em; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
code, kbd { font-family: var(--mono); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--muted); }
.mt { margin-top: 14px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 9px;
  padding: 0 16px;
  height: var(--topbar-h);
  font-weight: 800; font-size: 15px; letter-spacing: -.02em;
  color: #fff;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand span:not(.dot) { color: var(--brand-2); }
.brand .dot { width: 14px; height: 14px; background: var(--brand); flex-shrink: 0; }

.sidebar nav { padding: 8px 0; display: flex; flex-direction: column; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px;
  color: var(--sidebar-text);
  font-size: 13px; font-weight: 500;
  border-left: 2px solid transparent;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.sidebar nav a:hover { background: var(--sidebar-active-bg); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--sidebar-active-bg); color: #fff; border-left-color: var(--brand); }
.sidebar nav a .ico { width: 18px; text-align: center; font-size: 14px; opacity: .9; }
.nav-group {
  font-family: var(--mono);
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--sidebar-muted);
  padding: 14px 16px 5px;
}
.spacer { flex: 1; }
.org-box { padding: 12px 16px; border-top: 1px solid var(--sidebar-border); }
.org-box .name { color: #fff; font-weight: 600; font-size: 12.5px; }
.org-box .plan { font-family: var(--mono); color: var(--sidebar-muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-heading { font-size: 14px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }

.user { display: flex; align-items: center; gap: 10px; }
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font: inherit; font-size: 12.5px;
  transition: border-color var(--t) var(--ease);
}
.topbar-search:hover { border-color: var(--border-strong); }
.topbar-search-text { min-width: 120px; text-align: left; }
.topbar-search-kbd { margin-left: 4px; }
kbd {
  font-size: 10.5px; padding: 1px 5px; min-width: 18px; text-align: center;
  background: var(--surface-3); border: 1px solid var(--border); color: var(--muted);
}
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft);
  cursor: pointer; font-size: 14px; transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.icon-btn:hover { border-color: var(--border-strong); text-decoration: none; }
.tw-bell-badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--red); color: #fff; font-family: var(--mono);
  font-size: 9px; font-weight: 700; line-height: 1; padding: 2px 4px; min-width: 15px; text-align: center;
}
.theme-ico-dark { display: none; }
[data-theme="dark"] .theme-ico-light { display: none; }
[data-theme="dark"] .theme-ico-dark { display: inline; }
.avatar {
  width: 28px; height: 28px; display: inline-grid; place-items: center;
  background: var(--brand); color: var(--brand-ink);
  font-family: var(--mono); font-size: 11px; font-weight: 700;
}
.topbar-username { font-size: 12.5px; font-weight: 600; }
.signout-link { display: inline-flex; align-items: center; color: var(--muted); font-size: 12.5px; }
.signout-link:hover { color: var(--red); text-decoration: none; }
.signout-icon { display: none; }

.content { padding: 18px; flex: 1; }

/* Mobile sidebar */
.nav-scrim { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .14s var(--ease);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .14s; }
  body.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .menu-toggle { display: block; }
  .topbar-search-text, .topbar-username, .signout-text { display: none; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: -16px -16px 14px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); }
.card-link { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: var(--muted); }
.card-link:hover { color: var(--brand); }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* ---------- Metric tiles ---------- */
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--border-strong);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
  transition: border-color var(--t) var(--ease);
}
.metric:hover { border-color: var(--border-strong); }
.metric-top { display: flex; justify-content: flex-end; }
.metric-ico { font-size: 15px; opacity: .5; }
.metric-label { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.metric-value { font-family: var(--mono); font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.metric-foot { font-size: 11.5px; color: var(--muted-2); }
.metric.t-blue  { border-top-color: var(--blue); }
.metric.t-green { border-top-color: var(--green); }
.metric.t-amber { border-top-color: var(--amber); }
.metric.t-red   { border-top-color: var(--red); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); text-align: left; font-weight: 500;
  padding: 8px 12px; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.table tbody td { padding: 8px 12px; border-bottom: 1px solid var(--grid-line); vertical-align: middle; }
.table tbody td:first-child { white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--brand); }

/* ---------- Pills ---------- */
.pill {
  display: inline-block; font-family: var(--mono);
  font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 7px; border: 1px solid transparent; white-space: nowrap;
}
.pill.green { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.pill.amber { background: var(--amber-soft); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.pill.red   { background: var(--red-soft);   color: var(--red);   border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.pill.blue  { background: var(--blue-soft);  color: var(--blue);  border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.pill.gray  { background: var(--surface-3);  color: var(--muted); border-color: var(--border); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; font: inherit; font-size: 13px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand);
  cursor: pointer; white-space: nowrap;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), opacity var(--t) var(--ease);
}
.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--muted-2); }
.btn.ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.lg { padding: 11px 22px; font-size: 14px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 13px;
  padding: 8px 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--muted); }
input[type="color"] { padding: 2px; height: 34px; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--brand); }
textarea { resize: vertical; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.toolbar input, .toolbar select { width: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-head { margin-bottom: 16px; }

/* ---------- Flash ---------- */
.flash {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--muted-2);
}
.flash.success { background: var(--green-soft); border-left-color: var(--green); color: var(--text); }
.flash.error { background: var(--red-soft); border-left-color: var(--red); color: var(--text); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; }
.empty-title { font-weight: 700; font-size: 14px; margin-bottom: 5px; }
.empty-text { color: var(--muted); font-size: 13px; max-width: 360px; margin: 0 auto; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab {
  padding: 9px 16px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Hero (page banner) ---------- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand);
  padding: 16px 18px; margin-bottom: 16px;
}
.hero-eyebrow { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--brand); margin-bottom: 5px; }
.hero-text h1 { font-size: 20px; }
.hero-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Auth / centered pages ---------- */
.center-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg);
}
.auth-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border-strong); padding: 30px 28px; box-shadow: var(--shadow-lg); }
.auth-card .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; margin-bottom: 6px; }
.auth-card .brand span:not(.dot) { color: var(--brand); }
.auth-card .tag { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

/* ---------- Search palette ---------- */
.ld-search { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.ld-search[hidden] { display: none; }
.ld-search-scrim { position: absolute; inset: 0; background: rgba(6,8,12,.55); }
.ld-search-panel { position: relative; width: 600px; max-width: 92vw; background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); }
.ld-search-input { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.ld-search-input input { border: none; padding: 0; font-size: 15px; background: transparent; }
.ld-search-input input:focus { box-shadow: none; }
.ld-search-close { width: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.ld-search-results { max-height: 56vh; overflow-y: auto; }
.ld-search-group { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 10px 14px 4px; }
.ld-search-item { display: flex; align-items: center; gap: 11px; padding: 9px 14px; color: var(--text); }
.ld-search-item:hover, .ld-search-item.is-active { background: var(--surface-2); text-decoration: none; }
.ld-search-item.is-active { box-shadow: inset 2px 0 0 var(--brand); }
.ld-search-ico { width: 18px; text-align: center; opacity: .7; }
.ld-search-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ld-search-text strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ld-search-sub { font-size: 11.5px; color: var(--muted); }
.ld-search-empty { padding: 22px 16px; color: var(--muted); font-size: 13px; text-align: center; }
.ld-search-foot { display: flex; gap: 16px; padding: 9px 14px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
