/* ============================================================
   AquaVigil Portal — Deep Ocean Operations Console
   A dark, premium monitoring dashboard with water-inspired accents
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;500;600;700&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* --- Design Tokens --- */
:root {
    /* Surfaces */
    --bg-deep: #060b18;
    --bg-base: #0a1128;
    --bg-raised: #111d3a;
    --bg-overlay: #162040;
    --bg-hover: #1a2850;
    --bg-glass: rgba(17, 29, 58, 0.75);

    /* Accents — AquaVigil brand green */
    --cyan: #05ad48;
    --cyan-bright: #2dd65a;
    --cyan-dim: #048a3a;
    --cyan-glow: rgba(5, 173, 72, 0.25);
    --cyan-glow-strong: rgba(5, 173, 72, 0.45);

    /* Semantic */
    --success: #10b981;
    --success-dim: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-dim: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-dim: rgba(239, 68, 68, 0.15);

    /* Text */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-bright: #f1f5f9;

    /* Borders */
    --border: rgba(148, 163, 184, 0.1);
    --border-accent: rgba(5, 173, 72, 0.2);
    --border-strong: rgba(148, 163, 184, 0.2);

    /* Typography */
    --font-display: 'Chakra Petch', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Spacing & Shape */
    --radius: 10px;
    --radius-lg: 16px;
    --radius-sm: 6px;

    /* Sidebar */
    --sidebar-w: 240px;
    --header-h: 60px;
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-deep: #f0f2f5;
    --bg-base: #ffffff;
    --bg-raised: #ffffff;
    --bg-overlay: #f5f7fa;
    --bg-hover: #eef1f6;
    --bg-glass: rgba(255, 255, 255, 0.85);

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-bright: #0f172a;

    --border: rgba(0, 0, 0, 0.08);
    --border-accent: rgba(5, 173, 72, 0.25);
    --border-strong: rgba(0, 0, 0, 0.15);

    --success-dim: rgba(16, 185, 129, 0.1);
    --warning-dim: rgba(245, 158, 11, 0.1);
    --danger-dim: rgba(239, 68, 68, 0.1);
}

[data-theme="light"] .sidebar-logo {
    background: transparent;
}

[data-theme="light"] .auth-logo-img {
    background: transparent;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }

body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { color: var(--cyan-bright); }

/* --- Auth Layout (no sidebar) --- */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(5, 173, 72, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(5, 173, 72, 0.05) 0%, transparent 50%),
        var(--bg-deep);
}

/* Animated water ripple background */
.auth-layout::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-conic-gradient(from 0deg at 50% 50%, transparent 0deg, rgba(6,182,212,0.02) 1deg, transparent 2deg) 0 0 / 120px 120px;
    animation: authBgPulse 20s ease-in-out infinite;
    opacity: 0.5;
}

@keyframes authBgPulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.02); }
}

.auth-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 1rem;
    padding: 2.5rem;
    background: var(--bg-glass);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    box-shadow:
        0 0 40px rgba(5, 173, 72, 0.06),
        0 25px 50px rgba(0, 0, 0, 0.4);
    animation: cardFloat 0.6s ease-out;
}

@keyframes cardFloat {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo-img {
    max-width: 200px;
    height: auto;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
}

.auth-card h1 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 1.5rem;
    text-align: center;
    letter-spacing: 0.02em;
}

/* --- Form Controls --- */
.form-group {
    margin-bottom: 1.15rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.4rem;
    font-family: var(--font-display);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--bg-deep);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.93rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px var(--cyan-glow);
}

input::placeholder { color: var(--text-muted); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.3rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--cyan);
    color: var(--bg-deep);
    border-color: var(--cyan);
}
.btn-primary:hover {
    background: var(--cyan-bright);
    box-shadow: 0 0 20px var(--cyan-glow);
    color: var(--bg-deep);
}

.btn-secondary {
    background: var(--bg-overlay);
    color: var(--text-primary);
    border-color: var(--border-strong);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
}

.btn-full { width: 100%; }

.btn-active {
    background: var(--cyan-dim);
    color: var(--text-bright);
    border-color: var(--cyan);
}

/* --- App Layout (with sidebar) --- */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
        "sidebar header"
        "sidebar main";
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

/* Header Bar */
.header-bar {
    grid-area: header;
}

/* Main Content */
.main-content {
    grid-area: main;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    max-width: 160px;
    height: auto;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.sidebar-section {
    padding: 0.5rem 1.25rem 0.25rem;
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}

.sidebar-link:hover {
    background: var(--bg-raised);
    color: var(--text-primary);
    border-left-color: var(--cyan-dim);
}

.sidebar-link.active {
    background: rgba(5, 173, 72, 0.08);
    color: var(--cyan);
    border-left-color: var(--cyan);
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active svg { opacity: 1; }

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-overlay);
    border: 1px solid var(--border-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--cyan);
    flex-shrink: 0;
}

.sidebar-user-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    min-width: 0;
    flex: 1;
    border-radius: 6px;
    padding: 0.25rem;
    margin: -0.25rem;
    transition: background 0.15s;
}
.sidebar-user-link:hover { background: var(--bg-hover); }

.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-family: var(--font-mono);
}

.sidebar-logout {
    margin-left: auto;
    color: var(--text-muted);
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}
.sidebar-logout:hover {
    color: var(--danger);
    background: var(--danger-dim);
}
.sidebar-logout svg { width: 18px; height: 18px; }

.sidebar-version {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.5;
    padding: 0.4rem 0 0.6rem;
}

/* Header Bar — visual styles */
.header-bar {
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    padding: 0 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: var(--header-h);
}

.header-title {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: 0.02em;
}

.header-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.theme-toggle:hover {
    color: var(--cyan);
    border-color: var(--cyan-dim);
    background: var(--bg-overlay);
}
.theme-toggle svg { width: 18px; height: 18px; }

.header-time {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Mobile overlay — always positioned out of grid flow */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.mobile-overlay.open { display: block; }

/* Mobile menu toggle */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
}
.mobile-toggle svg { width: 24px; height: 24px; }

/* Main Content — visual styles */
.main-content {
    padding: 1.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    background:
        radial-gradient(ellipse at 70% 10%, rgba(5, 173, 72, 0.03) 0%, transparent 50%),
        var(--bg-deep);
    min-height: 0; /* prevent grid blowout */
}


.page-header {
    margin-bottom: 1.75rem;
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: 0.02em;
}

.page-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* --- Alerts --- */
.alert {
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.88rem;
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.alert-error {
    background: var(--danger-dim);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
}
.alert-success {
    background: var(--success-dim);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.3);
}
.alert-info {
    background: rgba(5, 173, 72, 0.1);
    color: var(--cyan-bright);
    border-color: rgba(5, 173, 72, 0.25);
}

.impersonate-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius);
    color: #fbbf24;
    font-size: 0.85rem;
}

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

.stat-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--border-accent); }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--cyan), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.stat-card:hover::before { opacity: 1; }

/* Clickable stat cards (Battery, Signal, Temp) */
.stat-clickable {
    cursor: pointer;
    user-select: none;
}
.stat-clickable:hover {
    border-color: var(--cyan-dim);
    background: var(--bg-overlay);
}
.stat-clickable.stat-active {
    border-color: var(--cyan);
    background: var(--bg-overlay);
}
.stat-clickable.stat-active::before { opacity: 1; }
.stat-chart-icon {
    width: 12px;
    height: 12px;
    vertical-align: middle;
    margin-left: 4px;
    opacity: 0.35;
    transition: opacity 0.2s;
}
.stat-clickable:hover .stat-chart-icon { opacity: 0.8; }
.stat-clickable.stat-active .stat-chart-icon { opacity: 1; color: var(--cyan); }

/* Metric detail chart */
.metric-chart-card {
    animation: metricSlideIn 0.25s ease-out;
}
.metric-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
@keyframes metricSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-bright);
    line-height: 1;
}

.stat-value.stat-cyan { color: var(--cyan); }
.stat-value.stat-success { color: var(--success); }
.stat-value.stat-warning { color: var(--warning); }
.stat-value.stat-danger { color: var(--danger); }

/* --- Cards --- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.card:hover {
    border-color: var(--border-accent);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.card-header {
    padding: 0.9rem 1.15rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-bright);
}
.editable-name { cursor: pointer; }
.editable-name:hover svg { opacity: 1 !important; }
.inline-rename {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
}
.base-station-link {
    color: var(--cyan-bright);
    text-decoration: none;
    transition: color 0.2s;
}
.base-station-link:hover {
    color: var(--cyan);
    text-decoration: underline;
}

.inline-rename input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    background: var(--bg-deep);
    border: 1px solid var(--border-accent);
    border-radius: 4px;
    color: var(--text-primary);
}

.card-body {
    padding: 1.15rem;
}

.card-body p {
    margin-bottom: 0.3rem;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.card-body strong { color: var(--text-primary); }

.card-online { border-left: 3px solid var(--success); }
.card-offline { border-left: 3px solid var(--danger); }

/* --- Status Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--font-display);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.22rem 0.6rem;
    border-radius: 100px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-online {
    background: var(--success-dim);
    color: var(--success);
}

.badge-online::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    50% { opacity: 0.8; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
}

.badge-offline {
    background: var(--danger-dim);
    color: #f87171;
}

.badge-offline::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--danger);
}

.badge-warning {
    background: var(--warning-dim);
    color: var(--warning);
}

.badge-ok {
    background: var(--success-dim);
    color: var(--success);
}

.badge-admin {
    background: rgba(5, 173, 72, 0.12);
    color: var(--cyan);
}

.badge-customer {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
}

/* --- Tank Gauge (Animated Water) --- */
.tank-visual {
    position: relative;
    width: 100px;
    height: 140px;
    margin: 0.5rem auto 1rem;
}

.tank-body {
    position: absolute;
    inset: 0;
    border: 2px solid var(--border-strong);
    border-radius: 6px 6px 14px 14px;
    overflow: hidden;
    background: var(--bg-deep);
}

/* Water fill with wave animation */
.tank-water {
    position: absolute;
    bottom: 0;
    left: -10%;
    width: 120%;
    transition: height 1s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(
        180deg,
        rgba(5, 173, 72, 0.6) 0%,
        rgba(5, 173, 72, 0.35) 100%
    );
}

.tank-water::before,
.tank-water::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    width: 200%;
    height: 16px;
    background: repeat-x;
    background-size: 50% 16px;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 16'%3E%3Cpath d='M0 8 Q25 0 50 8 Q75 16 100 8 Q125 0 150 8 Q175 16 200 8 V16 H0Z' fill='rgba(59,130,246,0.6)'/%3E%3C/svg%3E");
    animation: wave 3s linear infinite;
}

.tank-water::after {
    top: -6px;
    animation: wave 4s linear infinite reverse;
    opacity: 0.5;
}

@keyframes wave {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

.tank-percent {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.tank-percent span {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-bright);
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* Tank level color thresholds */
.tank-water.level-high { background: linear-gradient(180deg, rgba(59, 130, 246, 0.6), rgba(59, 130, 246, 0.35)); }
.tank-water.level-mid { background: linear-gradient(180deg, rgba(245, 158, 11, 0.6), rgba(245, 158, 11, 0.35)); }
.tank-water.level-mid::before,
.tank-water.level-mid::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 16'%3E%3Cpath d='M0 8 Q25 0 50 8 Q75 16 100 8 Q125 0 150 8 Q175 16 200 8 V16 H0Z' fill='rgba(245,158,11,0.6)'/%3E%3C/svg%3E");
}
.tank-water.level-low { background: linear-gradient(180deg, rgba(239, 68, 68, 0.6), rgba(239, 68, 68, 0.35)); }
.tank-water.level-low::before,
.tank-water.level-low::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 16'%3E%3Cpath d='M0 8 Q25 0 50 8 Q75 16 100 8 Q125 0 150 8 Q175 16 200 8 V16 H0Z' fill='rgba(239,68,68,0.6)'/%3E%3C/svg%3E");
}

.tank-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 0.75rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.tank-details strong { color: var(--text-primary); }
.tank-usage {
    grid-column: 1 / -1;
    color: var(--cyan-bright);
    border-top: 1px solid rgba(59, 130, 246, 0.15);
    padding-top: 0.35rem;
    margin-top: 0.15rem;
}

/* Usage summary stats row */
.usage-summary {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 1rem;
}
.usage-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 1rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 90px;
}
.usage-stat-value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--cyan);
    line-height: 1.2;
}
.usage-stat-label {
    font-family: var(--font-display);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 0.15rem;
}

.sparkline-container {
    height: 60px;
    margin-top: 0.75rem;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.15);
}

.tank-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-family: var(--font-mono);
}

.tank-actions {
    margin-top: 0.85rem;
    text-align: center;
}

/* --- Data Tables --- */
.table-wrap {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

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

.data-table th {
    background: var(--bg-overlay);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.data-table td {
    color: var(--text-secondary);
}

.data-table tbody tr {
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table code {
    background: var(--bg-deep);
    color: var(--cyan);
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

/* --- Charts --- */
.chart-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.chart-card h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chart-controls {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.chart-container {
    position: relative;
}

/* --- Section --- */
.section {
    margin-bottom: 1.75rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: 0.02em;
}

/* --- Forms (inline / admin) --- */
.form-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.form-card h3 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: end;
}

.form-row input,
.form-row select {
    flex: 1;
    min-width: 140px;
}

.inline-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: end;
}

.inline-form input,
.inline-form select {
    flex: 1;
    min-width: 120px;
}

.inline-form-sm {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.inline-form-sm select {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    min-width: 100px;
}

.action-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

/* --- Device Groups (admin) --- */
.device-group {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
}
.device-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid transparent;
    flex-wrap: wrap;
}
.device-group.expanded .device-group-header {
    border-bottom-color: var(--border);
}
.device-group-info h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
}
.device-group-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
}
.device-group-nodes {
    padding: 0;
}
.device-group-nodes .data-table {
    margin: 0;
    border: none;
    border-radius: 0;
}
.device-group-nodes .data-table thead th {
    background: rgba(148, 163, 184, 0.04);
}
.device-group-body {
    display: none;
}
.device-group.expanded .device-group-body {
    display: block;
}
.device-group-chevron {
    transition: transform 0.2s;
}
.device-group.expanded .device-group-chevron {
    transform: rotate(90deg);
}
.device-group-header:hover {
    background: var(--bg-hover);
}
.device-group-empty {
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Alert config form */
.alert-config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.form-hint {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* --- Auth Forms --- */
.auth-form .form-group { margin-bottom: 1.15rem; }

.auth-form button[type="submit"] {
    width: 100%;
    margin-top: 0.5rem;
}

.auth-links {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-links a { color: var(--cyan); }
.auth-links a:hover { color: var(--cyan-bright); }

/* --- Utility --- */
.text-muted { color: var(--text-muted); }
.text-cyan { color: var(--cyan); }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-sm { gap: 0.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

code {
    background: var(--bg-deep);
    color: var(--cyan);
    padding: 0.12rem 0.4rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
}

/* Divider */
.divider {
    height: 1px;
    background: var(--border);
    margin: 1.5rem 0;
}

/* --- Stagger animation for cards --- */
.card-grid > * {
    animation: fadeSlideUp 0.4s ease-out both;
}

.card-grid > *:nth-child(1) { animation-delay: 0s; }
.card-grid > *:nth-child(2) { animation-delay: 0.06s; }
.card-grid > *:nth-child(3) { animation-delay: 0.12s; }
.card-grid > *:nth-child(4) { animation-delay: 0.18s; }
.card-grid > *:nth-child(5) { animation-delay: 0.24s; }
.card-grid > *:nth-child(6) { animation-delay: 0.30s; }

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-h) 1fr;
        grid-template-areas:
            "header"
            "main";
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }

    .mobile-toggle { display: block; }

    .main-content { padding: 1.25rem; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid { grid-template-columns: 1fr; }

    .chart-controls { flex-wrap: wrap; }

    .data-table { font-size: 0.82rem; }
    .data-table th, .data-table td { padding: 0.5rem 0.65rem; }

    .section[style*="flex"] { flex-direction: column; }
    .form-card[style*="min-width"] { min-width: 0 !important; max-width: 100% !important; }
}

@media (max-width: 500px) {
    html { font-size: 14px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .tank-details { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .form-row input, .form-row select { min-width: 0; width: 100%; }
    .inline-form { flex-direction: column; }
    .inline-form input, .inline-form select { min-width: 0; width: 100%; }
    .inline-form-sm { flex-wrap: wrap; }
    .inline-form-sm select { min-width: 0; }
    .inline-form-sm input { width: 70px !important; }
    .alert-config-grid { grid-template-columns: 1fr !important; }

    /* Admin device groups */
    .device-group-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .device-group-header .action-group { flex-wrap: wrap; width: 100%; }
    .device-group-info { max-width: 100%; overflow: hidden; }
    .device-group-info h3 { flex-wrap: wrap; }
    .device-group-info code { word-break: break-all; }
    .device-group-meta { word-break: break-word; }
}

@media (max-width: 380px) {
    .stats-grid { grid-template-columns: 1fr; }
}
