:root {
    --bg: #0f1115;
    --surface: #181b21;
    --card: #20242c;
    --card-elev: #2a303a;
    --primary: #0ea5e9;
    --primary-2: #22d3ee;
    --accent: #34d399;
    --warn: #f59e0b;
    --danger: #ef4444;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.15);
    --shadow: 0 10px 40px rgba(0,0,0,0.35);
    --radius: 16px;
    --neon-cyan: #22d3ee;
    --neon-blue: #0ea5e9;
    --neon-emerald: #34d399;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, sans-serif; }

/* ===== PROFESSIONAL LOGIN SCREEN ===== */
.login-screen {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(14,165,233,0.18) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 80%, rgba(52,211,153,0.10) 0%, transparent 40%),
        linear-gradient(180deg, #0b1220 0%, #070b14 50%, #04060b 100%);
    overflow: hidden;
    z-index: 100;
    min-height: 100vh;
    min-width: 100vw;
}
.login-screen.hidden { display: none; }
.login-screen.tab.active { display: flex !important; }

/* ===== TABS ===== */
.tab { display: none; }
.tab.active { display: block; }

.login-backdrop {
    position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(34,211,238,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(34,211,238,0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(circle at 50% 50%, black 0%, transparent 70%);
    -webkit-mask-image: radial-gradient(circle at 50% 50%, black 0%, transparent 70%);
    animation: panGrid 60s linear infinite;
    pointer-events: none;
}
@keyframes panGrid {
    0% { transform: translate(0, 0); }
    100% { transform: translate(60px, 60px); }
}

.login-card {
    position: relative;
    width: min(420px, calc(100vw - 32px));
    padding: 40px 36px;
    background: rgba(15,23,42,0.82);
    border: 1px solid rgba(34,211,238,0.22);
    border-radius: var(--radius);
    box-shadow:
        0 24px 80px rgba(0,0,0,0.45),
        0 0 0 1px rgba(255,255,255,0.03),
        inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(18px);
    text-align: center;
    z-index: 10;
}

.login-logo {
    width: 72px; height: 72px;
    margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(14,165,233,0.20), rgba(34,211,238,0.10));
    border: 1px solid rgba(34,211,238,0.25);
    box-shadow: 0 0 30px rgba(14,165,233,0.15);
}
.login-logo svg {
    width: 40px; height: 40px;
    stroke: var(--neon-cyan);
    filter: drop-shadow(0 0 8px rgba(34,211,238,0.5));
}

.login-title {
    font-size: 1.75rem; font-weight: 700;
    margin: 0 0 6px;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, var(--text) 0%, var(--neon-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-subtitle {
    margin: 0 0 28px;
    color: var(--muted);
    font-size: 0.95rem;
}

.login-field { text-align: left; margin-bottom: 16px; }
.login-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 500;
}
.login-field input {
    width: 100%;
    padding: 12px 14px;
    background: rgba(2,6,23,0.55);
    border: 1px solid rgba(148,163,184,0.22);
    border-radius: 10px;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.login-field input:focus {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 0 3px rgba(34,211,238,0.12);
}

.login-error {
    min-height: 22px;
    margin-bottom: 12px;
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
}

.login-btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--neon-blue), var(--neon-cyan));
    color: #00101a;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(14,165,233,0.25);
    transition: transform .15s, box-shadow .15s;
}
.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(14,165,233,0.35);
}

.login-footer {
    margin: 24px 0 0;
    font-size: 0.75rem;
    color: var(--muted);
    opacity: 0.7;
}

/* ===== TOPBAR / NAV ===== */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: rgba(15,23,42,0.85);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.brand { display:flex; align-items:center; gap:10px; font-weight:700; color:var(--neon-cyan); }
.brand svg { stroke:var(--neon-cyan); filter:drop-shadow(0 0 6px rgba(34,211,238,0.35)); }
.nav { display:flex; gap:6px; flex-wrap:wrap; }
.nav-btn {
    padding: 7px 14px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: .15s;
}
.nav-btn:hover, .nav-btn.active {
    color: var(--text);
    background: rgba(34,211,238,0.10);
    border-color: rgba(34,211,238,0.25);
}
.top-actions { display:flex; gap:8px; }

/* ===== BUTTONS ===== */
.btn {
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: .15s;
}
.btn:hover { background: var(--card-elev); border-color: rgba(148,163,184,0.3); }
.btn.primary { background: var(--neon-blue); border-color: var(--neon-blue); color: #00101a; font-weight: 600; }
.btn.primary:hover { background: var(--neon-cyan); border-color: var(--neon-cyan); }
.btn.warn { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.35); color: var(--warn); }
.btn.danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.35); color: var(--danger); }
.btn-block { width: 100%; }

/* ===== LAYOUT ===== */
.container { padding: 20px; max-width: 1400px; margin: 0 auto; }
.hero { margin-bottom: 20px; }
.hero h1 { margin: 0 0 6px; font-size: 1.45rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.card-header { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1.05rem; }
.chart-card { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 320px; }

/* ===== STATS ===== */
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: transform .15s, border-color .15s;
}
.stat-card:hover { transform: translateY(-2px); border-color: rgba(34,211,238,0.25); }
.stat-title { display:flex; align-items:center; gap:8px; font-size: 0.9rem; color: var(--muted); margin-bottom: 8px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.stat-meta { font-size: 0.8rem; color: var(--muted); }
.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--neon-emerald); box-shadow:0 0 8px var(--neon-emerald); }
.status-dot.off { background:#64748b; box-shadow:none; }

/* ===== MAP ===== */
.map-layout { display:grid; grid-template-columns: 1fr 320px; gap:16px; height: calc(100vh - 160px); }
.map { border-radius: var(--radius); border: 1px solid var(--border); background:#0b1220; }
.map-sidebar { display:flex; flex-direction:column; gap:12px; overflow:auto; }
.sensor-list { display:flex; flex-direction:column; gap:8px; }
.legend { font-size: 0.8rem; color: var(--muted); display:flex; flex-direction:column; gap:6px; }
.legend-row { display:flex; align-items:center; gap:8px; }
.legend-dot { width:10px; height:10px; border-radius:50%; }

/* ===== TABLE ===== */
.table-wrap { overflow:auto; }
table { width:100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: rgba(255,255,255,0.02); }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ===== MODAL ===== */
.modal {
    display: none; position: fixed; inset: 0; z-index: 200;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    padding: 20px;
}
.modal.active { display: flex; }
.modal-content {
    width: min(900px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.modal-header { display:flex; justify-content:space-between; align-items:center; padding:16px 20px; border-bottom:1px solid var(--border); }
.modal-header .close { background:transparent; border:none; color:var(--muted); font-size:1.4rem; cursor:pointer; }
.modal-header .close:hover { color:var(--text); }
.modal-footer { display:flex; gap:8px; justify-content:flex-end; padding:16px 20px; border-top:1px solid var(--border); }

/* ===== FORM ===== */
.form { display:flex; flex-direction:column; gap:12px; }
.form-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:14px; }
.form-grid label { display:flex; flex-direction:column; gap:6px; font-size: 0.85rem; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea {
    padding: 10px 12px;
    background: rgba(2,6,23,0.45);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
    outline: none;
    border-color: var(--neon-cyan);
    box-shadow: 0 0 0 3px rgba(34,211,238,0.10);
}
.checkbox-inline { width: auto !important; accent-color: var(--neon-cyan); }

/* ===== PHOTOS ===== */
.photo-list { display:flex; flex-wrap:wrap; gap:8px; }
.photo-list img { width:80px; height:80px; object-fit:cover; border-radius:8px; border:1px solid var(--border); }

/* ===== CALCULATOR / SCHEMATIC ===== */
.calculator { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.calculator h4 { margin: 0 0 10px; font-size: 1rem; }
.calc-row { display:flex; gap:16px; flex-wrap:wrap; }
.calc-results { flex-direction:column; gap:6px; margin-top:12px; }
.calc-result { color: var(--neon-cyan); font-weight: 700; }
.schematic-wrap { display:grid; grid-template-columns: 1fr 1fr; gap:16px; }
.schematic-svg svg { width:100%; height:auto; max-height:520px; border-radius:12px; border:1px solid var(--border); background:#0b1220; }
.gps-warning { color:var(--warn); font-size:.85rem; margin:8px 0; }

/* ===== LOGGER TABS ===== */
.logger-tab { display:none; }
.logger-tab.active { display:block; }
.logger-tab-btn.active { background: rgba(34,211,238,0.15); border-color: var(--neon-cyan); color: var(--neon-cyan); }
.available-card.alert-zero { border-color: rgba(239,68,68,0.4); }
.available-card.archive-card { opacity: 0.75; }
.mini-chart-wrap { height:120px; border-radius:8px; background:var(--card); border:1px solid var(--border); padding:8px; }
.map-wrap { display:flex; align-items:center; justify-content:center; }
.no-entry { font-size:1.1rem; }
.badge { padding: 2px 6px; border-radius: 4px; }

/* ===== CHART CONTROLS ===== */
.chart-controls { display:flex; gap:8px; flex-wrap:wrap; margin: 12px 0; }
.btn-group { display:flex; gap:4px; flex-wrap:wrap; }
.btn-group .btn { border-radius: 6px; padding: 6px 10px; font-size: 0.8rem; }
.btn-group .btn.active-mode { background: rgba(34,211,238,0.15); border-color: var(--neon-cyan); color: var(--neon-cyan); }
.filters { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.filters input, .filters select { padding: 7px 10px; background:rgba(2,6,23,0.45); border:1px solid var(--border); border-radius:8px; color:var(--text); }
.chart-mode-hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }

/* ===== APP FOOTER ===== */
.app-footer { text-align:center; padding:16px 0; font-size:.85rem; color:var(--muted); border-top:1px solid var(--border); margin-top:24px; }
.footer-link { color:var(--primary); text-decoration:none; }
.footer-link:hover { text-decoration: underline; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .map-layout { grid-template-columns: 1fr; height: auto; }
    .map { height: 360px; }
    .schematic-wrap { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
    .nav { order: 3; width: 100%; }
}
@media (max-width: 520px) {
    .container { padding: 12px; }
    .login-card { padding: 28px 22px; }
    .card { padding: 14px; }
}

/* ===== HIDDEN / UTILITY ===== */
.hidden { display: none !important; }
.span-2 { grid-column: span 2; }
