:root {
  color-scheme: dark;
  --bg: #0d1016;
  --panel: #171b24;
  --raised: #1e2330;
  --border: #272e3d;
  --soft: #1f2530;
  --text: #e8ebf1;
  --muted: #98a1b3;
  --faint: #6b7487;
  --accent: #31c7c0;
  --accent-ink: #062623;
  --danger: #e5484d;
  --warn: #fab219;
  --ok: #3fae6a;
  /* data series (validated against --panel): revenue / expenses */
  --s1: #3987e5;
  --s2: #d95926;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: #5fd08a; }
.neg { color: #ff8a8e; }

/* shell */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 8px 14px; letter-spacing: .2px; }
.brand small { color: var(--accent); font: 600 10px var(--mono); margin-left: 6px; }
.nav-label { font-size: 11px; color: var(--faint); padding: 12px 8px 4px; }
.nav { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--r); color: var(--muted); }
.nav:hover { background: var(--raised); color: var(--text); }
.nav.on { background: var(--raised); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 54px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 22px; gap: 12px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top h1 { font-size: 16px; }
.top-r { display: flex; align-items: center; gap: 8px; }
.page { padding: 22px; max-width: 1280px; width: 100%; }
.bell { position: relative; }
.dot-badge { position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.menu { position: absolute; right: 0; top: 38px; width: 320px; max-height: 420px; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 12px 30px rgba(0,0,0,.45); z-index: 20; }
.menu-item { padding: 10px 12px; border-bottom: 1px solid var(--soft); display: block; font-size: 13px; }
.menu-item.unread { background: rgba(49,199,192,.07); }
.rel { position: relative; }

/* controls */
.btn { border: 1px solid var(--border); background: var(--raised); padding: 7px 13px; border-radius: var(--r); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.btn:hover { border-color: #3a4560; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.pri:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--raised); color: var(--text); }
.btn.danger { color: #ff8a8e; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: var(--r); font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }
.err { background: rgba(229,72,77,.1); border: 1px solid rgba(229,72,77,.35); color: #ff9a9d; padding: 8px 10px; border-radius: var(--r); font-size: 13px; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.seg a { padding: 6px 13px; color: var(--muted); font-size: 13px; cursor: pointer; }
.seg a.on { background: var(--raised); color: var(--text); }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.card h3 { font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stat .v { font-size: 26px; font-weight: 600; margin-top: 2px; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.stat .s { color: var(--faint); font-size: 12px; margin-top: 4px; }
.sec { font-size: 13px; color: var(--muted); margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; }
.empty { color: var(--faint); text-align: center; padding: 26px; border: 1px dashed var(--border); border-radius: 8px; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; color: var(--faint); font-size: 11.5px; font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--soft); font-size: 13px; vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--border); }
.scroll { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; border: 1px solid var(--border); white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #08131f; flex-shrink: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--raised); border: 1px solid var(--soft); border-radius: 20px; padding: 3px 8px 3px 4px; font-size: 12.5px; }
.chip button { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 0 0 0 2px; }
.chip button:hover { color: var(--danger); }
.ico { width: 15px; height: 15px; flex-shrink: 0; }

/* project cards */
.pcard { display: block; border-left: 3px solid var(--c, var(--accent)); }
.pcard:hover { border-color: #3a4560; border-left-color: var(--c, var(--accent)); }
.pcard h3 { color: var(--text); font-size: 15px; margin-bottom: 2px; }
.bar { height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }

/* kanban */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; }
.col { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; width: 270px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.col-h { padding: 10px 12px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--soft); }
.col-h .n { margin-left: auto; color: var(--faint); font: 400 12px var(--mono); }
.col-b { padding: 8px; overflow-y: auto; flex: 1; min-height: 44px; display: flex; flex-direction: column; gap: 8px; }
.tcard { background: var(--raised); border: 1px solid var(--soft); border-left: 3px solid var(--p, var(--faint)); border-radius: var(--r); padding: 9px 10px; cursor: grab; }
.tcard .t { font-size: 13px; margin-bottom: 7px; }
.tcard .m { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--faint); }
.tcard .m .late { color: #ff8a8e; }
.ghost-card { opacity: .35; }
.col-add { padding: 8px; border-top: 1px solid var(--soft); }
.col-add input { border: 0; background: transparent; padding: 4px; }

/* modal & toast */
.backdrop { position: fixed; inset: 0; background: rgba(5,7,10,.7); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; width: 600px; max-width: 100%; }
.modal.wide { width: 920px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--soft); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-b { padding: 16px 18px; }
#toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--raised); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 340px; }
.toast.bad { border-color: rgba(229,72,77,.5); }

/* roles / lists */
.role-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--soft); flex-wrap: wrap; }
.role-row:last-child { border: 0; }
.role-row .rl { width: 120px; color: var(--muted); font-size: 12.5px; flex-shrink: 0; }
.role-row .ch { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; min-width: 140px; }
.role-row select { width: 150px; padding: 5px 8px; font-size: 12.5px; }
.li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--soft); }
.li:last-child { border: 0; }
.done-txt { color: var(--faint); text-decoration: line-through; }
.upd { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--soft); }
.upd:first-child { border: 0; }
.upd .meta { color: var(--faint); font: 11px var(--mono); margin-bottom: 2px; }
.pre { white-space: pre-wrap; word-wrap: break-word; }

/* line items editor */
.items th, .items td { padding: 4px; }
.items input, .items select { padding: 6px 7px; }

/* charts */
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: #2a3040; stroke-width: 1; }
.chart .hit:hover { fill: rgba(255,255,255,.05); }
.hbar { display: grid; grid-template-columns: 150px 1fr 110px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.hbar .track { height: 10px; background: var(--raised); border-radius: 0 5px 5px 0; }
.hbar .track i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.tip { position: fixed; pointer-events: none; background: var(--raised); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 12px; z-index: 100; box-shadow: 0 6px 18px rgba(0,0,0,.4); }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 330px; padding: 28px; }

/* printable document (invoice / PO) */
.doc { background: #fff; color: #111; padding: 32px; border-radius: 6px; font-size: 13px; }
.doc h2 { font-size: 20px; margin-bottom: 4px; }
.doc table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.doc th { background: #f1f2f4; text-align: left; padding: 7px 8px; font-size: 12px; border: 1px solid #d4d7dd; }
.doc td { padding: 7px 8px; border: 1px solid #d4d7dd; vertical-align: top; }
.doc .num { text-align: right; font-variant-numeric: tabular-nums; }
.doc .two { display: flex; gap: 24px; justify-content: space-between; }
.doc .two > div { flex: 1; }
.doc .tot { margin-left: auto; width: 320px; }
.doc .tot td { border: 0; border-bottom: 1px solid #e3e5e9; }
.doc .small { color: #555; font-size: 12px; }

/* ---------- Glossy theme (opt-in, set by an Admin in Team & access) ---------- */
:root[data-theme="glossy"] {
  --panel: rgba(32, 38, 56, .58);
  --raised: rgba(255, 255, 255, .07);
  --border: rgba(255, 255, 255, .10);
  --soft: rgba(255, 255, 255, .07);
}
:root[data-theme="glossy"] body {
  background:
    radial-gradient(1100px 560px at 8% -8%, rgba(49, 199, 192, .16), transparent 60%),
    radial-gradient(900px 520px at 96% 0%, rgba(91, 141, 239, .14), transparent 58%),
    radial-gradient(700px 500px at 50% 110%, rgba(138, 95, 214, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
:root[data-theme="glossy"] .side {
  background: rgba(16, 19, 30, .55);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-right: 1px solid rgba(255, 255, 255, .08);
}
:root[data-theme="glossy"] .top {
  background: rgba(13, 16, 22, .55);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
:root[data-theme="glossy"] .card,
:root[data-theme="glossy"] .menu,
:root[data-theme="glossy"] .modal {
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, .09);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .38), inset 0 1px 0 rgba(255, 255, 255, .05);
  position: relative;
  isolation: isolate;
}
:root[data-theme="glossy"] .card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px; z-index: 1;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .28), transparent);
}
:root[data-theme="glossy"] .stat .v {
  background: linear-gradient(135deg, var(--accent), #8fe9e2 60%, #5b8def);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(49, 199, 192, .35));
}
:root[data-theme="glossy"] .pcard { transition: transform .16s ease, box-shadow .16s ease; }
:root[data-theme="glossy"] .pcard:hover { transform: translateY(-3px); box-shadow: 0 14px 34px rgba(0, 0, 0, .42), inset 0 1px 0 rgba(255, 255, 255, .06); }
:root[data-theme="glossy"] .btn.pri {
  background: linear-gradient(135deg, var(--accent), #5b8def);
  border: none; color: #04201d; box-shadow: 0 6px 20px rgba(49, 199, 192, .38), inset 0 1px 0 rgba(255, 255, 255, .35);
}
:root[data-theme="glossy"] .btn.pri:hover { filter: brightness(1.08); box-shadow: 0 8px 26px rgba(49, 199, 192, .5), inset 0 1px 0 rgba(255, 255, 255, .4); }
:root[data-theme="glossy"] .btn:not(.pri):not(.ghost) { background: rgba(255, 255, 255, .06); backdrop-filter: blur(8px); }
:root[data-theme="glossy"] .nav.on {
  background: rgba(49, 199, 192, .12);
  box-shadow: inset 2px 0 0 var(--accent), 0 0 18px rgba(49, 199, 192, .18);
}
:root[data-theme="glossy"] .nav:hover { background: rgba(255, 255, 255, .06); }
:root[data-theme="glossy"] .bar > i,
:root[data-theme="glossy"] .hbar .track i { background: linear-gradient(90deg, var(--s1), #8ec0ff); box-shadow: 0 0 10px rgba(91, 141, 239, .5); }
:root[data-theme="glossy"] .badge { backdrop-filter: blur(6px); background: rgba(255, 255, 255, .04); }
:root[data-theme="glossy"] input, :root[data-theme="glossy"] select, :root[data-theme="glossy"] textarea {
  background: rgba(255, 255, 255, .04);
  border-color: rgba(255, 255, 255, .12);
}
:root[data-theme="glossy"] .backdrop { background: rgba(5, 7, 12, .72); backdrop-filter: blur(4px); }
:root[data-theme="glossy"] .login .card { box-shadow: 0 20px 60px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .06); }
:root[data-theme="glossy"] .brand { background: linear-gradient(135deg, #fff, #9fb0c8); -webkit-background-clip: text; background-clip: text; color: transparent; }
:root[data-theme="glossy"] .brand small { -webkit-text-fill-color: var(--accent); }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { width: 100%; }
  .nav-label { display: none; }
  .page { padding: 14px; }
  .hbar { grid-template-columns: 100px 1fr 90px; }
}
@media print {
  body.printing #app { display: none !important; }
  body { background: #fff; }
  .side, .top, #toast-root, .no-print, .modal-h { display: none !important; }
  .backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { border: 0; width: 100%; background: #fff; }
  .modal-b { padding: 0; }
  .shell, .main, .page { display: block; padding: 0; max-width: none; }
  .doc { padding: 0; }
}
