/* CarToolbox base stylesheet */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --border: #d9dee3;
    --text: #1d2733;
    --muted: #64748b;
    --primary: #1f6feb;
    --primary-dark: #1a5fd0;
    --error: #c0392b;
    --success: #1e7e34;
    --warning: #b7791f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }

/* Top bar */
.topbar { background: #17212b; color: #fff; }
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: 0 1rem;
    display: flex; align-items: center; gap: 1.5rem; height: 52px;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 1rem; }
.nav a { color: #c3ccd6; padding: .3rem 0; }
.nav a.active, .nav a:hover { color: #fff; text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.access-until { color: #9fd3a1; font-size: .85rem; }
.username { color: #c3ccd6; font-size: .9rem; }
.lang-switch a { color: #8a97a5; margin-left: .35rem; font-size: .85rem; }
.lang-switch a.active { color: #fff; font-weight: 600; }
@media (max-width: 800px) {
    .topbar-inner {
        flex-wrap: wrap;
        height: auto;
        padding: .5rem 1rem;
        gap: .35rem 1rem;
    }
    .nav { flex-wrap: wrap; gap: .75rem; }
    .topbar-right { gap: .75rem; }
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; width: 100%; flex: 1; }
.footer { color: var(--muted); font-size: .8rem; padding: 1rem 0; }

/* Flash + states */
.flash { padding: .65rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-success { background: #e6f4ea; color: var(--success); border: 1px solid #bce3c5; }
.flash-error { background: #fdecea; color: var(--error); border: 1px solid #f5c6c0; }
.flash-warning { background: #fdf3e0; color: var(--warning); border: 1px solid #f0dcb4; }
.empty-state {
    background: var(--surface); border: 1px dashed var(--border); border-radius: 8px;
    padding: 2rem; text-align: center; color: var(--muted);
}
.text-error { color: var(--error); }
.text-muted { color: var(--muted); }

/* Buttons & forms */
.btn {
    display: inline-block; padding: .45rem .9rem; border-radius: 6px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text); cursor: pointer; font-size: .9rem;
}
.btn:hover { background: #eef1f4; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: #fdecea; }
.btn-sm { padding: .2rem .55rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: #c3ccd6; cursor: pointer; font-size: .9rem; padding: 0; }
.btn-link:hover { color: #fff; }
.inline-form { display: inline; }

label { display: block; margin: .8rem 0 .25rem; font-weight: 600; font-size: .85rem; }
input[type=text], input[type=password], input[type=date], select, textarea {
    width: 100%; padding: .45rem .6rem; border: 1px solid var(--border);
    border-radius: 6px; font-size: .9rem; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4f7; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.form-hint { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.form-error { color: var(--error); font-size: .85rem; margin: .5rem 0; }
.form-actions { margin-top: 1.25rem; display: flex; gap: .6rem; }
.checkbox-label { display: flex; align-items: center; gap: .45rem; font-weight: 400; }

/* Login */
.login-box {
    max-width: 360px; margin: 8vh auto; background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; padding: 2rem;
}
.login-box h1 { text-align: center; }
.login-box .btn-block { margin-top: 1.25rem; }

/* Dashboard tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 1.25rem; display: flex; flex-direction: column;
}
.tile-desc { color: var(--muted); font-size: .85rem; flex: 1; }
.tile-expiry { font-size: .85rem; margin: .5rem 0; }
.tile-expired { opacity: .7; }
.tile .btn { align-self: flex-start; }

/* Cards / stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    padding: 1rem 1.25rem;
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-card .stat-label { color: var(--muted); font-size: .85rem; }

/* Admin layout */
.admin-layout { display: grid; grid-template-columns: 210px 1fr; gap: 1.5rem; }
.admin-layout > * { min-width: 0; }
.admin-nav { display: flex; flex-direction: column; gap: .15rem; }
.admin-nav a { padding: .5rem .75rem; border-radius: 6px; color: var(--text); }
.admin-nav a.active { background: var(--primary); color: #fff; }
.admin-nav a:hover { text-decoration: none; background: #e3e9ef; }
.admin-nav a.active:hover { background: var(--primary-dark); }
.admin-nav .nav-alert { color: var(--warning); margin-left: .3rem; cursor: help; }
.admin-nav a.active .nav-alert { color: #ffd98a; }
@media (max-width: 800px) {
    .admin-layout { grid-template-columns: 1fr; }
    .admin-nav { flex-direction: row; flex-wrap: wrap; }
}

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f0f3f6; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge-ok { background: #e6f4ea; color: var(--success); }
.badge-error { background: #fdecea; color: var(--error); }
.badge-warning { background: #fdf3e0; color: var(--warning); }
.badge-muted { background: #eceff2; color: var(--muted); }

/* Filters, pagination */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; margin-bottom: 1rem; }
.filters > div { min-width: 140px; }
.filters label { margin-top: 0; }
.pagination { margin-top: 1rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 5px; background: var(--surface);
}
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Module access editor (user form) */
.module-access { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.module-access .module-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: .75rem;
    padding: .6rem .9rem; border-bottom: 1px solid var(--border);
}
.module-access .module-row:last-child { border-bottom: none; }
.module-access .module-name { flex: 1; min-width: 220px; }
.module-access input[type=date] { width: 160px; }
.module-access .quick-buttons { display: flex; gap: .3rem; }

.error-page { text-align: center; margin: 8vh 0; }
.error-page h1 { font-size: 4rem; margin-bottom: .5rem; }

pre.log-detail {
    background: #17212b; color: #d8e1ea; border-radius: 8px; padding: 1rem;
    overflow-x: auto; font-size: .82rem;
}

/* System / Security
   Fixed layout so expanding a <details> cell cannot widen the table: with
   auto layout the <pre> inside contributes its full max-content width, the
   table outgrows .table-wrap and the "Checked at" column slides out of view.
   Column widths come from the <colgroup>; the <pre> scrolls inside its cell. */
.system-table { table-layout: fixed; min-width: 680px; }
.system-table .col-check   { width: 184px; }
.system-table .col-status  { width: 96px; }
.system-table .col-checked { width: 176px; }
.system-table td { overflow-wrap: anywhere; }
.system-table .checked-at { white-space: nowrap; font-variant-numeric: tabular-nums; }
.system-table details { margin-top: .35rem; }
.system-table pre.log-detail { margin: .4rem 0 0; }

.system-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.section-head { margin-top: 2rem; }
.section-head-first { margin-top: 0; }

/* Notification delivery log — same fixed layout as the checks table, so an
   opened error block cannot widen the table (see .system-table). */
.notif-wrap { margin-top: .75rem; }
.notif-table { table-layout: fixed; min-width: 680px; }
.notif-table .col-when   { width: 176px; }
.notif-table .col-status { width: 96px; }
.notif-table .col-to     { width: 200px; }
.notif-table td { overflow-wrap: anywhere; }
.notif-table details { margin-top: .35rem; }
.notif-table summary { cursor: pointer; color: var(--error); font-size: .82rem; }
.notif-table pre.log-detail { margin: .4rem 0 0; }

/* OS update installation progress */
.install-box {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: .75rem 1rem; margin-bottom: 1rem;
}
.install-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .35rem; }
.install-box summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
pre.install-log { max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* Generic confirmation modal (reboot) */
.modal {
    position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .5);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-box {
    background: var(--surface); border-radius: 10px; width: min(560px, 100%);
    max-height: 85vh; display: flex; flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1rem; border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 600; }
.modal-body { padding: 1rem; overflow: auto; }
.modal-body p { margin: 0 0 .75rem; }
.modal-foot {
    display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
    padding: .75rem 1rem; border-top: 1px solid var(--border);
}
.modal-foot .checkbox-label { flex: 1 1 100%; margin: 0; font-size: .85rem; }
.modal-actions { margin-left: auto; display: flex; gap: .5rem; }

/* Reboot pre-flight result */
.preflight-loading, .preflight-ok, .preflight-warn, .preflight-block {
    border-radius: 6px; padding: .6rem .8rem; font-size: .88rem;
}
.preflight-loading { background: #eceff2; color: var(--muted); }
.preflight-ok { background: #e6f4ea; color: var(--success); border: 1px solid #bce3c5; }
.preflight-warn { background: #fdf3e0; color: var(--warning); border: 1px solid #f0dcb4; }
.preflight-block { background: #fdecea; color: var(--error); border: 1px solid #f5c6c0; }
.preflight-head { font-weight: 600; margin-bottom: .35rem; }
.preflight-ok ul, .preflight-warn ul, .preflight-block ul { margin: 0; padding-left: 1.2rem; }

.detail-table th { width: 180px; }

/* Action log: subject column (VIN / licence id / file name) */
.log-subject { font-variant-numeric: tabular-nums; word-break: break-all; }
.log-details-mark { color: var(--muted); margin-left: .3rem; text-decoration: none; }
.log-details-mark:hover { color: var(--primary); text-decoration: none; }

/* CMU Dump Creator */
.cmu-form { max-width: 640px; }
.cmu-bar {
    display: inline-block; width: 160px; max-width: 100%; height: 10px;
    background: #e3e9ef; border-radius: 5px; overflow: hidden; vertical-align: middle;
    margin-right: .5rem;
}
.cmu-bar span { display: block; height: 100%; background: var(--primary); transition: width .4s; }

/* CMU job-log modal */
.cmu-log-modal {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: rgba(0, 0, 0, .5); align-items: center; justify-content: center; padding: 1rem;
}
.cmu-log-box {
    background: var(--surface); border-radius: 10px; width: min(920px, 100%);
    max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.cmu-log-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem 1rem; border-bottom: 1px solid var(--border);
}
.cmu-log-title { font-weight: 600; }
.cmu-log-actions { display: flex; gap: .4rem; }
.cmu-log-pre {
    margin: 0; padding: 1rem; overflow: auto; flex: 1;
    background: #17212b; color: #d8e1ea; border-radius: 0 0 10px 10px;
    font-size: .8rem; line-height: 1.45; white-space: pre; word-break: normal;
}
