/* ================= Kargi Forge ERP ================= */
:root {
  --bg: #09090b;
  --panel: #111113;
  --panel-2: #17171a;
  --hover: rgba(255, 255, 255, .04);
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --text: #fafafa;
  --text-2: #d4d4d8;
  --muted: #a1a1aa;
  --dim: #71717a;
  --ember: #ff7a3d;
  --rose: #ff3d71;
  --gold: #ffc35a;
  --grad: linear-gradient(135deg, var(--ember), var(--rose));
  --ok: #4ade80;
  --err: #f87171;
  --rev: #e05a1c;
  --exp: #3b8ef0;
  --r: 14px;
  --sans: "Geist", system-ui, -apple-system, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --serif: "Instrument Serif", Georgia, serif;
  --side: 248px;
  --chip: #27272a;
  --pop: #1c1c20;
  --input-bg: #0c0c0e;
  --topbar-bg: rgba(9, 9, 11, .8);
  --side-bg: #0b0b0d;
  --foot-bg: #0e0e10;
  --ghost-hover: #1f1f23;
  --tab-on: #222226;
  --gate-card: rgba(17, 17, 19, .85);
  --track: rgba(255, 255, 255, .05);
  --grid: rgba(255, 255, 255, .06);
  --shadow-c: rgba(0, 0, 0, .8);
  --t-orange: #ff9a66; --t-blue: #7cb4ff; --t-green: #6ee7a0; --t-amber: #fcd27b; --t-red: #fca5a5; --t-violet: #c4b5fd;
  --danger-bg: #3f1d1d;
  --dot-neutral: #52525b;
  color-scheme: dark;
}

/* Light theme (daytime) */
:root[data-theme="light"] {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #f4f4f5;
  --hover: rgba(24, 24, 27, .04);
  --line: rgba(24, 24, 27, .09);
  --line-2: rgba(24, 24, 27, .16);
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #52525b;
  --dim: #71717a;
  --gold: #b45309;
  --ok: #15803d;
  --err: #dc2626;
  --chip: #e4e4e7;
  --pop: #ffffff;
  --input-bg: #ffffff;
  --topbar-bg: rgba(246, 246, 244, .85);
  --side-bg: #fbfbfa;
  --foot-bg: #fafafa;
  --ghost-hover: #ececee;
  --tab-on: #f1f1f2;
  --gate-card: rgba(255, 255, 255, .92);
  --track: rgba(24, 24, 27, .06);
  --grid: rgba(24, 24, 27, .08);
  --shadow-c: rgba(24, 24, 27, .22);
  --t-orange: #c2410c; --t-blue: #1d4ed8; --t-green: #15803d; --t-amber: #a16207; --t-red: #b91c1c; --t-violet: #6d28d9;
  --danger-bg: #fee2e2;
  --dot-neutral: #a1a1aa;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); transition: background-color .3s, color .3s; font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.i { flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.grow { flex: 1; }
.r { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--err); }
.warn { color: var(--gold); }
.link { color: var(--gold); }
.link:hover { text-decoration: underline; }
.strong { color: var(--text); font-weight: 500; }
.eyebrow { font: 500 .72rem var(--mono); color: var(--ember); letter-spacing: .12em; text-transform: uppercase; margin-bottom: 6px; }
h1 em, h2 em { font-family: var(--serif); font-weight: 400; font-style: italic; background: linear-gradient(120deg, var(--gold), var(--ember) 50%, var(--rose)); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: .05em; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .15s, box-shadow .15s; }
.btn.sm { height: 34px; padding: 0 12px; font-size: .86rem; border-radius: 9px; }
.btn.lg { height: 50px; font-size: 1rem; }
.btn.block { width: 100%; }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset; }
.btn.primary:hover { box-shadow: 0 8px 24px -10px var(--rose), 0 0 0 1px rgba(255, 255, 255, .2) inset; transform: translateY(-1px); }
.btn.ghost { background: var(--panel-2); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--ghost-hover); }
.btn.danger { color: var(--err); }
.btn.armed { background: rgba(248, 113, 113, .15); border-color: var(--err); color: var(--err); }
.btn.danger-solid { background: var(--danger-bg); color: var(--t-red); border-color: rgba(248, 113, 113, .4); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn-google { display: inline-flex; align-items: center; justify-content: center; gap: 10px; height: 44px; padding: 0 18px; border-radius: 10px; background: #fff; color: #18181b; border: 1px solid var(--line-2); font-weight: 500; cursor: pointer; }
.btn-google.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); border-color: var(--line); }
.linkish { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .85rem; padding: 4px; }
.linkish:hover { color: var(--text); }

input, select, textarea { width: 100%; background: var(--input-bg); border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--ember); box-shadow: 0 0 0 3px rgba(255, 122, 61, .15); }
input:disabled, select:disabled, textarea:disabled { opacity: .75; cursor: default; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--ember); }
select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23a1a1aa' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
select option { background: var(--pop); }
textarea { resize: vertical; }
.invalid { border-color: var(--err) !important; }
.sm-input { width: auto; height: 34px; padding: 0 10px; font-size: .86rem; }
.xs-input { width: 64px; height: 30px; padding: 0 8px; font-size: .84rem; display: inline-block; }

/* ---------- Gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(800px 500px at 50% -10%, rgba(255, 122, 61, .18), transparent 60%), var(--bg); }
.gate-card { width: min(420px, 100%); padding: 36px 30px; border-radius: 22px; background: var(--gate-card); border: 1px solid var(--line-2); backdrop-filter: blur(16px); text-align: center; box-shadow: 0 40px 80px -30px var(--shadow-c); }
.gate-logo { display: grid; place-items: center; margin-bottom: 16px; }
.gate-card h1 { font-size: 1.6rem; letter-spacing: -.03em; margin-bottom: 4px; }
.gate-card > p { color: var(--muted); margin-bottom: 22px; }
.gate-card strong { color: var(--text); }
.login { display: grid; gap: 12px; text-align: left; }
.login label { display: grid; gap: 6px; font-size: .84rem; color: var(--text-2); font-weight: 500; }
.login input { height: 44px; }
.login .linkish { justify-self: center; }
.form-msg { font-size: .85rem; min-height: 1.2em; text-align: center; }
.form-msg.err { color: var(--err); }
.form-msg.ok { color: var(--ok); }
.or { display: flex; align-items: center; gap: 12px; color: var(--dim); font-size: .8rem; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.back { display: inline-block; margin-top: 18px; color: var(--muted); font-size: .85rem; }
.row-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--ember); animation: spin .8s linear infinite; margin: 40px auto; }
.spinner.sm { width: 22px; height: 22px; border-width: 2.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--side-bg); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 600; letter-spacing: -.02em; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; scrollbar-width: thin; }
.nav-group { margin-top: 10px; }
.nav-group p { font: 500 .68rem var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--dim); padding: 8px 10px 4px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; color: var(--muted); font-size: .9rem; transition: background .12s, color .12s; position: relative; }
.side-nav a:hover { background: var(--hover); color: var(--text); }
.side-nav a.active { background: rgba(255, 122, 61, .1); color: var(--text); }
.side-nav a.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--grad); }
.side-nav a.active .i { color: var(--ember); }
.side-nav em { margin-left: auto; font-style: normal; font: 500 .7rem var(--mono); background: var(--ember); color: #1a0d05; border-radius: 999px; padding: 1px 7px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.side-user div { display: grid; min-width: 0; flex: 1; line-height: 1.3; }
.side-user strong { font-weight: 500; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user small { color: var(--dim); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--grad); color: #fff; font-weight: 600; font-size: .78rem; overflow: hidden; flex-shrink: 0; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.lg { width: 42px; height: 42px; font-size: .9rem; }
.mini-av { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--chip); color: var(--text-2); font-size: .66rem; font-weight: 600; flex-shrink: 0; }
.who-chip { display: inline-flex; align-items: center; gap: 7px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--topbar-bg); backdrop-filter: blur(12px); }
.top-title { font-weight: 500; color: var(--muted); }
.menu-btn { display: none; }
.view { padding: 28px 28px 64px; max-width: 1400px; width: 100%; margin: 0 auto; }
.scrim { display: none; }

/* ---------- Page structure ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); letter-spacing: -.035em; font-weight: 600; line-height: 1.1; }
.page-head p.muted { margin-top: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line-2); }
.seg button { width: 34px; height: 28px; display: grid; place-items: center; border: 0; background: none; border-radius: 7px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--chip); color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px 18px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); display: grid; gap: 4px; min-width: 0; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat strong { font-size: 1.65rem; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat small { color: var(--dim); font-size: .78rem; }
.link-stat { transition: border-color .15s, background .15s; }
.link-stat:hover { border-color: var(--line-2); background: var(--panel-2); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select { width: auto; height: 36px; padding-top: 0; padding-bottom: 0; font-size: .86rem; }
.search { position: relative; display: flex; align-items: center; min-width: 220px; flex: 0 1 300px; }
.search .i { position: absolute; left: 11px; color: var(--dim); pointer-events: none; }
.search input { height: 36px; padding-left: 34px; font-size: .88rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font: 500 .7rem var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--dim); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
.table th[data-sort] { cursor: pointer; }
.table th[data-sort]:hover { color: var(--text-2); }
.table th.r { text-align: right; }
.sort { margin-left: 4px; color: var(--ember); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--text-2); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-id], .table tr.clickable { cursor: pointer; }
.table tbody tr[data-id]:hover td, .table tr.clickable:hover td { background: var(--hover); }
.table tfoot td { font-weight: 600; color: var(--text); border-top: 1px solid var(--line-2); border-bottom: 0; }
.table.compact td, .table.compact th { padding: 8px 12px; }
.u { display: flex; align-items: center; gap: 10px; }
.u div { display: grid; line-height: 1.3; }
.u strong { color: var(--text); font-weight: 500; }
.u small { color: var(--dim); }

/* Pills & tones */
.pill { display: inline-flex; align-items: center; font: 500 .72rem var(--sans); padding: 2px 9px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.tone-neutral { color: var(--muted); border-color: var(--line-2); }
.tone-orange { color: var(--t-orange); border-color: rgba(255, 122, 61, .4); background: rgba(255, 122, 61, .08); }
.tone-blue { color: var(--t-blue); border-color: rgba(96, 165, 250, .4); background: rgba(96, 165, 250, .08); }
.tone-green { color: var(--t-green); border-color: rgba(74, 222, 128, .38); background: rgba(74, 222, 128, .07); }
.tone-amber { color: var(--t-amber); border-color: rgba(255, 195, 90, .4); background: rgba(255, 195, 90, .07); }
.tone-red { color: var(--t-red); border-color: rgba(248, 113, 113, .45); background: rgba(248, 113, 113, .08); }
.tone-violet { color: var(--t-violet); border-color: rgba(167, 139, 250, .4); background: rgba(167, 139, 250, .08); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; border: 0; background: var(--dim); }
.dot.tone-orange { background: var(--ember); } .dot.tone-blue { background: #60a5fa; } .dot.tone-green { background: var(--ok); }
.dot.tone-amber { background: var(--gold); } .dot.tone-red { background: var(--err); } .dot.tone-violet { background: #a78bfa; } .dot.tone-neutral { background: var(--dot-neutral); }
.box-chip { display: inline-block; font: .78rem var(--mono); padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2); margin: 2px 0; }

/* Empty */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--r); display: grid; justify-items: center; gap: 8px; }
.empty h3 { color: var(--text); font-size: 1.05rem; font-weight: 600; }
.empty.small { padding: 28px 16px; border: 0; }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--ember); margin-bottom: 4px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-2); font-size: .86rem; margin-bottom: 12px; }
.notice.warn { border-color: rgba(255, 195, 90, .4); color: var(--gold); }
.notice.ok { border-color: rgba(74, 222, 128, .35); color: var(--ok); }

/* ---------- Board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; max-height: calc(100vh - 290px); min-height: 160px; transition: border-color .15s, background .15s; }
.col.over { border-color: var(--ember); background: rgba(255, 122, 61, .04); }
.col header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 500; font-size: .88rem; border-bottom: 1px solid var(--line); }
.col .count { color: var(--dim); font-size: .8rem; }
.col-sum { margin-left: auto; color: var(--muted); font: .78rem var(--mono); }
.col-body { padding: 10px; display: grid; gap: 8px; overflow-y: auto; align-content: start; }
.col-empty { color: var(--dim); font-size: .82rem; text-align: center; padding: 18px 0; border: 1px dashed var(--line); border-radius: 10px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; cursor: grab; display: grid; gap: 7px; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--line-2); }
.card.dragging { opacity: .45; transform: rotate(1.5deg); }
.card strong { font-weight: 500; font-size: .9rem; line-height: 1.35; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .78rem; color: var(--muted); }
.card-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.card-meta .mini-av { margin-left: auto; }
.bar { width: 100%; height: 4px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--grad); border-radius: 4px; }

/* ---------- Drawer ---------- */
dialog.drawer { margin: 0 0 0 auto; height: 100%; max-height: 100%; width: min(560px, 100%); border: 0; border-left: 1px solid var(--line-2); background: var(--panel); color: var(--text); padding: 0; }
dialog.drawer.wide { width: min(860px, 100%); }
dialog.drawer::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px); }
dialog.drawer[open] { animation: slidein .22s ease; }
@keyframes slidein { from { transform: translateX(32px); opacity: 0; } }
.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 1.3rem; letter-spacing: -.025em; font-weight: 600; }
.drawer-head .sub { color: var(--dim); font-size: .8rem; margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 24px; }
.drawer-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--foot-bg); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > label { font-size: .8rem; font-weight: 500; color: var(--text-2); }
.field small { color: var(--dim); font-size: .76rem; }
.req { color: var(--ember); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 18px; }
.mini-stats div { padding: 12px 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); display: grid; }
.mini-stats span { font-size: .76rem; color: var(--dim); }
.mini-stats strong { font-size: 1.05rem; font-weight: 600; }
.choice { display: grid; gap: 8px; }
.choice label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-2); cursor: pointer; transition: border-color .15s, background .15s; }
.choice label:has(input:checked) { border-color: var(--ember); background: rgba(255, 122, 61, .06); }
.choice input { margin-top: 3px; }
.choice span { display: grid; }
.choice small { color: var(--muted); font-size: .8rem; }
.addr { display: flex; align-items: center; gap: 8px; }
.addr span { color: var(--muted); font-family: var(--mono); font-size: .86rem; white-space: nowrap; }
.cred { margin-top: 8px; padding: 18px; border-radius: 14px; border: 1px solid rgba(74, 222, 128, .35); background: rgba(74, 222, 128, .05); display: grid; gap: 10px; }
.cred h4 { display: flex; align-items: center; gap: 8px; color: var(--ok); }
.cred pre { font: .86rem/1.7 var(--mono); padding: 12px; border-radius: 10px; background: var(--input-bg); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-all; }

/* Tabs */
.tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 18px; }
.tabs button { background: none; border: 0; padding: 8px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: .88rem; }
.tabs button[aria-selected="true"] { background: var(--tab-on); color: var(--text); }

/* ---------- Panels & dashboard ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h3 { font-size: 1rem; font-weight: 600; letter-spacing: -.01em; }
.dash-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.dash-grid.two { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }
.quick .btn { height: 34px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--text); font-weight: 600; }
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--dim); font: 11px var(--sans); }
.chart path { transition: opacity .15s; }
.chart:hover path { opacity: .55; }
.chart path:hover { opacity: 1; }
.tip { position: absolute; pointer-events: none; min-width: 180px; padding: 10px 12px; border-radius: 10px; background: var(--pop); border: 1px solid var(--line-2); box-shadow: 0 16px 40px -12px var(--shadow-c); display: grid; gap: 4px; font-size: .82rem; z-index: 5; }
.tip span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tip b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.table-toggle { margin-top: 10px; font-size: .84rem; }
.table-toggle summary { color: var(--muted); cursor: pointer; }
.table-toggle table { margin-top: 10px; }

.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 130px) 1fr auto; gap: 10px; align-items: center; font-size: .84rem; }
.hb-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-track { height: 10px; border-radius: 4px; background: var(--track); overflow: hidden; }
.hb-track i { display: block; height: 100%; min-width: 2px; background: var(--rev); border-radius: 0 4px 4px 0; }
.hbars.blue .hb-track i { background: var(--exp); }
.hb-val { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.hb-val small { color: var(--dim); }

.list { list-style: none; display: grid; }
.list li > a, .list li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.list li > a { width: 100%; border: 0; padding: 0; }
.list li:last-child { border-bottom: 0; }
.list li > a:hover .li-main { color: var(--gold); }
.li-main { flex: 1; min-width: 0; display: grid; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-main small { color: var(--dim); font-size: .76rem; }
.li-side { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.feed { list-style: none; display: grid; gap: 12px; }
.feed li { display: flex; gap: 10px; align-items: flex-start; font-size: .86rem; }
.feed p { color: var(--muted); line-height: 1.4; }
.feed b { color: var(--text); font-weight: 500; }
.feed small { display: block; color: var(--dim); font-size: .74rem; }

/* ---------- Mail ---------- */
.mail { display: grid; grid-template-columns: 210px minmax(280px, 380px) 1fr; height: calc(100vh - 56px - 28px - 40px); min-height: 520px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.mail-side { padding: 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.mail-folders { display: grid; gap: 2px; }
.mail-folders button, .mail-boxes button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 9px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .88rem; }
.mail-folders button:hover, .mail-boxes button:hover { background: var(--hover); color: var(--text); }
.mail-folders button.on, .mail-boxes button.on { background: rgba(255, 122, 61, .1); color: var(--text); }
.mail-folders em { margin-left: auto; font: 500 .7rem var(--mono); font-style: normal; background: var(--ember); color: #1a0d05; padding: 1px 7px; border-radius: 999px; }
.mail-boxes { display: grid; gap: 2px; }
.mail-boxes p { font: 500 .68rem var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--dim); padding: 4px 10px; }
.mail-boxes button { font-family: var(--mono); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.mail-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.mail-list-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.mail-list-head .search { flex: 1; min-width: 0; }
.mail-items { overflow-y: auto; flex: 1; }
.mail-item { display: flex; gap: 10px; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; position: relative; }
.mail-item:hover { background: var(--hover); }
.mail-item.on { background: rgba(255, 122, 61, .08); }
.mail-item.unread::before { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--ember); }
.mail-item .av { width: 32px; height: 32px; font-size: .7rem; background: var(--chip); color: var(--text-2); }
.mail-item.unread .av { background: var(--grad); color: #fff; }
.mi-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.mi-top { display: flex; gap: 8px; align-items: baseline; }
.mi-top b { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.mail-item.unread .mi-top b { color: var(--text); font-weight: 600; }
.mi-top time { color: var(--dim); font-size: .74rem; white-space: nowrap; }
.mi-subj { display: flex; gap: 5px; align-items: center; color: var(--muted); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.unread .mi-subj { color: var(--text-2); }
.star-on { color: var(--gold) !important; }
.star-on .i { fill: var(--gold); }
.more { margin: 10px auto; display: flex; width: calc(100% - 20px); }
.mail-read { overflow-y: auto; padding: 20px 24px; min-width: 0; }
.read-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.read-head h2 { flex: 1; font-size: 1.25rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.3; }
.read-actions { display: flex; gap: 4px; }
.back-btn { display: none; }
.read-meta { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.read-meta > div { flex: 1; min-width: 0; display: grid; }
.read-meta small { color: var(--dim); font-size: .78rem; overflow-wrap: anywhere; }
.read-body { margin: 6px 0 14px; }
.mail-frame { width: 100%; min-height: 240px; border: 0; border-radius: 12px; background: #fff; }
.mail-text { white-space: pre-wrap; font: .9rem/1.6 var(--sans); color: var(--text-2); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.att { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line-2); font-size: .82rem; cursor: pointer; }
.att small { color: var(--dim); }
.att button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }
.read-foot { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--line); }
.setup-card { grid-column: 1 / -1; max-width: 640px; margin: 48px auto; padding: 32px; display: grid; gap: 12px; }
.setup-card ol { padding-left: 20px; display: grid; gap: 8px; color: var(--text-2); }
.setup-card code { font: .82rem var(--mono); background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }

.compose { display: grid; gap: 0; }
.c-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.c-row label { width: 64px; color: var(--dim); font-size: .84rem; flex-shrink: 0; }
.c-row input, .c-row select { border: 0; background: transparent; box-shadow: none !important; padding: 9px 4px; }
.rte-bar { display: flex; gap: 2px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rte-bar button { min-width: 30px; height: 30px; border-radius: 7px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.rte-bar button:hover { background: var(--hover); color: var(--text); }
.attach-btn { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); cursor: pointer; padding: 5px 10px; border-radius: 8px; }
.attach-btn:hover { background: var(--hover); color: var(--text); }
.rte { min-height: 280px; padding: 14px 4px; outline: none; line-height: 1.6; color: var(--text-2); overflow-wrap: anywhere; }
.rte a { color: var(--gold); text-decoration: underline; }
.rte ul, .rte ol { padding-left: 22px; }
.rte .sig { color: var(--muted); }
.rte table { max-width: 100%; }
.att-list { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }

/* ---------- Invoices ---------- */
.items { margin: 22px 0 8px; }
.items-head, .item-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px 120px 130px 34px; gap: 8px; align-items: center; }
.items-head { font: 500 .7rem var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--dim); padding: 0 2px 8px; border-bottom: 1px solid var(--line); }
.item-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.item-row input { height: 36px; }
.item-row .num { color: var(--text); }
.items > .btn { margin-top: 10px; }
.inv-bottom { display: grid; grid-template-columns: 1fr 300px; gap: 20px; margin-top: 14px; align-items: start; }
.totals { display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.totals > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .9rem; }
.totals > div > span { color: var(--muted); display: flex; align-items: center; gap: 4px; }
.totals .sm-input { width: 120px; text-align: right; }
.totals b { font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--line-2); padding-top: 10px; margin-top: 4px; font-size: 1.1rem; }
.totals .grand span { color: var(--text); font-weight: 600; }

/* ---------- Attendance ---------- */
.att-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.today-card { display: grid; gap: 14px; background: radial-gradient(400px 200px at 50% 0%, rgba(255, 122, 61, .12), transparent 70%), var(--panel); }
.clock { font-size: 3rem; font-weight: 600; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.today-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.today-stats div { display: grid; padding: 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.today-stats span { font-size: .72rem; color: var(--dim); }
.today-stats b { font-weight: 600; font-variant-numeric: tabular-nums; }
.mode { display: flex; gap: 16px; font-size: .88rem; }
.mode label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- Settings ---------- */
.settings-form { display: grid; gap: 18px; max-width: 900px; }
.settings-form h3 { font-size: .95rem; font-weight: 600; padding-top: 6px; border-top: 1px solid var(--line); padding-top: 18px; }
.settings-form h3:first-child { border-top: 0; padding-top: 0; }
.form-foot { display: flex; justify-content: flex-end; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; translate: -50% 16px; padding: 11px 16px; border-radius: 11px; background: var(--pop); border: 1px solid var(--line-2); font-size: .88rem; opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s; z-index: 1000; max-width: calc(100% - 32px); box-shadow: 0 16px 40px -12px var(--shadow-c); }
.toast.show { opacity: 1; translate: -50% 0; }
.toast[data-kind="err"] { border-color: rgba(248, 113, 113, .5); color: var(--t-red); }
.toast[data-kind="ok"] { border-color: rgba(74, 222, 128, .4); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .mail { grid-template-columns: 180px minmax(240px, 320px) 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; z-index: 60; transform: translateX(-100%); transition: transform .25s ease; }
  .app.nav-open .sidebar { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .6); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .55); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .view { padding: 20px 16px 56px; }
  .dash-grid, .dash-grid.two { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .att-grid { grid-template-columns: 1fr; }
  .mail { grid-template-columns: 1fr; height: calc(100vh - 56px - 76px); }
  .mail-side { border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; gap: 8px; }
  .mail-side > .btn { width: auto; }
  .mail-folders { display: flex; }
  .mail-folders button span { display: none; }
  .mail-boxes { display: none; }
  .mail-read { display: none; }
  .mail.reading .mail-list, .mail.reading .mail-side { display: none; }
  .mail.reading .mail-read { display: block; }
  .back-btn { display: inline-grid; }
  .inv-bottom { grid-template-columns: 1fr; }
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 70px 100px 34px; }
  .item-row input[data-k=desc] { grid-column: 1 / -1; }
  .item-row [data-amt] { display: none; }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .search { flex: 1 1 100%; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat strong { font-size: 1.3rem; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .hbar { grid-template-columns: 84px 1fr auto; }
  .topbar .btn { display: none; }
}

/* ---------- Mail (Resend Inboxes) ---------- */
.mail-boxes button { display: flex; align-items: center; gap: 6px; }
.mail-boxes button span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-boxes em { font: 500 .68rem var(--mono); font-style: normal; background: var(--ember); color: #1a0d05; padding: 0 6px; border-radius: 999px; }
.mail-boxes .missing { opacity: .7; }
.mail-boxes .missing small { color: var(--gold); font-family: var(--sans); font-size: .72rem; }
.mail-labels { display: grid; gap: 2px; }
.mail-labels p { display: flex; justify-content: space-between; align-items: center; font: 500 .68rem var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--dim); padding: 4px 10px; }
.mail-labels p .linkish { font-size: 1rem; padding: 0 4px; }
.mail-labels > button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 7px 10px; border-radius: 9px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .86rem; }
.mail-labels > button:hover { background: var(--hover); color: var(--text); }
.mail-labels > button.on { background: rgba(255, 122, 61, .1); color: var(--text); }
.mail-labels i, .label-menu i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.mail-labels > .muted { padding: 4px 10px; }
.mi-top .count { font: .7rem var(--mono); color: var(--dim); }
.mi-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.mi-labels.big { margin: -6px 0 14px; }
.lbl { font-size: .68rem; padding: 1px 7px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); color: color-mix(in srgb, var(--c) 70%, white); background: color-mix(in srgb, var(--c) 12%, transparent); }
.draft { font-size: .7rem; color: var(--err); margin-right: 2px; }
.read-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 16px; }
.label-menu { position: relative; }
.label-menu summary { list-style: none; }
.label-menu summary::-webkit-details-marker { display: none; }
.label-menu .menu { position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; min-width: 200px; padding: 8px; border-radius: 12px; background: var(--pop); border: 1px solid var(--line-2); box-shadow: 0 16px 40px -12px var(--shadow-c); display: grid; gap: 6px; }
.label-menu .check { gap: 8px; }
.msgs { display: grid; gap: 10px; }
.msg { border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); overflow: hidden; }
.msg.out { border-color: rgba(255, 122, 61, .25); }
.msg-head { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; cursor: pointer; }
.msg-head .av { width: 32px; height: 32px; font-size: .7rem; background: var(--chip); color: var(--text-2); }
.msg-head .av.me { background: var(--grad); color: #fff; }
.msg-who { flex: 1; min-width: 0; display: grid; line-height: 1.4; }
.msg-who small { color: var(--dim); font-size: .76rem; overflow-wrap: anywhere; }
.msg-snip { color: var(--dim); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.open .msg-snip { display: none; }
.msg-body, .msg .attachments, .msg-actions { display: none; }
.msg.open .msg-body { display: block; padding: 0 14px 10px; }
.msg.open .attachments { display: flex; padding: 0 14px; }
.msg.open .msg-actions { display: flex; gap: 10px; padding: 4px 10px 10px; }
.read-foot { margin-top: 16px; }
.setup-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Theme toggle & mobile ---------- */
.theme-icon { color: var(--text-2); }
.bottombar { display: none; }
.board { scroll-snap-type: x proximity; }
.col { scroll-snap-align: start; }

@media (max-width: 900px) {
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--topbar-bg); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottombar a, .bottombar button { display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--dim); font-size: .68rem; background: none; border: 0; cursor: pointer; }
  .bottombar .active { color: var(--ember); }
  .view { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .mail { height: calc(100dvh - 56px - 40px - 72px); min-height: 420px; }
  .mail-side { gap: 6px; }
  .mail-side > .btn { order: 3; height: 34px; padding: 0 12px; }
  .mail-boxes { display: flex; order: 1; width: 100%; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .mail-boxes p { display: none; }
  .mail-boxes button { width: auto; flex-shrink: 0; border: 1px solid var(--line-2); border-radius: 999px; padding: 5px 10px; }
  .mail-folders { order: 2; flex: 1; overflow-x: auto; scrollbar-width: none; }
  .mail-labels { display: none; }
  .read-tools .btn span, .read-tools .btn { font-size: .8rem; }
  .board { grid-auto-columns: 82%; }
  .col { max-height: none; }
  dialog.drawer { width: 100%; }
}

/* Lists become cards on phones */
@media (max-width: 640px) {
  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table-wrap:has(.table.cards) { border: 0; background: none; overflow: visible; }
  .table.cards tr { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px 14px; margin-bottom: 10px; }
  .table.cards td { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); max-width: none; white-space: normal; text-align: right; }
  .table.cards td:last-child { border-bottom: 0; }
  .table.cards td::before { content: attr(data-label); color: var(--dim); font-size: .78rem; text-align: left; flex-shrink: 0; }
  .table.cards td.strong { font-size: .98rem; padding-top: 10px; }
  .table.cards td.strong::before { display: none; }
  .table.cards td.strong { justify-content: flex-start; text-align: left; }
  .table.cards tbody tr[data-id]:hover td { background: none; }
  .page-head { align-items: flex-start; }
  .page-head .head-actions { width: 100%; }
  .head-actions .btn.primary { margin-left: auto; }
  .toolbar select { flex: 1 1 calc(50% - 4px); }
  .read-tools { gap: 4px; }
  .msg-head time { display: none; }
  .clock { font-size: 2.4rem; }
  .today-stats b { font-size: .86rem; }
  .gate-card { padding: 28px 20px; }
}

@media (max-width: 640px) {
  .head-actions.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .head-actions.quick .btn { width: 100%; margin: 0; }
}
@media (max-width: 900px) {
  .mail { grid-template-rows: auto minmax(0, 1fr); }
  .mail.reading { grid-template-rows: minmax(0, 1fr); }
  .mail-side { align-content: flex-start; align-items: center; }
  .mail-side > .btn[data-compose] {
    position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 40;
    height: 52px; padding: 0 20px; border-radius: 999px; box-shadow: 0 12px 30px -10px var(--rose);
  }
  .mail.reading .mail-side > .btn[data-compose] { display: none; }
  .mail-folders { width: 100%; }
  .mail-folders button { width: auto; flex: 1 0 auto; justify-content: center; }
}
