/*
 * TAMS Admin Panel -- single stylesheet, no framework.
 * Kept as one file on purpose: this is a small, four-page admin tool, so
 * splitting into multiple CSS files would only add HTTP requests (or build
 * tooling to bundle them) for no real organizational benefit at this size.
 * Sections below are ordered: tokens -> reset -> layout -> components -> pages -> responsive.
 */

/* ---------------------------------------------------------------------- */
/* 1. Design tokens                                                        */
/* ---------------------------------------------------------------------- */
:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;

    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-text-faint: #9ca3af;

    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-soft: #eff4ff;

    --color-success: #16a34a;
    --color-success-soft: #f0fdf4;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-danger-soft: #fef2f2;
    --color-warning: #d97706;
    --color-warning-soft: #fffbeb;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    --sidebar-width: 236px;
    --topbar-height: 60px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------------------------------------------------------------------- */
/* 2. Reset / base                                                         */
/* ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }

::selection { background: var(--color-primary-soft); color: var(--color-primary-hover); }

/* Compact, consistent focus ring instead of the browser default -- kept
   visible (never `outline: none` with nothing replacing it) for keyboard
   accessibility. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

/* ---------------------------------------------------------------------- */
/* 3. App shell layout (sidebar + topbar + content)                        */
/* ---------------------------------------------------------------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.sidebar__brand-mark {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar__brand-name {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
}

.sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-3);
    flex: 1;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar__link:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.sidebar__link--active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.sidebar__icon { flex-shrink: 0; }

.sidebar__footer {
    padding: var(--space-3);
    border-top: 1px solid var(--color-border);
}

.sidebar__link--logout:hover {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.app-shell__backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 30;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar__title {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
}

.topbar__toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}

.topbar__user-name {
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 500;
}

.page {
    padding: var(--space-6);
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.page-header p {
    color: var(--color-text-muted);
    font-size: 13px;
    margin-top: var(--space-1);
}

/* ---------------------------------------------------------------------- */
/* 4. Cards                                                                 */
/* ---------------------------------------------------------------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.card__body { padding: var(--space-5); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.stat-card__icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.stat-card--success .stat-card__icon { background: var(--color-success-soft); color: var(--color-success); }
.stat-card--danger .stat-card__icon { background: var(--color-danger-soft); color: var(--color-danger); }
.stat-card--warning .stat-card__icon { background: var(--color-warning-soft); color: var(--color-warning); }

.stat-card__value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card__label {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ---------------------------------------------------------------------- */
/* 5. Buttons                                                               */
/* ---------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border-strong);
    color: var(--color-text);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-bg); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--color-danger-hover); }

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
}
.btn-icon:hover { background: var(--color-bg); color: var(--color-text); }
.btn-icon--danger:hover { background: var(--color-danger-soft); color: var(--color-danger); border-color: #fecaca; }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: 12px; }

/* ---------------------------------------------------------------------- */
/* 6. Forms                                                                 */
/* ---------------------------------------------------------------------- */
.form-group { margin-bottom: var(--space-4); }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.form-label .form-optional {
    font-weight: 400;
    color: var(--color-text-faint);
}

.form-control {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: 14px;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.form-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.form-error {
    font-size: 12px;
    color: var(--color-danger);
    margin-top: var(--space-1);
    display: none;
}

.form-group--invalid .form-control { border-color: var(--color-danger); }
.form-group--invalid .form-error { display: block; }

.form-row { display: flex; gap: var(--space-4); }
.form-row > .form-group { flex: 1; min-width: 0; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

/* ---------------------------------------------------------------------- */
/* 7. Toolbar (search + actions row above the member table)                */
/* ---------------------------------------------------------------------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

.search-box svg {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-faint);
    pointer-events: none;
}

.search-box input {
    padding-left: 34px;
}

.toolbar__spacer { flex: 1; }

/* ---------------------------------------------------------------------- */
/* 8. Table                                                                 */
/* ---------------------------------------------------------------------- */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--color-text); }

th.sortable .sort-arrow { display: inline-block; margin-left: var(--space-1); opacity: 0.4; font-size: 11px; }
th.sortable.sort-active .sort-arrow { opacity: 1; color: var(--color-primary); }

tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg); }

.cell-name { font-weight: 600; }
.cell-muted { color: var(--color-text-muted); }

.row-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

.empty-state, .loading-state {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--color-text-muted);
}

/* ---------------------------------------------------------------------- */
/* 9. Badges                                                                */
/* ---------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge--success { background: var(--color-success-soft); color: var(--color-success); }
.badge--danger { background: var(--color-danger-soft); color: var(--color-danger); }

/* ---------------------------------------------------------------------- */
/* 10. Pagination                                                          */
/* ---------------------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.pagination__info { font-size: 12.5px; color: var(--color-text-muted); }

.pagination__pages { display: flex; gap: var(--space-1); }

.pagination__btn {
    min-width: 30px;
    height: 30px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.pagination__btn:hover:not(:disabled) { background: var(--color-bg); color: var(--color-text); }
.pagination__btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination__btn--active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* ---------------------------------------------------------------------- */
/* 11. Modal                                                                */
/* ---------------------------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 100;
}

.modal-overlay--open { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
}

.modal--sm { max-width: 380px; }

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.modal__title { font-size: 16px; font-weight: 700; }

.modal__close {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal__close:hover { background: var(--color-bg); color: var(--color-text); }

.modal__body { padding: var(--space-5); overflow-y: auto; }

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
}

.modal__icon-warning {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-danger-soft);
    color: var(--color-danger);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-4);
}

.modal__confirm-text { text-align: center; color: var(--color-text-muted); }
.modal__confirm-text strong { color: var(--color-text); }

/* ---------------------------------------------------------------------- */
/* 12. Toast notifications                                                  */
/* ---------------------------------------------------------------------- */
.toast-stack {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    background: var(--color-text);
    color: #fff;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    font-weight: 500;
    max-width: 320px;
    animation: toast-in 0.2s ease;
}

.toast--success { background: #14532d; }
.toast--error { background: #7f1d1d; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------- */
/* 13. Login page                                                          */
/* ---------------------------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: var(--space-4);
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-8) var(--space-6);
}

.login-card__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: var(--space-6);
}

.login-card__mark {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    margin-bottom: var(--space-3);
}

.login-card__title { font-size: 18px; font-weight: 700; }
.login-card__subtitle { font-size: 13px; color: var(--color-text-muted); margin-top: var(--space-1); }

.login-alert {
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    font-size: 13px;
    margin-bottom: var(--space-4);
}

.btn-block { width: 100%; padding: var(--space-3); font-size: 14px; }

/* ---------------------------------------------------------------------- */
/* 14. Tabs (Live Tracking's "Member Aktif" / "Peta Real-Time")            */
/* ---------------------------------------------------------------------- */
.tab-bar {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-4);
}

.tab-bar__item {
    padding: var(--space-3) var(--space-4);
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-bar__item:hover { color: var(--color-text); }
.tab-bar__item--active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.stat-grid--compact { margin-bottom: var(--space-4); }

/* ---------------------------------------------------------------------- */
/* 15. Member list (Live Tracking's "Member Aktif" panel)                  */
/* ---------------------------------------------------------------------- */
.member-list { list-style: none; margin: 0; padding: 0; }

.member-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.member-list__item:last-child { border-bottom: none; }
.member-list__item:hover { background: var(--color-bg); }

.member-list__main { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }

.member-list__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.member-list__dot--moving { background: var(--color-success); }
.member-list__dot--idle { background: var(--color-warning); }

.member-list__name { font-weight: 600; font-size: 13.5px; }
.member-list__note { font-size: 12px; color: var(--color-text-muted); margin-top: 1px; }
.member-list__meta { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* 16. Map (Leaflet) containers, markers, and floating detail card          */
/* ---------------------------------------------------------------------- */
.map-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.map-canvas {
    width: 100%;
    height: 560px;
    background: var(--color-bg);
}

/* Leaflet's default divIcon styling adds its own white box/border -- the
   member/start/finish icons below build their own circular markup, so that
   default chrome must be stripped or every marker would show a faint square
   behind the circle. */
.tams-map-marker { background: transparent !important; border: none !important; }

.map-detail-card {
    position: absolute;
    bottom: var(--space-4);
    left: var(--space-4);
    width: 280px;
    max-width: calc(100% - 32px);
    max-height: calc(100% - 32px);
    overflow-y: auto;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-4);
    z-index: 500;
}

.map-detail-card__close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}
.map-detail-card__close:hover { background: var(--color-bg); color: var(--color-text); }

.map-detail-card__title { font-weight: 700; font-size: 14px; padding-right: 24px; }
.map-detail-card__subtitle { font-size: 12px; color: var(--color-text-muted); margin-bottom: var(--space-2); }

.map-detail-card__row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2) 0 var(--space-3);
}

.map-detail-card__movement { font-size: 12px; font-weight: 600; color: var(--color-text-muted); }

.map-detail-card__field {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    font-size: 12.5px;
    padding: var(--space-2) 0;
    border-top: 1px solid var(--color-border);
}
.map-detail-card__field:first-of-type { border-top: none; padding-top: 0; }

.map-detail-card__label { color: var(--color-text-muted); flex-shrink: 0; }
.map-detail-card__value { font-weight: 600; text-align: right; word-break: break-word; }

/* ---------------------------------------------------------------------- */
/* 17. Riwayat Member: filter bar, stats, gap legend, calendar picker       */
/* ---------------------------------------------------------------------- */
.history-filter-bar {
    display: flex;
    align-items: flex-end;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.history-filter-bar__field { margin-bottom: 0; flex: 1; min-width: 180px; }

.history-stats {
    display: flex;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.history-stats__hero {
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius-md);
    padding: var(--space-5);
    min-width: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.history-stats__hero-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.history-stats__hero-label { font-size: 12.5px; opacity: 0.85; margin-top: 2px; }

.history-stats__tiles { flex: 1; min-width: 280px; margin-bottom: 0; }

.history-gap-legend {
    margin-top: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-danger-soft);
    color: var(--color-danger);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
}

.calendar__nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.calendar__month-label { font-weight: 700; font-size: 13.5px; }

.calendar__weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 11px;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.calendar__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar__cell {
    aspect-ratio: 1;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    color: var(--color-text);
}

.calendar__cell--empty { cursor: default; }
.calendar__cell--disabled { color: var(--color-text-faint); cursor: not-allowed; }
.calendar__cell--has-data { background: var(--color-primary-soft); color: var(--color-primary); font-weight: 600; }
.calendar__cell--has-data:hover { background: var(--color-primary); color: #fff; }
.calendar__cell--today { box-shadow: inset 0 0 0 1.5px var(--color-primary); }
.calendar__cell--selected { background: var(--color-primary); color: #fff; }

.calendar__loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--space-4);
    color: var(--color-text-muted);
    font-size: 12.5px;
}

/* ---------------------------------------------------------------------- */
/* 18. Responsive                                                          */
/* ---------------------------------------------------------------------- */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-lg);
    }

    .app-shell--sidebar-open .sidebar { transform: translateX(0); }
    .app-shell--sidebar-open .app-shell__backdrop { display: block; }

    .topbar__toggle { display: flex; }

    .page { padding: var(--space-4); }

    .form-row { flex-direction: column; gap: 0; }

    .map-canvas { height: 420px; }

    .map-detail-card { width: auto; right: var(--space-4); }

    .history-stats__hero { min-width: 100%; }
}

@media (max-width: 560px) {
    .topbar { padding: 0 var(--space-4); }
    .topbar__user-name { display: none; }
    .row-actions { gap: var(--space-1); }
    .pagination { flex-direction: column; align-items: stretch; text-align: center; }
}
