/*
 * Gaadiwala — application stylesheet.
 *
 * The brief is a working instrument, not a marketing site: an office clerk
 * enters lorry receipts in it all day, and a proprietor reads it to find out who
 * owes money. So it is built to look like well-printed freight paperwork —
 * ruled tables, figures that line up in their columns, field captions in a
 * condensed face, and colour used to mean something rather than to decorate.
 *
 * The one deliberate flourish is the number plate: commercial vehicles in India
 * carry black-on-yellow plates, so a registration number is rendered as one
 * wherever it appears. It is the single most scannable thing in a list of
 * trips, and it comes from the subject rather than from a palette.
 *
 * Typefaces are system faces only — CLAUDE.md §3 rule 2 rules out a webfont CDN.
 * Bahnschrift (Windows) and Avenir Next Condensed (macOS) give the condensed
 * grotesque of a route board; everything falls back to a normal grotesque.
 */

:root {
    /* Ink on paper. */
    --ink: #1b1d26;
    --ink-soft: #3d4453;
    --muted: #6b7486;

    --paper: #eceff5;
    --surface: #ffffff;
    --surface-alt: #f7f9fc;

    /* A docket book has visible rules; --rule-firm is the box line. */
    --rule: #d6dce6;
    --rule-firm: #a9b3c2;

    /* Stamp-pad ink: every action in the app is this colour. */
    --accent: #115bd3;
    --accent-dark: #0e49a9;
    --accent-wash: #e7effb;

    --ok: #15653f;
    --ok-wash: #e4f3ea;

    /* Receipt red: cancelled, overdue, destructive. */
    --alert: #b3271d;
    --alert-wash: #fdeceb;

    --warn-wash: #fdf3dd;
    --warn-rule: #ecd7a1;

    /* The commercial vehicle number plate. Used for nothing else. */
    --plate: #f6c500;
    --plate-ink: #16181f;

    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-condensed: Bahnschrift, "Avenir Next Condensed", "HelveticaNeue-CondensedBold",
        "Liberation Sans Narrow", "Arial Narrow", var(--font-ui);
    --font-mono: Consolas, "Cascadia Mono", "SF Mono", Menlo, "DejaVu Sans Mono", monospace;

    --radius: 8px;
    --radius-sm: 4px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.55 var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --------------------------------------------------------------- top bar */

.topbar {
    display: flex;
    align-items: center;
    gap: 26px;
    background: var(--surface);
    /* The band across the head of a ledger page. */
    border-top: 3px solid var(--accent);
    border-bottom: 1px solid var(--rule);
    padding: 13px 26px;
}

/*
 * The wordmark. It is a flat one-colour PNG at 651x108, so it is placed at a
 * fixed height and lets its width follow; the alt text carries the name for a
 * reader that does not load it.
 */
.brand {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    flex: none;
}

.brand img {
    display: block;
    height: 26px;
    width: auto;
}

/* The same wordmark, larger, over the sign-in card. */
.brand-mark {
    display: block;
    height: 34px;
    width: auto;
    margin: 0 auto 20px;
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
}

.nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 5px 9px;
    border-radius: var(--radius-sm);
    border-bottom: 2px solid transparent;
    transition: color 0.12s, background 0.12s;
}

.nav a:hover {
    color: var(--ink);
    background: var(--surface-alt);
}

.nav a.on {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--accent);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.nav-divider {
    width: 1px;
    align-self: stretch;
    margin: 3px 8px;
    background: var(--rule);
}

.who {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.who-name { font-weight: 600; }
.who-meta { color: var(--muted); }

/* --------------------------------------------------------------- layout */

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 30px 26px 72px;
}

h1 {
    font-family: var(--font-condensed);
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: 0.005em;
    margin: 0 0 10px;
}

h2 {
    font-family: var(--font-condensed);
    font-size: 1.1rem;
    font-weight: 700;
    margin: 22px 0 10px;
}

/* A section caption, ruled off like the divider on a printed form. */
h2.section {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    margin: 34px 0 12px;
}

h2.section::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 6px;
}

.page-head h1 { margin: 0; }

/* Buttons carry a top margin for forms; in a page header they must not. */
.page-head .button,
.page-head .record-actions { margin-top: 0; }

.lead { color: var(--muted); max-width: 62ch; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.inline { display: inline; }

.footer {
    color: var(--muted);
    font-family: var(--font-condensed);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 18px 26px;
    border-top: 1px solid var(--rule);
}

/* ---------------------------------------------------------- the identifiers */

/* Document numbers are identifiers, so they are set as such. */
.docnum {
    font-family: var(--font-mono);
    font-size: 0.94em;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/*
 * A commercial vehicle registration, as the plate on the truck: black on
 * yellow, condensed, slightly bevelled. The one flourish in the app.
 */
.plate {
    display: inline-block;
    background: var(--plate);
    color: var(--plate-ink);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    line-height: 1.35;
    padding: 1px 7px;
    border: 1px solid rgba(0, 0, 0, 0.42);
    border-radius: 3px;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.16);
    white-space: nowrap;
}

a .plate { text-decoration: none; }

/* The vehicle's own page: the plate is the heading. */
.plate-lg {
    font-size: 1.35rem;
    letter-spacing: 0.1em;
    padding: 3px 12px;
    border-radius: var(--radius-sm);
    border-width: 2px;
}

/* ---------------------------------------------------------------- tables */

table.data {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

table.data th,
table.data td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
}

table.data thead th {
    background: var(--surface-alt);
    font-family: var(--font-condensed);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
    /* The box line under a form's column headings. */
    border-bottom: 2px solid var(--rule-firm);
    white-space: nowrap;
}

table.data tbody tr:last-child td,
table.data tbody tr:last-child th { border-bottom: 0; }

table.data tbody tr:hover th,
table.data tbody tr:hover td { background: var(--surface-alt); }

/* Label / value tables on a detail page. */
table.data tbody th {
    width: 210px;
    font-family: var(--font-condensed);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    background: transparent;
}

table.data td.num,
table.data th.num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

table.data td .small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

table.data tfoot td {
    background: var(--surface-alt);
    border-top: 2px solid var(--rule-firm);
    border-bottom: 0;
    font-weight: 600;
}

table.line-items td { vertical-align: top; }
table.line-items input,
table.line-items select { width: 100%; }
table.line-items td.num input { text-align: right; }

.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--alert); font-weight: 600; }

/* ------------------------------------------------------------ status pills */

/* Stamped, not bubbled: square-ish, small caps, one tint per state. */
.pill {
    display: inline-block;
    font-family: var(--font-condensed);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    padding: 2px 8px;
    border-radius: 3px;
    border: 1px solid transparent;
    background: var(--accent-wash);
    color: var(--accent-dark);
    white-space: nowrap;
}

.pill-draft,
.pill-off {
    background: #eef1f6;
    border-color: #dde2ea;
    color: var(--muted);
}

.pill-issued,
.pill-sent,
.pill-received {
    background: var(--accent-wash);
    border-color: #cdd6f8;
    color: var(--accent-dark);
}

.pill-delivered,
.pill-paid,
.pill-ok {
    background: var(--ok-wash);
    border-color: #c3e2ce;
    color: var(--ok);
}

.pill-cancelled {
    background: var(--alert-wash);
    border-color: #f2c8c4;
    color: var(--alert);
}

/* ---------------------------------------------------------------- panels */

.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 22px 24px;
    margin: 22px 0;
}

.card h2 { margin: 24px 0 10px; }
.card h2:first-of-type { margin-top: 0; }

.card-narrow {
    max-width: 430px;
    margin: 56px auto;
    border-top: 3px solid var(--accent);
    padding: 26px 28px 28px;
}

/* A dead end — 403, 404, 500. Says what happened and offers the way out. */
.notice {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    max-width: 560px;
    margin: 48px auto;
    padding: 30px 32px 32px;
}

.notice .lead { margin-bottom: 4px; }

.empty {
    background: var(--surface);
    border: 1px dashed var(--rule-firm);
    border-radius: var(--radius);
    padding: 30px 24px;
    text-align: center;
    color: var(--muted);
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
    gap: 14px;
    margin: 16px 0 4px;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 14px 16px;
}

a.tile {
    color: inherit;
    text-decoration: none;
    transition: border-color 0.12s, background 0.12s;
}

a.tile:hover {
    border-color: var(--accent);
    background: var(--surface-alt);
}

.tile-label {
    display: block;
    font-family: var(--font-condensed);
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
}

.tile-value {
    display: block;
    font-size: 1.4rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    margin-top: 5px;
}

.tile-note {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 6px;
}

/* ------------------------------------------------------- banners and flashes */

.banner {
    padding: 11px 26px;
    border-bottom: 1px solid var(--rule);
    font-size: 0.9rem;
}

.banner-warning { background: var(--warn-wash); border-bottom-color: var(--warn-rule); }
.banner-info { background: var(--accent-wash); border-bottom-color: #cdd6f8; }

.container .banner {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.flash {
    padding: 11px 15px 11px 14px;
    border: 1px solid transparent;
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 0.9rem;
}

.flash-success {
    background: var(--ok-wash);
    border-color: #c3e2ce;
    border-left-color: var(--ok);
    color: #0f5734;
}

.flash-error {
    background: var(--alert-wash);
    border-color: #f2c8c4;
    border-left-color: var(--alert);
    color: #8e1f17;
}

.flash ul { margin: 0; padding-left: 18px; }

/* ----------------------------------------------------------------- forms */

label,
.label-text {
    display: block;
    margin: 14px 0 5px;
    font-family: var(--font-condensed);
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--rule-firm);
    border-radius: var(--radius-sm);
    font: inherit;
    background: var(--surface);
    color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(17, 91, 211, 0.18);
}

.hint {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 5px;
}

.fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px 20px;
}

/* A grid cell; an empty one is a deliberate gap in the form. */
.field { min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > label:first-child,
.field > .label-text:first-child { margin-top: 12px; }

label.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0 0;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    color: var(--ink);
}

label.check input {
    width: auto;
    margin: 0;
    accent-color: var(--accent);
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 22px;
}

/* ---------------------------------------------------------------- buttons */

.button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    text-decoration: none;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    margin-top: 16px;
    transition: background 0.12s, border-color 0.12s;
}

.button:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

.button-quiet {
    background: var(--surface);
    border-color: var(--rule-firm);
    color: var(--ink);
    font-weight: 500;
}

.button-quiet:hover { background: var(--surface-alt); border-color: var(--ink-soft); color: var(--ink); }

.button-danger { background: var(--alert); border-color: var(--alert); }
.button-danger:hover { background: #932018; border-color: #932018; }

.link-button {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.record-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.record-actions form { margin: 0; }
.record-actions .button { margin-top: 0; }

/* ------------------------------------------------------- filter / row forms */

.row-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.row-form label { margin: 0 0 5px; }
.row-form input { width: auto; }
.row-form .button { margin-top: 0; }

.filters {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 16px 0 20px;
}

.filters > div { display: flex; flex-direction: column; }
.filters input[type="text"] { width: 250px; }
.filters select { width: auto; }

.report-form { padding: 20px 24px; }
.report-form .form-actions { gap: 18px; }
.preset-on { font-weight: 700; text-decoration: none; }

blockquote {
    margin: 12px 0;
    padding-left: 14px;
    border-left: 3px solid var(--rule-firm);
    color: var(--muted);
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
    .topbar { flex-wrap: wrap; gap: 12px 18px; padding: 12px 18px; }
    .nav { order: 3; width: 100%; gap: 2px; }
    .nav-divider { display: none; }
    .who { margin-left: auto; }
    .container { padding: 24px 18px 56px; }
}

@media (max-width: 700px) {
    .fields { grid-template-columns: minmax(0, 1fr); }
    .filters input[type="text"] { width: 100%; }
    .filters > div { width: 100%; }

    /*
     * A freight table has six or seven columns and none of them is optional, so
     * on a narrow screen it scrolls sideways rather than being folded up into
     * something that no longer reads like a table.
     */
    table.data {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    table.data tbody th { width: auto; }
    table.data td .small { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ----------------------------------------------------------- pagination */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin: 14px 0 4px;
}

.pagination-count { margin: 0; }

.pager {
    display: flex;
    align-items: center;
    gap: 2px;
}

.pager a,
.pager-on,
.pager-off,
.pager-gap {
    min-width: 34px;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    text-align: center;
    text-decoration: none;
}

.pager a {
    color: var(--accent);
    border: 1px solid var(--rule);
    background: var(--surface);
    transition: border-color 0.12s, background 0.12s;
}

.pager a:hover { border-color: var(--accent); background: var(--accent-wash); }

.pager-on {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
    font-weight: 600;
}

.pager-off { color: var(--muted); border: 1px solid transparent; }
.pager-gap { color: var(--muted); min-width: 0; padding: 6px 2px; }

/* ------------------------------------------------ tenant letterhead settings */

.logo-preview {
    display: block;
    max-width: 320px;
    max-height: 110px;
    width: auto;
    height: auto;
    padding: 10px 12px;
    background: var(--surface-alt);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
}

input[type="file"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px dashed var(--rule-firm);
    border-radius: var(--radius-sm);
    font: inherit;
    background: var(--surface-alt);
}

/* A read-only tenant sees its settings, greyed, rather than an empty screen. */
input:disabled,
select:disabled,
textarea:disabled {
    background: var(--surface-alt);
    color: var(--muted);
    cursor: not-allowed;
}

.save-columns { margin: -8px 0 18px; }
