/* Palette and type pulled from ~/Documents/serenity.eg/Serenity-Design-System
   (tokens/colors.css, tokens/typography.css) — the same brand as the website,
   sized down for a dense financial-app UI instead of the marketing site's
   large display type. */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Jost:wght@400;500;600&display=swap');

:root {
  --bg: #F7F1E8;            /* sand-1: page background */
  --panel: #FFFFFF;          /* surface-raised: cards/tables */
  --ink: #3B3834;            /* ink-1 */
  --muted: #948C82;          /* ink-3 */
  --line: rgba(59,56,52,.14); /* border-subtle */
  --accent: #C89042;         /* brand-gold */
  --accent-hover: #A9742C;   /* brand-gold-deep */
  --accent-ink: #ffffff;
  --red: #B4543B;            /* danger (also unit-terracotta-deep) */
  --green: #4E7C4A;          /* success */
  --warning: #C4841D;
  --radius: 6px;
  --font-body: 'Jost', system-ui, sans-serif;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-sm: .78rem;         /* shared small size: sidebar submenu = table data */

  --sidebar-bg: #3B3834;     /* ink-1, warm charcoal instead of a generic dark */
  --sidebar-bg-hover: rgba(255,255,255,.07);
  --sidebar-bg-active: rgba(255,255,255,.12);
  --sidebar-text: #E9E2D6;
  --sidebar-text-dim: #B3A99C;
  --sidebar-heading: #A9742C;
  --sidebar-active-line: #C89042;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar-bg); }
.login { background: var(--panel); padding: 2.5rem; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); width: 300px; }
.login h1 { font-size: 1.15rem; margin: 0 0 1.2rem; }
.login label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 1rem; }
.login input { width: 100%; padding: .5rem .6rem; margin-top: .3rem; border: 1px solid var(--line); border-radius: 5px; font-size: .95rem; }
.login button { width: 100%; padding: .55rem; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 5px; font-size: .92rem; cursor: pointer; }
.login .err { color: var(--red); font-size: .82rem; }

#app { display: flex; min-height: 100vh; }

/* ---- sidebar ---------------------------------------------------------- */
nav.sidebar {
  width: 190px; flex-shrink: 0; background: var(--sidebar-bg);
  padding: .7rem 0; display: flex; flex-direction: column; gap: 0;
  overflow-y: auto;
}
nav.sidebar .brand {
  font-weight: 600; padding: .3rem 1rem .9rem; font-size: .95rem; color: #fff;
  display: flex; align-items: center; gap: .45rem;
}
nav.sidebar .brand .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sidebar-active-line); flex-shrink: 0; }
nav.sidebar .section-label {
  padding: .7rem 1rem .25rem; font-size: .66rem; font-weight: 700; letter-spacing: .07em;
  color: var(--sidebar-heading); text-transform: uppercase;
}
nav.sidebar a, nav.sidebar .reports-toggle {
  display: flex; align-items: center; gap: .55rem;
  padding: .38rem 1rem; color: var(--sidebar-text); text-decoration: none; font-size: .83rem;
  border-left: 2px solid transparent; line-height: 1.3;
}
nav.sidebar a:hover, nav.sidebar .reports-toggle:hover { background: var(--sidebar-bg-hover); }
nav.sidebar a.active, nav.sidebar .reports-toggle.active { border-left-color: var(--sidebar-active-line); background: var(--sidebar-bg-active); font-weight: 600; color: #fff; }
nav.sidebar .icon { width: 14px; height: 14px; flex-shrink: 0; opacity: .85; }
nav.sidebar .reports-toggle {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: flex; align-items: center; gap: .55rem; padding: .38rem 1rem; font-size: .83rem;
  color: var(--sidebar-text); border-left: 2px solid transparent;
}
nav.sidebar .reports-toggle .label { flex: 1; }
nav.sidebar .reports-toggle .chev { font-size: .62rem; color: var(--sidebar-text-dim); transition: transform .15s ease; }
nav.sidebar .reports-toggle[aria-expanded="true"] .chev { transform: rotate(-180deg); }
nav.sidebar .reports-submenu { display: flex; flex-direction: column; }
nav.sidebar .reports-submenu[hidden] { display: none; }
nav.sidebar .reports-submenu a { padding: .32rem 1rem .32rem 2.2rem; font-size: .78rem; color: var(--sidebar-text-dim); border-left: 2px solid transparent; }
nav.sidebar .reports-submenu a:hover { color: var(--sidebar-text); }
nav.sidebar .reports-submenu a.active { color: #fff; font-weight: 600; border-left-color: var(--sidebar-active-line); }
nav.sidebar .new-menu { padding: 0 .8rem; display: flex; flex-direction: column; gap: .35rem; }
nav.sidebar .new-menu a {
  background: rgba(255,255,255,.08); color: #fff; border-radius: 5px; text-align: left;
  border-left: none; font-size: .78rem; padding: .4rem .6rem; justify-content: flex-start;
}
nav.sidebar .new-menu a:hover { background: rgba(255,255,255,.16); }
nav.sidebar .spacer { flex: 1; }
nav.sidebar .logout { color: var(--sidebar-text-dim); font-size: .78rem; }

main { flex: 1; padding: 1.4rem 1.8rem; max-width: 1200px; min-width: 0; overflow-x: auto; }
h1 { font-family: var(--font-display); font-size: 1.3rem; margin: 0 0 .9rem; font-weight: 600; color: var(--ink); }
h2 { font-family: var(--font-display); font-size: 1rem; margin: 1.3rem 0 .5rem; font-weight: 600; color: var(--ink); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .7rem; margin-bottom: 1.2rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .85rem; }
.card .label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card .value { font-size: 1.2rem; font-weight: 600; margin-top: .2rem; }
.card .value.neg { color: var(--red); }
.card .value.pos { color: var(--green); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; font-size: var(--font-sm); }
table th, table td { text-align: left; padding: .38rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table td.wrap { white-space: normal; }
table th { font-size: .66rem; text-transform: uppercase; font-weight: 700; color: var(--muted); letter-spacing: .03em; background: var(--bg); border-bottom: 1px solid var(--line); }
table tr:last-child td { border-bottom: none; }
table tr.clickable:hover { background: var(--bg); cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: .05rem .45rem; border-radius: 99px; font-size: .68rem; font-weight: 600; }
.badge.paid { background: rgba(78,124,74,.14); color: var(--green); }
.badge.unpaid { background: rgba(180,84,59,.14); color: var(--red); }
.badge.partially_paid { background: rgba(196,132,29,.16); color: var(--warning); }
.badge.na { background: var(--bg); color: var(--muted); }

.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.toolbar select, .toolbar input { padding: .32rem .5rem; border: 1px solid var(--line); border-radius: 5px; font-size: .78rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1rem; }

form.stack { display: flex; flex-direction: column; gap: .8rem; max-width: 520px; }
form.stack label { font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; gap: .25rem; }
form.stack input, form.stack select, form.stack textarea { padding: .42rem .55rem; border: 1px solid var(--line); border-radius: 5px; font-size: .88rem; font-family: inherit; color: var(--ink); }
form.stack button { align-self: flex-start; padding: .48rem 1.2rem; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 5px; font-size: .84rem; cursor: pointer; }
form.stack button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
form.stack .row { display: flex; gap: .7rem; }
form.stack .row > * { flex: 1; }

.line-item { border: 1px dashed var(--line); border-radius: 6px; padding: .7rem; margin-bottom: .5rem; }
.line-item .row { margin-bottom: .45rem; }
.remove-line { color: var(--red); background: none; border: none; cursor: pointer; font-size: .76rem; padding: 0; }

.error { background: #f6e5e0; color: var(--red); padding: .5rem .8rem; border-radius: 6px; font-size: .8rem; margin-bottom: .9rem; }
.success { background: #e3f0ec; color: var(--green); padding: .5rem .8rem; border-radius: 6px; font-size: .8rem; margin-bottom: .9rem; }
.muted { color: var(--muted); font-size: .8rem; }
.back-link { display: inline-block; margin-bottom: .9rem; color: var(--muted); text-decoration: none; font-size: .8rem; }
.back-link:hover { text-decoration: underline; }

.loading { color: var(--muted); padding: 2rem 0; }

/* ---- Chart of accounts: master-detail --------------------------------- */
.accounts-layout { display: flex; gap: 1rem; align-items: flex-start; }
.accounts-list { width: 260px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.accounts-list .cat-header {
  display: flex; justify-content: space-between; padding: .4rem .7rem; background: var(--bg);
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.accounts-list .cat-header:first-child { border-top: none; }
.accounts-list .acct-row {
  display: flex; justify-content: space-between; gap: .5rem; padding: .32rem .7rem .32rem 1.1rem;
  font-size: .8rem; cursor: pointer; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.accounts-list .acct-row:hover { background: var(--bg); }
.accounts-list .acct-row.active { background: var(--accent); color: #fff; }
.accounts-list .acct-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accounts-list .acct-row .bal { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.register-panel { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; }
.register-panel h2 { margin-top: 0; }
.panel-title-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; }
.panel-title-row h1, .panel-title-row h2 { margin: 0; }
.icon-btn {
  width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font-size: 1.05rem; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { filter: brightness(1.1); }

/* ---- modal ------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,20,24,.45); display: flex;
  align-items: flex-start; justify-content: center; padding-top: 6vh; z-index: 100;
}
.modal-box {
  background: var(--panel); border-radius: 8px; width: 440px; max-width: calc(100vw - 2rem);
  max-height: 86vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.modal-box h2 {
  margin: 0; padding: .9rem 1.1rem; font-size: .8rem; letter-spacing: .04em; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.modal-box form.stack { padding: 1rem 1.1rem; max-width: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; padding-top: .3rem; }
.modal-actions button.secondary { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.modal-summary { background: var(--bg); border-radius: 6px; padding: .6rem .8rem; font-size: .82rem; display: flex; justify-content: space-between; }

/* ---- right-side drawer (invoice preview) -------------------------------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(10,20,24,.35); z-index: 90; }
.drawer-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 620px; max-width: 94vw;
  background: var(--bg); box-shadow: -8px 0 30px rgba(0,0,0,.25); z-index: 91;
  overflow-y: auto; display: flex; flex-direction: column;
}
.drawer-header {
  display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  padding: .7rem 1.1rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1;
}
.drawer-header h2 { margin: 0; font-size: .92rem; }
.drawer-body { padding: 1.3rem; flex: 1; }
.drawer-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.drawer-actions button {
  padding: .38rem .75rem; border-radius: 5px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: .78rem; color: var(--ink);
}
.drawer-actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.drawer-actions button.icon { width: 28px; padding: .38rem 0; text-align: center; }

/* ---- invoice document (matches the real printed invoice layout) -------- */
.invoice-doc {
  background: #fff; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 2.2rem 2.2rem 1.6rem; font-family: Helvetica, Arial, sans-serif;
  color: #1a1a1a; font-size: .82rem; line-height: 1.5;
  box-shadow: 0 1px 8px rgba(0,0,0,.15);
}
.invoice-doc-wrap { cursor: zoom-in; }
.invoice-doc-wrap:hover .invoice-doc { box-shadow: 0 1px 8px rgba(0,0,0,.3); }
.invoice-doc .invoice-logo { display: block; height: 56px; width: auto; margin: 0 auto 1.2rem; }
.invoice-doc .invoice-top { display: flex; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.8rem; }
.invoice-doc .bill-to { font-weight: 700; }
.invoice-doc .biz-address { text-align: left; white-space: pre-line; }
.invoice-doc .invoice-title { text-align: center; font-style: italic; font-weight: 700; font-size: 1.25rem; margin: 1.2rem 0 1.4rem; }
.invoice-doc table {
  width: 100%; border-collapse: collapse; font-size: .82rem; background: none; border-radius: 0; overflow: visible;
}
/* This has to fight the app-wide dense-table rules (nowrap, uppercase gray
   headers) so the invoice stays plain black-on-white like the real printed
   one, and so a long line-item description wraps instead of spilling past
   the page edge. */
.invoice-doc th, .invoice-doc td {
  white-space: normal; overflow-wrap: anywhere; background: none; text-transform: none;
  font-size: inherit; letter-spacing: normal; color: inherit;
}
.invoice-doc .invoice-meta { margin-bottom: 1.2rem; }
.invoice-doc .invoice-meta td { padding: .1rem 0; }
.invoice-doc .invoice-meta td:first-child { font-weight: 700; width: 150px; }
.invoice-doc .invoice-items th { text-align: left; border-bottom: 2px solid #222; padding-bottom: .3rem; font-weight: 700; }
.invoice-doc .invoice-items td { padding: .25rem 0; }
.invoice-doc .invoice-items td:first-child { padding-right: 1rem; }
.invoice-doc .invoice-items tbody tr:last-child td { border-bottom: 1px solid #999; padding-bottom: .5rem; }
.invoice-doc .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invoice-doc .tax-breakdown { margin: .9rem 0 1.3rem; }
.invoice-doc .tax-breakdown th { font-weight: 700; padding-bottom: .25rem; }
.invoice-doc .tax-breakdown th:first-child, .invoice-doc .tax-breakdown td:first-child { text-align: left; }
.invoice-doc .tax-total td { font-weight: 700; padding-top: .5rem; border-top: 1px solid #999; }
.invoice-doc .invoice-terms { font-style: italic; white-space: pre-line; margin: 1.8rem 0 1.4rem; }
.invoice-doc .invoice-footer {
  text-align: center; font-style: italic; font-size: .7rem; color: #444;
  white-space: pre-line; border-top: 1px solid #ccc; padding-top: .6rem;
}

/* ---- lightbox (enlarged invoice) ---------------------------------------- */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(10,20,24,.8); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 2vw; overflow: auto;
}
.lightbox-overlay .invoice-doc { max-width: 680px; width: 100%; }
.lightbox-close {
  position: fixed; top: 18px; right: 22px; z-index: 201; background: #fff; border: none;
  border-radius: 50%; width: 34px; height: 34px; font-size: 1.1rem; cursor: pointer;
}

@media print {
  .invoice-doc { box-shadow: none; }
}
