:root {
    --brand: #1a3d6d;
    --brand-2: #24508c;
    --bg: #f3f5f9;
    --card: #ffffff;
    --line: #e3e7ee;
    --ink: #1c2330;
    --ink-2: #5a6474;
    --ink-3: #8a93a3;
    --good: #1a7f37;
    --good-bg: #dcf3e2;
    --warn: #9a5b00;
    --warn-bg: #fdf0d5;
    --bad: #b42318;
    --bad-bg: #fde4e1;
    --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand-2); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
input, select, textarea, button { font: inherit; color: inherit; }

/* layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #dfe7f3; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { flex: none; width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; }
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; background: var(--brand); color: #fff; margin: 0 auto 12px; border-radius: 14px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a, .me-name { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: #dfe7f3; text-decoration: none; }
.side nav a:hover, .me-name:hover { background: rgba(255, 255, 255, .08); }
.side nav a.on, .me-name.on { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; }
.side svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.me { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .15); padding-top: 12px; }
.me-name small { display: block; font-size: 12px; opacity: .7; font-weight: 400; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; font-weight: 700; flex: none; }
.logout { display: block; padding: 8px 12px; color: #b9c6da; font-size: 13px; }

.main { padding: 24px 32px 48px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.top h1 { font-size: 24px; flex: 1; }
.menu-btn { display: none; background: none; border: 0; padding: 4px; cursor: pointer; }
.menu-btn svg { width: 26px; height: 26px; fill: var(--ink); }

/* pieces */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin-bottom: 14px; }
.card h3 { font-size: 14px; margin: 20px 0 4px; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + .form-actions { margin-top: 18px; }
.grid2.wide-left { grid-template-columns: 1.6fr 1fr; align-items: start; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c7cfdb; background: #f8f9fb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; padding: 11px; }
.link-danger { background: none; border: 0; color: var(--bad); cursor: pointer; padding: 0; text-decoration: underline; }
form.inline { display: inline; }

label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
label input, label select, label textarea, .card > textarea { display: block; width: 100%; margin-top: 5px; font-weight: 400; color: var(--ink); }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
    border: 1px solid #cfd6e1; border-radius: 7px; padding: 8px 10px; background: #fff; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(36, 80, 140, .35); border-color: var(--brand-2); }
textarea { resize: vertical; width: 100%; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
label.check input { width: auto; margin: 0; }
.help { display: block; font-weight: 400; color: var(--ink-3); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .pill { margin-right: 6px; }
.danger-zone { margin-top: 8px; text-align: right; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash.good { background: var(--good-bg); color: var(--good); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.paid { background: var(--good-bg); color: var(--good); }
.pill.unpaid { background: #e8edf5; color: #3b4a61; }
.pill.overdue { background: var(--bad-bg); color: var(--bad); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.list th.num { text-align: right; }
.list td { padding: 11px 10px; border-bottom: 1px solid var(--line); }
.list tbody tr:hover { background: #f8fafc; }
.list tbody tr:last-child td { border-bottom: 0; }
.list a.strong { text-decoration: none; }
.list .empty { text-align: center; color: var(--ink-2); padding: 28px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.acts { text-align: right; white-space: nowrap; }
.acts > * + * { margin-left: 6px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.tile-label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.tile strong { display: block; font-size: 24px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 13px; color: var(--ink-3); }
.tile.warn { border-color: #f3b9b2; }
.tile.warn strong { color: var(--bad); }

/* bar chart: one series, so no legend; the card title names it */
.chart { display: flex; align-items: stretch; gap: 14px; height: 220px; padding-top: 8px; border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to top, transparent 0, transparent 49px, #eef1f5 49px, #eef1f5 50px); }
.bar-col { flex: 1; display: flex; flex-direction: column; position: relative; outline: none; cursor: default; }
.bar-track { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.bar { width: min(56px, 70%); background: var(--brand-2); border-radius: 4px 4px 0 0; transition: background .15s; }
.bar-col:hover .bar, .bar-col:focus .bar { background: var(--brand); }
.bar-label { position: absolute; bottom: -24px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--ink-3); }
.chart + * { margin-top: 30px; }
.card:has(.chart) { padding-bottom: 36px; }
.tip { position: absolute; left: 50%; top: 0; transform: translate(-50%, -100%); background: var(--ink); color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 6px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 2; }
.tip b { display: block; font-size: 14px; }
.bar-col:hover .tip, .bar-col:focus .tip { opacity: 1; }

/* invoices page */
.filters { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 600; }
.tabs a span { font-weight: 400; color: var(--ink-3); margin-left: 2px; }
.tabs a.on { background: #e8edf5; color: var(--brand); }
.search input { width: 280px; max-width: 100%; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 14px; color: var(--ink-2); }

/* invoice form */
.items th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 0 6px 6px; }
.items th.num { text-align: right; }
.items th small { text-transform: none; letter-spacing: 0; }
.items td { padding: 4px 6px; }
.items input { width: 100%; }
.items .qty { width: 90px; }
.items .price { width: 160px; }
.items .line { width: 120px; color: var(--ink-2); }
.items .remove { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--ink-3); cursor: pointer; padding: 4px 8px; }
.items .remove:hover { color: var(--bad); }
#tyi-add { margin-top: 8px; }
.sum { width: auto; min-width: 280px; margin: 8px 0 0 auto; font-variant-numeric: tabular-nums; }
.sum th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 4px 24px 4px 0; }
.sum td { text-align: right; }
.sum .grand th, .sum .grand td { font-weight: 700; font-size: 18px; color: var(--ink); border-top: 2px solid var(--brand); padding-top: 8px; }

.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.logo-row img { max-height: 64px; max-width: 180px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand) 0%, #0f2747 100%); }
.login-card { background: #fff; width: 100%; max-width: 380px; border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); text-align: center; }
.login-card h1 { font-size: 22px; }
.login-card .muted { margin: 4px 0 20px; }
.login-card label { text-align: left; }
.login-card label.check { margin: 4px 0 16px; }
.login-logo { max-height: 70px; max-width: 220px; margin-bottom: 12px; }
.forgot { display: inline-block; margin-top: 14px; font-size: 13px; }

/* phones and small tablets */
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .side { position: fixed; z-index: 10; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
    .side.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
    .menu-btn { display: block; }
    .main { padding: 16px; }
    .top h1 { font-size: 20px; }
    .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
    .chart { gap: 8px; }
}
@media (max-width: 520px) {
    .two { grid-template-columns: 1fr; gap: 0; }
    .top .btn { padding: 8px 12px; }
    .items .price { width: 110px; }
    .items .qty { width: 70px; }
    .search, .search input { width: 100%; }
    .list .hide-sm { display: none; }
    .list.inv a.strong { white-space: nowrap; }
    .list td, .list th { padding-left: 6px; padding-right: 6px; }
}

/* settings: switches and bank accounts */
.switch { display: flex; align-items: flex-start; gap: 12px; font-weight: 600; color: var(--ink); cursor: pointer; margin-bottom: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 42px; height: 24px; border-radius: 999px; background: #c5ccd8; position: relative; transition: background .15s; margin-top: 1px; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + .track { background: var(--brand-2); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid rgba(36, 80, 140, .45); outline-offset: 2px; }
.switch small { display: block; font-weight: 400; color: var(--ink-3); }
.due-days[hidden] { display: none; }
.bank-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 10px; }
.bank-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fafbfd; }
.bank-item-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.bank-item textarea { margin: 0; }
.bank-remove { background: none; border: 0; color: var(--bad); cursor: pointer; font-size: 13px; text-decoration: underline; padding: 0; }

/* dashboard: date range + filter tiles */
.range-bar { display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.range-bar label { margin: 0; }
.range-select select { min-width: 180px; }
.range-custom { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.range-custom[hidden] { display: none; }
.range-label { color: var(--ink-2); font-weight: 600; padding-bottom: 9px; }
.range-label small { font-weight: 400; color: var(--ink-3); }
a.tile.filter { display: block; color: inherit; text-decoration: none; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
a.tile.filter:hover { border-color: #b8c3d4; box-shadow: 0 2px 8px rgba(26, 61, 109, .08); }
a.tile.filter.on { border: 2px solid var(--brand-2); padding: 15px 17px; box-shadow: 0 2px 10px rgba(26, 61, 109, .12); }
a.tile.filter.on .tile-sub b { color: var(--brand-2); }
.chart.dense { gap: 3px; }
.chart.dense .bar { width: 80%; border-radius: 3px 3px 0 0; }
@media (max-width: 860px) {
    .chart.dense .bar-label:not(.key) { visibility: hidden; }
    .chart.dense .bar-label { font-size: 11px; white-space: nowrap; }
}
@media (max-width: 520px) {
    .range-select, .range-select select { width: 100%; }
    .range-custom label { flex: 1; }
}
.btn.danger { color: var(--bad); border-color: #f1c4bf; background: #fff; }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
