/* Selikta Invoices */
:root {
  --bg: #F3F5F4;
  --paper: #FFFFFF;
  --ink: #1E2A32;
  --ink-2: #4A5862;
  --ink-3: #7B8790;
  --line: #DCE2E0;
  --line-2: #EBEFEE;
  --plum: #7A2E7E;
  --plum-ink: #5E2161;
  --plum-wash: #F4ECF4;
  --paid: #2F7A55;
  --paid-wash: #E6F2EB;
  --open: #9A6700;
  --open-wash: #FBF1DC;
  --overdue: #B42318;
  --overdue-wash: #FBE7E5;
  --radius: 6px;
  --rail: 232px;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-feature-settings: "tnum" 1;
}
a { color: var(--plum); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail {
  background: var(--ink);
  color: #C9D2D7;
  padding: 22px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: #fff;
  display: grid; place-items: center; flex: none;
}
.brand-mark img { display: block; width: 22px; height: 22px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-name small { display: block; font-weight: 500; color: #8FA0AA; font-size: 12px; }
.rail a.nav {
  display: flex; align-items: center; gap: 10px;
  color: #C9D2D7; padding: 9px 10px; border-radius: var(--radius); font-weight: 600; font-size: 14px;
}
.rail a.nav:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.rail a.nav.on { background: rgba(255,255,255,.1); color: #fff; box-shadow: inset 3px 0 0 var(--plum); }
.rail svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.rail .spacer { flex: 1; }
.rail .who { font-size: 12.5px; color: #8FA0AA; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.rail .who strong { color: #DDE4E8; display: block; font-size: 13px; }
.rail .new-btn { margin: 0 0 14px; }

.main { min-width: 0; padding: 28px 36px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); margin-top: 4px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font: 600 14px/1 var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #C4CCCA; text-decoration: none; background: #FAFBFB; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--plum); border-color: var(--plum); color: #fff; }
.btn-primary:hover { background: var(--plum-ink); border-color: var(--plum-ink); color: #fff; }
.btn-danger { color: var(--overdue); }
.btn-danger:hover { background: var(--overdue-wash); border-color: #F0C2BD; }
.btn-danger-solid { background: var(--overdue); color: #fff; border-color: var(--overdue); }
.btn-danger-solid:hover { background: #92180F; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.field .err { font-size: 13px; color: var(--overdue); margin-top: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); font: 14.5px var(--font); font-feature-settings: "tnum" 1;
}
textarea { height: auto; min-height: 84px; padding: 9px 11px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--plum); box-shadow: 0 0 0 3px var(--plum-wash); }
.has-err input, .has-err select, .has-err textarea { border-color: var(--overdue); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); font-size: 14px; margin: 0; }
.check input { width: 16px; height: 16px; accent-color: var(--plum); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.panel-body { padding: 20px; }
.panel-head { padding: 14px 20px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack > * + * { margin-top: 18px; }

/* ---------- flash ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 18px; font-weight: 600; font-size: 14px; border: 1px solid; }
.flash.ok { background: var(--paid-wash); color: var(--paid); border-color: #BFDCCB; }
.flash.error { background: var(--overdue-wash); color: var(--overdue); border-color: #F0C2BD; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12.5px; color: var(--ink-3); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: #FAFBFB; white-space: nowrap;
}
table.data th.num { text-align: right; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #FAFBFB; }
table.data tr.rowlink { cursor: pointer; }
table.data tfoot td { font-weight: 700; border-top: 1px solid var(--line); background: #FAFBFB; }
td .desc { color: var(--ink-3); font-size: 13px; display: block; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-no { font-weight: 700; color: var(--ink); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill.paid { background: var(--paid-wash); color: var(--paid); }
.pill.open { background: var(--open-wash); color: var(--open); }
.pill.overdue { background: var(--overdue-wash); color: var(--overdue); }

/* ---------- filters ---------- */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: 4px; color: var(--ink-2); font-weight: 600; font-size: 13.5px; }
.tabs a:hover { text-decoration: none; background: var(--line-2); }
.tabs a.on { background: var(--ink); color: #fff; }
.filters select, .filters input[type=search] { width: auto; height: 36px; }
.filters select { max-width: 260px; }
.filters input[type=search] { min-width: 240px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-size: 13.5px; color: var(--ink-3); border-top: 1px solid var(--line-2); }

/* ---------- dashboard ---------- */
.owing-head { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: end; margin-bottom: 22px; }
.owing-total .amount { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }
.owing-total .amount small { font-size: 18px; font-weight: 700; color: var(--ink-3); margin-right: 4px; }
.owing-total p { color: var(--ink-2); margin: 6px 0 0; }
.owing-total .od { color: var(--overdue); font-weight: 700; }
.year-line { font-size: 14px; color: var(--ink-2); border-left: 3px solid var(--plum); padding: 4px 0 4px 14px; }
.year-line strong { color: var(--ink); }
.bar { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; margin-top: 6px; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--overdue); }
.bar i.b { background: var(--open); }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.dash-grid > *, .inv-layout > *, .owing-head > * { min-width: 0; }
.form-lower { display: grid; grid-template-columns: 1fr 320px; gap: 28px; margin-top: 22px; }
.form-lower > * { min-width: 0; }

/* ---------- invoice view ---------- */
.inv-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.sheet-wrap { background: #E4E9E7; border-radius: 8px; padding: 28px; overflow-x: auto; }
.sheet {
  background: #fff; width: 100%; max-width: 794px; min-height: 1000px; margin: 0 auto;
  box-shadow: 0 1px 2px rgba(30,42,50,.08), 0 8px 24px rgba(30,42,50,.08);
  padding: 56px 60px;
}
.side { position: sticky; top: 20px; }
.balance { padding: 18px 20px; }
.balance .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; color: var(--ink-2); }
.balance .row.total { border-top: 1px solid var(--line-2); margin-top: 6px; padding-top: 10px; color: var(--ink); font-weight: 700; font-size: 16px; }
.balance .status-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.side .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 20px 18px; }
.side .actions .wide { grid-column: span 2; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 20px; border-top: 1px solid var(--line-2); font-size: 13.5px; }
.timeline li .when { color: var(--ink-3); font-size: 12.5px; }
.timeline li .what { font-weight: 600; }
.timeline li .body { color: var(--ink-2); white-space: pre-line; margin-top: 2px; }

details.drawer { border-top: 1px solid var(--line-2); }
details.drawer summary { padding: 13px 20px; cursor: pointer; font-weight: 700; font-size: 14px; list-style: none; display: flex; justify-content: space-between; }
details.drawer summary::-webkit-details-marker { display: none; }
details.drawer summary::after { content: "+"; color: var(--ink-3); font-weight: 600; }
details.drawer[open] summary::after { content: "–"; }
details.drawer .drawer-body { padding: 0 20px 18px; }

/* ---------- invoice form ---------- */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 12.5px; color: var(--ink-3); text-align: left; font-weight: 600; padding: 0 6px 6px; }
.items td { padding: 4px 6px; vertical-align: top; }
.items td.desc-cell { width: 55%; }
.items textarea { min-height: 38px; height: 38px; }
.items .qty { width: 80px; }
.items .amt { width: 130px; text-align: right; }
.items .line-total { padding-top: 13px; text-align: right; font-weight: 600; white-space: nowrap; }
.items .tax-cell { padding-top: 12px; text-align: center; }
.items .rm { padding-top: 5px; }
.totals-box { margin-left: auto; width: 320px; font-size: 14px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 5px 0; color: var(--ink-2); }
.totals-box .row.grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 17px; color: var(--ink); }
.form-foot { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 16px 20px; border-top: 1px solid var(--line-2); background: #FAFBFB; border-radius: 0 0 8px 8px; }

/* ---------- client ---------- */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.contact { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: space-between; gap: 10px; }
.contact:first-child { border-top: 0; }

/* ---------- reports ---------- */
.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; align-items: end; height: 190px; padding: 10px 4px 0; }
.chart .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 3px; position: relative; }
.chart .b1 { background: var(--plum); border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .b2 { background: #B9C4C1; border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; align-items: end; height: 100%; }
.chart-x { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; font-size: 12px; color: var(--ink-3); text-align: center; padding: 6px 4px 0; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .panel-body { padding: 28px; }
.auth .brand { color: var(--ink); padding: 0 0 22px; }
.auth-logo { text-align: center; margin-bottom: 20px; }
.auth-logo img { display: block; margin: 0 auto 8px; width: 100px; height: auto; }
.auth-title { font-weight: 700; font-size: 15px; color: var(--ink); }
.auth-title small { display: block; font-weight: 500; font-size: 13px; color: var(--ink-3); }
.auth .brand-name small { color: var(--ink-3); }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(30,42,50,.3); color: var(--ink); }
dialog::backdrop { background: rgba(30,42,50,.45); }
dialog .panel-head { border-bottom: 1px solid var(--line-2); }
dialog .panel-body { max-height: 70vh; overflow: auto; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .inv-layout, .dash-grid { grid-template-columns: 1fr; }
  .side { position: static; }
  .sheet { padding: 36px 32px; min-height: 0; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 12px; align-items: center; gap: 2px; }
  .brand { padding: 4px 8px 4px 2px; }
  .brand-name small, .rail .who, .rail .spacer { display: none; }
  .rail .new-btn { margin: 0 0 0 auto; order: 2; height: 32px; }
  .rail a.nav { padding: 7px 9px; font-size: 13px; order: 3; }
  .rail a.nav svg { display: none; }
  .main { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .owing-head, .form-lower { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .rail { width: 100%; }
  .filters input[type=search] { min-width: 0; width: 100%; }
  .sheet-wrap { padding: 10px; }
  .sheet { padding: 22px 18px; }
  .totals-box { width: 100%; }
  .items thead { display: none; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; border-bottom: 1px solid var(--line-2); padding: 8px 0; }
  .items td { padding: 0; }
  .items td.desc-cell { grid-column: span 2; width: auto; }
  .items .qty, .items .amt { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
