:root {
  --backdrop: #d3d5cb;    /* grey canvas behind the floating panels */
  --bg: #f6f7f2;          /* warm off-white content panel */
  --panel: #ffffff;
  --ink: #161616;         /* near-black */
  --ink-soft: #3a3d36;
  --muted: #8a8f82;       /* warm grey */
  --line: #ebece4;
  --accent: #c8f135;      /* lime / chartreuse */
  --accent-deep: #b6df1f;
  --accent-ink: #1c2400;  /* readable text on lime */
  --danger: #d83a3a;
  --radius: 22px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(22, 22, 22, .04), 0 8px 24px rgba(22, 22, 22, .05);
  --shadow-sm: 0 1px 2px rgba(22, 22, 22, .05);

  /* Spacing scale (4-pt base). Use semantic names, not numeric. */
  --space-1: 0.25rem;     /*  4px */
  --space-2: 0.5rem;      /*  8px */
  --space-3: 0.75rem;     /* 12px */
  --space-4: 1rem;        /* 16px */
  --space-4h: 1.25rem;    /* 20px — half-step between 4 and 5 */
  --space-5: 1.5rem;      /* 24px */
  --space-6: 2rem;        /* 32px */
  --space-7: 3rem;        /* 48px */
  --measure-form: 480px;  /* max width for centered forms inside panels */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--backdrop);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
h3 { font-size: .95rem; margin: 1.3rem 0 .6rem; }
.muted { color: var(--muted); }

/* ---- App shell ---- */
.shell { display: grid; grid-template-columns: 248px 1fr; gap: 1rem;
  padding: 1rem; min-height: 100vh; align-items: start; }

.sidebar {
  position: sticky; top: 1rem; height: calc(100vh - 2rem);
  display: flex; flex-direction: column;
  padding: 1.5rem 1rem; gap: 1.5rem;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .65rem; padding: .25rem .5rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; font-weight: 800; font-size: 1.1rem;
}
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }

.side-nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .75rem; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 550; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav-item svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.nav-item.active { background: var(--ink); color: #fff; }
.nav-item.active svg { fill: var(--accent); }

.side-foot { display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--line); padding-top: 1rem; }
.who { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  background: var(--accent); color: var(--accent-ink); border-radius: 50%; font-weight: 700; }
.who-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout button { display: grid; place-items: center; width: 34px; height: 34px;
  background: none; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; color: var(--muted); }
.logout button:hover { color: var(--danger); border-color: var(--danger); }
.logout svg { width: 18px; height: 18px; fill: currentColor; }

/* ---- Page rhythm ----
   The content column is a vertical stack with one gap token: sections are
   siblings, spacing happens at the stack, never on per-section margins.
   Override `--stack-gap` per page when a tighter or airier beat fits. */
.content { background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: var(--space-6); min-height: calc(100vh - 2rem); width: 100%;
  display: grid; align-content: start; gap: var(--stack-gap, var(--space-4h)); }
.content > * { margin-block: 0; }

/* ---- Headers ---- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.page-head .muted { margin: .15rem 0 0; }
.page-head-meta { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.page-back { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted);
  font-weight: 600; font-size: .9rem; padding: .35rem .6rem .35rem .45rem;
  border-radius: 999px; transition: color .12s, background .12s; }
.page-back:hover { color: var(--ink); background: var(--bg); text-decoration: none; }
.page-back svg { width: 14px; height: 14px; fill: currentColor; }
.relative-date { display: inline-block; padding: .2rem .55rem; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: .72rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; }
.relative-date.is-today { background: var(--accent); color: var(--accent-ink); }

/* ---- Messages ---- */
.messages { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-2); }
.msg { padding: .65rem .9rem; border-radius: var(--radius-sm); font-size: .92rem; }
.msg.success { background: #eef8d2; color: #4d6b00; }
.msg.error { background: #fde7e7; color: var(--danger); }

/* ---- Stat cards ---- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4h); }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.35rem; box-shadow: var(--shadow); }
.stat-card.feature { background: var(--ink); border-color: var(--ink); color: #fff; }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 550; text-transform: uppercase; letter-spacing: .04em; }
.stat-card.feature .stat-label { color: rgba(255,255,255,.6); }
.stat-value { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; margin-top: .35rem; display: flex; align-items: baseline; gap: .4rem; }
.stat-value .unit { font-size: .95rem; font-weight: 500; color: var(--muted); }
.stat-card.feature .stat-value .unit { color: rgba(255,255,255,.55); }
.stat-pill { display: inline-block; margin-top: .75rem; padding: .25rem .7rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .9rem; }

/* ---- Panels & layout ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1.1fr; gap: var(--space-4h); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.35rem 1.45rem; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--space-4); }
.empty { padding: 1.5rem 0; text-align: center; }

/* ---- Donut ---- */
.donut-wrap { display: flex; align-items: center; gap: var(--space-5); }
.donut { width: 170px; height: 170px; flex: none; }
.donut-track { fill: none; stroke: var(--line); stroke-width: 22; }
.donut-seg { fill: none; stroke-width: 22; transform: rotate(-90deg); transform-origin: 80px 80px;
  stroke-linecap: butt; }
.donut-seg.round { stroke-linecap: round; }
.donut-num { font-size: 22px; font-weight: 800; fill: var(--ink); text-anchor: middle; letter-spacing: -.02em; }
.donut-cap { font-size: 11px; fill: var(--muted); text-anchor: middle; text-transform: uppercase; letter-spacing: .08em; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; display: flex; flex-direction: column; gap: .6rem; }
.legend li { display: flex; align-items: center; gap: .6rem; font-size: .92rem; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-weight: 700; }
.big-stat { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 .3rem; }
.big-stat .muted { font-weight: 600; }

/* ---- Bar chart ---- */
.bars { display: flex; align-items: flex-end; gap: .5rem; height: 200px; padding-top: 1.2rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.bar-amt { font-size: .62rem; color: var(--muted); margin-bottom: .35rem; opacity: 0; transition: opacity .12s;
  white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-col:hover .bar-amt { opacity: 1; }
.bar-track { flex: 1; width: 100%; max-width: 46px; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; min-height: 3px; background: var(--accent); border-radius: 7px 7px 3px 3px;
  transition: height .2s ease; }
.bar-col.current .bar-fill { background: var(--ink); }
.bar-col.current .bar-amt { opacity: 1; color: var(--ink); font-weight: 700; }
.bar-label { margin-top: .5rem; font-size: .72rem; color: var(--muted); font-weight: 600; }
.bar-col.current .bar-label { color: var(--ink); }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data.flush { border: none; box-shadow: none; border-radius: 0; }
table.data th, table.data td { padding: .7rem .9rem; text-align: left; border-bottom: 1px solid var(--line); }
table.data.flush th:first-child, table.data.flush td:first-child { padding-left: 0; }
table.data.flush th:last-child, table.data.flush td:last-child { padding-right: 0; }
table.data thead th { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
table.data tbody tr:last-child td { border-bottom: 1px solid var(--line); }
table.data tfoot td { font-weight: 800; border-bottom: none; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .55rem; vertical-align: middle; flex: none; }

/* ---- Calendar ---- */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-nav { display: flex; gap: .5rem; }
.cal-nav a { padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--ink); font-weight: 550; font-size: .9rem; }
.cal-nav a:hover { text-decoration: none; border-color: var(--ink); }
table.calendar { width: 100%; border-collapse: separate; border-spacing: 6px; table-layout: fixed; }
table.calendar th { padding: .35rem .5rem; color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left; text-transform: uppercase; letter-spacing: .04em; }
table.calendar td { height: 104px; vertical-align: top; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0; transition: box-shadow .12s; }
table.calendar td:hover { box-shadow: var(--shadow-sm); }
table.calendar td.muted-day { background: transparent; border-style: dashed; }
table.calendar td.selectable { cursor: pointer; user-select: none; }
table.calendar td.today { border-color: var(--ink); border-width: 2px; }
table.calendar td.holiday { background: #fbfbe9; }
table.calendar td.selected { border-color: var(--accent-deep); background: #f4fbcf;
  box-shadow: inset 0 0 0 2px var(--accent-deep); }
.day-inner { display: block; height: 100%; padding: .5rem; color: var(--ink); }
.daynum { display: inline-block; font-weight: 700; font-size: .85rem; margin-bottom: .3rem; color: var(--ink); }
a.daynum:hover { color: var(--ink); text-decoration: underline; }
td.today .daynum { display: inline-grid; place-items: center; width: 24px; height: 24px;
  background: var(--accent); color: var(--accent-ink); border-radius: 50%; }
.tag { display: block; font-size: .72rem; color: #fff; padding: .12rem .4rem; border-radius: 6px;
  margin-bottom: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.holiday-tag { background: #b6df1f; color: var(--accent-ink); }

/* ---- Bulk action bar ---- */
.bulk-bar {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  z-index: 50; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  max-width: calc(100vw - 2rem);
  padding: .6rem .75rem .6rem 1rem;
  background: var(--ink); color: #fff;
  border-radius: 999px; box-shadow: 0 12px 32px rgba(22, 22, 22, .28);
}
.bulk-bar[hidden] { display: none; }
.bulk-count { font-size: .92rem; white-space: nowrap; }
.bulk-count strong { color: var(--accent); font-size: 1.05rem; }
.bulk-sep { width: 1px; height: 24px; background: rgba(255, 255, 255, .18); }
.bulk-bar select, .bulk-bar input[type=text] {
  width: auto; padding: .45rem .6rem; border-radius: 999px; border: 1px solid rgba(255,255,255,.2);
  background: #2a2c24; color: #fff; font-size: .9rem; }
.bulk-bar input[type=text].bulk-holiday { width: 140px; }
.bulk-bar input::placeholder { color: rgba(255,255,255,.45); }
.bulk-bar select:focus, .bulk-bar input:focus { outline: none; border-color: var(--accent); box-shadow: none; }
.bulk-bar select option { color: var(--ink); }
.bulk-bar button { padding: .45rem .9rem; font-size: .9rem; }
.bulk-bar button:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.bulk-bar button:not(.primary):hover { border-color: #fff; }
.bulk-clear { color: rgba(255,255,255,.7) !important; border-color: transparent !important; }
.bulk-clear:hover { color: #fff !important; }

/* ---- Banners, panels for day view ---- */
.banner { display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.1rem; border-radius: var(--radius); }
.banner.holiday { background: #fbfbe9; border: 1px solid #eef0c4; }
.list-head { display: flex; align-items: center; justify-content: space-between; }

/* ---- Forms ---- */
form.stacked label { display: block; margin-bottom: .9rem; font-weight: 600; font-size: .9rem; }
form.stacked input, form.stacked select, form.stacked textarea { display: block; width: 100%; margin-top: .35rem; font-weight: 400; }
form.inline { display: flex; gap: .6rem; align-items: center; }
.card-form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-5); box-shadow: var(--shadow); max-width: var(--measure-form); }

input[type=text], input[type=password], input[type=number], input[type=email], input[type=date], select, textarea {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; color: var(--ink); background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(200,241,53,.4); }
input[type=color] { padding: 0; height: 42px; width: 64px; border: 1px solid var(--line); border-radius: var(--radius-sm); width: 64px; }

button, .btn { font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); padding: .55rem 1rem; border-radius: 999px; display: inline-block; }
button:hover, .btn:hover { text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
button.danger, .btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.link-danger { color: var(--danger); background: none; border: none; padding: 0 0 0 .7rem; cursor: pointer; font-weight: 600; }
.link-danger:hover { text-decoration: underline; }

/* ---- Invoices & company ---- */
.prefill-bar { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; }
.prefill-bar label { font-weight: 600; font-size: .9rem; display: block; }
.prefill-bar select, .prefill-bar input { display: block; width: auto; margin-top: .35rem; font-weight: 400; }
.prefill-bar button { flex: none; }
.invoice-meta { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--space-3);
  margin-bottom: var(--space-5); }
.invoice-meta label { font-weight: 600; font-size: .9rem; }
.invoice-meta select, .invoice-meta input { display: block; width: 100%; margin-top: .35rem; font-weight: 400; }
.invoice-lines td { vertical-align: top; }
.invoice-lines input { width: 100%; }
.invoice-lines th:first-child { width: 46%; }
.form-actions { display: flex; gap: var(--space-3); margin-top: var(--space-4); }
.company-panel { max-width: 560px; }
.numbering-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.numbering-hint { font-size: .85rem; margin: -.4rem 0 .9rem; }
.logo-preview { display: block; max-height: 80px; max-width: 240px; margin-bottom: .75rem;
  padding: .5rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); }
label.checkbox { font-weight: 600; font-size: .9rem; }
label.checkbox input { width: auto; display: inline; margin-right: .35rem; }

/* ---- Auth ---- */
.container { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth-card { max-width: 380px; width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 2.25rem; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.4rem; letter-spacing: -.02em; }
.auth-card .muted { margin: .5rem 0 0; }
.auth-card form { margin-top: 1.5rem; }
.auth-card label { display: block; margin-bottom: 1rem; font-weight: 600; font-size: .9rem; }
.auth-card input { margin-top: .35rem; }
.auth-card button { width: 100%; margin-top: .5rem; }

@media (max-width: 880px) {
  .shell { grid-template-columns: 76px 1fr; }
  .brand-name, .nav-item span, .who-name { display: none; }
  .nav-item { justify-content: center; }
  .side-foot { flex-direction: column; gap: .75rem; }
  .content { padding: var(--space-5) var(--space-4); --stack-gap: var(--space-4); }
  .stat-row, .grid-2 { gap: var(--space-4); }
  .stat-row, .grid-2 { grid-template-columns: 1fr; }
  .donut-wrap { flex-direction: column; }
  table.calendar td { height: 74px; }
}
