:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #fafbfd;
    --border: #e6e8ef;
    --text: #1a2138;
    --text-muted: #6b7388;
    --primary: #2b59ff;
    --primary-hover: #1f49e0;
    --primary-soft: #eaf0ff;
    --success: #15a36b;
    --success-soft: #e3f7ee;
    --warning: #d18b00;
    --warning-soft: #fdf3dc;
    --danger: #d63b3b;
    --danger-soft: #fce4e4;
    --shadow: 0 1px 2px rgba(20,30,60,.04), 0 4px 14px rgba(20,30,60,.04);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

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

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 200;
    transition: transform .25s ease;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.brand-mark {
    width: 38px; height: 38px; min-width: 38px;
    background: linear-gradient(135deg, var(--primary), #5a3bff);
    color: #fff;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; letter-spacing: .5px; font-size: 13px;
}
.brand-logo-img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: -.01em; word-break: break-word; }
.brand-sub { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    font-size: 13.5px;
    text-decoration: none;
}
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 18px; font-size: 14px; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); padding: 14px 12px 6px; }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    background: var(--surface-2); margin-bottom: 8px;
}
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff;
    font-weight: 700; display: flex; align-items: center; justify-content: center;
    text-transform: uppercase; font-size: 13px; flex-shrink: 0;
}
.user-name { font-weight: 600; font-size: 13px; word-break: break-word; }
.user-role { font-size: 11.5px; color: var(--text-muted); }
.logout {
    display: block; text-align: center; padding: 8px;
    border-radius: var(--radius-sm); color: var(--text-muted);
    font-size: 12.5px; border: 1px solid var(--border);
    text-decoration: none;
}
.logout:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }

/* ── Mobile top bar ── */
.menu-toggle {
    display: none;
    position: fixed; top: 12px; left: 14px; z-index: 300;
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background: var(--primary); border: none; cursor: pointer;
    flex-direction: column; align-items: center; justify-content: center; gap: 5px;
    box-shadow: 0 2px 10px rgba(43,89,255,.3);
}
.menu-toggle span {
    display: block; width: 20px; height: 2px;
    background: #fff; border-radius: 2px;
    transition: transform .2s, opacity .2s;
}
.menu-toggle.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.overlay {
    display: none;
    position: fixed; inset: 0; z-index: 150;
    background: rgba(0,0,0,.35);
}
.overlay.visible { display: block; }

/* ── Content ── */
.content { flex: 1; padding: 28px 36px; min-width: 0; }
.content.full { display: flex; align-items: center; justify-content: center; padding: 24px; min-height: 100vh; }

.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    margin-bottom: 22px; flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head {
    padding: 14px 18px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.card-title { font-weight: 600; font-size: 14.5px; }
.card-body { padding: 18px; }
.card-pad-tight .card-body { padding: 0; }

/* ── Stats ── */
.stats {
    display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: 20px;
}
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 5px; letter-spacing: -.02em; }
.stat-foot { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.stat.accent-primary { border-left: 3px solid var(--primary); }
.stat.accent-success { border-left: 3px solid var(--success); }
.stat.accent-warning { border-left: 3px solid var(--warning); }
.stat.accent-danger  { border-left: 3px solid var(--danger); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td {
    text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
table.data th {
    background: var(--surface-2); font-weight: 600; color: var(--text-muted);
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.neg { color: var(--danger); }
.amount.pos { color: var(--success); }
.empty { padding: 36px 20px; text-align: center; color: var(--text-muted); }

/* ── Forms ── */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-row.col-3 { grid-template-columns: repeat(3, 1fr); }
.form-row.col-4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
    font: inherit; border: 1px solid var(--border); background: #fff;
    border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text);
    transition: border-color .15s, box-shadow .15s; width: 100%;
    -webkit-appearance: none; appearance: none;
}
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7388' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43,89,255,.12); }
.field textarea { resize: vertical; min-height: 75px; }
.field input[type="file"] { padding: 8px; cursor: pointer; background: var(--surface-2); }
.field input[type="color"] { padding: 4px 6px; height: 40px; cursor: pointer; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; flex-wrap: wrap; }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 13.5px; border: 1px solid transparent;
    cursor: pointer; transition: background .15s, transform .05s; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #128a5b; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b73131; color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ── Badges ── */
.badge {
    display: inline-block; padding: 3px 8px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; background: var(--surface-2);
    color: var(--text-muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge.b-pending { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.b-paid    { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.b-admin   { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.b-staff   { background: var(--surface-2); color: var(--text-muted); }
.badge.b-office  { background: #eef2ff; color: #3a4ec0; border-color: transparent; }
.badge.b-self    { background: #fdf2f8; color: #b1397b; border-color: transparent; }
.badge.b-leave   { background: #e8f5e9; color: #2e7d32; border-color: transparent; }
.badge.b-absent  { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.b-half    { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.b-remote  { background: #e3f2fd; color: #1565c0; border-color: transparent; }

/* ── Filters bar ── */
.filters {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    padding: 12px 14px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px;
}
.filters .field { min-width: 130px; flex: 1; }
.filters .field input, .filters .field select { padding: 8px 10px; }
.filters-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* ── Flash ── */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash { padding: 11px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 13.5px; }
.flash-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.flash-error   { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.flash-info    { background: var(--primary-soft);  border-color: transparent; color: var(--primary); }

/* ── Login ── */
.login-card {
    width: 100%; max-width: 400px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 36px 28px;
    box-shadow: 0 8px 30px rgba(20,30,60,.08);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.login-hint { margin-top: 18px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 12px; color: var(--text-muted); line-height: 1.55; }
.login-hint strong { color: var(--text); }

/* ── Bar charts ── */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 100px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #5a3bff); border-radius: 999px; }
.bar-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Receipt image ── */
.receipt-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.8); z-index: 9999; align-items: center; justify-content: center; }
.lightbox.show { display: flex; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 10px; }
.lightbox-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 32px; cursor: pointer; line-height: 1; }

/* ── Calendar ── */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.cal-nav-btns { display: flex; gap: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; }
.cal-hd { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--text-muted); padding: 6px 0; text-transform: uppercase; }
.cal-day {
    min-height: 70px; background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 6px; cursor: pointer;
    transition: background .15s; position: relative;
}
.cal-day:hover { background: var(--primary-soft); border-color: var(--primary); }
.cal-day.today { border-color: var(--primary); background: var(--primary-soft); }
.cal-day.empty { background: transparent; border-color: transparent; cursor: default; pointer-events: none; }
.cal-day.other-month { opacity: .4; }
.cal-day-num { font-size: 13px; font-weight: 600; }
.cal-day-events { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.cal-event { font-size: 10.5px; padding: 1px 4px; border-radius: 3px; font-weight: 600; line-height: 1.4; }
.cal-event.leave   { background: #e8f5e9; color: #2e7d32; }
.cal-event.absent  { background: var(--danger-soft); color: var(--danger); }
.cal-event.half    { background: var(--warning-soft); color: var(--warning); }
.cal-event.remote  { background: #e3f2fd; color: #1565c0; }
.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.cal-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ── Settings sections ── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 14px; }

/* ── Helpers ── */
.hr { height: 1px; background: var(--border); margin: 16px 0; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.center { text-align: center; }
.gap-sm { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.two-col { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }

/* ── Image upload preview ── */
.img-preview { margin-top: 8px; max-width: 200px; max-height: 150px; border-radius: 8px; border: 1px solid var(--border); display: none; }

/* ────────── RESPONSIVE ────────── */
@media (max-width: 768px) {
    .menu-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    .sidebar.open { transform: translateX(0); }

    .content { padding: 64px 16px 20px; }
    .content.full { padding: 24px; }

    .page-head { gap: 8px; }
    .page-title { font-size: 18px; }

    .stats { grid-template-columns: 1fr 1fr; }
    .form-row, .form-row.col-3, .form-row.col-4 { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .bar-row { grid-template-columns: 90px 1fr 85px; }

    table.data th, table.data td { padding: 9px 10px; font-size: 12.5px; }

    .cal-grid { gap: 2px; }
    .cal-day { min-height: 50px; padding: 4px; }
    .cal-day-num { font-size: 12px; }
    .cal-event { font-size: 9.5px; }
    .cal-hd { font-size: 10.5px; }
}

@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr; }
    .filters { padding: 10px; }
    .card-body { padding: 14px; }
    .cal-day { min-height: 40px; }
    .cal-day-events { display: none; }
}

/* ── Modal ── */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 800;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal-box {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    display: flex; flex-direction: column;
    max-height: 90vh; overflow: hidden;
}
.modal-head {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
    background: none; border: none; font-size: 18px; cursor: pointer;
    color: var(--text-muted); line-height: 1; padding: 4px 6px;
    border-radius: var(--radius-sm); transition: background .15s;
}
.modal-close:hover { background: var(--surface-2); }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-foot {
    padding: 14px 20px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0;
}
.receipt-wrap {}
.receipt-summary { background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 4px; }
.receipt-sumrow { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 13.5px; }
.receipt-sumrow.highlight { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 15px; font-weight: 700; }

/* ── Photo grid (6-up) ── */
.photo-grid-6 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.photo-slot { display: flex; flex-direction: column; gap: 6px; }
.photo-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.photo-drop {
    border: 2px dashed var(--border); border-radius: var(--radius-sm);
    min-height: 100px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: border-color .15s, background .15s;
    overflow: hidden; padding: 8px;
    background: var(--surface-2);
}
.photo-drop:hover { border-color: var(--primary); background: var(--primary-soft); }
.photo-placeholder { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-muted); font-size: 11.5px; }
.photo-placeholder span:first-child { font-size: 22px; }

/* ── Photo thumbnails (in detail view) ── */
.photo-grid-thumb { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-thumb-wrap { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.photo-thumb { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; transition: transform .15s, box-shadow .15s; }
.photo-thumb:hover { transform: scale(1.06); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.photo-thumb-label { font-size: 10px; color: var(--text-muted); text-align: center; }

/* ── Vehicle status badges ── */
.badge.b-available { background: var(--success-soft); color: var(--success); }
.badge.b-rented    { background: var(--warning-soft); color: var(--warning); }
.badge.b-repair    { background: var(--danger-soft);  color: var(--danger);  }
.badge.b-passive   { background: var(--surface-2);    color: var(--text-muted); }

/* ── Responsive adjustments ── */
@media (max-width: 768px) {
    .photo-grid-6 { grid-template-columns: repeat(2, 1fr); }
    .vehicle-top-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 480px) {
    .photo-grid-6 { grid-template-columns: repeat(2, 1fr); }
}
