/**
 * Safeline Admin — Design System
 * Palette pulled directly from safeline.rw's own variables.css
 */
:root {
    --color-primary: #63C51F;
    --color-primary-hover: #55A819;
    --color-primary-light: rgba(99, 197, 31, 0.08);
    --color-primary-text: #3B760D;
    --color-secondary: #001832;
    --color-secondary-hover: #002040;

    --color-white: #FFFFFF;
    --color-bg: #F8F9FB;
    --color-surface: #FFFFFF;
    --color-border: #E5E9F0;
    --color-border-light: #EEF1F6;
    --color-text: #1A2233;
    /* Requested: no muted/secondary gray text anywhere in the admin panel -
       both tokens now resolve to the same near-black as regular body text.
       Kept as separate variables (not merged into one) so every existing
       .text-muted/var(--color-text-secondary) usage still works unchanged. */
    --color-text-secondary: #1A2233;
    --color-text-muted: #1A2233;

    --color-success: #63C51F;
    --color-success-bg: #EAF7E0;
    --color-warning: #C2410C;
    --color-warning-bg: #FBEAE0;
    --color-danger: #C62828;
    --color-danger-bg: #FBE9E9;
    --color-info: #3B82F6;
    --color-info-bg: #E9F1FE;

    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 24, 50, 0.05), 0 1px 3px rgba(0, 24, 50, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 24, 50, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 24, 50, 0.12);

    --sidebar-width: 260px;
    --topbar-height: 68px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-heading); color: var(--color-secondary); font-weight: 700; margin: 0; }
a { color: var(--color-primary-text); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }
::selection { background: var(--color-primary-light); }

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

.sidebar {
    width: var(--sidebar-width); flex-shrink: 0;
    background: var(--color-secondary); color: rgba(255,255,255,0.85);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar__brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar__brand img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.sidebar__brand span { font-family: var(--font-heading); font-weight: 700; color: #fff; font-size: 17px; }
.sidebar__nav { padding: 4px 10px 20px; flex: 1; }
.sidebar__top, .sidebar__submenu { list-style: none; margin: 0; padding: 0; }
.sidebar__nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin: 1px 0; border-radius: 8px;
    color: #fff; font-size: 13.5px; font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.sidebar__nav a i { width: 18px; text-align: center; font-size: 14px; color: rgba(255,255,255,0.5); }
.sidebar__nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar__nav a.active { background: var(--color-primary); color: #fff; }
.sidebar__nav a.active i { color: #fff; }

.sidebar__group {
    display: flex; align-items: center; justify-content: space-between; cursor: pointer;
    padding: 14px 14px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
    color: #fff; font-weight: 700; user-select: none;
}
.sidebar__group:hover { color: rgba(255,255,255,0.85); }
.sidebar__chevron { transition: transform .15s ease; font-size: 10px; }
.sidebar__group.collapsed .sidebar__chevron { transform: rotate(-90deg); }
.sidebar__submenu { overflow: hidden; max-height: 600px; transition: max-height .2s ease; }
.sidebar__submenu.collapsed { max-height: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-height); background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-family: var(--font-heading); font-size: 19px; color: var(--color-secondary); font-weight: 700; }
.topbar__user { display: flex; align-items: center; gap: 12px; }
.topbar__user .avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--color-primary-light);
    color: var(--color-primary-text); display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.topbar__user .name { font-size: 13px; font-weight: 600; color: var(--color-text); }
.topbar__user .role { font-size: 11px; color: var(--color-text-muted); }

/* ---------- Notification bell ---------- */
.notif-bell { position: relative; }
.notif-bell__btn {
    position: relative; background: none; border: none; cursor: pointer;
    width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    color: var(--color-text-secondary); font-size: 17px; transition: background .15s ease;
}
.notif-bell__btn:hover { background: var(--color-bg); color: var(--color-secondary); }
.notif-bell__badge {
    position: absolute; top: 3px; right: 3px; background: var(--color-danger); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 1; border-radius: var(--radius-full);
    min-width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.notif-bell__panel {
    display: none; position: absolute; top: 46px; right: 0; width: 340px; max-height: 420px; overflow-y: auto;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 6px;
    box-shadow: var(--shadow-lg); z-index: 30;
}
.notif-bell__panel.open { display: block; }
.notif-bell__header { padding: 12px 16px; font-weight: 700; font-size: 13px; color: var(--color-secondary); border-bottom: 1px solid var(--color-border); }
.notif-bell__empty { padding: 24px 16px; text-align: center; color: var(--color-text-muted); font-size: 12.5px; }
.notif-bell__section-title { padding: 10px 16px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); font-weight: 700; }
.notif-bell__item { padding: 8px 16px; font-size: 12.5px; border-bottom: 1px solid var(--color-border-light); display: block; color: var(--color-text); }
.notif-bell__item:hover { background: var(--color-bg); }
.notif-bell__item-meta { color: var(--color-text-muted); font-size: 11px; margin-top: 2px; }
.notif-bell__item-row { position: relative; }
.notif-bell__item-row.unread .notif-bell__item { font-weight: 700; background: var(--color-primary-light); }
.notif-bell__item-row.unread::before {
    content: ''; position: absolute; left: 6px; top: 14px; width: 6px; height: 6px;
    border-radius: 50%; background: var(--color-primary);
}
.notif-bell__item-row.unread .notif-bell__item { padding-left: 22px; }

.content { padding: 24px; flex: 1; }

/* ---------- Live Map ---------- */
.live-map-content { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-height)); padding: 0; }
.live-map-layout { display: flex; flex: 1; min-height: 0; }
.live-map-sidebar { width: 320px; flex-shrink: 0; border-right: 1px solid var(--color-border); background: #fff; display: flex; flex-direction: column; }
.live-map-sidebar__header { padding: 16px; border-bottom: 1px solid var(--color-border); }
.live-map-sidebar__list { flex: 1; overflow-y: auto; }
.live-map-canvas { flex: 1; position: relative; }

/* ---------- Sidebar footer / logout ---------- */
.sidebar__footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar__logout {
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); color: #fff;
    border-radius: 8px; padding: 9px 12px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
    transition: background .15s ease, border-color .15s ease;
}
.sidebar__logout:hover { background: var(--color-danger); border-color: var(--color-danger); }

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 6px; box-shadow: var(--shadow-sm);
}
.card__header {
    padding: 16px 20px; border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card__header h3 { font-size: 15.5px; }
.card__body { padding: 20px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 6px; padding: 18px 20px; box-shadow: var(--shadow-sm); }
.kpi-card__label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); font-weight: 700; }
.kpi-card__value { font-family: var(--font-mono); font-size: 28px; font-weight: 700; color: var(--color-secondary); margin-top: 6px; }
.kpi-card__trend { font-size: 12px; margin-top: 6px; font-weight: 600; }
.kpi-card__trend.up { color: var(--color-primary-text); }
.kpi-card__trend.down { color: var(--color-danger); }
.kpi-card__trend.flat { color: var(--color-text-muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px; justify-content: center;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all .15s ease; line-height: 1.2; white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-secondary); color: #fff; }
.btn-secondary:hover { background: var(--color-secondary-hover); }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { border-color: var(--color-secondary); }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Row actions (table row "Actions" dropdown) ---------- */
/* A table row can only comfortably fit 1-2 buttons before it wraps to a
   second line and squeezes neighboring columns (e.g. "10 / 10" breaking
   onto two lines). Keep one primary action inline (usually "View") and
   push everything else behind a compact dropdown, opened via
   openRowMenu() in datatable.js. */
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions__menu {
    position: fixed; min-width: 170px; background: var(--color-surface);
    border: 1px solid var(--color-border); border-radius: 6px; box-shadow: var(--shadow-lg);
    padding: 6px 0; z-index: 500;
}
.row-actions__item {
    display: block; width: 100%; text-align: left; background: none; border: none;
    padding: 8px 14px; font-family: inherit; font-size: 13px; color: var(--color-text);
    cursor: pointer;
}
.row-actions__item:hover { background: var(--color-bg); }
.row-actions__item--danger { color: var(--color-danger); }
.row-actions__item:disabled { opacity: 0.5; cursor: not-allowed; }
.row-actions__item:disabled:hover { background: none; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--color-text-secondary); margin-bottom: 6px; }
.form-group label.required::after { content: ' *'; color: var(--color-danger); font-weight: 700; }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: 13.5px; color: var(--color-text); background: var(--color-surface);
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.form-control.is-invalid { border-color: var(--color-danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px var(--color-danger-bg); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-hint { font-size: 11.5px; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 11.5px; color: var(--color-danger); margin-top: 4px; display: none; }
.form-error.show { display: block; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data-table thead th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--color-text-muted); font-weight: 700; padding: 10px 16px;
    border-bottom: 1px solid var(--color-border); background: #FBFCFE;
}
table.data-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--color-border-light); font-size: 13px; }
table.data-table tbody tr:hover { background: #FAFBFD; }
table.data-table tbody tr:last-child td { border-bottom: none; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--color-text-muted); font-size: 13.5px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: var(--radius-full);
    font-size: 11px; font-weight: 700; text-transform: capitalize;
}
.badge-success { background: var(--color-success-bg); color: var(--color-primary-text); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-neutral { background: #EEF1F6; color: var(--color-text-secondary); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-top: 1px solid var(--color-border); font-size: 12.5px; color: var(--color-text-muted); }
.pagination__controls { display: flex; gap: 6px; }
.pagination__controls button {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    padding: 5px 10px; font-size: 12px; cursor: pointer; font-family: inherit; color: var(--color-text);
}
.pagination__controls button:disabled { opacity: .4; cursor: not-allowed; }
.pagination__controls button:not(:disabled):hover { border-color: var(--color-primary); color: var(--color-primary-text); }

/* ---------- Toast ---------- */
#toast-stack {
    position: fixed; top: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    background: var(--color-secondary); color: #fff;
    padding: 13px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    font-size: 13px; font-weight: 500; line-height: 1.4;
    animation: toast-in .25s cubic-bezier(0.16, 1, 0.3, 1);
    border-left: 4px solid var(--color-primary);
}
.toast.toast-error { border-left-color: var(--color-danger); }
.toast.toast-warning { border-left-color: var(--color-warning); }
.toast i { margin-top: 1px; }
.toast.toast-success i { color: var(--color-primary); }
.toast.toast-error i { color: #F87171; }
.toast.toast-warning i { color: #FBBF24; }
.toast .toast-close { margin-left: auto; cursor: pointer; opacity: .6; background: none; border: none; color: #fff; font-size: 14px; }
.toast .toast-close:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ---------- Login page ---------- */
.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(rgba(0,24,50,0.55), rgba(0,24,50,0.65)), url('../img/login-bg.jpg');
    background-size: cover; background-position: center;
}
.login-card {
    width: 460px; min-height: 520px; padding: 44px 40px;
    display: flex; flex-direction: column; justify-content: center;
    background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px; box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.login-card label { color: rgba(255,255,255,0.85); }
.login-card__logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card__logo img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; }
.login-card__logo span { font-family: var(--font-heading); font-weight: 700; font-size: 20px; color: #fff; }
.login-card h2 { text-align: center; font-size: 15px; color: rgba(255,255,255,0.85); font-family: var(--font-body); font-weight: 600; margin-bottom: 20px; }
.login-error { background: var(--color-danger-bg); color: var(--color-danger); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 16px; display: none; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 24, 50, 0.5); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-box {
    background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-box__header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--color-border); }

/* Google Places Autocomplete's suggestion dropdown is appended straight to
   <body>, outside the modal - without forcing it above the modal overlay's
   z-index, it renders invisible behind it the moment a form field (e.g.
   product pickup location) sits inside a modal. */
.pac-container { z-index: 10000 !important; }
.modal-box__header h3 { font-size: 16px; }
.modal-box__close { background: none; border: none; font-size: 18px; color: var(--color-text-muted); cursor: pointer; }
.modal-box__body { padding: 22px; }
.modal-box__footer { padding: 16px 22px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Misc ---------- */
.text-muted { color: var(--color-text-muted); }
.spinner {
    width: 18px; height: 18px; border: 2.5px solid rgba(0,0,0,0.1); border-top-color: var(--color-primary);
    border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters .form-control { width: auto; min-width: 160px; }

/* ---------- Responsive ---------- */

/* Hamburger toggle - hidden on desktop, shown once the sidebar becomes an
   off-canvas drawer at the tablet breakpoint below. */
.topbar__menu-btn { display: none; background: none; border: none; font-size: 19px; color: var(--color-secondary); cursor: pointer; padding: 6px 10px 6px 0; }
.sidebar__overlay { display: none; }

@media (max-width: 1024px) {
    /* Sidebar becomes a fixed off-canvas drawer instead of pushing content over. */
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 100;
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar__overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,24,50,0.45);
        z-index: 90;
    }
    .sidebar__overlay.open { display: block; }
    .topbar__menu-btn { display: inline-flex; }
    .topbar__title { font-size: 16px; }
}

@media (max-width: 768px) {
    .content { padding: 14px; }
    .card__header { padding: 14px 16px; }
    .card__body { padding: 16px; }
    .topbar { padding: 0 14px; }
    .topbar__user .name, .topbar__user .role { display: none; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
    .kpi-card { padding: 14px; }
    .kpi-card__value { font-size: 22px; }
    .modal-box__body, .modal-box__header, .modal-box__footer { padding: 14px 16px; }
    .modal-box__footer { flex-wrap: wrap; }
    .tabs { overflow-x: auto; padding: 0 12px; }
    .tabs button { white-space: nowrap; padding: 12px 12px; }
    .notif-bell__panel { width: calc(100vw - 32px); max-width: 340px; right: -8px; }
    .login-card { width: calc(100vw - 32px); min-height: 0; padding: 30px 24px; }

    /* Live Map: side-by-side panel + map doesn't fit a phone screen -
       stack the driver list above the map instead, each getting a fixed
       share of the viewport height. */
    .live-map-layout { flex-direction: column; }
    .live-map-sidebar { width: 100%; height: 40vh; border-right: none; border-bottom: 1px solid var(--color-border); }
    .live-map-canvas { min-height: 45vh; }
}
