/*
 * Theme for Brandstofverbruik, derived from SeriesTracker's DuckieTV-styled
 * theme: black background, condensed display font for headings, fixed left
 * icon action bar, purple (#6a3fb3) accent for interactive elements.
 *
 * All themeable colors are CSS variables; a light variant overrides them
 * under :root[data-theme="light"]. Literal #fff below is only used for text
 * on fixed-color backgrounds (purple/red fills). --chart-1/--chart-2 are the
 * chart series colors, validated for colorblind separation per theme.
 */

:root {
    --bg: #000;
    --panel-bg: #1a1a1a;
    --panel-bg-alt: #222;
    --border: #333;
    --grid-line: #2a2a2a;
    --text: #ddd;
    --text-muted: #999;
    --accent: #d75555;
    --accent-hover: #e57373;
    --success: #47a447;
    --text-strong: #fff;
    --actionbar-bg: #0c0c0c;
    --actionbar-hover: rgba(70, 70, 70, 0.6);
    --row-hover: rgba(255, 255, 255, 0.03);
    --tooltip-bg: #111;
    --shadow: rgba(0, 0, 0, 0.5);
    --good-text: #7ed67e;
    --bad-text: #e0b060;
    --warning-text: #e0b060;
    --danger-text: #ff6b6b;
    --chart-1: #9a6bd8;
    --chart-2: #c27a28;
    color-scheme: dark;
}

/* Light theme: toggled via Settings, rendered as <html data-theme="light">. */
:root[data-theme="light"] {
    --bg: #f2f2f5;
    --panel-bg: #fff;
    --panel-bg-alt: #e8e8ee;
    --border: #d2d2da;
    --grid-line: #e6e6ec;
    --text: #222;
    --text-muted: #666;
    --accent: #b3261e;
    --accent-hover: #d75555;
    --text-strong: #000;
    --actionbar-bg: #fff;
    --actionbar-hover: rgba(0, 0, 0, 0.07);
    --row-hover: rgba(0, 0, 0, 0.03);
    --tooltip-bg: #fff;
    --shadow: rgba(0, 0, 0, 0.18);
    --good-text: #2e7d32;
    --bad-text: #9a6a00;
    --warning-text: #9a6a00;
    --danger-text: #c62828;
    --chart-1: #6a3fb3;
    --chart-2: #c06a10;
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Roboto', helvetica, sans-serif;
}

h1, h2, h3 {
    font-family: 'Bebas Neue', 'Roboto', helvetica, sans-serif;
    letter-spacing: 1px;
    font-weight: normal;
    color: var(--text-strong);
}

a {
    color: var(--accent-hover);
    text-decoration: none;
}

a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* --- Left action bar --- */

#actionbar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 58px;
    background-color: var(--actionbar-bg);
    border-right: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#actionbar .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    font-size: 26px;
    color: var(--text-strong);
    text-decoration: none;
}

#actionbar .logo:hover {
    color: var(--text-strong);
}

#actionbar .logo.active {
    background-color: rgba(106, 63, 179, 0.3);
    border-left: 3px solid #6a3fb3;
}

#actionbar ul {
    list-style: none;
    margin: 20px 0 0 0;
    padding: 0;
    width: 100%;
}

#actionbar li {
    width: 58px;
    height: 58px;
    transition: background-color 0.2s;
}

#actionbar li.active {
    background-color: rgba(106, 63, 179, 0.3);
    border-left: 3px solid #6a3fb3;
}

#actionbar li:hover {
    background-color: var(--actionbar-hover);
}

#actionbar li a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 22px;
    color: var(--text-strong);
    text-decoration: none;
}

#actionbar li a:hover {
    color: var(--text-strong);
}

/* Logout button, pinned to the bottom of the action bar. */
#actionbar .logout-form {
    margin-top: auto;
    width: 58px;
}

#actionbar .logout-form button {
    width: 58px;
    height: 58px;
    background: none;
    border: 0;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}

#actionbar .logout-form button:hover {
    background-color: var(--actionbar-hover);
    color: var(--text-strong);
}

/* --- Main content --- */

.main {
    margin-left: 58px;
    padding: 28px 35px;
    min-height: 100vh;
}

.flash-message, .message {
    padding: 10px 15px;
    margin-bottom: 15px;
    border-radius: 3px;
    background: var(--panel-bg-alt);
    border-left: 3px solid var(--accent);
    cursor: pointer;
}

.message.success {
    border-left-color: var(--success);
}

.message.info, .message.warning {
    border-left-color: #6a3fb3;
}

.message.hidden {
    display: none;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0 auto 0 0;
    font-size: 36px;
}

.page-header-sub {
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 24px;
}

.muted {
    color: var(--text-muted);
}

.strong {
    font-weight: 500;
    color: var(--text-strong);
}

/* Vehicle picker (layout, only with more than one vehicle). */
.vehicle-picker {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin: -12px 0 12px;
    color: var(--text-muted);
}

.vehicle-picker select {
    padding: 5px 8px;
    background: var(--panel-bg-alt);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-size: 13px;
}

/* --- Tables --- */

.table-scroll {
    overflow-x: auto;
    margin-bottom: 24px;
}

.table-scroll table {
    margin-bottom: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    background: var(--panel-bg);
}

table th, table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
}

table th {
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 12px;
    white-space: nowrap;
}

table tr:hover {
    background: var(--row-hover);
}

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

td.good {
    color: var(--good-text);
}

td.bad {
    color: var(--bad-text);
}

.refuels-table td {
    white-space: nowrap;
}

.refuels-table td.notes {
    white-space: normal;
    min-width: 200px;
    color: var(--text-muted);
    font-size: 13px;
}

.refuels-table tr.is-start td {
    color: var(--text-muted);
    font-style: italic;
}

td.actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.icon-btn {
    display: inline-block;
    padding: 4px 6px;
    color: var(--text-muted);
    font-size: 13px;
}

.icon-btn:hover {
    color: #6a3fb3;
    text-decoration: none;
}

.icon-btn-danger:hover {
    color: var(--danger-text);
}

.license-plate {
    display: inline-block;
    padding: 1px 8px;
    background: #f2c200;
    border-radius: 3px;
    color: #000;
    font-weight: 700;
    letter-spacing: 1px;
}

/* Summary tables on the statistics page: no own background (sit in a panel). */
.summary-table {
    margin: 0;
    background: transparent;
}

.summary-table td:first-child {
    color: var(--text-muted);
}

/* --- Forms --- */

.form-panel {
    max-width: 760px;
    padding: 20px 24px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0 16px;
}

.input {
    margin-bottom: 16px;
}

.input label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.input.required label::after {
    content: ' *';
    color: #6a3fb3;
}

.input input, .input textarea, .input select {
    width: 100%;
    padding: 8px 10px;
    background: var(--panel-bg-alt);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.input input:focus, .input textarea:focus, .input select:focus {
    outline: none;
    border-color: #6a3fb3;
}

.input.error input, .input.error textarea {
    border-color: var(--danger-text);
}

.error-message {
    margin-top: 4px;
    color: var(--danger-text);
    font-size: 12px;
}

.form-hint {
    margin: 0 0 16px;
    color: var(--text-muted);
    font-size: 13px;
}

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

.btn-primary {
    display: inline-block;
    background: #6a3fb3;
    border: 1px solid #6a3fb3;
    border-radius: 3px;
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    padding: 8px 18px;
    cursor: pointer;
}

.btn-primary:hover {
    background: #7d4fce;
    border-color: #7d4fce;
    color: #fff;
    text-decoration: none;
}

.btn-secondary {
    color: var(--text-muted);
    font-size: 13px;
}

.btn-secondary:hover {
    color: var(--text);
}

/* Theme picker chips (settings page). */
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
}

.chip {
    background: var(--panel-bg-alt);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

.chip:hover {
    border-color: #6a3fb3;
}

.chip-radio {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.chip-radio:checked + .chip {
    background: #6a3fb3;
    border-color: #6a3fb3;
    color: #fff;
}

.chip-radio:focus-visible + .chip {
    outline: 2px solid #6a3fb3;
    outline-offset: 2px;
}

/* --- Hover detail tooltip (used across the app) --- */

.app-tooltip {
    display: none;
    position: absolute;
    z-index: 3000;
    max-width: 320px;
    background: var(--tooltip-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    box-shadow: 0 4px 16px var(--shadow);
    pointer-events: none;
}

.app-tooltip.visible {
    display: block;
}

.app-tooltip strong {
    display: block;
    color: var(--text-strong);
    font-size: 13px;
    margin-bottom: 6px;
}

.app-tooltip pre {
    margin: 0;
    color: var(--text);
    font-family: 'Roboto', helvetica, sans-serif;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

[data-tooltip-title] {
    cursor: help;
}

/* --- Stat tiles + panels (overview, statistics page) --- */

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 14px 16px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.stat-tile-value {
    font-family: 'Bebas Neue', 'Roboto', helvetica, sans-serif;
    font-size: 34px;
    letter-spacing: 1px;
    line-height: 1.1;
    color: var(--text-strong);
    font-variant-numeric: tabular-nums;
}

.stat-tile-label {
    font-weight: 500;
    color: var(--text);
}

.stat-tile-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.stats-panels {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.stats-panel {
    min-width: 0;
    padding: 14px 18px 16px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.stats-panel-wide {
    margin-bottom: 16px;
}

.stats-panel h2 {
    margin: 0 0 12px;
    font-size: 22px;
}

.stat-empty {
    margin: 0;
    color: var(--text-muted);
}

.chart-box {
    position: relative;
    height: 240px;
}

.chart-box-tall {
    height: 320px;
}

/* --- Status page --- */

.status-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-header h1 {
    margin-right: auto;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.status-tile {
    padding: 12px 14px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 3px;
}

.status-tile h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.status-tile h2 i {
    color: var(--text-muted);
    font-size: 16px;
    margin-right: 4px;
}

.status-tile.status-ok {
    border-left-color: var(--success);
}

.status-tile.status-warn {
    border-left-color: var(--warning-text);
}

.status-tile.status-error {
    border-left-color: var(--danger-text);
}

.status-line {
    margin: 0;
    font-size: 14px;
}

.status-icon {
    width: 16px;
    color: var(--text-muted);
}

.status-ok > .status-line .status-icon {
    color: var(--success);
}

.status-warn > .status-line .status-icon {
    color: var(--warning-text);
}

.status-error > .status-line .status-icon {
    color: var(--danger-text);
}

.status-details {
    list-style: none;
    margin: 4px 0 0;
    padding: 0 0 0 22px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-left: 22px;
}

.status-actions .btn-primary {
    padding: 5px 10px;
    font-size: 12px;
}

.status-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 0 5px;
    background: #6a3fb3;
    border-radius: 3px;
    color: #fff;
    font-size: 11px;
}

.status-note {
    margin: 12px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

/* --- Login pages (no action bar) --- */

body.no-nav .main {
    margin-left: 0;
}

.auth-panel {
    max-width: 380px;
    margin: 8vh auto 0;
    padding: 24px 28px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.auth-panel-wide {
    max-width: 520px;
}

.auth-panel h1 {
    margin-top: 0;
}

.auth-steps {
    margin: 0 0 20px;
    padding-left: 20px;
    line-height: 1.5;
}

.auth-steps li {
    margin-bottom: 10px;
}

/* The QR code stays black on white in both themes so every app can scan it. */
.qr-code {
    display: block;
    width: fit-content;
    margin: 10px 0;
    padding: 8px;
    background: #fff;
    border-radius: 4px;
    line-height: 0;
}

.auth-steps .muted {
    display: block;
}

.totp-secret {
    display: block;
    margin-top: 6px;
    font-size: 15px;
    letter-spacing: 1px;
    word-break: break-all;
    user-select: all;
}

.input input.totp-code {
    max-width: 160px;
    font-size: 20px;
    letter-spacing: 4px;
}

/* --- Narrow screens (phones) --- */

@media (max-width: 600px) {
    /* Action bar moves to the bottom of the screen as a horizontal tab bar. */
    #actionbar {
        top: auto;
        bottom: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: 0;
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #actionbar .logo,
    #actionbar li,
    #actionbar .logout-form {
        flex: 1;
        width: auto;
        height: 52px;
    }

    #actionbar ul {
        display: flex;
        flex: 5;
        margin: 0;
    }

    #actionbar .logo {
        font-size: 22px;
    }

    #actionbar li a {
        font-size: 20px;
    }

    #actionbar .logout-form button {
        width: 100%;
        height: 52px;
    }

    #actionbar .logo.active,
    #actionbar li.active {
        border-left: 0;
        box-shadow: inset 0 3px 0 #6a3fb3;
    }

    .main {
        margin-left: 0;
        padding: 20px 16px calc(72px + env(safe-area-inset-bottom));
    }

    body.no-nav .main {
        padding-bottom: 20px;
    }

    /* 16px keeps iOS from zooming in when a field gets focus. */
    .input input, .input textarea, .input select, .vehicle-picker select {
        font-size: 16px;
    }

    /*
     * Tables marked .table-cards become one card per row: .card-title, an
     * optional .card-head and td.actions on the first line, then the cells with their data-label
     * above the value in three columns; .card-wide spans the full width.
     */
    .table-scroll {
        overflow-x: visible;
    }

    .table-cards,
    .table-cards tbody {
        display: block;
        background: transparent;
    }

    .table-cards thead {
        display: none;
    }

    .table-cards tr {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px 12px;
        margin-bottom: 10px;
        padding: 12px 14px;
        background: var(--panel-bg);
        border: 1px solid var(--border);
        border-radius: 4px;
    }

    .table-cards tr:hover {
        background: var(--panel-bg);
    }

    .table-cards td,
    .table-cards td.num,
    .refuels-table.table-cards td {
        display: block;
        padding: 0;
        border: 0;
        text-align: left;
        white-space: normal;
        min-width: 0;
        font-size: 15px;
    }

    .table-cards td:empty {
        display: none;
    }

    .table-cards td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        color: var(--text-muted);
        font-size: 11px;
        font-style: normal;
        font-weight: 500;
        text-transform: uppercase;
    }

    .table-cards td.card-title {
        grid-column: 1 / 3;
        align-self: center;
        color: var(--text-strong);
        font-size: 16px;
        font-weight: 500;
    }

    /* A .card-head cell shares the first line: title | head | actions. */
    .table-cards tr:has(> .card-head) td.card-title {
        grid-column: 1;
        grid-row: 1;
        align-self: end;
    }

    .table-cards td.card-head {
        grid-column: 2;
        grid-row: 1;
    }

    .table-cards td.actions {
        grid-column: 3;
        grid-row: 1;
        width: auto;
        text-align: right;
    }

    .table-cards td.card-wide {
        grid-column: 1 / -1;
    }

    .table-cards .icon-btn {
        padding: 6px 9px;
        font-size: 16px;
    }

    /* Inside a stats panel: separator lines instead of nested cards. */
    .summary-table.table-cards tr {
        margin: 0;
        padding: 12px 0;
        background: transparent;
        border: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
    }

    .summary-table.table-cards tr:last-child {
        border-bottom: 0;
    }

    .summary-table.table-cards td:first-child {
        color: var(--text-strong);
    }

    .summary-table:not(.table-cards) :is(th, td) {
        padding: 8px 6px;
    }

    .summary-table:not(.table-cards) tr > :first-child {
        padding-left: 0;
    }

    .summary-table:not(.table-cards) tr > :last-child {
        padding-right: 0;
    }

    .stats-panels {
        grid-template-columns: 1fr;
    }

    .stat-tiles {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .stat-tile {
        padding: 10px 12px;
    }

    .stat-tile-value {
        font-size: 28px;
    }

    .page-header h1 {
        font-size: 30px;
    }
}
