/* SugarSalt Finance */
:root {
  --orange: #EF6905;
  --orange-dark: #C95503;
  --orange-soft: #FDEEE3;
  --navy: #172B4D;
  --navy-2: #22385E;
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --ink: #1B2433;
  --muted: #5E6C84;
  --line: #E2E5EA;
  --green: #17845A;
  --green-soft: #E3F4EC;
  --red: #C8372D;
  --red-soft: #FBE7E5;
  --amber: #9A6200;
  --amber-soft: #FFF3D6;
  --blue-soft: #E7EEF9;
  --radius: 10px;
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--navy); }
a:hover { color: var(--orange-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.35rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
small { display: block; font-size: .8rem; }
code { background: #EEF0F3; padding: .1rem .35rem; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid rgba(239, 105, 5, .45); outline-offset: 2px; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 248px; flex: none; background: var(--navy); color: #C9D3E3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand:hover { color: #fff; }
.brand strong { display: block; font-size: .98rem; }
.brand small { color: #93A3BE; font-size: .75rem; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--orange); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: .9rem; letter-spacing: .02em; flex: none; }
.brand-mark.big { width: 52px; height: 52px; font-size: 1.15rem; margin-bottom: 1rem; }
.side nav { padding: .6rem .6rem 1rem; flex: 1; }
.nav-group { margin-top: .7rem; }
.nav-head { display: block; font-size: .76rem; color: #8597B4; padding: .2rem .6rem .3rem; }
.nav-link { display: flex; justify-content: space-between; align-items: center; padding: .48rem .6rem; border-radius: 7px; color: #DCE3EE; text-decoration: none; font-size: .92rem; }
.nav-link:hover { background: var(--navy-2); color: #fff; }
.nav-link.on { background: rgba(239,105,5,.16); color: #fff; box-shadow: inset 3px 0 0 var(--orange); }
.count { background: var(--orange); color: #fff; border-radius: 20px; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; min-width: 1.5rem; text-align: center; }
.side-foot { padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; display: grid; gap: .15rem; }
.side-foot a { color: #fff; text-decoration: none; }
.side-foot span { color: #8597B4; }
.side-foot a:last-child { color: #F7B27D; margin-top: .3rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 1rem; padding: .9rem 1.6rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top h1 { flex: 1; margin: 0; }
.menu-btn { display: none; }
.content { padding: 1.4rem 1.6rem 3rem; max-width: 1320px; width: 100%; }

.quick { position: relative; }
.quick summary { list-style: none; cursor: pointer; }
.quick summary::-webkit-details-marker { display: none; }
.quick-menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(23,43,77,.14); min-width: 230px; padding: .35rem; z-index: 20; }
.quick-menu a { display: block; padding: .55rem .7rem; text-decoration: none; border-radius: 6px; color: var(--ink); }
.quick-menu a:hover { background: var(--bg); }

/* Cards and layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; margin-bottom: 1.1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 2.4rem 1.2rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .6rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.1rem; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.stack { display: grid; gap: .8rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .8rem; }
form.inline { display: inline-flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* Forms */
label { display: grid; gap: .3rem; font-size: .86rem; font-weight: 600; color: #344055; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea { font: inherit; font-size: .93rem; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #CBD2DC; border-radius: 7px; padding: .5rem .65rem; width: 100%; min-height: 38px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
input[type="file"] { padding: .4rem; background: var(--bg); }
input:focus, select:focus, textarea:focus { border-color: var(--orange); outline: none; box-shadow: 0 0 0 3px rgba(239,105,5,.18); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem 1rem; display: grid; gap: .7rem; margin: 0; }
legend { font-weight: 700; padding: 0 .35rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .9rem; border-radius: 7px; border: 1px solid #CBD2DC; background: #fff; color: var(--ink); padding: .5rem .95rem; cursor: pointer; text-decoration: none; min-height: 38px; white-space: nowrap; }
.btn:hover { border-color: var(--navy); color: var(--ink); }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); color: #fff; }
.btn-danger { color: var(--red); border-color: #E7B4AF; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn-small { padding: .3rem .65rem; min-height: 32px; font-size: .84rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--navy); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

/* Segmented filters */
.seg { display: inline-flex; background: #E9ECF1; border-radius: 8px; padding: 3px; flex-wrap: wrap; }
.seg a { padding: .35rem .75rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-size: .86rem; font-weight: 600; }
.seg a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(23,43,77,.12); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); background: #F9FAFB; padding: .6rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .65rem .75rem; border-bottom: 1px solid #EEF0F3; vertical-align: top; }
.table tbody tr:hover { background: #FBFBFC; }
.table.small td, .table.small th { padding: .4rem .55rem; font-size: .82rem; }
.table tr.hdr td { font-weight: 700; background: var(--orange-soft); }
.table tfoot td { font-weight: 700; background: #F9FAFB; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--green); }
.out { color: var(--red); }
.narr { display: block; max-width: 420px; word-break: break-word; }
.proof { font-size: .84rem; max-width: 300px; }
.file { display: inline-block; background: var(--blue-soft); border-radius: 5px; padding: .05rem .45rem; margin: .1rem .15rem .1rem 0; text-decoration: none; font-size: .8rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.thread { margin-top: .35rem; font-size: .82rem; }
.thread summary { cursor: pointer; color: var(--navy); }
.thread p { margin: .3rem 0 0; }

/* Pills */
.pill { display: inline-block; font-size: .76rem; font-weight: 700; border-radius: 20px; padding: .14rem .6rem; white-space: nowrap; }
.pill-missing { background: var(--red-soft); color: var(--red); }
.pill-requested { background: var(--amber-soft); color: var(--amber); }
.pill-attached, .pill-matched { background: var(--green-soft); color: var(--green); }
.pill-not_needed { background: #ECEEF2; color: var(--muted); }
.pill-draft { background: #ECEEF2; color: var(--muted); }
.pill-issued { background: var(--blue-soft); color: var(--navy); }
.pill-paid { background: var(--green-soft); color: var(--green); }
.pill-overdue, .pill-cancelled { background: var(--red-soft); color: var(--red); }
.pill-partly { background: var(--amber-soft); color: var(--amber); }

/* Flash */
.flash { border-radius: 8px; padding: .65rem .9rem; margin-bottom: 1rem; font-size: .92rem; border: 1px solid; }
.flash-ok { background: var(--green-soft); border-color: #B9E2CF; color: #0F5E40; }
.flash-err { background: var(--red-soft); border-color: #F0C1BC; color: #8E241C; }
.flash-warn { background: var(--amber-soft); border-color: #F1DCA6; color: #6E4700; }

/* Coverage meter: the one bold element */
.coverage { display: grid; grid-template-columns: 1fr minmax(160px, 320px) auto; gap: 1.2rem; align-items: center; border-left: 5px solid var(--orange); }
.coverage h2 { margin-bottom: .2rem; }
.coverage p { margin: 0; }
.meter { height: 12px; border-radius: 12px; background: #EDEFF3; overflow: hidden; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), #F59A4D); border-radius: 12px; }
.meter-pct { font-size: 1.6rem; font-variant-numeric: tabular-nums; color: var(--navy); }

/* Year strip on the dashboard */
.year-strip { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .45rem; }
.year-strip a { text-decoration: none; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .5rem .5rem; display: grid; gap: .35rem; background: #fff; }
.year-strip a:hover { border-color: var(--orange); }
.year-strip .mname { font-size: .8rem; font-weight: 700; }
.year-strip .bar { height: 46px; background: #EDEFF3; border-radius: 5px; position: relative; overflow: hidden; }
.year-strip .bar span { position: absolute; bottom: 0; left: 0; right: 0; background: var(--orange); }
.year-strip .bar.full span { background: var(--green); }
.year-strip .pct { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.year-strip .future { opacity: .45; pointer-events: none; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; }
.stats > div, .stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.stats span, .stat span { display: block; font-size: .82rem; color: var(--muted); font-weight: 600; }
.stats strong, .stat strong { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.stat small { color: var(--muted); }
.stat a { text-decoration: none; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; font-size: .92rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* Dialog */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(640px, 94vw); max-height: 92vh; box-shadow: 0 24px 60px rgba(23,43,77,.3); }
.dlg::backdrop { background: rgba(23,43,77,.45); }
.dlg-head { display: flex; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem .6rem; }
.dlg-head p { margin: 0; font-size: .86rem; word-break: break-word; }
.dlg .seg { margin: 0 1.25rem .9rem; }
.dlg-pane { padding: 0 1.25rem 1.25rem; }

/* Invoice editor */
.items td { padding: .35rem .4rem; }
.items input, .items select { min-height: 34px; padding: .35rem .5rem; font-size: .88rem; }
.items .w-desc { min-width: 240px; }
.totals { margin-left: auto; width: min(360px, 100%); }
.totals td { padding: .3rem .5rem; }
.totals tr.grand td { font-size: 1.1rem; font-weight: 700; border-top: 2px solid var(--navy); }

/* Printable invoice */
.inv-doc { background: #fff; max-width: 880px; margin: 0 auto; padding: 2.2rem 2.4rem; border: 1px solid var(--line); border-radius: var(--radius); }
.inv-top { display: flex; justify-content: space-between; gap: 2rem; border-bottom: 3px solid var(--navy); padding-bottom: 1rem; margin-bottom: 1.2rem; }
.inv-top img { max-height: 64px; max-width: 220px; }
.inv-title { text-align: right; }
.inv-title h2 { font-size: 1.5rem; color: var(--navy); margin-bottom: .3rem; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.2rem; font-size: .9rem; }
.inv-parties h3 { font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
.inv-doc .table th { background: var(--navy); color: #fff; }
.inv-foot { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.5rem; margin-top: 1.2rem; font-size: .88rem; }
.sign { text-align: right; margin-top: 3rem; font-size: .88rem; }
.stamp { display: inline-block; border: 2px solid var(--red); color: var(--red); padding: .2rem .8rem; font-weight: 700; transform: rotate(-4deg); border-radius: 6px; }

/* Auth pages */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; background: var(--navy); }
.auth-box { background: #fff; border-radius: 14px; padding: 2rem; width: min(460px, 100%); }
.auth-box h1 { font-size: 1.4rem; }

/* Responsive */
@media (max-width: 1100px) { .grid3 { grid-template-columns: 1fr 1fr; } .year-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  body.side-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(23,43,77,.4); }
  .menu-btn { display: inline-flex; }
  .menu-btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: .4rem .7rem; }
  .top { padding: .7rem 1rem; }
  .top h1 { font-size: 1.1rem; }
  .content { padding: 1rem .9rem 3rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .coverage { grid-template-columns: 1fr auto; }
  .coverage .coverage-text { grid-column: 1 / -1; }
  .inv-doc { padding: 1.2rem; }
  .inv-parties, .inv-foot { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media print {
  .side, .top, .no-print, .flash { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .content { padding: 0; max-width: none; }
  .inv-doc { border: 0; padding: 0; max-width: none; }
  .inv-doc .table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4; margin: 14mm; }
}

[hidden] { display: none !important; }

a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--orange); }
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: .8rem; align-items: end; height: 220px; padding-top: .5rem; border-bottom: 1px solid var(--line); }
.bar-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: .3rem; }
.bar-pair { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 100%; }
.bar-pair span { width: 38%; max-width: 28px; border-radius: 4px 4px 0 0; min-height: 1px; }
.b-in { background: var(--green); }
.b-out { background: var(--red); }
.bar-label { text-align: center; font-size: .8rem; color: var(--muted); }
.legend { margin: .6rem 0 0; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.key-in { background: var(--green); } .key-out { background: var(--red); margin-left: .6rem; }
.legend .muted { margin-left: auto; }

/* Pending documents as stacked cards on phones */
@media (max-width: 860px) {
  .table.docs thead { display: none; }
  .table.docs, .table.docs tbody { display: block; }
  .table.docs tr { display: grid; grid-template-columns: 1fr auto; gap: .3rem .8rem; padding: .85rem .95rem; border-bottom: 1px solid var(--line); }
  .table.docs td { display: block; border: 0; padding: 0; }
  .table.docs td:empty { display: none; }
  .table.docs td:nth-child(1) { order: 1; color: var(--muted); font-size: .85rem; }
  .table.docs td:nth-child(3), .table.docs td:nth-child(4) { order: 2; font-weight: 700; }
  .table.docs td:nth-child(2) { order: 3; grid-column: 1 / -1; }
  .table.docs td:nth-child(5) { order: 4; align-self: center; }
  .table.docs td:nth-child(7) { order: 5; text-align: right; }
  .table.docs td:nth-child(6) { order: 6; grid-column: 1 / -1; max-width: none; }
  .narr { max-width: none; }
}
.dlg-head { align-items: flex-start; }
