/* ==========================================================================
   VSD Billing - interface styles.
   --p (primary) and --a (accent) are set per install from Settings > Branding
   (an inline :root block in head.ejs), so the colours follow VSD's brand.
   ========================================================================== */
@font-face { font-family: Poppins; src: url(/assets/fonts/Poppins-Regular.ttf) format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: Poppins; src: url(/assets/fonts/Poppins-Medium.ttf) format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: Poppins; src: url(/assets/fonts/Poppins-SemiBold.ttf) format('truetype'); font-weight: 600; font-display: swap; }

:root {
  --p: #1f2429; --a: #3f6f9f; --tint: #dbe7f5;   /* logo: charcoal, deeper blue, pale-blue bar */
  --ink: #1d2533; --body: #3a4250; --muted: #6b7482;
  --bg: #f3f5f8; --card: #fff; --line: #dde2e9; --line-2: #c9d1db;
  --ok: #1d7a4a; --ok-bg: #e7f5ec; --warn: #9a5b00; --warn-bg: #fff4de;
  --bad: #b3261e; --bad-bg: #fdecea; --info: #1f5aa6; --info-bg: #e8f0fb;
  --radius: 12px; --shadow: 0 2px 10px rgba(12, 24, 44, .06);
  --pad: clamp(1rem, 2vw, 2rem);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--body); font: 400 15px/1.55 Poppins, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--p); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); font-weight: 600; line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.1rem; } h3 { font-size: .98rem; }
p { margin: 0 0 .8rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 99; }
.skip-link:focus { left: 1rem; }
:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 1rem; padding: .6rem var(--pad); min-height: 60px; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand img { height: 36px; width: auto; display: block; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--p); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .95rem; letter-spacing: .02em; }
.brand-sub { font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: #fff; background: var(--a); border-radius: 6px; padding: .15rem .45rem; }
.search { flex: 1; max-width: 460px; display: flex; }
.search input { border-radius: 10px 0 0 10px; }
.search button { border: 1px solid var(--p); background: var(--p); color: #fff; border-radius: 0 10px 10px 0; padding: 0 .9rem; cursor: pointer; display: grid; place-items: center; }
.search button svg { width: 18px; height: 18px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .8rem; }
.me { display: flex; align-items: center; gap: .5rem; color: var(--ink); }
.avatar { width: 34px; height: 34px; border-radius: 10px; background: var(--tint); color: var(--p); display: grid; place-items: center; font-size: .78rem; font-weight: 600; }
.nav-toggle { display: none; }

.body-row { display: flex; align-items: stretch; min-height: calc(100vh - 61px); background: linear-gradient(90deg, var(--p) 0 248px, transparent 248px); }
.sidenav { width: 248px; flex-shrink: 0; background: var(--p); background-image: linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,0) 40%);
  padding: 1rem .7rem 1.5rem; position: sticky; top: 61px; align-self: flex-start; max-height: calc(100vh - 61px); overflow-y: auto; scrollbar-width: thin; }
.sidenav ul { list-style: none; margin: 0 0 .3rem; padding: 0; }
.sidenav a { display: flex; align-items: center; gap: .6rem; padding: .52rem .75rem; border-radius: 9px; color: rgba(255,255,255,.82); font-weight: 500; font-size: .92rem; }
.sidenav a:hover { background: rgba(255,255,255,.09); color: #fff; text-decoration: none; }
.sidenav a.active { background: #fff; color: var(--p); box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.sidenav a .ico { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }
.nav-group { font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: rgba(255,255,255,.55); padding: 1rem .75rem .35rem; }
.nav-foot { border-top: 1px solid rgba(255,255,255,.12); margin-top: .8rem; padding-top: .6rem; }
.nav-foot button { background: none; border: 0; color: rgba(255,255,255,.7); font: inherit; font-size: .88rem; padding: .45rem .75rem; cursor: pointer; }
.nav-foot button:hover { color: #fff; text-decoration: underline; }
.content { flex: 1; min-width: 0; padding: var(--pad) var(--pad) 3rem; }
.footer { color: var(--muted); font-size: .78rem; padding: 1.5rem 0 0; }

/* ---------- page furniture ---------- */
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: .6rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head .sub { color: var(--muted); margin: .15rem 0 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btn-row form { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .7rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.main-side { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1rem; align-items: start; }
.stack > * + * { margin-top: 1rem; }
.meta { color: var(--muted); font-size: .84rem; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 1.4rem; text-align: center; color: var(--muted); background: #fafbfc; }
.empty strong { display: block; color: var(--ink); margin-bottom: .2rem; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---------- KPI tiles ---------- */
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .95rem 1.1rem; box-shadow: var(--shadow); display: block; color: inherit; border-top: 3px solid var(--p); }
.kpi:hover { text-decoration: none; border-color: var(--line-2); }
.kpi .label { font-size: .76rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 1.45rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: .15rem; }
.kpi .hint { font-size: .8rem; color: var(--muted); }
.kpi.bad { border-top-color: var(--bad); } .kpi.bad .value { color: var(--bad); }
.kpi.good { border-top-color: var(--a); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--p); border-bottom: 2px solid var(--p); padding: .55rem .6rem; white-space: nowrap; }
table.data td { border-bottom: 1px solid var(--line); padding: .6rem .6rem; vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fafbfd; }
table.data tfoot td { border-top: 2px solid var(--p); border-bottom: 0; font-weight: 600; color: var(--ink); }
table.data th.num, table.data td.num { text-align: right; }
.row-link { font-weight: 600; }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .14rem .5rem; border-radius: 999px; background: #eef1f5; color: var(--body); white-space: nowrap; vertical-align: middle; }
.b-draft { background: #eef1f5; color: #4b5563; }
.b-issued, .b-sent, .b-running { background: var(--info-bg); color: var(--info); }
.b-partial, .b-planned, .b-expired { background: var(--warn-bg); color: var(--warn); }
.b-paid, .b-accepted, .b-completed, .b-active { background: var(--ok-bg); color: var(--ok); }
.b-void, .b-declined, .b-cancelled, .b-overdue { background: var(--bad-bg); color: var(--bad); }

/* ---------- forms ---------- */
label { display: block; font-size: .82rem; font-weight: 500; color: var(--ink); margin: .7rem 0 .25rem; }
input, select, textarea { width: 100%; font: inherit; font-size: .93rem; color: var(--ink); background: #fff; border: 1px solid var(--line-2); border-radius: 9px; padding: .55rem .7rem; }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: .15rem; height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--a) 45%, transparent); border-color: var(--a); }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.form-narrow { max-width: 620px; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.inline-form > div { flex: 1 1 140px; }
.inline-form > div.grow { flex: 3 1 240px; }
.inline-form label { margin-top: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem 1rem 1rem; margin: 1rem 0 0; }
legend { font-weight: 600; color: var(--ink); padding: 0 .4rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  padding: .6rem 1.05rem; border-radius: 10px; border: 1px solid var(--p); background: var(--p); color: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-accent { background: var(--a); border-color: var(--a); }
.btn-secondary { background: #fff; color: var(--p); border-color: var(--line-2); }
.btn-secondary:hover { border-color: var(--p); filter: none; }
.btn-danger { background: #fff; color: var(--bad); border-color: #efb8b3; }
.btn-danger:hover { background: var(--bad-bg); filter: none; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 8px; }
.btn-link { background: none; border: 0; padding: 0; color: var(--p); font: inherit; font-size: .85rem; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--bad); }

details.editor > summary { cursor: pointer; font-size: .8rem; color: var(--p); list-style: none; margin-top: .25rem; }
details.editor > summary::-webkit-details-marker { display: none; }
details.editor > summary::before { content: "\25B8  "; }
details.editor[open] > summary::before { content: "\25BE  "; }
details.panel { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
details.panel > summary { cursor: pointer; padding: .8rem 1rem; font-weight: 600; color: var(--ink); }
details.panel > div { padding: 0 1rem 1rem; }

/* ---------- flash ---------- */
.flash { border-radius: 10px; padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; font-size: .92rem; }
.flash-success { background: var(--ok-bg); border-color: #b7e0c6; color: #14532d; }
.flash-error { background: var(--bad-bg); border-color: #f2c2bd; color: #7f1d1d; }
.flash-info { background: var(--info-bg); border-color: #c4d7f2; color: #1e3a6e; }
.flash-warn { background: var(--warn-bg); border-color: #f1d8a5; color: #6b4000; }

/* ---------- document page ---------- */
.doc-status { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; color: var(--muted); font-size: .9rem; }
.totals { margin-left: auto; max-width: 340px; font-size: .92rem; }
.totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand { border-top: 2px solid var(--p); margin-top: .35rem; padding-top: .45rem; font-weight: 600; color: var(--ink); font-size: 1.05rem; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.progress { height: 8px; background: #eaeef3; border-radius: 99px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--a); border-radius: 99px; }
.link-box { word-break: break-all; background: #f7f9fb; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; font-size: .85rem; }

/* ---------- bar chart (reports) ---------- */
.bars { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .45rem; align-items: end; height: 190px; padding-top: .5rem; }
.bars .col { display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .bar { width: 44%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .inv { background: var(--p); } .bars .rec { background: var(--a); }
.bars .lbl { font-size: .7rem; color: var(--muted); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, color-mix(in srgb, var(--tint) 55%, #fff) 0%, var(--tint) 100%); }
.auth-card { width: 100%; max-width: 410px; background: #fff; border-radius: 16px; padding: 2rem 1.8rem; box-shadow: 0 24px 60px rgba(31,36,41,.16); }
.auth-card .logo { display: block; width: 210px; max-width: 70%; height: auto; margin: .2rem auto 1.4rem; }
.auth-card .brand-mark { margin: 0 auto .6rem; width: 52px; height: 52px; font-size: 1.2rem; border-radius: 14px; }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 1.2rem; }
.auth-card .btn { width: 100%; margin-top: 1.1rem; padding: .75rem; }
.auth-card .links { text-align: center; margin-top: 1rem; font-size: .88rem; }
.qr { display: block; margin: .6rem auto; border: 1px solid var(--line); border-radius: 10px; padding: .4rem; background: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .main-side { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .nav-toggle { display: inline-grid; place-items: center; width: 42px; height: 40px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; color: var(--p); font-size: 1.25rem; cursor: pointer; order: -1; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .topbar-inner { flex-wrap: wrap; }
  .me-name { display: none; }
  .body-row { display: block; }
  .sidenav { display: none; width: auto; position: static; max-height: none; margin: .8rem; border-radius: 14px; }
  body.nav-open .sidenav { display: block; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .body-row { background: none; }
}
@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 1.15rem; }
  h1 { font-size: 1.3rem; }
  table.data { font-size: .84rem; }
  .hide-sm { display: none; }
}
@media print {
  .topbar, .sidenav, .btn, .btn-row, .flash, details.editor, form { display: none !important; }
  .content { padding: 0; } body { background: #fff; }
}
