:root {
    --color-primary: #081088;
    --color-primary-dark: #040951;
    --color-accent: #d99c2b;
    --color-bg: #f4f6f7;
    --color-surface: #ffffff;
    --color-border: #e2e6e8;
    --color-text: #1f2a2e;
    --color-text-muted: #6b7a80;
    --color-success: #1e8e5a;
    --color-danger: #c0392b;
    --color-warning: #b7791f;
    --color-info: #2a6f97;
    --radius: 8px;
    --sidebar-width: 240px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
}

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

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-primary-dark);
    color: #e7f2ef;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    z-index: 40;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.brand-mark {
    width: 60px; height: 60px;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-text strong { display: block; font-size: 16px; }
.brand-text small { color: #b7cfc8; font-size: 12px; }

.sidebar-nav { padding: 10px 0 30px; display: flex; flex-direction: column; }
.sidebar-nav a {
    color: #cfe4de;
    padding: 10px 18px;
    font-size: 13.5px;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar-nav a.active { background: rgba(255,255,255,.1); border-left-color: var(--color-accent); color: #fff; font-weight: 600; }
.sidebar-nav a.disabled { opacity: .4; cursor: not-allowed; }
.nav-group-label {
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: .06em;
    color: #7fa79c;
    padding: 16px 18px 4px;
}

.app-main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-search { flex: 0 1 320px; margin: 0 16px; }
.topbar-search input {
    width: 100%; padding: 7px 12px; border: 1px solid var(--color-border); border-radius: 6px;
    font-size: 13px; background: var(--color-bg);
}
.topbar-search input:focus { outline: none; border-color: var(--color-primary); background: #fff; }
@media (max-width: 700px) { .topbar-search { display: none; } }
.sidebar-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--color-text-muted); }
.user-name { font-weight: 600; color: var(--color-text); }
.user-role { background: #eef4f2; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.btn-link { background: none; border: none; color: var(--color-primary); cursor: pointer; font-size: 13px; padding: 0; }

.btn-link-disco {
    font-weight: 700;
    animation: disco-flash 1.2s linear infinite;
}
@keyframes disco-flash {
    0%   { color: #ff2d55; text-shadow: 0 0 6px #ff2d55; }
    16%  { color: #ff9500; text-shadow: 0 0 6px #ff9500; }
    33%  { color: #ffe600; text-shadow: 0 0 6px #ffe600; }
    50%  { color: #34c759; text-shadow: 0 0 6px #34c759; }
    66%  { color: #00c7ff; text-shadow: 0 0 6px #00c7ff; }
    83%  { color: #5856d6; text-shadow: 0 0 6px #5856d6; }
    100% { color: #ff2d55; text-shadow: 0 0 6px #ff2d55; }
}

.content { padding: 24px; max-width: 1400px; width: 100%; }

.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: #e7f6ee; color: #146c43; border: 1px solid #b7e4cb; }
.alert-danger { background: #fbeae8; color: #a3271b; border: 1px solid #f2c0ba; }
.alert-warning { background: #fdf3e0; color: #8a5a09; border: 1px solid #f3ddab; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 14px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.kpi-tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.kpi-tile .kpi-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi-tile .kpi-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.kpi-tile.accent-danger .kpi-value { color: var(--color-danger); }
.kpi-tile.accent-warning .kpi-value { color: var(--color-warning); }
.kpi-tile.accent-success .kpi-value { color: var(--color-success); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); text-align: left; }
table.data-table th { background: #fafcfb; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
table.data-table tr:hover td { background: #f8faf9; }
.table-responsive { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
.table-responsive table.data-table { border: none; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #e7f6ee; color: #146c43; }
.badge-danger { background: #fbeae8; color: #a3271b; }
.badge-warning { background: #fdf3e0; color: #8a5a09; }
.badge-secondary { background: #eceef0; color: #4a555a; }
.badge-info { background: #e6f1f7; color: #2a6f97; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 6px; border: 1px solid transparent; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: #f3f5f5; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--color-text-muted); }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 9px 11px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 13.5px; font-family: inherit; background: #fff;
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(8,16,136,.12); }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 900px) { .form-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 12.5px; }
.pagination a:hover { background: #f3f5f5; text-decoration: none; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination .ellipsis { border-color: transparent; color: var(--color-text-muted); padding-left: 2px; padding-right: 2px; }
.pagination-jump { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
.pagination-jump input[type="number"] { width: 70px; }

.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--color-border); margin-left: 8px; }
.timeline li { padding: 0 0 18px 20px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--color-primary); border: 2px solid #fff; }
.timeline .event-title { font-weight: 600; font-size: 13.5px; }
.timeline .event-date { font-size: 11.5px; color: var(--color-text-muted); }

.text-muted { color: var(--color-text-muted); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary)); }
.login-card { background: #fff; border-radius: 12px; padding: 36px; width: 100%; max-width: 460px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.subtitle { color: var(--color-text-muted); font-size: 12.5px; margin: 0 0 24px; text-align: center; }
.login-logo { display: block; max-width: 100%; width: 100%; height: auto; margin: 0 auto 12px; }

.password-toggle-btn {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    background: none; border: none; padding: 6px; margin: 0;
    color: var(--color-text-muted); cursor: pointer; display: flex; align-items: center;
}
.password-toggle-btn:hover { color: var(--color-text); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .sidebar-toggle { display: block; }

    /* Tapping anywhere outside the open sidebar closes it — without this, the
       only way to close it was tapping the toggle again or navigating away. */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .35);
        z-index: 35;
    }
    .sidebar-backdrop.open { display: block; }
}

/*
 * Touch-friendly segmented control for job-completion checklists/ratings
 * (PVM/Sanitization). min-width:90px is deliberately generous for a normal
 * tap target, but a 4-option row (Overall Condition: Excellent/Good/Fair/Poor)
 * needs 360px+gaps just for itself — more than the available content width
 * on a real phone (375px viewport minus .content/.card padding). Found by
 * actually rendering this at 375px width, not just at a desktop breakpoint.
 */
.touch-radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.touch-radio-group label { flex: 1; min-width: 90px; text-align: center; padding: 12px 8px; border: 1px solid var(--color-border); border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; }
.touch-radio-group input { display: none; }
.touch-radio-group label:has(input:checked) { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.checklist-item { border-bottom: 1px solid var(--color-border); padding: 14px 0; }

@media (max-width: 480px) {
    .content { padding: 16px; }
    .card { padding: 16px; }
    .touch-radio-group label { min-width: 0; padding: 12px 4px; font-size: 12.5px; }
}
