/* ---- Tokens ----
   Ink rail + paper workspace; signal-teal accent (server status-LED green-teal);
   Space Grotesk carries numbers & headings, Inter carries body. */
:root {
  --ink: #171c28;
  --ink-2: #202737;
  --rail-text: #97a1b4;
  --workspace: #f4f6f8;
  --card: #ffffff;
  --line: #e4e8ed;
  --text: #1e2430;
  --muted: #67707f;
  --accent: #0e9484;
  --accent-dark: #0b7263;
  --accent-soft: #e2f3f0;
  --amber: #c77e0a;
  --amber-soft: #fdf3e2;
  --red: #c2412e;
  --red-soft: #fbeae7;
  --radius: 10px;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-body); font-size: 14px; color: var(--text); background: var(--workspace); }
h1, h2, h3, .num { font-family: var(--font-display); }
a { color: var(--accent-dark); }
button { font-family: var(--font-body); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  linear-gradient(160deg, var(--ink) 0%, #1d2434 55%, #14332f 100%); }
.login-card { width: min(400px, 92vw); background: var(--card); border-radius: 14px; padding: 34px 32px; box-shadow: 0 24px 60px rgba(10,14,22,.45); }
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.login-card h1 { font-size: 21px; margin: 0; letter-spacing: -.01em; }
.login-card p.sub { color: var(--muted); margin: 4px 0 20px; font-size: 13px; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--ink); color: var(--rail-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.rail .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; color: #fff; }
.rail .brand span { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.rail a.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--rail-text); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; }
.rail a.nav:hover { background: var(--ink-2); color: #e8ecf3; }
.rail a.nav.active { background: var(--ink-2); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.rail .access { font-size: 10px; font-weight: 600; letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; background: rgba(255,255,255,.08); }
.rail .access.w { color: #7be0d2; }
.rail .spacer { flex: 1; }
.rail .userchip { border-top: 1px solid rgba(255,255,255,.09); padding: 12px 10px 4px; font-size: 12.5px; }
.rail .userchip b { color: #fff; display: block; font-weight: 600; }
.rail .userchip .role { text-transform: capitalize; }
.rail .userchip .links { margin-top: 8px; display: flex; gap: 12px; }
.rail .userchip a { color: var(--rail-text); cursor: pointer; text-decoration: none; }
.rail .userchip a:hover { color: #fff; }

.main { padding: 26px 30px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---- Cards / KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.kpi .num { font-size: 26px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .shell { grid-template-columns: 60px 1fr; } .rail a.nav span.txt, .rail .brand span, .rail .userchip, .rail .access { display:none; } .main { padding: 18px 14px 50px; } }
.card h2 { font-size: 15px; margin: 0 0 12px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 34px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge.teal { background: var(--accent-soft); color: var(--accent-dark); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.gray { background: #eef0f3; color: var(--muted); }

/* ---- Forms ---- */
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font-weight: 500; font-size: 13.5px; cursor: pointer; }
.btn:hover { border-color: #c9cfd8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.error-box { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,19,28,.5); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { background: var(--card); border-radius: 14px; width: min(620px, 100%); max-height: 88vh; overflow: auto; padding: 24px 26px; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Toolbar / search ---- */
.toolbar { display: flex; gap: 10px; align-items: center; }
.toolbar input[type="search"] { width: 240px; }

/* ---- Access matrix (Users page) ---- */
.matrix select { padding: 5px 8px; width: auto; font-size: 12.5px; }
.matrix td { padding: 8px 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 13.5px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.3); }

/* ---- Pipeline mini-bars ---- */
.pipe-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.pipe-row .stage { width: 92px; color: var(--muted); }
.pipe-row .bar { flex: 1; height: 8px; background: #eef0f3; border-radius: 6px; overflow: hidden; }
.pipe-row .bar i { display: block; height: 100%; background: var(--accent); }
.pipe-row .val { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: no-preference) {
  .modal { animation: pop .16s ease-out; }
  @keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
}

/* ================= v2 polish ================= */

/* ---- Shell with topbar ---- */
.workarea { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 30px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topdate { margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-size: 12.5px; font-weight: 600; flex: none; }

/* ---- Global search ---- */
.gsearch-wrap { position: relative; display: flex; align-items: center; gap: 8px; background: var(--workspace); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: min(420px, 50vw); color: var(--muted); }
.gsearch-wrap:focus-within { border-color: var(--accent); background: #fff; }
.gsearch-wrap .ico { width: 15px; height: 15px; flex: none; }
.gsearch-wrap input { border: none; background: transparent; padding: 0; font-size: 13.5px; outline: none !important; }
.gsearch-wrap .kbd { font-size: 10.5px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; background: #fff; color: var(--muted); }
.search-pop { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 16px 40px rgba(15,19,28,.14); overflow: hidden; max-height: 60vh; overflow-y: auto; }
.sp-group { font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding: 9px 13px 4px; }
.sp-item { display: block; padding: 8px 13px; cursor: pointer; color: var(--text); text-decoration: none; }
.sp-item:hover { background: var(--accent-soft); }
.sp-item b { display: block; font-size: 13px; font-weight: 600; }
.sp-item span { font-size: 12px; color: var(--muted); }
.sp-empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---- Rail icons ---- */
.ico { width: 16px; height: 16px; vertical-align: -3px; }
.navlabel { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rail a.nav .ico { flex: none; opacity: .75; }
.rail a.nav.active .ico { opacity: 1; color: #7be0d2; }

/* ---- KPI cards ---- */
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-ico { color: var(--accent); background: var(--accent-soft); border-radius: 7px; width: 27px; height: 27px; display: grid; place-items: center; flex: none; }
.kpi-ico .ico { width: 14px; height: 14px; }
.card.kpi { transition: box-shadow .15s ease, transform .15s ease; }
.card.kpi:hover { box-shadow: 0 6px 18px rgba(15,19,28,.07); transform: translateY(-1px); }

/* ---- Revenue chart ---- */
.chart-card { margin-bottom: 22px; }
.chart { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; min-width: 0; }
.chart-bar { width: 100%; max-width: 58px; background: #bfe3dd; border-radius: 6px 6px 2px 2px; transition: height .4s cubic-bezier(.2,.8,.2,1); }
.chart-bar.now { background: var(--accent); }
.chart-col:hover .chart-bar { background: var(--accent-dark); }
.chart-val { font-family: var(--font-display); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; height: 14px; }
.chart-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- Segmented control ---- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: none; background: transparent; padding: 8px 14px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--ink); color: #fff; }

/* ---- Kanban board ---- */
.kanban { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; align-items: start; }
@media (max-width: 1100px) { .kanban { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .kanban { grid-template-columns: repeat(2, 1fr); } }
.kb-col { background: #eef0f4; border-radius: 10px; padding: 9px; min-height: 130px; border: 1.5px dashed transparent; }
.kb-col.over { border-color: var(--accent); background: var(--accent-soft); }
.kb-head { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 2px 4px; }
.kb-count { background: var(--card); border-radius: 10px; padding: 0 7px; font-size: 11px; }
.kb-total { font-family: var(--font-display); font-size: 11.5px; color: var(--muted); padding: 1px 4px 7px; font-variant-numeric: tabular-nums; min-height: 20px; }
.kb-cards { display: flex; flex-direction: column; gap: 7px; }
.kb-card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; cursor: grab; box-shadow: 0 1px 2px rgba(15,19,28,.05); }
.kb-card:hover { border-color: #c6cdd6; }
.kb-card.dragging { opacity: .45; }
.kb-card b { display: block; font-size: 12.8px; line-height: 1.35; }
.kb-company { font-size: 11.5px; color: var(--muted); display: block; margin-top: 1px; }
.kb-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.kb-meta .num { font-family: var(--font-display); font-size: 12px; font-variant-numeric: tabular-nums; }
.kb-owner { width: 21px; height: 21px; border-radius: 50%; background: var(--ink-2); color: #cfd6e0; font-size: 9.5px; font-weight: 600; display: grid; place-items: center; }

/* ---- Sortable headers ---- */
.main table th { cursor: pointer; user-select: none; }
.main table th.sorted-asc::after { content: " ↑"; color: var(--accent-dark); }
.main table th.sorted-desc::after { content: " ↓"; color: var(--accent-dark); }

/* ---- Toast variants ---- */
.toast.error { background: var(--red); }
.toast.success { background: var(--accent-dark); }

/* ---- Page entrance ---- */
@media (prefers-reduced-motion: no-preference) {
  .main > * { animation: fadeUp .28s ease-out both; }
  .main > *:nth-child(2) { animation-delay: .04s; }
  .main > *:nth-child(3) { animation-delay: .08s; }
  @keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---- Login polish ---- */
.login-card p.tagline { color: var(--muted); font-size: 12px; margin: 18px 0 0; text-align: center; }

/* ---- Mobile adjustments for topbar ---- */
@media (max-width: 900px) {
  .topbar { padding: 10px 14px; }
  .topdate { display: none; }
  .gsearch-wrap .kbd { display: none; }
}

/* ---- SGD summary box (tax invoices) ---- */
.sgd-box { border: 1.5px solid var(--ink); border-radius: 8px; padding: 10px 14px; margin: 12px 0 0 auto; width: fit-content; min-width: 240px; }
.sgd-box div { display: flex; justify-content: space-between; gap: 24px; font-size: 12.5px; padding: 2px 0; }
.sgd-box span { color: var(--muted); }
.sgd-box b { font-variant-numeric: tabular-nums; font-family: var(--font-display); }
