:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1e2530; --muted: #6b7280;
  --line: #e3e6ea; --brand: #2b3a55; --brand2: #3d5a99;
  --green: #157347; --red: #b02a37; --warn: #b7791f;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--brand2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, monospace; }
.right { text-align: right; }
.hidden { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; background: var(--brand);
  color: #fff; padding: 10px 18px; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topnav { display: flex; gap: 14px; margin-left: 18px; }
.topnav a { color: #cbd3e0; font-size: 14px; }
.topnav a:hover { color: #fff; text-decoration: none; }
.assign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.assign-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox .muted { color: #cbd3e0; }
.banner { background: #fff7e6; border-bottom: 1px solid #f0d9a8; color: #7a5b12;
  padding: 8px 18px; font-size: 13px; }
.banner a { color: #7a5b12; text-decoration: underline; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.badge-warn { background: #ffe8b3; color: #7a5b12; }

.container { max-width: 1040px; margin: 22px auto; padding: 0 18px; }
.pagefoot { text-align: center; padding: 24px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.pagehead h1 { margin: 0; font-size: 22px; }
.titlewrap { display: flex; align-items: center; gap: 14px; }
.detail-logo { max-height: 48px; max-width: 130px; object-fit: contain; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* buttons */
.btn { display: inline-block; background: #fff; border: 1px solid var(--line); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: #c3c9d2; text-decoration: none; }
.btn-primary { background: var(--brand2); border-color: var(--brand2); color: #fff; }
.btn-primary:hover { background: #34518c; }
.btn-danger { background: #fff; border-color: #e3b6ba; color: var(--red); }
.btn-danger:hover { background: #fdecee; }
.btn-google { background: #fff; border: 1px solid #dadce0; width: 100%; font-weight: 600; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-xs { padding: 2px 7px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; align-items: center; }
.card:hover { border-color: var(--brand2); text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.card-logo { width: 54px; height: 54px; border-radius: 8px; background: #eef1f5;
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.card-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card-logo .mono { font-weight: 700; color: var(--brand); }
.card-title { font-weight: 700; }
.empty { background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 32px; text-align: center; }

/* panels & tables */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.table td.right, .table th.right { text-align: right; }
.table td.l, .table th.l { text-align: left; }
.row-cancelled { opacity: .55; }
.link { color: var(--brand2); }
.pill { padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: capitalize; }
.pill-issued { background: #e3f0ff; color: #1c4f91; }
.pill-sent { background: #e6f4ea; color: var(--green); }
.pill-paid { background: #d8f5e3; color: var(--green); }
.pill-cancelled { background: #fde0e3; color: var(--red); }
.pill-draft { background: #eee; color: #555; }

/* forms */
.form { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin-bottom: 16px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 12px 14px; }
legend { font-weight: 700; padding: 0 6px; color: var(--brand); }
label { display: block; margin-bottom: 10px; font-size: 13px; color: #40474f; }
label.check { display: flex; align-items: center; gap: 8px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #cfd4db;
  border-radius: 8px; font-size: 14px; margin-top: 3px; background: #fff; }
input[type=checkbox] { width: auto; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.row-actions { display: flex; gap: 10px; }
.logo-form, .danger-form { max-width: 460px; }
.logo-preview img { max-height: 70px; border: 1px solid var(--line); padding: 6px; border-radius: 8px; }

/* invoice editor */
.invoice-form .items-edit { width: 100%; border-collapse: collapse; margin: 6px 0; }
.items-edit th { font-size: 12px; color: var(--muted); text-align: right; padding: 4px 6px; }
.items-edit th.l { text-align: left; }
.items-edit td { padding: 3px 4px; }
.items-edit input { margin: 0; }
.items-edit .desc { min-width: 220px; }
.items-edit .qty, .items-edit .gst, .items-edit .rate { text-align: right; }
.cell-taxable { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.items-edit.simple .qty-col, .items-edit.simple .unit-col { display: none; }
.totals-panel { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.tp-row { display: flex; justify-content: space-between; padding: 4px 0; }
.tp-row.grand { border-top: 2px solid var(--brand); margin-top: 6px; padding-top: 8px; font-size: 17px; font-weight: 700; }
.tp-words { margin-top: 8px; }
.tp-supply { margin-top: 4px; }

/* invoice view */
.kv td { padding: 5px 10px; border-bottom: 1px solid var(--line); }
.kv td:first-child { color: var(--muted); width: 180px; }
.totals-final { max-width: 340px; margin-left: auto; margin-top: 10px; }
.totals-final > div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-final .grand { border-top: 2px solid var(--brand); margin-top: 6px; padding-top: 8px; font-size: 18px; font-weight: 700; }

/* reports */
.filterbar { display: flex; gap: 12px; align-items: flex-end; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 16px; }
.filterbar label { margin: 0; }
.filterbar select { min-width: 130px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat-primary { background: var(--brand); color: #fff; }
.stat-n { font-size: 20px; font-weight: 700; }
.stat-l { font-size: 12px; color: var(--muted); }
.stat-primary .stat-l { color: #cbd3e0; }
.totrow td { font-weight: 700; border-top: 2px solid var(--brand); }

/* flatpickr brand accent */
.flatpickr-day.selected, .flatpickr-day.selected:hover,
.flatpickr-day.selected.startRange, .flatpickr-day.selected.endRange {
  background: var(--brand2); border-color: var(--brand2);
}
.flatpickr-day.today { border-color: var(--brand2); }
.flatpickr-months .flatpickr-month, .flatpickr-weekdays, span.flatpickr-weekday { background: var(--brand); }
.flatpickr-months .flatpickr-prev-month svg, .flatpickr-months .flatpickr-next-month svg,
.flatpickr-current-month, .flatpickr-weekday { fill: #fff; color: #fff; }

/* inline series forms */
.inline-form { display: inline-block; margin: 0; padding: 0; border: none; background: none; }
.inline-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px;
  padding: 10px; border: 1px dashed var(--line); border-radius: 8px; background: none; }
.inline-add input { width: auto; margin: 0; }
.tiny { width: 140px !important; padding: 4px 8px; margin: 0; }
.inline-due { max-width: 200px; }

/* notices */
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.notice-info { background: #eef4ff; border: 1px solid #cfe0ff; }
.notice-success { background: #e6f4ea; border: 1px solid #b7e0c4; }
.notice-error { background: #fdecee; border: 1px solid #f2c2c7; color: #7a1f28; }
.error { background: #fdecee; border: 1px solid #f2c2c7; color: #7a1f28; padding: 9px 12px; border-radius: 8px; margin: 10px 0; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 30px; width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.stack > * { margin-bottom: 10px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 16px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
