:root {
    --bg: #0b0f14;
    --surface: #121820;
    --surface-2: #1a222d;
    --border: #2a3544;
    --text: #e8edf4;
    --muted: #8b9bb0;
    --accent: #27a9f5;
    --accent-hover: #1e8fd4;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --font: "DM Sans", system-ui, -apple-system, sans-serif;
    --scrollbar-size: 9px;
    --scrollbar-thumb: #3a4a5e;
    --scrollbar-thumb-hover: #4d6178;
}

html {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

*::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

*::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 99px;
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 99px;
    border: 2px solid transparent;
    background-clip: padding-box;
    min-height: 40px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

/* —— Login —— */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(39, 169, 245, 0.25), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(34, 197, 94, 0.08), transparent),
        var(--bg);
    z-index: 0;
}

.login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: var(--shadow);
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.login-logo-accent {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.login-subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.login-form .field {
    margin-bottom: 18px;
}

.login-form label,
.field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 6px;
}

.login-form input,
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-form input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(39, 169, 245, 0.2);
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 18px;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s, color 0.15s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: #fff;
}

.btn-block {
    width: 100%;
    padding: 13px;
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--muted);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

/* —— Shell —— */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.app-brand {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.app-brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}

.app-brand-title:hover {
    color: var(--text);
}

.app-brand-title span {
    color: var(--accent);
}

.app-brand-meta {
    font-size: 0.75rem;
    color: var(--muted);
    margin-left: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.header-user {
    font-size: 0.8rem;
    color: var(--muted);
}

.app-main {
    flex: 1;
    padding: 14px 16px 28px;
    max-width: none;
    margin: 0;
    width: 100%;
}

/* —— Layout con nav lateral —— */
.panel-layout {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    width: 100%;
}

@media (max-width: 800px) {
    .panel-layout {
        grid-template-columns: 1fr;
    }
}

.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    position: sticky;
    top: 64px;
}

@media (max-width: 800px) {
    .side-nav {
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
    }
}

.side-nav-link {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.side-nav-link:hover {
    color: var(--text);
    background: rgba(39, 169, 245, 0.06);
}

.side-nav-link.active {
    color: var(--text);
    background: rgba(39, 169, 245, 0.12);
    border: 1px solid rgba(39, 169, 245, 0.25);
}

.panel-content {
    min-width: 0;
}

.page-title {
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 700;
}

.page-desc {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 0.9rem;
}

/* —— Stats / cards —— */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.stat-card-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 4px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--text);
    margin-bottom: 16px;
}

.card .card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-body {
    padding: 16px;
}

.card-body-muted {
    color: var(--muted);
    font-size: 0.9rem;
}

/* —— Tables —— */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.data-table tbody tr:hover td {
    background: var(--surface-2);
}

.data-table .empty-cell {
    color: var(--muted);
    text-align: center;
    padding: 28px 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.badge-muted {
    background: rgba(139, 155, 176, 0.15);
    color: var(--muted);
}

.badge-accent {
    background: rgba(39, 169, 245, 0.15);
    color: #7dd3fc;
}

.muted {
    color: var(--muted);
}

.stack-gap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* —— Forms —— */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

@media (max-width: 700px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.form-grid .field-full {
    grid-column: 1 / -1;
}

.field {
    margin-bottom: 0;
}

.field .hint {
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--muted);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #fecaca;
}

.btn-link {
    background: transparent;
    color: var(--accent);
    border: none;
    padding: 6px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
}

.check-row input {
    width: auto;
    margin: 0;
}

.check-row span {
    font-size: 0.875rem;
}

.inline-form {
    display: inline;
    margin: 0;
}

.map-placeholder {
    height: 420px;
    border-radius: 8px;
    background:
        radial-gradient(ellipse 70% 50% at 50% 40%, rgba(39, 169, 245, 0.12), transparent),
        var(--surface-2);
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.map-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.client-map {
    width: 100%;
    height: min(70vh, 640px);
    min-height: 420px;
    border-radius: 8px;
    background: var(--surface-2);
    z-index: 0;
}

.map-card-body {
    padding: 12px !important;
}

.map-wrap {
    position: relative;
}

.map-speed-hud {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(18, 24, 32, 0.94);
    border: 1px solid #2a3544;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
    color: #e8edf4;
    font-size: 0.85rem;
    font-weight: 700;
    max-width: calc(100% - 24px);
}

.map-speed-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #8b9bb0;
    flex-shrink: 0;
}

.map-speed-value {
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    min-width: 1.5ch;
}

.map-speed-unit {
    color: #8b9bb0;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}

.map-speed-meta {
    color: #8b9bb0;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    border-left: 1px solid #2a3544;
    padding-left: 8px;
    margin-left: 2px;
}

.map-speed-hud.is-ok {
    border-color: rgba(34, 197, 94, 0.45);
}

.map-speed-hud.is-ok .map-speed-dot {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.7);
}

.map-speed-hud.is-warn {
    border-color: rgba(245, 158, 11, 0.5);
}

.map-speed-hud.is-warn .map-speed-dot {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.7);
}

.map-speed-hud.is-over {
    border-color: rgba(239, 68, 68, 0.55);
}

.map-speed-hud.is-over .map-speed-dot {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.75);
    animation: map-speed-pulse 1s ease-in-out infinite;
}

.map-speed-hud.is-idle .map-speed-dot {
    background: #8b9bb0;
}

@keyframes map-speed-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.mp-limit {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #8b9bb0;
}

.mp-limit.is-ok { color: #86efac; }
.mp-limit.is-warn { color: #fcd34d; }
.mp-limit.is-over { color: #fca5a5; }

.map-hint {
    margin: 10px 0 0;
    font-size: 0.8rem;
    line-height: 1.4;
}

.map-device-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 6px 10px;
    font: inherit;
    font-size: 0.8rem;
}

.map-dot-wrap {
    background: transparent !important;
    border: none !important;
}

.map-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #1a222d;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--muted);
}

.live-dot::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

.live-dot.is-error::before {
    background: var(--danger);
    animation: none;
}

.live-dot.is-error {
    color: #fca5a5;
}

.leaflet-container {
    font-family: var(--font);
    background: var(--surface-2);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.limit-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.limit-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.8rem;
}

.feature-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.feature-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.feature-row:first-child {
    padding-top: 0;
}

.feature-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

@media (max-width: 640px) {
    .app-header {
        padding: 12px 14px;
    }

    .app-main {
        padding: 10px 12px 20px;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-card-value {
        font-size: 1.25rem;
    }

    .map-placeholder {
        height: 280px;
    }

    .client-map {
        min-height: 280px;
        height: 55vh;
    }
}

/* —— SweetAlert2 (tema oscuro del panel) —— */
.swal2-popup.gt-swal {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
    border-radius: 14px !important;
    font-family: var(--font) !important;
}

.swal2-popup.gt-swal .swal2-title {
    color: var(--text) !important;
    font-size: 1.2rem !important;
}

.swal2-popup.gt-swal .swal2-html-container {
    color: var(--muted) !important;
    font-size: 0.9rem !important;
}

.swal2-popup.gt-swal .swal2-icon {
    margin-top: 1.2em;
}

.swal2-styled.gt-swal-confirm {
    background: var(--accent) !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    box-shadow: none !important;
}

.swal2-styled.gt-swal-confirm.gt-swal-danger {
    background: var(--danger) !important;
}

.swal2-styled.gt-swal-cancel {
    background: transparent !important;
    color: var(--muted) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    box-shadow: none !important;
}

.swal2-styled.gt-swal-cancel:hover {
    color: var(--text) !important;
    border-color: var(--muted) !important;
}

div:where(.swal2-container).gt-swal-container {
    backdrop-filter: blur(4px);
}

.swal2-toast.gt-swal-toast {
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
    box-shadow: var(--shadow) !important;
}

