/* ===== Company dashboard ===== */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --ink: #0f172a; --ink-2: #334155;
  --muted: #64748b; --line: #e2e8f0; --line-2: #eef2f6;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-soft: #eff4ff; --accent-ink: #fff;
  --side: #0f172a; --side-ink: #cbd5e1; --side-muted: #64748b; --side-active: #1e293b;
  --good: #15803d; --good-soft: #dcfce7; --warn: #a16207; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --neutral-soft: #f1f5f9;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --ink: #e5e7eb; --ink-2: #cbd5e1;
    --muted: #94a3b8; --line: #1f2937; --line-2: #1a2333;
    --accent: #60a5fa; --accent-2: #93c5fd; --accent-soft: #172554; --accent-ink: #0b1120;
    --side: #070b14; --side-active: #111a2e;
    --good: #4ade80; --good-soft: #052e16; --warn: #fbbf24; --warn-soft: #3a2a05;
    --bad: #f87171; --bad-soft: #3b0d0d; --info: #93c5fd; --info-soft: #172554;
    --neutral-soft: #1e293b; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box }
html, body { margin: 0 }
body { background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased }
a { color: var(--accent); text-decoration: none }
a:hover { text-decoration: underline }
h1, h2, h3 { margin: 0; letter-spacing: -.01em }
h1 { font-size: 22px; font-weight: 700 }
h2 { font-size: 15px; font-weight: 600 }
.muted { color: var(--muted) }
.small { font-size: 12.5px }
.num, td.num, .t th.num, .doc th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap }
.svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700;
  font-size: 15px; line-height: 1.2 }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg,#3b82f6,#6366f1);
  display: grid; place-items: center; font-weight: 800; color: #fff; flex: none }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted);
  padding: 14px 12px 6px }
.side a.nav { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px;
  color: var(--side-ink); font-weight: 500 }
.side a.nav:hover { background: var(--side-active); text-decoration: none; color: #fff }
.side a.nav.on { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #3b82f6 }
.side .spacer { flex: 1 }
.side form button { all: unset; display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; width: calc(100% - 24px); color: var(--side-ink) }
.side form button:hover { background: var(--side-active); color: #fff }
.side .who { padding: 8px 12px; font-size: 12px; color: var(--side-muted) }

.main { min-width: 0 }
.topbar { display: none }
.page { max-width: 1240px; margin: 0 auto; padding: 26px 28px 60px }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px }
.page-head .sub { color: var(--muted); margin-top: 3px }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center }

/* ---- cards & grid ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow) }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line-2) }
.card-b { padding: 18px }
.grid { display: grid; gap: 16px }
.grid > * { min-width: 0 }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)) }
.g-2 { grid-template-columns: 1.6fr 1fr }
.g-2e { grid-template-columns: 1fr 1fr }
.g-3 { grid-template-columns: repeat(3, 1fr) }
.mb { margin-bottom: 16px }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px }
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 500 }
.kpi .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent) }
.kpi .ic.g { background: var(--good-soft); color: var(--good) }
.kpi .ic.w { background: var(--warn-soft); color: var(--warn) }
.kpi .ic.b { background: var(--bad-soft); color: var(--bad) }
.kpi .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px;
  letter-spacing: -.02em }
.kpi .foot { font-size: 12px; color: var(--muted) }

/* ---- tables ---- */
.table-wrap { overflow-x: auto }
table.t { width: 100%; border-collapse: collapse }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle }
.t tr:last-child td { border-bottom: 0 }
.t tbody tr:hover td { background: var(--surface-2) }
.t tfoot td { font-weight: 700; border-top: 1px solid var(--line); background: var(--surface-2) }
.t .strong { font-weight: 600; color: var(--ink) }
.empty { padding: 36px; text-align: center; color: var(--muted) }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--ink-2) }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor }
.b-active, .b-sent, .b-planning { background: var(--info-soft); color: var(--info) }
.b-completed, .b-paid, .b-accepted { background: var(--good-soft); color: var(--good) }
.b-on_hold, .b-draft { background: var(--warn-soft); color: var(--warn) }
.b-cancelled, .b-overdue, .b-rejected, .b-low { background: var(--bad-soft); color: var(--bad) }

/* ---- progress ---- */
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; min-width: 80px }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent) }
.bar.g > span { background: var(--good) }
.bar.w > span { background: var(--warn) }

/* ---- forms & buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; line-height: 1.3 }
.btn:hover { background: var(--surface-2); text-decoration: none }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600 }
.btn.primary:hover { background: var(--accent-2) }
.btn.danger { color: var(--bad) }
.btn.sm { padding: 5px 10px; font-size: 12.5px }
.btn.ghost { border-color: transparent; background: transparent }
.icon-btn { all: unset; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; display: inline-grid }
.icon-btn:hover { color: var(--bad); background: var(--bad-soft) }

label.f { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2) }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email],
input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 400 }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent) }
textarea { min-height: 80px; resize: vertical }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px }
.form-grid .full { grid-column: 1 / -1 }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end }
.inline-form > * { flex: 1 1 130px }
.inline-form > .btn { flex: 0 0 auto }

.flash { background: var(--info-soft); color: var(--info); border: 1px solid transparent; padding: 10px 14px;
  border-radius: 8px; margin-bottom: 16px; font-weight: 500 }
.alert { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 8px }

/* ---- tabs / filters ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap }
.tabs a:hover { color: var(--ink); text-decoration: none }
.tabs a.on { color: var(--accent); border-color: var(--accent) }
.tabs .count { background: var(--neutral-soft); color: var(--muted); border-radius: 999px; padding: 0 7px;
  font-size: 11.5px; margin-left: 4px }

/* ---- detail ---- */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 }
.dl dt { color: var(--muted) }
.dl dd { margin: 0; font-weight: 500 }
.fin { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 }
.fin > div { padding: 16px 18px; border-right: 1px solid var(--line-2) }
.fin > div:last-child { border-right: 0 }
.fin .label { color: var(--muted); font-size: 12.5px }
.fin .value { white-space: nowrap; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px }
.pos { color: var(--good) } .neg { color: var(--bad) }

/* ---- chart ---- */
.chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; align-items: end; height: 190px;
  padding: 8px 4px 0; border-bottom: 1px solid var(--line); position: relative }
.chart .col { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; cursor: default }
.chart .b { width: 100%; max-width: 44px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px }
.chart .col:hover .b { background: var(--accent-2) }
.chart .tip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 2 }
.chart .col:hover .tip, .chart .col:focus .tip { opacity: 1 }
.chart-x { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; text-align: center; font-size: 12px;
  color: var(--muted); padding-top: 6px }
.chart .gl { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); font-size: 11px; color: var(--muted) }

/* ---- line items editor ---- */
.items td { padding: 6px 6px; border-bottom: 1px solid var(--line-2) }
.items input { padding: 7px 9px }
.totals { margin-left: auto; width: min(340px, 100%) }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 17px }

/* ---- printable document ---- */
.doc { background: #fff; color: #0f172a; max-width: 860px; margin: 0 auto; padding: 48px 52px; border-radius: 12px;
  border: 1px solid var(--line); box-shadow: var(--shadow) }
.doc .muted { color: #64748b }
.doc-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start;
  padding-bottom: 24px; border-bottom: 2px solid #0f172a }
.doc-title { font-size: 30px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #1d4ed8; text-align: right }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: 3px 16px; margin-top: 10px; text-align: right; font-size: 13px }
.doc-meta dt { color: #64748b } .doc-meta dd { margin: 0; font-weight: 600 }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 24px 0 }
.doc-parties h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #64748b }
.doc table { width: 100%; border-collapse: collapse; margin-top: 8px }
.doc th { background: #0f172a; color: #fff; text-align: left; padding: 9px 10px; font-size: 12px; font-weight: 600 }
.doc td { padding: 10px; border-bottom: 1px solid #e2e8f0 }
.doc .totals .grand { border-color: #0f172a }
.doc-foot { margin-top: 32px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; font-size: 12.5px }
.doc-foot h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #64748b }
.stamp { display: inline-block; border: 3px solid #15803d; color: #15803d; padding: 4px 14px; font-weight: 800;
  letter-spacing: .1em; transform: rotate(-6deg); border-radius: 6px; font-size: 20px; margin-top: 10px }
.pre { white-space: pre-line }

/* ---- files page ---- */
.drop { text-align: center; border: 2px dashed var(--line); padding: 22px }

/* ---- responsive ---- */
@media (max-width: 1000px) { .g-2, .g-2e, .g-3 { grid-template-columns: 1fr } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr }
  .side { position: fixed; left: 0; top: 0; z-index: 30; width: 250px; transform: translateX(-100%);
    transition: transform .2s }
  .shell.open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4) }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; font-weight: 700 }
  .page { padding: 18px 16px 50px }
  .g-kpi { grid-template-columns: 1fr 1fr; gap: 10px }
  .kpi { padding: 12px 14px }
  .kpi .value { font-size: 17px; margin-top: 2px }
  .kpi .ic { display: none }
  .fin > div { border-right: 0; border-bottom: 1px solid var(--line-2) }
  .doc { padding: 24px 18px }
  .doc-head, .doc-parties, .doc-foot { grid-template-columns: 1fr; flex-direction: column }
  .doc-title, .doc-meta { text-align: left }
  .dl { grid-template-columns: 110px 1fr }
}

@media print {
  @page { margin: 14mm }
  body { background: #fff }
  .side, .topbar, .no-print, .flash { display: none !important }
  .shell { display: block }
  .page { padding: 0; max-width: none }
  .doc { border: 0; box-shadow: none; padding: 0; max-width: none }
  .doc th { -webkit-print-color-adjust: exact; print-color-adjust: exact }
}
