:root {
    --bg: #0f172a;
    --sidebar: #1a2b4a;
    --sidebar-hover: #243a5e;
    --accent: #3b82f6;
    --accent-soft: #dbeafe;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --surface: #f8fafc;
    --white: #ffffff;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--surface);
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ─────────────────────────────────────────────────────────────── */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1a2b4a 50%, #1e3a5f 100%);
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--white);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-brand {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-brand h1 {
    font-size: 1.35rem;
    color: var(--sidebar);
    margin-top: 0.5rem;
}

.login-brand p {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.login-logo {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
}

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover { background: #2563eb; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: #eef2f7; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

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

.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand strong {
    display: block;
    font-size: 1rem;
    color: white;
}

.sidebar-brand span {
    font-size: 0.75rem;
    color: #94a3b8;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    list-style: none;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.7rem 0.85rem;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--sidebar-hover);
    color: white;
    text-decoration: none;
}

.sidebar-nav .icon {
    width: 1.25rem;
    text-align: center;
    opacity: 0.85;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.8rem;
}

.sidebar-footer .user {
    color: white;
    font-weight: 600;
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.sidebar-footer a {
    color: #94a3b8;
    font-size: 0.8rem;
}

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

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar h1 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--sidebar);
}

.topbar-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

.content {
    flex: 1;
    padding: 1.5rem;
    overflow: auto;
    min-height: 0;
}

.content-full {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Cards & stats ───────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}

.stat-card .label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--sidebar);
    margin-top: 0.25rem;
}

.panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.panel-body { padding: 1.25rem; }
.panel-body.no-padding { padding: 0; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

table.data-table th,
table.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table.data-table th {
    background: var(--surface);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
}

table.data-table tr:hover td { background: #f8fafc; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #dcfce7; color: var(--success); }
.badge-advertencia { background: #fef3c7; color: var(--warning); }
.badge-inactivo { background: #fee2e2; color: var(--danger); }
.badge-activo { background: #dcfce7; color: var(--success); }
.badge-muted { background: #f1f5f9; color: var(--muted); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.toolbar input[type="search"],
.toolbar input[type="datetime-local"],
.toolbar select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    min-width: 160px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--muted);
}

.pagination .btns { display: flex; gap: 0.5rem; }

.empty-state {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ── Map page ────────────────────────────────────────────────────────── */
body.page-mapa {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.page-mapa .app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

body.page-mapa .main {
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
}

body.page-mapa .topbar {
    flex-shrink: 0;
}

body.page-mapa .content.content-full {
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
}

body.page-mapa .map-layout {
    flex: 1 1 0%;
}

.map-layout {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.map-sidebar {
    width: 300px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.map-sidebar-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.map-sidebar-header h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.map-sidebar input[type="search"] {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
}

.terminal-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.terminal-list li {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.terminal-list li:hover,
.terminal-list li.active { background: var(--accent-soft); }

.terminal-list .nombre { font-weight: 600; font-size: 0.9rem; }
.terminal-list .meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.terminal-list .empty { padding: 1.5rem 1rem; color: var(--muted); font-size: 0.85rem; cursor: default; }

#map {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.leaflet-popup-content {
    font-size: 0.85rem;
    line-height: 1.5;
    min-width: 180px;
}

.leaflet-popup-content strong { color: var(--sidebar); }

@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .sidebar-nav { display: flex; overflow-x: auto; padding: 0.5rem; }
    .sidebar-nav li { flex-shrink: 0; }
    .sidebar-footer { display: none; }
    body.page-mapa .app-shell { height: 100vh; height: 100dvh; }
    .map-layout { flex-direction: column; }
    .map-sidebar {
        width: 100%;
        height: auto;
        max-height: 35vh;
        min-height: 0;
        flex: 0 0 auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    #map { flex: 1 1 auto; min-height: 0; }
}
