/*
 * The Luckin Malaysia tool family's look, as the e-Invoice site
 * (luckin-sok-myinvois, src/app/globals.css) and the Budget Coordinator
 * (frontend/src/styles/tokens.css): every colour derives from the logo's deer
 * blue, #35317b, darkened for hover and lightened for tints. White header
 * after lkcoffee.com, as the e-Invoice site has it. Light only, like both.
 */
:root {
  --brand: #35317b; --brand-dark: #292660; --brand-ring: rgba(53, 49, 123, 0.15);
  --page: #f8f8fa; --card: #ffffff; --tint: #ebeaf2; --tint-hover: #dfdeea; --line: #e5e4ee;
  --ink: #201f33; --muted: #625f85; --faint: #8e8ba8;
  --danger: #d92d20; --danger-bg: #fef2f1; --success: #12805c; --success-bg: #ecfbf4;
  --info-bg: #eef1ff; --warning: #b45309; --warning-bg: #fff7e6;
  --radius: 6px; --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

/* Header: white bar, colour logo, active nav underlined in brand blue. */
.top { position: sticky; top: 0; z-index: 10; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
.top-inner { max-width: 1400px; margin: 0 auto; height: 60px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand img { height: 36px; width: auto; display: block; }
.brand span { font-size: 13px; font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 12px; }
.top nav { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.top nav a { font-size: 13px; line-height: 30px; font-weight: 600; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.top nav a:hover { color: var(--ink); }
.top nav a.current { color: var(--brand); border-bottom-color: var(--brand); }
.top .who { font-size: 13px; color: var(--faint); }
.top nav form { margin: 0; } .top nav button.link { font-size: 13px; font-weight: 600; line-height: 30px; }
@media (max-width: 760px) { .top-inner { height: auto; padding: 10px 16px; flex-wrap: wrap; } .brand span { display: none; } }

main { padding: 24px 16px 40px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 20px; font-weight: 600; margin: 4px 0 16px; }
h2 { font-size: 15px; font-weight: 600; margin: 20px 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-card); }
.card > h2:first-child { margin-top: 0; }
.narrow { max-width: 560px; }
.muted { color: var(--muted); }
.note { color: var(--muted); }
.status { font-size: 13px; font-weight: 500; color: var(--faint); margin-left: 8px; }
.inline { display: inline-flex; gap: 8px; align-items: center; }

/* Buttons and fields, as the e-Invoice form's (sized for a desk, not a phone). */
button, a.button { font: inherit; font-size: 14px; font-weight: 500; height: 38px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; text-decoration: none; transition: background .15s, border-color .15s; }
button:hover, a.button:hover { background: var(--page); color: var(--ink); }
button.primary, a.button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover, a.button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { border: 0; background: none; color: var(--brand); padding: 0; height: auto; font-weight: 500; }
button.link:hover { background: none; color: var(--brand-dark); text-decoration: underline; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0 10px; height: 38px; max-width: 100%; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; padding: 8px 10px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
input[readonly] { background: var(--page); color: var(--muted); }
input[type="checkbox"] { height: auto; accent-color: var(--brand); }
label { font-size: 13px; font-weight: 600; color: var(--muted); }

/* Filters, tabs and toolbars. */
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-card); margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 4px; }
.filters .right { margin-left: auto; align-self: center; }
.filters .range { display: flex; align-items: center; gap: 6px; color: var(--faint); font-weight: 400; }
.filters a { align-self: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px 18px; margin: 0 0 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 0; text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a.current { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .n { font-size: 12px; font-weight: 600; background: var(--tint); color: var(--muted); border-radius: 9px; padding: 0 7px; margin-left: 4px; }
.tabs a.current .n { background: var(--brand); color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 0 0 10px; }
.legend { margin-left: auto; display: flex; gap: 8px; }
.count { background: var(--brand); color: #fff; border-radius: 9px; padding: 0 7px; font-size: 12px; margin-left: 2px; }

/* Tags and chips. */
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.tag.overdue { background: var(--danger-bg); color: var(--danger); }
.tag.due-soon { background: var(--warning-bg); color: var(--warning); }
.tag.trusted { background: var(--success-bg); color: var(--success); }
.tag.ignored, .tag.unknown { background: var(--tint); color: var(--muted); }
.chip { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 9px; border-radius: 10px; background: var(--tint); color: var(--ink);
  text-decoration: none; font-size: 12px; }
.chip:hover { background: var(--tint-hover); color: var(--ink); }
.chip.st-needs_review, .chip.st-unread, .chip.st-deferred, .chip.st-needs_manual_download { background: var(--warning-bg); color: var(--warning); }
.chip.st-failed { background: var(--danger-bg); color: var(--danger); }
.chip.st-confirmed { background: var(--success-bg); color: var(--success); }

/* Tables. */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card);
  overflow-x: auto; }
.bills { width: 100%; border-collapse: collapse; }
.bills th, .bills td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
.bills th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--page); }
.bills tbody tr:hover td { background: var(--page); }
.bills tbody tr:last-child td { border-bottom: 0; }
.bills .num { text-align: right; font-variant-numeric: tabular-nums; }
.bills td.wrap { white-space: normal; min-width: 220px; }
.bills tr.overdue td, .bills tr.overdue:hover td { background: var(--danger-bg); }
.bills tr.overdue td:nth-child(2) { color: var(--danger); font-weight: 600; }
.bills tr.due-soon td, .bills tr.due-soon:hover td { background: var(--warning-bg); }
.bills tr.due-soon td:nth-child(2) { color: var(--warning); font-weight: 600; }
.bills.emails tr.action td:first-child { box-shadow: inset 3px 0 0 var(--brand); }

/* Notices, as the e-Invoice site's banner pairs. */
.flash { background: var(--info-bg); color: var(--brand-dark); padding: 10px 14px; border-radius: var(--radius); margin: 0 0 14px; font-weight: 500; }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.warnings { background: var(--warning-bg); color: var(--warning); padding: 10px 12px 10px 30px; border-radius: var(--radius); }
.error-text { color: var(--danger); }

/* Detail pages. */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); font-size: 13px; font-weight: 600; } dd { margin: 0; overflow-wrap: anywhere; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.fields label, .confirm label { display: flex; flex-direction: column; gap: 4px; }
.fields button { grid-column: 1 / -1; justify-self: start; }
.fields p.muted { grid-column: 1 / -1; font-size: 13px; margin: 0; }
@media (max-width: 600px) { .fields { grid-template-columns: 1fr; } }
.fields.sender { margin-top: 10px; } .fields.sender .check { grid-column: 1 / -1; }
.fields label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; }
.confirm { margin-top: 16px; display: grid; gap: 12px; } .confirm button { justify-self: start; } .confirm input { width: 100%; }
.item-line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-line form.inline { margin-left: 8px; }
.viewer iframe { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: var(--radius); }
.viewer img { max-width: 100%; }
pre.body { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--page);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; max-height: 70vh; overflow-y: auto; color: var(--ink); }
details { margin-top: 14px; }
details > summary { cursor: pointer; font-weight: 600; color: var(--brand); }
details.danger > summary { color: var(--muted); }
details.danger form { display: flex; gap: 8px; align-items: end; margin-top: 10px; flex-wrap: wrap; }
.inline-form { margin-top: 12px; }
.bills td.note-cell { white-space: normal; }
.stack { display: grid; gap: 16px; }
.narrow-form { max-width: 760px; }
.row-actions { display: flex; gap: 14px; align-items: center; }
.row-actions form { margin: 0; }
button.link.danger { color: var(--danger); }
button.link.danger:hover { color: var(--danger); }
.month-nav { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.month-nav form { gap: 6px; } .month-nav .right { margin-left: auto; }
.summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.tag.owner { background: var(--tint); color: var(--brand); }
.bills.outlets td.bill-cell { white-space: normal; min-width: 190px; position: relative; padding-right: 36px; }
.bills.outlets td.outlet-cell { white-space: normal; min-width: 200px; }
.bills.outlets td.st-missing { background: #fffafa; }
.bills.outlets .tick { display: inline-flex; gap: 6px; align-items: center; }
.bills.outlets .edit { position: absolute; top: 9px; right: 10px; font-size: 12px; color: var(--faint); }
.kind { font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 8px; white-space: nowrap; }
.kind.owner { background: var(--tint); color: var(--brand); } .kind.utility { background: var(--info-bg); color: var(--muted); }
.chased { font-size: 12px; color: var(--success); font-weight: 600; }
.fields .wide { grid-column: 1 / -1; }
.email-draft { margin: 0 0 14px; display: grid; gap: 10px; }
.email-draft label { display: flex; flex-direction: column; gap: 4px; }
.email-draft label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.email-draft textarea { width: 100%; font: 13px/1.5 var(--font); }
.warnings ul { margin: 4px 0 0; }
.pager { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; margin: 16px 0 0; }
.pager .button { min-width: 38px; }
.pager .current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .gap { color: var(--faint); padding: 0 4px; }
