:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #eef7f5;
    --ink: #20252b;
    --muted: #667085;
    --line: #d9e0e6;
    --primary: #0f766e;
    --primary-strong: #0b5f59;
    --accent: #f59e0b;
    --danger: #dc2626;
    --success: #15803d;
    --info: #2563eb;
    --shadow: 0 14px 40px rgba(32, 37, 43, 0.10);
    --radius: 8px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
    letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 2.1; }

.auth-body {
    display: grid;
    place-items: center;
    padding: 18px;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.10), rgba(245, 158, 11, 0.12)),
        var(--bg);
}
.auth-shell { width: min(100%, 430px); }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.auth-card h1 { margin: 22px 0 6px; font-size: 1.7rem; }

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-lockup strong { display: block; line-height: 1.1; }
.brand-lockup small { display: block; color: var(--muted); margin-top: 3px; }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    font-size: 0.9rem;
}

.form-stack, .form-grid { display: grid; gap: 14px; }
.form-grid { grid-template-columns: 1fr; }
label span, .weekdays > span {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
    color: #344054;
    font-size: 0.9rem;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--ink);
    min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(15, 118, 110, 0.18);
    border-color: var(--primary);
}
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.password-field button {
    position: absolute;
    right: 5px;
    top: 5px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border-radius: 8px;
    padding: 10px 14px;
    border: 1px solid transparent;
    font-weight: 800;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-huge { width: 100%; min-height: 62px; font-size: 1.05rem; }
.button-row, .row-actions, .form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form-actions { margin-top: 4px; }
.text-link, .mini-link { color: var(--primary); font-weight: 700; display: inline-block; margin-top: 12px; }
.mini-link { font-size: 0.82rem; margin-top: 5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.text-danger { color: var(--danger); }

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin: 12px 0;
    border: 1px solid transparent;
    font-weight: 700;
}
.alert-success { background: #eaf8ef; border-color: #b7e4c7; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.app-body {
    min-height: 100vh;
    display: block;
}
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 292px);
    background: #20252b;
    color: #fff;
    padding: 18px 14px;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    z-index: 30;
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 20;
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
.sidebar-brand { margin-bottom: 18px; }
.sidebar-brand .brand-mark { background: var(--primary); }
.side-nav { display: grid; gap: 3px; }
.side-nav a, .nav-logout {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px;
    border-radius: 8px;
    color: #d9dee5;
    border: 0;
    background: transparent;
}
.side-nav a.active, .side-nav a:hover, .nav-logout:hover { background: rgba(255, 255, 255, 0.10); color: #fff; }
.logout-form { margin-top: 16px; }
.menu-fab {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 10;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.main-shell { padding: 14px; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.topbar h1 { margin: 2px 0 0; font-size: 1.45rem; }
.topbar small { color: var(--muted); font-weight: 700; }
.user-chip {
    display: none;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    font-weight: 700;
}
.content { display: grid; gap: 16px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: 0 6px 22px rgba(32, 37, 43, 0.05);
}
.embedded-panel { box-shadow: none; }
.narrow-panel { max-width: 900px; }
.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.panel-header.tight { margin-bottom: 10px; }
.panel-header h2 { margin: 0; font-size: 1.1rem; }
.panel-header p { margin: 4px 0 0; color: var(--muted); }

.stats-grid, .detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.stat-card, .detail-card {
    position: relative;
    overflow: hidden;
    min-height: 104px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}
.stat-card small, .detail-card small { color: var(--muted); font-weight: 800; }
.stat-card strong, .detail-card strong { display: block; margin-top: 8px; font-size: 1.75rem; }
.stat-card svg {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 30px;
    height: 30px;
    color: rgba(15, 118, 110, 0.35);
}
.stat-card.success svg { color: rgba(21, 128, 61, 0.40); }
.stat-card.warn svg { color: rgba(245, 158, 11, 0.55); }
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.map {
    min-height: 320px;
    border-radius: 8px;
    border: 1px solid var(--line);
    overflow: hidden;
    background: #dbe5e8;
}
.map-small { min-height: 300px; }
.map-live { min-height: 420px; }
.route-map { min-height: 420px; }
.employee-map { min-height: 360px; margin-top: 12px; }

.filter-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: end;
    margin: 12px 0;
}
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}
.data-table th, .data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}
.data-table th {
    color: #475467;
    font-size: 0.82rem;
    text-transform: uppercase;
}
.data-table td small { display: block; color: var(--muted); margin-top: 3px; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 28px !important; }
.compact-table { max-height: 430px; overflow: auto; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.78rem;
    font-weight: 800;
    background: #eef2f7;
    color: #475467;
}
.badge-success, .badge-finalizada { background: #dcfce7; color: #166534; }
.badge-muted, .badge-agendada { background: #eef2f7; color: #475467; }
.badge-em_andamento { background: #ccfbf1; color: #0f766e; }
.badge-cancelada { background: #fee2e2; color: #991b1b; }
.badge-attention { background: #fef3c7; color: #92400e; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
}
.icon-button.danger { color: var(--danger); }
.row-actions form { display: inline; }

.weekdays {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.weekdays > span { width: 100%; margin-bottom: 0; }
.weekdays label, .check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}
.weekdays input, .check-row input {
    width: auto;
    min-height: 0;
}
.route-builder {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 18px;
}
.stop-row {
    display: grid;
    grid-template-columns: 38px 68px minmax(180px, 1fr);
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 8px;
    background: #fff;
}
.stop-row.selected { outline: 3px solid rgba(15, 118, 110, 0.18); border-color: var(--primary); }
.stop-row input:nth-of-type(n+3) { grid-column: span 3; }
.drag-handle { color: var(--muted); }

.timeline { display: grid; gap: 12px; }
.timeline article {
    border-left: 4px solid var(--accent);
    padding: 10px 0 10px 12px;
}
.timeline h3 { margin: 7px 0 4px; font-size: 1rem; }
.timeline p { margin: 0 0 5px; color: #475467; }
.timeline small { color: var(--muted); }

.trip-live-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}
.live-card {
    border: 1px solid var(--line);
    border-left: 5px solid var(--primary);
    border-radius: 8px;
    padding: 12px;
}
.live-card.stale { border-left-color: var(--danger); background: #fff7f7; }
.live-card span, .live-card small { display: block; color: var(--muted); margin-top: 3px; }

.empty-state {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 8px;
    padding: 38px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}
.empty-state svg { width: 44px; height: 44px; color: var(--muted); }
.empty-state h2 { margin: 0; }
.empty-state p { margin: 0; color: var(--muted); }
.info-callout {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: var(--surface-soft);
    border: 1px solid #b7e4dc;
    border-radius: 8px;
    padding: 12px;
    margin-top: 14px;
}
.info-callout p { margin: 0; color: #24534f; }

.mobile-body {
    background: #f8fafb;
    min-height: 100vh;
}
.mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
}
.mobile-content {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 14px 12px 28px;
}
.mobile-alert { width: min(calc(100% - 24px), 760px); margin: 12px auto; }
.mobile-hero {
    background: #20252b;
    color: #fff;
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 12px;
}
.mobile-hero small { color: #b9c1ca; font-weight: 800; }
.mobile-hero h1 { margin: 4px 0; font-size: 1.6rem; }
.mobile-hero p { margin: 0; color: #e6ebf0; }
.driver-trip-card, .employee-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}
.trip-status-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-weight: 800;
}
.driver-trip-card h2, .employee-route h2 { margin: 12px 0 4px; font-size: 1.35rem; }
.driver-trip-card p, .employee-route p { color: var(--muted); margin: 0; }
.gps-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}
.gps-grid div {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    min-height: 74px;
}
.gps-grid small { display: block; color: var(--muted); font-weight: 800; }
.gps-grid strong { display: block; margin-top: 6px; overflow-wrap: anywhere; }
.driver-actions { display: grid; gap: 10px; margin-top: 14px; }
.wake-row {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
}
.wake-row small { display: block; color: var(--muted); margin-top: 3px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
    display: block;
    width: 52px;
    height: 30px;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
}
.switch span::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    transition: transform 160ms ease;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(22px); }

.modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: end center;
    background: rgba(15, 23, 42, 0.48);
    padding: 12px;
    z-index: 50;
}
.modal.open { display: grid; }
.modal-card {
    width: min(100%, 560px);
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    max-height: 92vh;
    overflow: auto;
}

@media (max-width: 720px) {
    .data-table, .data-table thead, .data-table tbody, .data-table th, .data-table td, .data-table tr {
        display: block;
        min-width: 0;
    }
    .data-table thead { display: none; }
    .data-table tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 6px;
    }
    .data-table td {
        border-bottom: 0;
        display: grid;
        grid-template-columns: 120px 1fr;
        gap: 8px;
        padding: 8px;
    }
    .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
    }
    .row-actions { justify-content: flex-start; }
}

@media (min-width: 760px) {
    .main-shell { padding: 24px 24px 24px 316px; }
    .sidebar { transform: none; }
    .menu-fab, .sidebar-backdrop { display: none; }
    .user-chip { display: flex; }
    .topbar h1 { font-size: 1.8rem; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-2 { grid-column: span 2; }
    .filter-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-row.wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr); }
    .route-builder { grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr); }
    .detail-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .modal { place-items: center; }
    .stop-row { grid-template-columns: 38px 68px 1fr 1.2fr 130px 130px 120px 1fr 38px; }
    .stop-row input:nth-of-type(n+3) { grid-column: auto; }
}

@media (min-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
