/* Thiseni Enterprises — simple, large, touch-friendly UI */
:root {
    --navy: #0b2a5b;
    --blue: #1d4e9e;
    --blue-soft: #e8eef9;
    --line: #c9d5ea;
    --ink: #13213a;
    --muted: #55637a;
    --bg: #f3f6fb;
    --card: #ffffff;
    --danger: #b3261e;
    --danger-soft: #fdecea;
    --ok: #16733a;
    --ok-soft: #e6f4ea;
    --radius: 14px;
    --tap: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
    font-size: 18px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}
h1 { font-size: 1.6rem; margin: 0 0 .75rem; color: var(--navy); }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; color: var(--navy); }
a { color: var(--blue); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1rem;
    padding: .6rem 1rem;
    padding-top: max(.6rem, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.2rem; }
.brand img { background: #fff; border-radius: 50%; padding: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.4); }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a {
    color: #dbe6fb;
    text-decoration: none;
    padding: .55rem .9rem;
    border-radius: 10px;
    font-weight: 600;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.mainnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.mainnav a.active { background: #fff; color: var(--navy); }

.container { max-width: 1000px; margin: 0 auto; padding: 1rem; }

.appfooter { display: flex; justify-content: center; gap: 1.5rem; padding: 1.5rem 1rem 2rem; }
.linkbtn { background: none; border: 0; color: var(--muted); font-size: 1rem; text-decoration: underline; cursor: pointer; padding: .5rem; }

/* ---------- Cards, flash ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 1.25rem; box-shadow: 0 1px 3px rgba(11,42,91,.08); margin-bottom: 1rem; }
.center { text-align: center; }
.lead { font-size: 1.15rem; color: var(--muted); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .95rem; margin: .4rem 0 0; }
.flash { padding: .9rem 1.1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 600; font-size: 1.1rem; }
.flash-success { background: var(--ok-soft); color: var(--ok); border: 2px solid #a7d8b5; }
.flash-error { background: var(--danger-soft); color: var(--danger); border: 2px solid #f1b5b0; }
.badge { display: inline-block; background: var(--blue-soft); color: var(--navy); border-radius: 999px; padding: .1rem .75rem; font-size: 1.1rem; vertical-align: middle; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: var(--tap); padding: .6rem 1.3rem;
    border-radius: 12px; border: 2px solid transparent;
    font: inherit; font-weight: 700; font-size: 1.05rem;
    text-decoration: none; cursor: pointer; white-space: nowrap;
    transition: filter .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--navy); color: #fff; }
.btn-light { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-danger { background: #fff; color: var(--danger); border-color: #e7a8a3; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-xl { min-height: 64px; font-size: 1.25rem; padding: .8rem 2rem; }
.btn-small { min-height: 44px; padding: .35rem .8rem; font-size: .95rem; }
form.inline { display: inline; margin: 0; }

/* ---------- Dashboard ---------- */
.dash { display: grid; gap: 1rem; }
.dash-new {
    display: flex; align-items: center; gap: 1.25rem;
    background: linear-gradient(135deg, var(--blue), var(--navy));
    color: #fff; text-decoration: none;
    border-radius: 20px; padding: 1.75rem 1.5rem;
    box-shadow: 0 6px 18px rgba(11,42,91,.25);
}
.dash-new:hover { filter: brightness(1.08); }
.dash-plus { font-size: 3.5rem; line-height: 1; font-weight: 300; width: 72px; height: 72px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; flex: none; }
.dash-new strong { display: block; font-size: 2rem; }
.dash-new small { font-size: 1.05rem; opacity: .9; }
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.dash-tile {
    background: #fff; border-radius: 18px; padding: 1.5rem 1rem; text-align: center;
    text-decoration: none; color: var(--navy); box-shadow: 0 1px 3px rgba(11,42,91,.1);
    border: 2px solid transparent; display: flex; flex-direction: column; align-items: center; gap: .3rem;
}
.dash-tile:hover { border-color: var(--blue); }
.dash-icon { width: 48px; height: 48px; color: var(--blue); }
.dash-tile strong { font-size: 1.35rem; }
.dash-tile small { color: var(--muted); font-size: .95rem; }
.dash-today { text-align: center; color: var(--muted); margin: .5rem 0 0; }

/* ---------- Forms ---------- */
.bigform { display: grid; gap: 1.1rem; }
.field { display: grid; gap: .35rem; margin: 0; }
.field > span, .field > label > span { font-weight: 700; color: var(--navy); font-size: 1.05rem; }
.field input, .field select, .field textarea {
    width: 100%; font: inherit; font-size: 1.15rem;
    min-height: var(--tap); padding: .6rem .85rem;
    border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(29,78,158,.18); }
.field em { color: var(--danger); font-style: normal; font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); background: #fffafa; }
.row-add { display: flex; gap: .6rem; }
.row-add select { flex: 1; min-width: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .25rem; }
.form-card { max-width: 720px; margin: 0 auto 1rem; }

/* Dialog */
.modal { border: 0; border-radius: 18px; padding: 1.5rem; width: min(480px, calc(100vw - 2rem)); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(11,42,91,.45); }

/* Login */
.login-card { max-width: 420px; margin: 2rem auto; text-align: center; }
.login-logo { margin: 0 0 .25rem; line-height: 0; }
.login-logo img { width: 200px; height: auto; max-width: 70%; }
.login-card .bigform { text-align: left; margin-top: 1rem; }

/* ---------- Lists ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.searchbar { display: grid; grid-template-columns: 2fr 1fr auto; gap: 1rem; align-items: end; }
.searchbar-actions { display: flex; gap: .5rem; }
.inv-list { display: grid; gap: .75rem; }
.inv-item { padding: 1rem; margin: 0; }
.inv-main { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "no cust amt" "no sub amt"; gap: 0 1rem; text-decoration: none; color: var(--ink); align-items: center; }
.inv-no { grid-area: no; font-weight: 800; color: var(--navy); background: var(--blue-soft); border-radius: 10px; padding: .4rem .7rem; }
.inv-cust { grid-area: cust; font-weight: 700; font-size: 1.15rem; }
.inv-sub { grid-area: sub; color: var(--muted); font-size: .95rem; }
.inv-amt { grid-area: amt; font-weight: 800; color: var(--navy); font-size: 1.15rem; white-space: nowrap; }
.inv-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1.5rem 0; }

.vehicle-list { list-style: none; margin: 0; padding: 0; }
.vehicle-list li { display: flex; align-items: center; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.vehicle-list li:last-child { border-bottom: 0; }
.veh-no { font-weight: 800; font-size: 1.2rem; color: var(--navy); min-width: 8rem; }
.veh-actions { margin-left: auto; display: flex; gap: .4rem; }
.inline-form { grid-template-columns: 1fr auto; align-items: end; }
.inline-form input[type=hidden] { display: none; }

/* ---------- Invoice view ---------- */
.actions-bar { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.sheet-frame { width: 100%; max-width: 794px; margin: 0 auto 1.5rem; overflow: hidden; }
.sheet-scaler { width: 794px; transform-origin: top left; }

/* The invoice itself: fixed A4 size so screen, print, PDF and JPG all match. */
.sheet {
    width: 794px; height: 1123px;
    background: #fff; color: #10223f;
    font-family: "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
    font-size: 15px; line-height: 1.45;
    display: flex; flex-direction: column;
    box-shadow: 0 4px 20px rgba(11,42,91,.15);
    position: relative; overflow: hidden;
}
.sheet > * { flex-shrink: 0; }
.sheet-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 44px 52px 24px;
    border-bottom: 5px solid #0b2a5b;
    position: relative;
}
.sheet-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: -10px; height: 2px; background: #1d4e9e; }
.sheet-brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.sheet-logo { width: 90px; height: 90px; flex: none; display: block; }
.sheet-brand h1 { font-size: 29px; letter-spacing: 1.5px; margin: 0 0 6px; color: #0b2a5b; font-weight: 800; white-space: nowrap; }
.sheet-brand p { margin: 0; font-size: 15px; color: #26406b; }
.sheet-title {
    flex: none; margin-left: 20px;
    background: #0b2a5b; color: #fff; font-weight: 800; letter-spacing: 4px;
    font-size: 20px; padding: 10px 22px; border-radius: 6px; margin-top: 4px;
}
.sheet-meta {
    display: grid; grid-template-columns: 1fr 220px;
    margin: 34px 52px 24px;
    border: 1.5px solid #0b2a5b; border-radius: 6px; overflow: hidden;
}
.meta-item { padding: 10px 16px; border-bottom: 1px solid #c9d5ea; display: flex; flex-direction: column; }
.meta-item:nth-child(odd) { border-right: 1px solid #c9d5ea; }
.meta-item:nth-last-child(-n+2) { border-bottom: 0; }
.meta-item span { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: #1d4e9e; font-weight: 700; }
.meta-item strong { font-size: 18px; color: #0b2a5b; word-break: break-word; }

.sheet-table { margin: 0 52px 40px; width: calc(100% - 104px); border-collapse: collapse; flex: 1 1 auto; }
.sheet-table th, .sheet-table td { border: 1.5px solid #0b2a5b; padding: 10px 16px; text-align: left; vertical-align: top; }
.sheet-table thead th { background: #0b2a5b; color: #fff; font-size: 14px; letter-spacing: 1px; }
.sheet-table .amt { width: 190px; text-align: right; white-space: nowrap; }
.sheet-table td.amt { font-size: 17px; font-weight: 700; }
.desc-row td { height: 100%; }
.desc-text { font-size: 16px; white-space: normal; word-break: break-word; min-height: 120px; }
.bank { margin-top: 28px; border: 1px dashed #1d4e9e; border-radius: 6px; padding: 12px 16px; background: #f4f7fd; max-width: 380px; }
.bank-title { font-weight: 800; color: #0b2a5b; margin-bottom: 4px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.bank dl { display: grid; grid-template-columns: 120px 1fr; margin: 0; gap: 2px 8px; font-size: 14px; }
.bank dt { color: #26406b; }
.bank dt::after { content: ":"; }
.bank dd { margin: 0; font-weight: 700; color: #0b2a5b; }
.sheet-table tfoot th { background: #e8eef9; color: #0b2a5b; font-size: 18px; font-weight: 800; letter-spacing: .5px; }
.sheet-table tfoot th.amt { font-size: 20px; }

.sheet-foot { background: #0b2a5b; color: #fff; text-align: center; padding: 18px 40px 20px; border-top: 4px solid #1d4e9e; }
.sheet-foot p { margin: 0; font-size: 14px; letter-spacing: .3px; }
.sheet-foot p:first-child { font-weight: 700; font-size: 15px; }

/* Used automatically when the description is very long */
.sheet-compact .desc-text { min-height: 0; }
.sheet-compact .bank { margin-top: 14px; padding: 8px 14px; }
.sheet-compact .sheet-meta { margin: 24px 52px 16px; }
.sheet-compact .sheet-head { padding-top: 32px; }

/* Off-screen copy used to create PDF/JPG at full size */
.export-host { position: fixed; left: -10000px; top: 0; width: 794px; }
.export-host .sheet { box-shadow: none; }

/* Report PDF pages (built off-screen by app.js) */
.rsheet { width: 794px; height: 1123px; background: #fff; color: #10223f; padding: 44px 52px 0; position: relative; overflow: hidden;
    font-family: "Segoe UI", Roboto, "Noto Sans", "Noto Sans Sinhala", "Iskoola Pota", Arial, sans-serif; font-size: 13px; line-height: 1.4; }
.rsheet-head { border-bottom: 4px solid #0b2a5b; padding-bottom: 12px; margin-bottom: 18px; }
.rsheet-head h1 { font-size: 26px; letter-spacing: 1px; color: #0b2a5b; margin: 0 0 4px; }
.rsheet-head p { margin: 0; color: #26406b; font-size: 13px; }
.rsheet h2 { font-size: 18px; margin: 0 0 4px; color: #0b2a5b; }
.rsheet-period { margin: 0 0 14px; font-weight: 600; color: #26406b; }
.rsheet-stats { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-bottom: 16px; }
.rsheet-stat { border: 1.5px solid #c9d5ea; border-radius: 6px; padding: 8px 14px; }
.rsheet-stat span { display: block; color: #55637a; font-size: 12px; font-weight: 600; }
.rsheet-stat strong { font-size: 22px; color: #0b2a5b; }
.rsheet-stat-main { background: #0b2a5b; border-color: #0b2a5b; }
.rsheet-stat-main span { color: #c9d8f3; }
.rsheet-stat-main strong { color: #fff; }
.rsheet-table { width: 100%; border-collapse: collapse; }
.rsheet-table th, .rsheet-table td { border: 1px solid #0b2a5b; padding: 5px 8px; text-align: left; vertical-align: top; }
.rsheet-table thead th { background: #0b2a5b; color: #fff; font-size: 12px; }
.rsheet-table tbody tr:nth-child(even) td { background: #f4f7fd; }
.rsheet-table td:nth-child(1) { width: 60px; font-weight: 700; }
.rsheet-table td:nth-child(2) { width: 88px; white-space: nowrap; }
.rsheet-table td:nth-child(4) { width: 110px; }
.rsheet-table .amt { text-align: right; white-space: nowrap; width: 120px; }
.rsheet-table tfoot th { background: #e8eef9; color: #0b2a5b; font-size: 14px; }
.rsheet-pageno { position: absolute; bottom: 24px; right: 52px; font-size: 11px; color: #55637a; }

/* ---------- Reports ---------- */
.report-form { display: grid; gap: 1rem; }
.period-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.period-tab input { position: absolute; opacity: 0; pointer-events: none; }
.period-tab span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); border: 2px solid var(--line); border-radius: 12px; font-weight: 700; color: var(--navy); cursor: pointer; text-align: center; padding: .3rem; }
.period-tab input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.period-tab input:focus-visible + span { box-shadow: 0 0 0 4px rgba(29,78,158,.25); }
.report-period { font-size: 1.1rem; }
.stat-row { display: grid; grid-template-columns: 1fr 2fr; gap: 1rem; margin-bottom: 1rem; }
.stat { background: #fff; border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(11,42,91,.08); }
.stat span { display: block; color: var(--muted); font-weight: 600; }
.stat strong { font-size: 2rem; color: var(--navy); }
.stat-main { background: var(--navy); }
.stat-main span { color: #c9d8f3; }
.stat-main strong { color: #fff; }
.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(11,42,91,.08); }
.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); text-align: left; }
.report-table thead th { background: var(--navy); color: #fff; }
.report-table tfoot th { background: var(--blue-soft); color: var(--navy); font-size: 1.1rem; }
.report-table .amt { text-align: right; white-space: nowrap; }
.print-only { display: none; }

/* Busy overlay */
.busy { position: fixed; inset: 0; background: rgba(11,42,91,.35); display: grid; place-items: center; z-index: 100; }
.busy-box { background: #fff; padding: 1.25rem 2rem; border-radius: 14px; font-weight: 700; font-size: 1.2rem; color: var(--navy); }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
    body { font-size: 17px; }
    .topbar { padding: .5rem .75rem; }
    .brand span { font-size: 1.05rem; }
    .mainnav { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); }
    .mainnav a { justify-content: center; padding: .5rem .25rem; font-size: .95rem; }
    .container { padding: .75rem; }
    .dash-new { padding: 1.4rem 1.1rem; }
    .dash-new strong { font-size: 1.7rem; }
    .dash-plus { width: 60px; height: 60px; font-size: 3rem; }
    .dash-grid { grid-template-columns: 1fr; }
    .dash-tile { flex-direction: row; text-align: left; padding: 1rem 1.25rem; gap: 1rem; }
    .dash-tile small { margin-left: auto; text-align: right; font-size: .85rem; max-width: 45%; }
    .two-col, .searchbar, .stat-row, .inline-form { grid-template-columns: 1fr; }
    .row-add { flex-direction: column; }
    .form-actions .btn, .searchbar-actions .btn { flex: 1; }
    .inv-main { grid-template-columns: auto 1fr; grid-template-areas: "no amt" "cust cust" "sub sub"; gap: .3rem .75rem; }
    .inv-amt { text-align: right; }
    .actions-bar .btn, .actions-bar form { flex: 1 1 45%; }
    .actions-bar form .btn { width: 100%; }
    .veh-actions { margin-left: 0; width: 100%; }
    .veh-actions .btn, .veh-actions form { flex: 1; }
    .veh-actions form .btn { width: 100%; }
    .period-tab span { font-size: .95rem; }

    /* Report table becomes stacked rows so the amount is always visible */
    .report-table thead { display: none; }
    .report-table tbody tr {
        display: grid; grid-template-columns: auto 1fr auto;
        grid-template-areas: "no date amt" "cust cust cust" "veh veh veh";
        gap: 0 .75rem; padding: .6rem .9rem; border-bottom: 1px solid var(--line);
    }
    .report-table tbody td { border: 0; padding: 0; }
    .report-table tbody td:nth-child(1) { grid-area: no; font-weight: 800; }
    .report-table tbody td:nth-child(2) { grid-area: date; color: var(--muted); }
    .report-table tbody td:nth-child(3) { grid-area: cust; font-weight: 600; }
    .report-table tbody td:nth-child(4) { grid-area: veh; color: var(--muted); font-size: .95rem; }
    .report-table tbody td:nth-child(5) { grid-area: amt; font-weight: 800; color: var(--navy); }
    .report-table tfoot tr { display: flex; justify-content: space-between; background: var(--blue-soft); }
    .report-table tfoot th { border: 0; }
}

/* ---------- Printing ---------- */
@media print {
    @page { size: A4; margin: 12mm; }
    @page invoice { size: A4; margin: 0; }
    .sheet-frame { page: invoice; }
    body { background: #fff; font-size: 12pt; }
    .no-print, .topbar, .appfooter, .flash { display: none !important; }
    .container { max-width: none; padding: 0; margin: 0; }
    .sheet-frame { overflow: visible; height: auto !important; margin: 0; }
    .sheet-scaler { transform: none !important; }
    .sheet { box-shadow: none; width: 210mm; height: 296mm; }
    .sheet-frame, .sheet-scaler { width: 210mm !important; max-width: none; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    .print-only { display: block; }
    .report-print-head h1 { margin: 0; }
    .report-print-head p { margin: 0 0 .5rem; }
    .stat { box-shadow: none; border: 1px solid var(--line); }
    .table-wrap { overflow: visible; box-shadow: none; }
    .report-table a { color: inherit; text-decoration: none; }
}
