:root {
    --bg: #eef3fb;
    --card: #ffffff;
    --text: #15233b;
    --muted: #5b6d88;
    --line: #d7e1ef;
    --primary: #1264f5;
    --primary-2: #0b4cc0;
    --danger: #d03445;
    --ok: #1d9a57;
    --warn: #d48a12;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;

    --shadow-sm: 0 1px 2px rgba(15, 28, 48, 0.06);
    --shadow: 0 10px 30px rgba(18, 34, 58, 0.08);
}

* {
    box-sizing: border-box;
}

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

body.app-body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 420px at 100% -40px, rgba(18, 100, 245, 0.16), transparent 58%),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 55%, #e8eef8 100%);
    min-height: 100vh;
    line-height: 1.45;
}

body.driver-modal-open {
    overflow: hidden;
}

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

a:hover {
    color: var(--primary-2);
}

p,
small {
    color: var(--muted);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    color: var(--text);
    line-height: 1.25;
}

.container,
.app-container {
    width: 100%;
    max-width: 1220px;
    margin: 0 auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .container,
    .app-container {
        padding: 20px;
    }
}

@media (min-width: 1024px) {
    .container,
    .app-container {
        padding: 24px;
    }
}

.app-topbar,
.mobile-header {
    position: sticky;
    top: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 66px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(14px);
}

.app-topbar__title,
.driver-header-top strong {
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    letter-spacing: 0.01em;
    color: var(--text);
}

.app-topbar__actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.wake-lock-toggle {
    min-width: 150px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.wake-lock-toggle span {
    color: inherit !important;
    font-weight: 800;
}

.wake-lock-hint {
    margin: 8px 16px 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(212, 138, 18, 0.25);
    background: rgba(212, 138, 18, 0.08);
    color: #7f5a10;
    font-size: 0.8rem;
}

.app-tabs,
.driver-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    scrollbar-width: thin;
}

.app-tabs::-webkit-scrollbar,
.driver-nav::-webkit-scrollbar {
    height: 6px;
}

.app-tabs::-webkit-scrollbar-thumb,
.driver-nav::-webkit-scrollbar-thumb {
    background: rgba(21, 35, 59, 0.25);
    border-radius: 999px;
}

.app-tab,
.driver-nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--muted) !important;
    background: #fff;
    transition: all 0.18s ease;
}

.app-tab:hover,
.driver-nav a:hover {
    border-color: rgba(18, 100, 245, 0.5);
    color: var(--primary) !important;
}

.app-tab.active,
.driver-nav a.active {
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
    border-color: var(--primary-2);
    color: #fff !important;
}

.section,
.card,
.kpi-card,
.chart-card,
.tracking-stat-card,
.afiliado-card,
.afiliado-table-card {
    background: var(--card) !important;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.section {
    padding: 16px;
}

.section + .section,
.card + .card {
    margin-top: 16px;
}

.section__header,
.card-header,
.afiliado-table-header,
.driver-shipments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.section__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.grid,
.kpi-grid,
.driver-kpi-grid,
.afiliado-cards-grid,
.tracking-stats-grid {
    display: grid;
    gap: 12px;
}

.kpi-grid,
.driver-kpi-grid,
.afiliado-cards-grid,
.tracking-stats-grid {
    grid-template-columns: 1fr;
}

@media (min-width: 680px) {
    .kpi-grid,
    .driver-kpi-grid,
    .afiliado-cards-grid,
    .tracking-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .kpi-grid,
    .driver-kpi-grid,
    .tracking-stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .afiliado-cards-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.kpi-card,
.tracking-stat-card,
.afiliado-card {
    padding: 14px;
}

.kpi-card .kpi-label,
.tracking-stat-card span {
    font-size: 0.82rem;
    color: var(--muted);
}

.kpi-card .kpi-value,
.tracking-stat-card strong {
    margin-top: 6px;
    color: var(--text);
    font-size: clamp(1.15rem, 2vw, 1.65rem);
    font-weight: 700;
}

.btn,
button,
input[type="button"],
input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.btn:hover,
button:hover,
input[type="button"]:hover,
input[type="submit"]:hover {
    transform: translateY(-1px);
}

.btn:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(18, 100, 245, 0.22);
    outline-offset: 1px;
}

.btn,
.btn--primary,
.btn-primary,
button.btn-primary {
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
    border-color: var(--primary-2);
    color: #fff !important;
}

.btn:hover,
.btn--primary:hover,
.btn-primary:hover,
button.btn-primary:hover {
    filter: brightness(0.98);
    color: #fff !important;
}

.btn.secondary,
.btn--ghost,
.btn-ghost,
.btn-outline,
button.secondary,
button.btn-ghost,
button.btn--ghost {
    background: #fff;
    border-color: var(--line);
    color: var(--text) !important;
}

.btn.secondary:hover,
.btn--ghost:hover,
.btn-ghost:hover,
.btn-outline:hover,
button.secondary:hover,
button.btn-ghost:hover,
button.btn--ghost:hover {
    border-color: rgba(18, 100, 245, 0.45);
    color: var(--primary) !important;
}

.btn--sm,
.btn-sm {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.8rem;
}

.badge,
.afiliado-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: rgba(18, 100, 245, 0.12);
    color: var(--primary) !important;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge--info,
.badge-info,
.badge-default,
.badge-secondary {
    background: rgba(18, 100, 245, 0.12) !important;
    color: var(--primary) !important;
}

.badge--ok,
.badge--success,
.badge-success,
.afiliado-badge.success {
    background: rgba(29, 154, 87, 0.13) !important;
    color: var(--ok) !important;
}

.badge--danger,
.badge-danger,
.afiliado-badge.danger {
    background: rgba(208, 52, 69, 0.13) !important;
    color: var(--danger) !important;
}

.badge-warning,
.afiliado-badge.warning {
    background: rgba(212, 138, 18, 0.14) !important;
    color: var(--warn) !important;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
}

.input,
.select,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="file"],
textarea,
select {
    width: 100%;
    min-height: 44px;
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line) !important;
    background: #fff !important;
    color: var(--text) !important;
    font-size: 0.93rem;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: #8da0be;
}

.table-wrapper,
.afiliado-table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.table,
.afiliado-table {
    width: 100%;
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
}

.table th,
.table td,
.afiliado-table th,
.afiliado-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    color: var(--text);
}

.table thead th,
.afiliado-table thead th {
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #6a7c99;
    background: #f7faff;
}

.table tbody tr:hover,
.afiliado-table tbody tr:hover {
    background: #f8fbff;
}

.table tbody tr:last-child td,
.afiliado-table tbody tr:last-child td {
    border-bottom: 0;
}

.text-center {
    text-align: center;
}

.alert {
    margin: 10px 0 14px;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid rgba(18, 100, 245, 0.2);
    background: rgba(18, 100, 245, 0.08);
    color: var(--text);
}

.driver-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

.driver-page-header p {
    margin: 6px 0 0;
}

.driver-kpis-inline,
.driver-shipments-kpis {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.driver-kpi {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 11px;
    background: #fff;
    color: var(--muted);
    font-size: 0.77rem;
}

.driver-kpi strong {
    color: var(--text);
}

.driver-inline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.driver-signature-modal[hidden],
.driver-sos-modal[hidden] {
    display: none !important;
}

.driver-signature-modal,
.driver-sos-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(10, 20, 36, 0.72);
}

.driver-signature-card,
.driver-sos-modal-card {
    width: min(640px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 16px;
}

.driver-signature-header,
.driver-sos-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.driver-signature-close,
.driver-sos-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: rgba(21, 35, 59, 0.08);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.driver-signature-subtitle {
    margin: 8px 0 10px;
}

.driver-signature-error {
    margin-bottom: 10px;
    border-radius: 10px;
    border: 1px solid rgba(208, 52, 69, 0.3);
    background: rgba(208, 52, 69, 0.08);
    color: var(--danger);
    padding: 10px;
}

.driver-signature-location,
.driver-sos-media-actions,
.driver-signature-actions,
.driver-sos-submit,
.tracking-control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tracking-control-row {
    margin-top: 10px;
}

.driver-signature-pad-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

#deliverySignatureCanvas {
    width: 100%;
    height: 220px;
    display: block;
    touch-action: none;
}

.signature-thumb {
    width: 138px;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.delivery-status-time {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--muted);
}

.driver-sos-camera-preview,
.driver-sos-media-preview img,
.driver-sos-media-preview video {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--line);
}

.sos-fab,
.driver-sos-floating-button {
    position: fixed;
    right: 16px;
    bottom: 18px;
    z-index: 1800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    border: 1px solid rgba(131, 7, 24, 0.2);
    background: linear-gradient(180deg, #ef4e5f 0%, #c9253a 100%);
    box-shadow: 0 18px 34px rgba(201, 37, 58, 0.34);
    color: #fff !important;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-decoration: none;
    cursor: pointer;
}

.sos-fab:hover,
.driver-sos-floating-button:hover {
    color: #fff !important;
    transform: translateY(-2px);
}

.page-header {
    margin-bottom: 14px;
}

.page-header p {
    margin-top: 6px;
}

.admin-container,
.afiliado-content {
    padding-bottom: 28px;
}

.admin-topbar,
.afiliado-topbar {
    background: rgba(255, 255, 255, 0.92) !important;
    border-bottom: 1px solid var(--line) !important;
    backdrop-filter: blur(12px);
}

.admin-sidebar,
.afiliado-sidebar {
    background: #fff !important;
    border-right: 1px solid var(--line) !important;
}

.admin-sidebar-nav a,
.admin-sidebar-footer > a,
.afiliado-sidebar-link {
    border-radius: 10px;
}

.admin-content,
.afiliado-main,
.afiliado-content {
    background: transparent !important;
}

.driver-shipments-table .table {
    min-width: 1060px;
}

.card-body {
    padding: 0 14px 14px;
}

.card-header {
    padding: 14px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0;
}

.driver-empty,
.app-empty,
.afiliado-empty-state {
    border: 1px dashed var(--line);
    border-radius: 12px;
    background: #f7faff;
    text-align: center;
    padding: 20px;
}

.driver-empty p,
.app-empty p,
.afiliado-empty-state p {
    margin: 0;
}

.driver-grid-list {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 8px;
}

.status-timeline {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.status-chip.is-done {
    border-color: rgba(29, 154, 87, 0.35);
    background: rgba(29, 154, 87, 0.12);
    color: var(--ok);
}

.status-chip.is-active {
    border-color: rgba(18, 100, 245, 0.35);
    background: rgba(18, 100, 245, 0.12);
    color: var(--primary);
}

.pickup-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .table.table--responsive,
    .afiliado-table.table--responsive {
        min-width: 100%;
        border: 0;
    }

    .table.table--responsive thead,
    .afiliado-table.table--responsive thead {
        display: none;
    }

    .table.table--responsive tbody,
    .afiliado-table.table--responsive tbody {
        display: grid;
        gap: 10px;
        padding: 10px;
    }

    .table.table--responsive tr,
    .afiliado-table.table--responsive tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 10px 12px;
        background: #fff;
        box-shadow: var(--shadow-sm);
    }

    .table.table--responsive td,
    .afiliado-table.table--responsive td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
        border: 0;
        border-bottom: 1px dashed var(--line);
        padding: 8px 0;
    }

    .table.table--responsive td:last-child,
    .afiliado-table.table--responsive td:last-child {
        border-bottom: 0;
        padding-bottom: 0;
    }

    .table.table--responsive td::before,
    .afiliado-table.table--responsive td::before {
        content: attr(data-label);
        display: inline-block;
        min-width: 112px;
        color: var(--muted);
        font-size: 0.72rem;
        font-weight: 700;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }

    .table.table--responsive td[colspan],
    .afiliado-table.table--responsive td[colspan] {
        display: block;
        border: 0;
        padding: 6px 0;
    }

    .table.table--responsive td[colspan]::before,
    .afiliado-table.table--responsive td[colspan]::before {
        content: none;
    }

    .table.table--responsive td[data-label="Acoes"],
    .table.table--responsive td[data-label="Acao"],
    .afiliado-table.table--responsive td[data-label="Acoes"],
    .afiliado-table.table--responsive td[data-label="Acao"] {
        flex-wrap: wrap;
    }

    .table,
    .afiliado-table {
        min-width: 100%;
    }

    .driver-shipments-table .table {
        min-width: 100%;
    }

    .driver-sos-floating-button,
    .sos-fab {
        width: 62px;
        height: 62px;
        right: 14px;
        bottom: 14px;
    }

    .app-topbar__actions {
        gap: 6px;
    }

    .wake-lock-toggle {
        min-width: 120px;
        padding: 8px 10px;
        font-size: 0.74rem;
    }
}

@media (min-width: 1024px) {
    .driver-container {
        max-width: 1240px;
    }
}
