:root {
  --ink: #1d1d1f;
  --ink-2: #3a3a3d;
  --muted: #6e6e73;
  --line: #e3e3e6;
  --line-2: #d1d1d6;
  --bg: #ffffff;
  --soft: #f7f7f8;
  --gold: #c9a646;
  --gold-dark: #8c6d1f;
  --gold-soft: #faf5e6;
  --red: #c0392b;
  --red-soft: #fbeceb;
  --green: #1e7a46;
  --green-soft: #e8f4ec;
  --blue: #2a5d9f;
  --blue-soft: #eaf0f8;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --radius: 4px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Roboto", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 500; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
small, .muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.red { color: var(--red); }
.green { color: var(--green); }
.nowrap { white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: 60px; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { height: 44px; width: auto; display: block; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--gold);
  display: grid; place-items: center; font-weight: 700; font-size: 18px; font-family: Georgia, serif;
}
.brand-text b { font-weight: 700; letter-spacing: 2px; }
.brand-text i { font-style: normal; color: var(--gold); letter-spacing: 2px; font-size: 12px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.nav-toggle { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line-2);
  background: var(--gold-soft); color: var(--gold-dark); font-weight: 500; cursor: pointer; font-family: inherit;
}

/* Dropdown menus */
.quick-new, .usermenu, .dropdown { position: relative; }
.menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 190px; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,.08); padding: 6px 0;
}
.menu.right, .quick-new .menu { left: auto; right: 0; }
.open > .menu { display: block; }
.menu a, .menu button {
  display: block; width: 100%; text-align: left; padding: 8px 16px; color: var(--ink);
  background: none; border: 0; font: inherit; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--soft); text-decoration: none; }
.menu .danger { color: var(--red); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-head { padding: 8px 16px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-weight: 500; }
.menu-head small { display: block; font-weight: 400; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
  width: 220px; flex: none; border-right: 1px solid var(--line); padding: 14px 10px;
  position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; background: #fff;
}
.sidebar a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin-bottom: 2px;
  color: var(--ink-2); border-radius: var(--radius); border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--soft); text-decoration: none; }
.sidebar a.active { background: var(--gold-soft); color: var(--ink); border-left-color: var(--gold); font-weight: 500; }
.sidebar a.active .ic { color: var(--gold-dark); }
.main { flex: 1; min-width: 0; padding: 24px 32px 60px; max-width: 1280px; }

/* ---------- Page head ---------- */
.crumbs { font-size: 13px; margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--line-2); background: #fff; color: var(--ink);
  font: 500 14px "Roboto", Arial, sans-serif; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--soft); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #000; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn-gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); }
.btn-danger { color: var(--red); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--gold-dark); padding: 0; height: auto; font-weight: 400; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.split { display: inline-flex; }
.split > .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split > .dropdown > .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left-color: rgba(255,255,255,.25); padding: 0 9px; }
.split > .dropdown > .btn:not(.btn-dark) { border-left-color: var(--line-2); margin-left: -1px; }
.caret { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; }

/* ---------- Panels & cards ---------- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.panel.pad, .pad { padding: 20px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.panel-head .actions { margin-left: auto; display: flex; gap: 8px; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.stat { padding: 16px 20px; border-right: 1px solid var(--line); color: var(--ink); }
.stat:last-child { border-right: 0; }
.stat:hover { background: var(--soft); text-decoration: none; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 500; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.alert .label, .stat.alert .value { color: var(--red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 500; }
.tabs .count { color: var(--muted); font-size: 12px; margin-left: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-weight: 500; font-size: 13px; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fff; white-space: nowrap;
}
table.list th a { color: var(--muted); }
table.list th.num, table.lines th.num { text-align: right; }
table.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:hover td { background: #fbfbfc; }
table.list tr.clickable { cursor: pointer; }
table.list tfoot td { font-weight: 500; border-bottom: 0; }
table.list .chk { width: 32px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.b-grey { background: #f0f0f2; color: #55555a; }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-gold { background: var(--gold-soft); color: var(--gold-dark); }
.b-strike { text-decoration: line-through; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--ink-2); }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius);
  font: 14px "Roboto", Arial, sans-serif; color: var(--ink); background: #fff;
}
textarea { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
.field { margin-bottom: 16px; }
.fields { display: grid; gap: 16px; }
.fields-4 { grid-template-columns: repeat(4, 1fr); }
.fields-3 { grid-template-columns: repeat(3, 1fr); }
.fields-2 { grid-template-columns: repeat(2, 1fr); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: 16px; height: 16px; accent-color: var(--gold); }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--line); background: var(--soft); align-items: flex-end; }
.searchbar .grow { flex: 1; min-width: 200px; }
.searchbar label { font-size: 12px; }

/* ---------- Invoice editor ---------- */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-weight: 500; font-size: 13px; color: var(--muted); text-align: left; padding: 8px; background: var(--soft); border: 1px solid var(--line); }
table.lines td { border: 1px solid var(--line); padding: 0; vertical-align: top; }
table.lines td input, table.lines td textarea { border: 0; border-radius: 0; height: 40px; }
table.lines td textarea { min-height: 40px; height: 40px; padding: 10px; resize: vertical; }
table.lines td input:focus, table.lines td textarea:focus { outline: 2px solid var(--gold); outline-offset: -2px; }
table.lines td.amount { padding: 10px; text-align: right; background: var(--soft); white-space: nowrap; }
table.lines td.del { width: 36px; text-align: center; }
table.lines td.del button { background: none; border: 0; color: var(--muted); cursor: pointer; height: 40px; width: 36px; font-size: 18px; }
table.lines td.del button:hover { color: var(--red); }
.item-pick { position: relative; }
.suggest {
  display: none; position: absolute; left: 0; top: 100%; z-index: 20; min-width: 320px; max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.08);
}
.suggest.show { display: block; }
.suggest div { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.suggest div:hover, .suggest div.hl { background: var(--soft); }
.suggest small { white-space: nowrap; }

.totals { width: 360px; margin-left: auto; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .row.total { border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-size: 18px; font-weight: 500; padding: 10px 0; margin-top: 6px; }
.totals .row.due { font-size: 18px; font-weight: 500; padding-top: 10px; }

.meta { display: flex; flex-wrap: wrap; gap: 14px 36px; }
.meta dt { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.meta dd { margin: 0; font-weight: 500; }

/* ---------- Dashboard bars ---------- */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; padding: 10px 0 0; border-bottom: 1px solid var(--line); }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar span.fill { width: 100%; max-width: 56px; background: var(--ink-2); border-radius: 2px 2px 0 0; min-height: 2px; }
.bar.overdue span.fill { background: var(--gold); }
.bar small.v { font-size: 11px; margin-bottom: 4px; color: var(--muted); }
.bar-labels { display: flex; gap: 14px; padding-top: 6px; }
.bar-labels div { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Customer header ---------- */
.initials {
  width: 40px; height: 40px; border-radius: 4px; background: var(--gold-soft); color: var(--gold-dark);
  display: grid; place-items: center; font-weight: 500; flex: none;
}
.initials.sm { width: 30px; height: 30px; font-size: 12px; }
.who { display: flex; align-items: center; gap: 10px; }

/* ---------- Flash ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash-ok { background: var(--green-soft); border-color: #cfe6d8; color: var(--green); }
.flash-err { background: var(--red-soft); border-color: #f1cfcb; color: var(--red); }
.flash-warn { background: var(--amber-soft); border-color: #f0dfaa; color: var(--amber); }

/* ---------- Modal ---------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; align-items: center; justify-content: center; padding: 16px; }
.modal.show { display: flex; }
.modal-box { background: #fff; border-radius: 6px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal-box .panel-head { font-weight: 500; }
.modal-box .foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Login ---------- */
body.bare { background: var(--soft); }
.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.login .panel { padding: 28px; }
.login .brand { justify-content: center; margin-bottom: 24px; }
.login .brand img { height: 56px; }

/* ---------- Printable invoice ---------- */
.doc { max-width: 820px; margin: 0 auto; background: #fff; padding: 48px; border: 1px solid var(--line); }
.doc-top { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 36px; }
.doc-top img { height: 70px; }
.doc-title { font-size: 28px; font-weight: 300; letter-spacing: 3px; text-transform: uppercase; }
.doc-from { text-align: right; font-size: 13px; color: var(--ink-2); white-space: pre-line; }
.doc-info { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.doc-info .to { white-space: pre-line; }
.doc-info dl { display: grid; grid-template-columns: auto auto; gap: 4px 18px; margin: 0; font-size: 13px; }
.doc-info dt { color: var(--muted); }
.doc-info dd { margin: 0; text-align: right; }
.doc table.list th { border-bottom: 2px solid var(--ink); color: var(--ink); }
.doc .gold-rule { height: 3px; background: var(--gold); margin: 0 0 28px; }
.doc-foot { margin-top: 40px; font-size: 12px; color: var(--muted); white-space: pre-line; border-top: 1px solid var(--line); padding-top: 14px; }
.paid-stamp { display: inline-block; border: 2px solid var(--green); color: var(--green); padding: 4px 14px; font-weight: 700; letter-spacing: 2px; transform: rotate(-4deg); }
.print-bar { max-width: 820px; margin: 20px auto; display: flex; gap: 8px; justify-content: flex-end; padding: 0 16px; }

@media print {
  .no-print, .topbar, .sidebar, .print-bar { display: none !important; }
  body, body.bare { background: #fff; }
  .doc { border: 0; padding: 0; max-width: none; }
  .main { padding: 0; }
  @page { margin: 14mm; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .fields-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .sidebar { position: fixed; left: 0; top: 60px; z-index: 25; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.08); }
  body.nav-open .sidebar { transform: none; }
  .main { padding: 16px 16px 60px; }
  .brand-text i { display: none; }
  .fields-4, .fields-3, .fields-2 { grid-template-columns: 1fr; }
  .totals { width: 100%; }
  .meta { gap: 12px 24px; }
  .meta > div { min-width: 40%; }
  .table-wrap table.list { min-width: 600px; }
  .doc { padding: 20px; }
  .doc-top, .doc-info { flex-direction: column; }
  .doc-from { text-align: left; }
  .stat .value { font-size: 18px; }
}
