/* =====================================================================
   CARL — "The Ledger" design system
   Internal finance tooling: precise, tabular, trustworthy.
   ===================================================================== */
:root {
  --ink:        #14181f;
  --ink-soft:   #47505e;
  --ink-faint:  #8a94a3;
  --paper:      #f4f6f8;
  --surface:    #ffffff;
  --line:       #e4e7ec;
  --line-strong:#cdd3db;

  --accent:     #1f5fcc;   /* primary actions */
  --accent-ink: #16408c;
  --emerald:    #0e9f6e;   /* approved / positive */
  --emerald-bg: #e6f6ef;
  --amber:      #b7791f;   /* pending / in-review */
  --amber-bg:   #fbf3e2;
  --rose:       #cf3b3b;   /* rejected / variance-over */
  --rose-bg:    #fbeaea;
  --slate-bg:   #eef1f4;

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

  --radius: 8px;
  --shadow: 0 1px 2px rgba(20,24,31,.06), 0 8px 24px rgba(20,24,31,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ---------- Reference codes & numbers: the signature ---------- */
.ref { font-family: var(--mono); font-weight: 600; letter-spacing: -.2px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* =====================  LOGIN  ===================== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 20% -10%, #eef3fb, transparent),
    var(--paper);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 36px 32px;
}
.brand { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.brand-mark {
  font-family: var(--mono); font-weight: 700; font-size: 24px;
  letter-spacing: -1px; color: var(--ink);
}
.brand-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
.brand-sub { color: var(--ink-faint); font-size: 12px; letter-spacing: .4px; text-transform: uppercase; margin-bottom: 26px; }
.login-card h1 { font-size: 18px; margin: 0 0 18px; }
.hint {
  margin-top: 18px; padding: 12px 14px; background: var(--slate-bg);
  border-radius: var(--radius); font-size: 12px; color: var(--ink-soft);
}
.hint code { font-family: var(--mono); color: var(--ink); }

/* =====================  SHELL  ===================== */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #c7cfdb; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand-mark { color: #fff; font-size: 20px; }
.sidebar .brand { padding: 0 8px 4px; }
.sidebar .brand-sub { color: #6b7688; padding: 0 8px; margin-bottom: 22px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 7px; color: #c7cfdb; cursor: pointer; font-weight: 500;
  border: none; background: transparent; width: 100%; text-align: left; font-size: 13.5px;
}
.nav-item:hover { background: #1f2632; color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .ic { width: 18px; text-align: center; opacity: .9; }
.nav-spacer { flex: 1; }
.nav-user { padding: 12px 8px; border-top: 1px solid #262e3b; margin-top: 8px; }
.nav-user .u-name { color: #fff; font-weight: 600; font-size: 13px; }
.nav-user .u-role { color: #6b7688; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.nav-user button {
  margin-top: 8px; background: transparent; color: #9aa5b5;
  border: 1px solid #313a49; border-radius: 6px; padding: 5px 10px;
  cursor: pointer; font-size: 12px; width: 100%;
}
.nav-user button:hover { color: #fff; border-color: #48546a; }

.main { padding: 28px 34px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.4px; }
.page-head .sub { color: var(--ink-faint); font-size: 13px; margin-top: 2px; }

/* =====================  BUTTONS  ===================== */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 7px; font-weight: 600; font-size: 13px;
}
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.emerald { background: var(--emerald); border-color: var(--emerald); color: #fff; }
.btn.rose { background: var(--surface); border-color: var(--rose); color: var(--rose); }
.btn.rose:hover { background: var(--rose-bg); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* =====================  CARDS / STATS  ===================== */
.grid { display: grid; gap: 16px; }
.stat-grid { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); }
.stat .value { font-family: var(--mono); font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -1px; }
.stat .meta { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.stat.accent { border-left: 3px solid var(--accent); }
.stat.amber  { border-left: 3px solid var(--amber); }
.stat.emerald{ border-left: 3px solid var(--emerald); }
.stat.rose   { border-left: 3px solid var(--rose); }

/* =====================  TABLE  ===================== */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-faint); padding: 11px 16px; background: #fafbfc; border-bottom: 1px solid var(--line);
  font-weight: 700;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafbfc; }
.t-amount { text-align: right; }
td.t-amount, th.t-amount { text-align: right; }
.muted { color: var(--ink-faint); }
.empty { padding: 44px; text-align: center; color: var(--ink-faint); }

/* =====================  PILLS  ===================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 20px; font-size: 11.5px; font-weight: 700; letter-spacing: .2px;
  text-transform: capitalize;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.pending  { background: var(--amber-bg); color: var(--amber); }
.pill.reviewed { background: #e7effb; color: var(--accent); }
.pill.approved { background: var(--emerald-bg); color: var(--emerald); }
.pill.released { background: #e7effb; color: var(--accent-ink); }
.pill.liquidated { background: var(--slate-bg); color: var(--ink-soft); }
.pill.paid { background: var(--emerald-bg); color: var(--emerald); }
.pill.rejected { background: var(--rose-bg); color: var(--rose); }

/* variance badges */
.var-over  { color: var(--rose); font-weight: 600; }
.var-under { color: var(--emerald); font-weight: 600; }
.var-zero  { color: var(--ink-faint); }

/* =====================  FORMS  ===================== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 9px 11px;
  font-family: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,95,204,.12);
}
.field textarea { resize: vertical; min-height: 64px; }
.field .req { color: var(--rose); }

/* line items editor */
.items-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.items-table th { font-size: 11px; text-transform: uppercase; color: var(--ink-faint); text-align: left; padding: 6px 8px; }
.items-table td { padding: 4px 8px; }
.items-table input { width: 100%; }
.item-total { text-align: right; font-family: var(--mono); font-weight: 700; padding: 10px 8px 0; }

/* =====================  MODAL  ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,31,.45);
  display: grid; place-items: start center; padding: 40px 20px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 720px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .16s ease-out;
}
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head .x { border: none; background: none; font-size: 22px; color: var(--ink-faint); cursor: pointer; line-height: 1; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* detail rows */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: 0; }
.dl dt { padding: 9px 0; color: var(--ink-faint); font-size: 12.5px; border-bottom: 1px solid var(--line); }
.dl dd { padding: 9px 0; margin: 0; border-bottom: 1px solid var(--line); font-weight: 500; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); font-weight: 700; margin: 22px 0 10px; }

/* activity timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; }
.timeline .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex-shrink: 0; }
.timeline .t-body { font-size: 13px; }
.timeline .t-meta { color: var(--ink-faint); font-size: 11.5px; }

/* attachments */
.attach-list { list-style: none; padding: 0; margin: 8px 0 0; }
.attach-list li { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; }
.attach-list .a-name { font-size: 13px; display: flex; align-items: center; gap: 8px; }

/* alert banners */
.banner { padding: 11px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; gap: 8px; }
.banner.warn { background: var(--amber-bg); color: #8a5a09; border: 1px solid #f0dcae; }
.banner.info { background: #e7effb; color: var(--accent-ink); border: 1px solid #cfe0fb; }

/* filters */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft);
  padding: 6px 13px; border-radius: 20px; cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* toast */
#toast-root { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); animation: pop .16s ease-out; max-width: 340px;
}
.toast.err { background: var(--rose); }
.toast.ok  { background: var(--emerald); }

/* misc */
.spinner { text-align: center; padding: 60px; color: var(--ink-faint); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; font-weight: 600; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .brand, .sidebar .brand-sub { width: 100%; }
  .nav-item { width: auto; }
  .nav-spacer { display: none; }
  .nav-user { width: 100%; border-top: 1px solid #262e3b; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid, .dl { grid-template-columns: 1fr; }
  .dl dt { border: none; padding-bottom: 0; }
  .main { padding: 20px; }
}
