/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg:        #f1f5f9;
    --color-surface:   #ffffff;
    --color-primary:   #1d4ed8;
    --color-primary-h: #1e40af;
    --color-danger:    #dc2626;
    --color-text:      #1e293b;
    --color-muted:     #64748b;
    --color-border:    #e2e8f0;
    --radius:          0.5rem;
    --shadow:          0 4px 24px rgba(0,0,0,.08);
    --font:            'Inter', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
}

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.login-card {
    background: var(--color-surface);
    border-radius: calc(var(--radius) * 2);
    box-shadow: var(--shadow);
    padding: 2.5rem 2.25rem;
    width: 100%;
    max-width: 400px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 2rem;
}

.login-brand svg {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.login-brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -.02em;
}

.login-card h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: .25rem;
}

.login-card .subtitle {
    font-size: .875rem;
    color: var(--color-muted);
    margin-bottom: 1.75rem;
}

/* ── Alert ────────────────────────────────────────────────────────────────── */
.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--color-danger);
    font-size: .875rem;
    padding: .75rem 1rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* ── Form ─────────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--color-muted);
    margin-bottom: .375rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.form-group input {
    width: 100%;
    padding: .625rem .875rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .9375rem;
    font-family: var(--font);
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(29,78,216,.15);
}

/* ── Button ───────────────────────────────────────────────────────────────── */
.btn-primary {
    display: block;
    width: 100%;
    padding: .75rem 1rem;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    margin-top: 1.5rem;
    transition: background .15s, transform .1s;
}

.btn-primary:hover  { background: var(--color-primary-h); }
.btn-primary:active { transform: scale(.98); }

/* ── App Layout (sidebar + main) ─────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 0 1.25rem 1.5rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.sidebar-brand svg {
    width: 28px;
    height: 28px;
    color: var(--color-primary);
    flex-shrink: 0;
}

.sidebar-nav {
    list-style: none;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .625rem 1.25rem;
    color: var(--color-muted);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    border-radius: 0;
    transition: background .1s, color .1s;
}

.sidebar-nav a svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-nav a:hover { background: var(--color-bg); color: var(--color-text); }
.sidebar-nav a.active { background: #eff6ff; color: var(--color-primary); font-weight: 600; border-right: 3px solid var(--color-primary); }

.sidebar-footer {
    padding: 1rem 1.25rem 0;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-user {
    flex: 1;
    font-size: .8125rem;
    color: var(--color-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    padding: .35rem .75rem;
    background: transparent;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .75rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    color: var(--color-text);
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn-logout:hover { background: var(--color-bg); border-color: #cbd5e1; }

.main-content {
    padding: 2rem 2.5rem;
    min-width: 0;
}

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.page-actions { display: flex; gap: .5rem; align-items: center; }
.breadcrumb { color: var(--color-muted); text-decoration: none; font-size: .9375rem; }
.breadcrumb:hover { color: var(--color-primary); text-decoration: underline; }

/* ── Buttons (general) ────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}

.btn-primary  { background: var(--color-primary); color: #fff; margin-top: 0; width: auto; font-size: .875rem; padding: .5rem 1rem; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1.5px solid var(--color-border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger  { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .3rem .7rem; font-size: .8125rem; }

/* ── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: calc(var(--radius) * 1.5);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
}

.stat-label {
    font-size: .8125rem;
    color: var(--color-muted);
    font-weight: 500;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: calc(var(--radius) * 1.5);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.mb-6 { margin-bottom: 1.5rem; }

/* ── Data table ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.data-table th {
    padding: .625rem 1rem;
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbfc; }
.data-table a { color: var(--color-primary); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }

.text-right { text-align: right; }
.text-muted { color: var(--color-muted); }
.text-danger { color: var(--color-danger); }

.row-deleted td { opacity: .55; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 9999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.badge-active   { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-deleted  { background: #fee2e2; color: #991b1b; }
.badge-action-update { background: #fef9c3; color: #854d0e; }
.badge-action-delete { background: #fee2e2; color: #991b1b; }

/* ── Alert ────────────────────────────────────────────────────────────────── */
.alert {
    border-radius: var(--radius);
    font-size: .875rem;
    padding: .75rem 1rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--color-danger); }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* ── Form card ────────────────────────────────────────────────────────────── */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: calc(var(--radius) * 1.5);
    padding: 1.75rem 2rem;
    max-width: 480px;
}

.form-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1.25rem;
}

.form-hint { font-weight: 400; color: var(--color-muted); font-size: .75rem; }

/* ── Detail grid (truck log detail) ─────────────────────────────────────────*/
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.detail-field {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: .875rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.detail-field--full { grid-column: 1 / -1; }

.detail-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
}

.detail-value {
    font-size: .9375rem;
    font-weight: 500;
    color: var(--color-text);
}

.detail-value--highlight {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
}

.img-link { margin-left: .4rem; text-decoration: none; }

/* ── Image overlay modal ─────────────────────────────────────────────────── */
.img-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.85);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease-in-out;
    z-index: 9999;
}
.img-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.img-overlay-img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    display: block;
}
.img-overlay-close {
    position: absolute;
    top: 18px;
    right: 18px;
    background: rgba(255,255,255,0.06);
    color: #fff;
    border: none;
    font-size: 20px;
    line-height: 1;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.img-overlay-close:focus { outline: 2px solid rgba(255,255,255,0.12); }

/* ── API key display ─────────────────────────────────────────────────────── */
.api-key {
    font-family: monospace;
    font-size: .8125rem;
    background: var(--color-bg);
    padding: .2rem .4rem;
    border-radius: 4px;
    word-break: break-all;
    user-select: all;
}

/* ── Toggle ─────────────────────────────────────────────────────────────── */
.toggle-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .8125rem;
    color: var(--color-muted);
    cursor: pointer;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    padding: 2.5rem;
    text-align: center;
    color: var(--color-muted);
    font-size: .9375rem;
}
.empty-state a { color: var(--color-primary); }

/* ── Dashboard (legacy — kept for login page) ─────────────────────────────── */
.topbar       { display: none; }   /* replaced by sidebar layout */
