/* ==========================================================================
   Sur Bathiang ERP
   --------------------------------------------------------------------------
   The palette is borrowed from a mixing console's meter bridge: green for
   signal, amber for approaching limit, red for clip. Those three states map
   directly onto the operational ones this tool has to show at a glance —
   settled / outstanding / overdue — so colour carries meaning, not decoration.
   ========================================================================== */

:root {
  /* Ground and ink — a slate with a cool blue bias, not a neutral grey. */
  --ground:      #F4F6F8;
  --surface:     #FFFFFF;
  --surface-2:   #EDF1F5;
  --line:        #D9E0E8;
  --line-strong: #C2CCD8;

  --ink:         #131A22;
  --ink-2:       #47566A;
  --ink-3:       #74839A;

  /* Console meter states. */
  --signal:      #1E8E5A;   /* healthy / paid / complete   */
  --signal-bg:   #E4F3EC;
  --hold:        #B87514;   /* pending / due / in progress */
  --hold-bg:     #FAF0DD;
  --clip:        #C0392B;   /* overdue / stalled / error   */
  --clip-bg:     #FBEAE8;
  --idle:        #5B6B80;   /* neutral / closed / archived */
  --idle-bg:     #E9EDF2;

  /* Brand accent — deep console blue, used for interactive affordances. */
  --accent:      #1D4E7C;
  --accent-ink:  #FFFFFF;
  --accent-soft: #E6EEF6;

  --radius:      6px;
  --radius-sm:   4px;
  --sidebar-w:   232px;
  --header-h:    56px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
          Menlo, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(19, 26, 34, .06);
  --shadow:    0 2px 8px rgba(19, 26, 34, .08);
  --shadow-lg: 0 8px 28px rgba(19, 26, 34, .14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:      #0E141B;
    --surface:     #161E27;
    --surface-2:   #1D2732;
    --line:        #27333F;
    --line-strong: #35434F;

    --ink:         #E8EDF3;
    --ink-2:       #A2B1C2;
    --ink-3:       #74849A;

    --signal:      #46B884;  --signal-bg: #12291F;
    --hold:        #D9A03C;  --hold-bg:   #2C2416;
    --clip:        #E06B5C;  --clip-bg:   #2E1A18;
    --idle:        #8494A8;  --idle-bg:   #1E2833;

    --accent:      #5A9BD4;  --accent-ink: #0E141B;  --accent-soft: #17293A;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow:    0 2px 8px rgba(0, 0, 0, .38);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --ground: #0E141B; --surface: #161E27; --surface-2: #1D2732;
  --line: #27333F; --line-strong: #35434F;
  --ink: #E8EDF3; --ink-2: #A2B1C2; --ink-3: #74849A;
  --signal: #46B884; --signal-bg: #12291F;
  --hold: #D9A03C;   --hold-bg: #2C2416;
  --clip: #E06B5C;   --clip-bg: #2E1A18;
  --idle: #8494A8;   --idle-bg: #1E2833;
  --accent: #5A9BD4; --accent-ink: #0E141B; --accent-soft: #17293A;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 2px 8px rgba(0,0,0,.38);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.5);
}

/* ── Base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Money and any column of digits line up. */
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

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

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}

.brand {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: .78rem; letter-spacing: -.02em;
  flex: 0 0 auto;
}
.brand-name { font-weight: 650; font-size: .92rem; letter-spacing: -.01em; }
.brand-sub  { font-size: .68rem; color: var(--ink-3); line-height: 1; }

.nav { padding: .75rem .5rem; overflow-y: auto; flex: 1 1 auto; }
.nav-group-label {
  font-size: .66rem; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
  padding: .75rem .75rem .3rem;
}
.nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .75rem; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; font-size: .855rem;
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a svg { width: 16px; height: 16px; flex: 0 0 auto; opacity: .85; }

.sidebar-foot { border-top: 1px solid var(--line); padding: .6rem .75rem; flex: 0 0 auto; }
.who { display: flex; align-items: center; gap: .55rem; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-2);
  display: grid; place-items: center; font-size: .72rem; font-weight: 650;
  flex: 0 0 auto;
}
.who-name { font-size: .8rem; font-weight: 600; line-height: 1.2; }
.who-role { font-size: .68rem; color: var(--ink-3); text-transform: capitalize; }

.main { flex: 1 1 auto; margin-left: var(--sidebar-w); min-width: 0; }

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.25rem;
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 1.02rem; font-weight: 650; letter-spacing: -.015em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.content { padding: 1.25rem; max-width: 1400px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-family: inherit; font-size: .83rem; font-weight: 600;
  padding: .48rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-danger  { color: var(--clip); border-color: var(--line-strong); }
.btn-danger:hover { background: var(--clip-bg); border-color: var(--clip); }
.btn-sm { padding: .3rem .6rem; font-size: .76rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: .9rem; font-weight: 650; letter-spacing: -.01em; }
.card-head .btn { margin-left: auto; }
.card-body { padding: 1rem; }
.card-foot {
  padding: .6rem 1rem; border-top: 1px solid var(--line);
  background: var(--surface-2); font-size: .78rem; color: var(--ink-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── KPI tiles ────────────────────────────────────────────────────────── */
.kpis {
  display: grid; gap: .75rem; margin-bottom: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .85rem .95rem;
  box-shadow: var(--shadow-sm);
  /* The left rail carries the state colour — readable before the number. */
  border-left: 3px solid var(--idle);
}
.kpi.is-signal { border-left-color: var(--signal); }
.kpi.is-hold   { border-left-color: var(--hold); }
.kpi.is-clip   { border-left-color: var(--clip); }
.kpi-label {
  font-size: .7rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: .3rem;
}
.kpi-value {
  font-size: 1.5rem; font-weight: 700; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; line-height: 1.15; color: var(--ink);
}
.kpi-meta { font-size: .75rem; color: var(--ink-2); margin-top: .2rem; }
.kpi-delta { font-weight: 600; }
.kpi-delta.up   { color: var(--signal); }
.kpi-delta.down { color: var(--clip); }

/* ── Tables ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .83rem; }
table.data th {
  text-align: left; font-size: .7rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3);
  padding: .55rem .75rem; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .primary { font-weight: 600; color: var(--ink); }
table.data .muted   { color: var(--ink-3); }
table.data a { font-weight: 550; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink-2); font-size: .92rem; margin-bottom: .25rem; }

/* ── Pills ────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .715rem; font-weight: 600; line-height: 1;
  padding: .26rem .5rem; border-radius: 100px; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.pill.ok   { background: var(--signal-bg); color: var(--signal); }
.pill.wait { background: var(--hold-bg);   color: var(--hold); }
.pill.new  { background: var(--accent-soft); color: var(--accent); }
.pill.work { background: var(--idle-bg);   color: var(--idle); }
.pill.bad  { background: var(--clip-bg);   color: var(--clip); }
/* A dot before the label so state survives greyscale and colour-blindness. */
.pill::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; flex: 0 0 auto;
}
.pill.plain::before { display: none; }

/* ── Filters ──────────────────────────────────────────────────────────── */
.filters {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .75rem 1rem; border-bottom: 1px solid var(--line);
}
.filters input[type="search"], .filters input[type="text"],
.filters input[type="date"], .filters select {
  font-family: inherit; font-size: .82rem;
  padding: .42rem .6rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  min-width: 0;
}
.filters input[type="search"] { flex: 1 1 220px; }
.filters label { font-size: .78rem; color: var(--ink-2); display: flex; align-items: center; gap: .35rem; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(2, 1fr); }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: .73rem; color: var(--ink-3); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: .87rem;
  padding: .52rem .65rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.check { flex-direction: row; align-items: center; gap: .5rem; }
.check input { width: auto; }
.form-actions {
  display: flex; gap: .5rem; align-items: center;
  padding-top: 1rem; margin-top: 1rem; border-top: 1px solid var(--line);
}

/* ── Alerts ───────────────────────────────────────────────────────────── */
.alert {
  padding: .65rem .85rem; border-radius: var(--radius);
  font-size: .84rem; margin-bottom: 1rem;
  border: 1px solid; display: flex; gap: .5rem; align-items: flex-start;
}
.alert-success { background: var(--signal-bg); border-color: var(--signal); color: var(--signal); }
.alert-error   { background: var(--clip-bg);   border-color: var(--clip);   color: var(--clip); }
.alert-info    { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.alert ul { margin: 0; padding-left: 1.1rem; }

/* ── Detail header ────────────────────────────────────────────────────── */
.detail-head {
  display: flex; align-items: flex-start; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.detail-title h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.025em; line-height: 1.2; }
.detail-meta { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .35rem;
               font-size: .82rem; color: var(--ink-2); }
.detail-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

.grid-2 { display: grid; gap: 1rem; grid-template-columns: 2fr 1fr; align-items: start; }
.grid-halves { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* Definition rows in a detail sidebar. */
.dl { display: flex; flex-direction: column; }
.dl-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .83rem;
}
.dl-row:last-child { border-bottom: none; }
.dl-key { color: var(--ink-3); }
.dl-val { font-weight: 550; text-align: right; }

/* ── Money summary strip on a project ─────────────────────────────────── */
.money-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
.money-cell { background: var(--surface); padding: .8rem 1rem; }
.money-cell .k { font-size: .68rem; font-weight: 600; letter-spacing: .06em;
                 text-transform: uppercase; color: var(--ink-3); }
.money-cell .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums;
                 letter-spacing: -.02em; margin-top: .15rem; }
.money-cell.owed .v { color: var(--clip); }
.money-cell.settled .v { color: var(--signal); }

/* ── Bar chart (income trend) ─────────────────────────────────────────── */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 130px; padding-top: .5rem; }
.chart-col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end;
             align-items: center; gap: .3rem; min-width: 0; height: 100%; }
.chart-bar {
  width: 100%; background: var(--accent); border-radius: 2px 2px 0 0;
  min-height: 2px; position: relative; transition: opacity .12s;
}
.chart-col:hover .chart-bar { opacity: .78; }
.chart-label { font-size: .65rem; color: var(--ink-3); white-space: nowrap; }

/* ── Pagination ───────────────────────────────────────────────────────── */
.pager { display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem;
         border-top: 1px solid var(--line); font-size: .8rem; color: var(--ink-2); }
.pager .spacer { margin-left: auto; }
.pager a, .pager span.current {
  padding: .28rem .55rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); font-weight: 600; font-size: .78rem;
}
.pager span.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pager a:hover { background: var(--surface-2); text-decoration: none; }

/* ── Auth page ────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
             background: var(--ground); }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: .65rem; justify-content: center;
              margin-bottom: 1.25rem; }
.auth-brand .brand-mark { width: 34px; height: 34px; font-size: .92rem; }
.auth-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -.02em; }
.auth-sub { font-size: .78rem; color: var(--ink-3); }
.auth-foot { text-align: center; font-size: .74rem; color: var(--ink-3); margin-top: 1rem; }

/* ── Mobile ───────────────────────────────────────────────────────────── */
.menu-toggle { display: none; }

@media (max-width: 900px) {
  .grid-2, .grid-halves { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .menu-toggle { display: inline-flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }

  .scrim {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
    z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }

  .content { padding: .85rem; }
  .money-strip { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.3rem; }
  .filters { padding: .6rem .75rem; }
  .filters input[type="search"] { flex: 1 1 100%; }
  .detail-actions { margin-left: 0; width: 100%; }
}

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

@media print {
  .sidebar, .topbar, .filters, .form-actions, .detail-actions, .pager { display: none !important; }
  .main { margin-left: 0; }
  .card { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
}
