@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&family=Montserrat+Alternates:wght@600;700&display=swap');

/* ... (Previous CSS) ... */

:root {
    /* Color Palette - Refined Green Industrial */
    --bg-base: #f7faf7;
    /* Calm Mint White */
    --bg-accent: #eff4ef;
    /* Subtle Green Tint */
    --surface: #ffffff;
    --surface-2: #fcfdfc;
    --ink: #1f2a1f;
    /* Deep Forest Evergreen */
    --ink-muted: #5a6a5c;
    /* Muted Sage */
    --accent: #2f8f5b;
    /* Professional Emerald */
    --accent-2: #1e6f46;
    /* Darker Forest */
    --accent-soft: #eaf3ee;
    /* Very Light Sage */
    --danger: #d9493c;
    /* Softened Red */
    --success: #2f8f5b;
    --warning: #d97706;

    /* Shadows & Depths */
    /* Shadows & Depths */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.08);
    /* sharper definition */
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.15), 0 4px 6px -2px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.06);

    /* Borders & Radius - Normalized for industrial feel */
    /* Borders & Radius - Normalized for industrial feel */
    --border-color: #cbd5cb;
    /* Stronger Sage-Grey */
    --radius-lg: 8px;
    /* Standardized for professionalism */
    --radius-md: 6px;
    --radius-sm: 4px;
}

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

html,
body {
    height: 100%;
}

body {
    font-family: 'Inter', 'Manrope', system-ui, -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app-screen {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#login-screen .app-footer,
#login-screen footer {
    display: none !important;
}

.login-footer-text {
    display: none !important;
    /* Hide footer text on login page */
}

#login-screen .login-footer-text {
    display: none !important;
}

.view {
    flex: 1;
    display: none;
    flex-direction: column;
    min-height: 0;
    /* Allow flex to work properly */
}

.view.active {
    display: flex;
}

.view .container {
    flex: 1;
    display: block;
    /* Change from flex to block for normal flow */
    padding: 20px;
    overflow: visible;
    /* Remove container scroll, use page scroll */
    min-height: 0;
}

/* Responsive Design - Only apply mobile styles on small screens */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        padding: 10px 15px;
        gap: 10px;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
    }

    .nav-links a {
        margin-left: 0;
        font-size: 0.9rem;
        padding: 8px 12px;
    }

    .container {
        padding: 10px;
    }

    .device-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .card {
        padding: 15px;
    }

    .modal-content {
        width: 95%;
        padding: 20px;
        max-height: 90vh;
    }

    .status-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .prime-controls {
        flex-direction: column;
        gap: 15px;
    }

    .prime-group {
        width: 100%;
    }

    .inline-form {
        padding: 15px;
    }

    .header-row {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .view .container {
        display: flex;
        flex-direction: column;
    }

    /* Mobile scroll UX: avoid nested scroll containers.
       Keep the active view in normal document flow (no inner scrolling). */
    #app-screen > .view {
        flex: 1 1 auto !important;
        overflow: visible !important;
    }
}

@media (max-width: 480px) {
    .nav-brand {
        font-size: 1.2rem;
    }

    .card h2 {
        font-size: 1rem;
    }

    .card h3 {
        font-size: 1rem;
    }

    .modal-content {
        padding: 15px;
    }
}

/* Screens */
.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#login-screen.active {
    display: flex;
}

#app-screen.active {
    display: flex;
    flex-direction: column;
}

/* Login */
/* Login - Full Screen Wrapper */
#login-screen {
    flex: 1;
    display: flex;
    /* overridden by .screen.active but good fallback */
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% 0%, rgba(47, 143, 91, 0.15) 0%, rgba(20, 30, 20, 0) 70%),
        linear-gradient(180deg, #1A261A 0%, #111811 100%);
    background-size: cover;
    background-attachment: fixed;
    position: relative;
    overflow: hidden;
}

/* Add a subtle mesh/grid overlay for industrial feel */
#login-screen::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* Login Container - Middle Layer (Layout only) */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 20px;
    background: transparent;
    /* Removed old gradient */
    position: relative;
    z-index: 1;
}

.login-container h1 {
    font-family: 'Montserrat Alternates', 'Space Grotesk', 'Manrope', sans-serif;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(47, 143, 91, 0.4);
    margin-bottom: 32px;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
}

/* Login Form - The Card */
#login-form {
    background: rgba(255, 255, 255, 0.98);
    padding: 40px;
    border-radius: 20px;
    box-shadow:
        0 20px 40px -4px rgba(0, 0, 0, 0.4),
        0 8px 16px -4px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 440px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0;
    backdrop-filter: blur(8px);
    transition: transform 0.3s ease;
}

#login-form input {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 16px;
    background: #fcfdfc;
    /* var(--surface-2) */
    border: 1px solid #cbd5cb;
    /* var(--border-color) */
    border-radius: 10px;
    font-size: 0.95rem;
    color: #1f2a1f;
    /* var(--ink) */
    transition: all 0.2s ease;
}

#login-form input:focus {
    outline: none;
    border-color: #2f8f5b;
    /* var(--accent) */
    box-shadow: 0 0 0 3px rgba(47, 143, 91, 0.15);
    background: #ffffff;
}

#login-form button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow: 0 12px 26px rgba(47, 143, 91, 0.32);
}

#login-form button:hover {
    transform: translateY(-2px);
}

#login-form button:active {
    transform: translateY(0);
}

.error-message {
    color: #e74c3c;
    margin-top: 10px;
    font-size: 14px;
}

.login-footer-text {
    display: none !important;
    /* Hide footer text on login page */
    text-align: center;
    padding: 20px 0 0 0;
    margin-top: 25px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
}

#login-screen .login-footer-text {
    display: none !important;
}

.login-footer-text p {
    display: none !important;
    margin: 6px 0;
    color: rgba(255, 255, 255, 0.9);
}

.login-footer-text strong {
    color: #fff;
    font-weight: 600;
}

.login-footer-text a {
    color: rgba(255, 255, 255, 0.95);
    text-decoration: underline;
    transition: color 0.2s;
}

.login-footer-text a:hover {
    color: #fff;
    text-decoration: none;
}

/* Viewer Read-only Styles */
.viewer-readonly {
    background-color: #f5f5f5 !important;
    opacity: 0.95;
    pointer-events: none !important;
}

/* Tab Styles - Professional Industrial */
.tab-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding: 0 8px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--ink-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover {
    color: var(--ink);
    background-color: var(--bg-accent);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
    background-color: rgba(47, 143, 91, 0.08);
    /* Subtle green tint for active state */
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-content {
    padding: 10px 0;
}

.viewer-readonly h3 {
    color: #666 !important;
}

.viewer-readonly input,
.viewer-readonly select,
.viewer-readonly textarea,
.viewer-readonly button,
.viewer-readonly strong {
    background-color: #e0e0e0 !important;
    color: #666 !important;
    cursor: not-allowed !important;
    border-color: #ccc !important;
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Make all viewer inputs gray */
.viewer-readonly * {
    color: #666 !important;
}

.viewer-readonly input:disabled,
.viewer-readonly select:disabled,
.viewer-readonly textarea:disabled,
.viewer-readonly button:disabled {
    background-color: #e0e0e0 !important;
    color: #666 !important;
    cursor: not-allowed !important;
    opacity: 0.7 !important;
    pointer-events: none !important;
}

.viewer-readonly input[disabled],
.viewer-readonly select[disabled],
.viewer-readonly textarea[disabled],
.viewer-readonly button[disabled] {
    background-color: #e0e0e0 !important;
    color: #666 !important;
    cursor: not-allowed !important;
    opacity: 0.7 !important;
    pointer-events: none !important;
}

.viewer-readonly .status-row span,
.viewer-readonly .stats-row span {
    color: #666 !important;
}

.viewer-readonly .status-row strong,
.viewer-readonly .stats-row strong {
    color: #666 !important;
}

.viewer-readonly select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    pointer-events: none !important;
}

/* Additional protection for viewer inputs */
input[disabled],
select[disabled],
textarea[disabled] {
    pointer-events: none !important;
    user-select: none !important;
}

/* Navbar - Professional Deep Green */
.navbar {
    background: #111811;
    /* Deep Industrial Evergreen */
    color: #f7faf7;
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-brand {
    font-family: 'Montserrat Alternates', 'Space Grotesk', 'Manrope', sans-serif;
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-links a {
    color: #a3b3a3;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8125rem;
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.nav-links a:hover {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.08);
}

.nav-links a.active {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.12);
}

/* Views */
.view {
    display: none;
    flex-direction: column;
}

.view.active {
    display: flex;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 20px;
    flex-wrap: nowrap;
}

.header-row h2 {
    font-family: 'Space Grotesk', 'Manrope', sans-serif;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0.3px;
}

/* Map */
#map {
    width: 100%;
}

/* Device Grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 20px;
    align-items: start;
    justify-items: stretch;
    /* Stretch cards to fill cell width */
}

/* Smaller grids for admin pages */
#users-list.device-grid,
#companies-list.device-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    max-width: 100%;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}

/* Offline Status */
.card.offline {
    background-color: #e8e8e8 !important;
    color: #666 !important;
    border: 1px solid #ccc !important;
    opacity: 0.7;
}

.card.offline h2 {
    color: #666 !important;
}

/* Legacy offline styles removed to allow semantic colors */

.card h2 {
    margin: 0 0 16px 0;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.card h3 {
    margin: 0 0 12px 0;
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 600;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 8px 0;
    font-size: 0.875rem;
    width: 100%;
}

.status-row span {
    color: var(--ink-muted);
    font-weight: 400;
}

.status-row strong {
    color: var(--ink);
    font-weight: 600;
}

.badge {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.badge.on {
    background-color: var(--accent-soft);
    color: var(--accent-2);
    border: 1px solid rgba(47, 143, 91, 0.1);
}

.badge.off {
    background-color: #fee2e2;
    color: var(--danger);
    border: 1px solid rgba(217, 73, 60, 0.1);
}

/* Map */
.map-shell {
    position: relative;
    height: calc(100vh - 92px);
    padding: 18px 18px 22px;
}

#map {
    height: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    border: 1px solid rgba(31, 42, 31, 0.08);
    overflow: hidden;
}

.map-overlay {
    position: absolute;
    top: 30px;
    left: 34px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 16px;
    padding: 16px 18px;
    box-shadow: 0 12px 30px rgba(18, 30, 22, 0.2);
    border: 1px solid rgba(31, 42, 31, 0.08);
    backdrop-filter: blur(8px);
    z-index: 1000;
}

.map-overlay-title {
    font-family: 'Space Grotesk', 'Manrope', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 4px;
}

.map-overlay-sub {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin-bottom: 10px;
}

.map-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--ink-muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.legend-dot.online {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 143, 91, 0.15);
}

.legend-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 0 3px rgba(224, 75, 63, 0.15);
}

@media (max-width: 768px) {
    .map-shell {
        height: calc(100vh - 120px);
        padding: 12px;
    }

    .map-overlay {
        top: 18px;
        left: 18px;
        right: 18px;
        width: auto;
    }
}

/* Device detail view */
.device-detail .card {
    margin-bottom: 16px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.settings-card h4 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--accent-2);
}

.tab-dark {
    background: #152018;
    border-radius: 12px;
    padding: 16px;
    color: #ffffff;
}

.tab-dark .stats-row {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.tab-dark .stats-row strong,
.tab-dark .stats-row span {
    color: #ffffff;
}

.tab-dark p {
    color: #ffffff;
}

.device-log {
    background-color: #f2f6f2;
    padding: 10px;
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--ink);
}

/* Log filter buttons */
.log-filter-btn {
    transition: all 0.2s ease;
}

.log-filter-btn:hover {
    background: #f0f0f0 !important;
    border-color: #bbb !important;
}

.log-filter-btn.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}

.device-mini-map {
    height: 200px;
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(31, 42, 31, 0.1);
    box-shadow: 0 10px 22px rgba(18, 30, 22, 0.08);
}

.company-header,
.location-header {
    width: 100%;
    box-sizing: border-box;
}

/* Map markers */
.marker-dot {
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.15);
    border: 2px solid #ffffff;
}

.marker-online {
    background: var(--accent);
}

.marker-offline {
    background: var(--danger);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.98) 0%, var(--surface-2) 100%);
    padding: 40px;
    border-radius: 22px;
    width: 90%;
    max-width: 820px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 28px 70px rgba(13, 25, 18, 0.3);
    border: 1px solid rgba(31, 42, 31, 0.08);
}

.modal-content h2 {
    margin-top: 0;
    padding-top: 0;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(47, 143, 91, 0.35);
    color: var(--accent-2);
    font-size: 1.7rem;
}

.close {
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #e74c3c;
}

/* Inline Forms */
.inline-form {
    background: linear-gradient(160deg, #ffffff 0%, #f4f8f5 100%);
    padding: 20px;
    border-radius: var(--radius-md);
    margin: 15px 0;
    border: 1px solid rgba(47, 143, 91, 0.2);
    box-shadow: 0 10px 22px rgba(31, 42, 31, 0.08);
}

.inline-form h4 {
    margin-top: 0;
    color: #4CAF50;
}

.inline-form input,
.inline-form select {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.inline-form button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
}

.inline-form .cancel-btn {
    background-color: #999;
}

.inline-form button:hover {
    opacity: 0.9;
}

.back-btn {
    background-color: #666;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 20px;
}

.back-btn:hover {
    background-color: #555;
}

.location-card {
    margin-bottom: 20px;
}

.company-info-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.edit-form {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.edit-form input {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.edit-form button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
}

.edit-form .cancel-btn {
    background-color: #999;
}

/* Admin Sections */
.admin-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.admin-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 70vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.admin-section h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.admin-section>div {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

button {
    padding: 10px 20px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 3px solid rgba(0, 0, 0, 0.15);
    /* Stronger matte depth */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: var(--accent-2);
}

button:active {
    border-bottom-width: 0;
    transform: translateY(1px);
}

button:disabled {
    background-color: var(--border-color);
    color: var(--ink-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

button.danger {
    background-color: var(--danger);
}

button.danger:hover {
    background-color: #be123c;
    /* Rose 700 */
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--ink);
    transition: all 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 0.85em;
}

/* Large Modal */
.large-modal {
    max-width: 800px;
}

/* Device Detail Styles */
.device-info {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
}

.device-info p {
    margin: 5px 0;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background-color: #f5f5f5;
    border-radius: 4px;
    margin-bottom: 5px;
}

.prime-controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.prime-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.prime-group label {
    font-weight: 600;
    min-width: 60px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.small-btn {
    padding: 5px 10px;
    font-size: 0.85em;
    margin-top: 5px;
}

/* Company/Location Sections */
/* Add padding to container to prevent border overlap */
#device-list {
    padding: 10px 0;
}

/* Add padding to prevent border overlap */
#device-list {
    padding: 10px 0;
    margin: 0;
}

.company-section,
.admin-company-section {
    margin-bottom: 20px;
    margin-top: 10px;
    border: 1px solid rgba(31, 42, 31, 0.1);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(15, 24, 18, 0.08);
    background: var(--surface);
}

.company-header,
.admin-company-header {
    background: var(--accent);
    color: white;
    padding: 16px 20px;
    margin: 0;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.location-header,
.admin-location-header {
    background-color: rgba(47, 143, 91, 0.12);
    color: var(--accent-2);
    padding: 12px 15px;
    margin: 0;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(31, 42, 31, 0.1);
}

.company-content,
.admin-company-content {
    padding: 15px;
    margin-top: 0;
    padding-top: 10px;
}

.location-content,
.admin-location-content {
    padding: 15px;
}

.toggle-icon {
    font-size: 0.8em;
    transition: transform 0.2s;
}

.admin-location-section {
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}

/* Company Detail Styles */
.company-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #4CAF50;
}

.company-info-card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-item label {
    font-weight: 600;
    color: #666;
    font-size: 0.9rem;
}

.info-item span {
    color: #333;
    font-size: 1rem;
}

.info-item.full-width {
    grid-column: 1 / -1;
}

.info-item a {
    color: #4CAF50;
    text-decoration: none;
}

.info-item a:hover {
    text-decoration: underline;
}

.company-locations-section {
    margin-top: 30px;
}

.company-locations-section h3 {
    color: #4CAF50;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
}

.back-btn {
    /* Baseline overrides these */
    cursor: pointer;
    font-size: 0.875rem;
}

.back-btn:hover {
    background-color: var(--ink);
}

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

.btn-secondary {
    background-color: var(--bg-accent);
    color: var(--ink-muted);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #dce7dc;
    color: var(--ink);
}

.btn-danger {
    background-color: #fee2e2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.btn-danger:hover {
    background-color: var(--danger);
    color: white;
}

/* Footer */
.app-footer {
    background: #111811;
    /* Match Navbar */
    color: #a3b3a3;
    text-align: center;
    padding: 1.5rem 2rem;
    margin-top: 48px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    width: 100%;
}

/* Login page: remove the white gap above footer without changing footer height */
#login-screen.active ~ footer.app-footer {
    /* Override later global rules that set margin-top:auto for sticky footer */
    margin-top: 0 !important;
}

/* Limit company section width on PC */
.company-section,
.admin-company-section {
    max-width: 450px;
    width: 100%;
    margin-left: 0;
    margin-right: auto;
}

/* Mode switch colors: Orange = NO (checked), Blue = NC (unchecked) */
.mode-switch .mode-slider {
    background-color: #2196F3;
    /* Blue (NC) */
}

.mode-switch input:checked+.mode-slider {
    background-color: #ff9800;
    /* Orange (NO) */
}

#app-screen {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
}

#app-screen>.view {
    flex: 1 1 auto;
    min-height: 0;
    /* Use page (body) scroll; avoid nested scroll containers (mobile UX) */
    overflow: visible;
}

.app-footer p {
    margin: 8px 0;
    font-size: 0.95rem;
    font-weight: 500;
}

.app-footer strong {
    font-weight: 700;
    color: #fff;
}

.app-footer a {
    color: white;
    text-decoration: underline;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: #e8f5e9;
    text-decoration: none;
}

/* Modern Design Enhancements */
.card {
    transition: all 0.3s ease;
}

.card:hover {
    transform: none;
    box-shadow: 0 12px 26px rgba(18, 30, 22, 0.08);
}

/* Viewer readonly fields - FORCE STYLING */
.viewer-readonly input[disabled],
.viewer-readonly input[readonly],
.viewer-readonly select[disabled],
.viewer-readonly select[readonly],
input[disabled][readonly],
select[disabled][readonly],
input[readonly][disabled],
select[readonly][disabled] {
    background-color: #e0e0e0 !important;
    color: #666 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    opacity: 0.7 !important;
    border-color: #ccc !important;
    user-select: none !important;
}

/* Also hide register button for viewers */
body:has([data-role="viewer"]) #btn-register-device,
body.viewer #btn-register-device {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
}

.inline-form {
    background: linear-gradient(135deg, #f9f9f9 0%, #ffffff 100%);
    border: 2px solid #4CAF50;
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.1);
}

.inline-form h4 {
    color: #4CAF50;
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.inline-form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Responsive adjustments for company detail */
@media (max-width: 768px) {
    .company-detail-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}


/* Layout fixes for location rows */
.status-row.location-row span {
    min-width: 70px;
}

.company-section,
.admin-company-section,
.location-section,
.admin-location-section,
.company-content,
.admin-company-content,
.location-content,
.admin-location-content {
    width: 100%;
    box-sizing: border-box;
}

.prime-controls {
    justify-content: space-between;
}

.prime-group {
    flex: 1;
}

.prime-group:last-child {
    justify-content: flex-end;
}


/* Status alignment */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

/* Status row in detail views */
.device-detail .status-row span {
    min-width: 100px;
}

/* Collapse spacing */
.company-content[style*="display: none"],
.location-content[style*="display: none"],
.admin-company-content[style*="display: none"],
.admin-location-content[style*="display: none"] {
    padding: 0;
}

/* Device summary bar */
.device-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 14px 0 22px;
}

.device-summary .summary-item {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.1);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    box-shadow: 0 8px 20px rgba(15, 24, 18, 0.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.device-summary .summary-item span {
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.device-summary .summary-item strong {
    color: var(--accent-2);
    font-size: 1.2rem;
}

/* Status rows styling */
.status-row .badge {
    flex-shrink: 0;
}

/* RBAC preview UI */
.rbac-context-bar {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.12);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.rbac-context-bar .context-title {
    color: var(--accent-2);
    font-weight: 600;
}

.rbac-context-bar .context-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.context-select {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(31, 42, 31, 0.12);
    background: white;
}

.context-hint {
    color: var(--muted);
    font-size: 0.85rem;
}

.rbac-preview {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.12);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 24px;
    box-shadow: 0 12px 26px rgba(18, 30, 22, 0.08);
}

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

.toolbar-title {
    font-weight: 600;
    color: var(--accent-2);
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.chip {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(31, 42, 31, 0.15);
    background: #f6faf7;
    color: var(--accent-2);
    font-size: 0.85rem;
    cursor: pointer;
}

.chip.active {
    background: linear-gradient(135deg, #1e6f46, #2f8f5b);
    color: white;
    border-color: transparent;
}

.count-pill {
    background: rgba(47, 143, 91, 0.12);
    color: var(--accent-2);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
}

.rbac-table {
    display: grid;
    gap: 8px;
}

.rbac-row {
    display: grid;
    grid-template-columns: 1.4fr 0.9fr 1.1fr 0.7fr 0.8fr 0.8fr;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #f8fbf9;
    align-items: center;
}

.rbac-row.rbac-head {
    background: transparent;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
}

.rbac-row .muted {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 4px;
}

.role-badge {
    background: rgba(31, 42, 31, 0.1);
    color: var(--accent-2);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    display: inline-flex;
}

.status-pill {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    display: inline-flex;
    justify-content: center;
    min-width: 90px;
}

.status-pill.online {
    background: rgba(47, 143, 91, 0.18);
    color: #1e6f46;
}

.status-pill.warn {
    background: rgba(255, 152, 0, 0.18);
    color: #c76d00;
}

.status-pill.offline {
    background: rgba(220, 53, 69, 0.2);
    color: #c62828;
}

.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--ink-muted);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-ghost:hover {
    background-color: var(--bg-accent);
    color: var(--ink);
    border-color: var(--ink-muted);
}

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

@media (max-width: 900px) {
    .rbac-row {
        grid-template-columns: 1fr;
    }

    .rbac-row.rbac-head {
        display: none;
    }
}


/* Device filters */
.device-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0 18px;
}

.device-filter-btn {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.12);
    border-radius: 999px;
    padding: 8px 14px;
    color: var(--accent-2);
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 20px rgba(15, 24, 18, 0.08);
}

.device-filter-btn.active {
    background: linear-gradient(135deg, #1e6f46, #2f8f5b);
    color: white;
    border-color: transparent;
}

.device-filter-btn.offline {
    color: #b71c1c;
    border-color: rgba(220, 53, 69, 0.3);
}

.device-filter-btn.offline.active {
    background: linear-gradient(135deg, #b71c1c, #d32f2f);
    color: white;
}

.filter-count {
    background: rgba(31, 42, 31, 0.08);
    color: inherit;
    border-radius: 999px;
    padding: 2px 8px;
    font-weight: 600;
}

.device-filter-btn.offline .filter-count {
    background: rgba(220, 53, 69, 0.2);
}


/* Company detail preview */
.rbac-company-preview {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.12);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-top: 24px;
    box-shadow: 0 12px 26px rgba(18, 30, 22, 0.08);
}

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

.company-preview-header h3 {
    margin: 0 0 4px;
    color: var(--accent-2);
}

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

.company-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.company-tab {
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(31, 42, 31, 0.12);
    background: #f6faf7;
    color: var(--accent-2);
    cursor: pointer;
}

.company-tab.active {
    background: linear-gradient(135deg, #1e6f46, #2f8f5b);
    color: white;
    border-color: transparent;
}

/* Tab panel visibility: hide inactive, show active */
.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.company-tab-panel {
    background: #f8fbf9;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.overview-card {
    background: white;
    border-radius: 12px;
    padding: 14px;
    border: 1px solid rgba(31, 42, 31, 0.08);
}

.audit-panel {
    background: #f3f7f4;
}

.audit-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.audit-list {
    display: grid;
    gap: 10px;
}

.audit-item {
    background: white;
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(31, 42, 31, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

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


/* Admin page header (shared) */
.admin-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(47, 143, 91, 0.35);
}

.admin-page-header h2 {
    margin: 0;
    color: var(--accent-2);
    font-family: 'Space Grotesk', 'Manrope', sans-serif;
    font-weight: 600;
}

/* Unified card style */
.card {
    background: var(--surface);
    border: 1px solid rgba(31, 42, 31, 0.12);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 26px rgba(18, 30, 22, 0.08);
}

.card:hover {
    transform: none;
    box-shadow: 0 12px 26px rgba(18, 30, 22, 0.08);
}

/* ==================== ALARM CARD STYLES ==================== */

.alarm-card {
    border-left: 4px solid var(--accent);
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.alarm-card.has-active-alarm {
    border-left-color: #f44336;
    background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
    animation: alarmPulse 2s ease-in-out infinite;
}

@keyframes alarmPulse {

    0%,
    100% {
        box-shadow: 0 12px 26px rgba(244, 67, 54, 0.15);
    }

    50% {
        box-shadow: 0 12px 36px rgba(244, 67, 54, 0.3);
    }
}

.alarm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(31, 42, 31, 0.1);
}

.alarm-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alarm-icon {
    font-size: 1.2rem;
}

.active-alarm-badge {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    color: white;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    animation: badgePulse 1.5s ease-in-out infinite;
}

@keyframes badgePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.alarm-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.alarm-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: #f8fbf9;
    border-radius: 10px;
    border: 1px solid rgba(31, 42, 31, 0.08);
    transition: all 0.2s ease;
}

.alarm-row.alarm-active {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    border-color: rgba(244, 67, 54, 0.3);
}

.alarm-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.alarm-name {
    font-weight: 600;
    color: var(--ink);
}

.alarm-mode,
.alarm-details {
    font-size: 0.8rem;
    color: var(--ink-muted);
}

.alarm-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.alarm-badge {
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.alarm-badge.ok {
    background: rgba(47, 143, 91, 0.15);
    color: #1e6f46;
}

.alarm-badge.triggered {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    color: white;
    animation: triggeredPulse 1s ease-in-out infinite;
}

@keyframes triggeredPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.motor-stop-indicator {
    font-size: 1rem;
    color: #FF9800;
    cursor: help;
}

.ofa-reset-info {
    padding: 8px 14px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 8px;
    font-size: 0.85rem;
    color: #1976D2;
    margin-top: -5px;
    margin-left: 14px;
}

.alarm-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid rgba(31, 42, 31, 0.1);
}

.buzzer-status {
    font-size: 0.85rem;
    color: var(--ink-muted);
}

.btn-alarm-history {
    background: transparent;
    border: 1px solid rgba(31, 42, 31, 0.2);
    color: var(--accent-2);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0;
    box-shadow: none;
}

.btn-alarm-history:hover {
    background: rgba(47, 143, 91, 0.1);
    border-color: var(--accent);
}

/* Alarm History Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.alarm-history-modal {
    background: white;
    border-radius: 20px;
    padding: 28px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(13, 25, 18, 0.35);
}

.alarm-history-modal h3 {
    margin: 0 0 20px;
    color: var(--accent-2);
    font-size: 1.3rem;
}

.alarm-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.alarm-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: #f8fbf9;
    border-radius: 10px;
    border-left: 3px solid transparent;
    flex-wrap: wrap;
    gap: 8px;
}

.alarm-history-item.triggered {
    border-left-color: #f44336;
    background: #ffebee;
}

.alarm-history-item.cleared {
    border-left-color: #4CAF50;
    background: #e8f5e9;
}

.alarm-history-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.alarm-type {
    font-weight: 600;
    color: var(--ink);
}

.alarm-event {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.alarm-event.triggered {
    background: #f44336;
    color: white;
}

.alarm-event.cleared {
    background: #4CAF50;
    color: white;
}

.alarm-history-date {
    font-size: 0.8rem;
    color: var(--ink-muted);
}

.acknowledged-badge {
    background: rgba(33, 150, 243, 0.15);
    color: #1976D2;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Responsive alarm card */
@media (max-width: 480px) {
    .alarm-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .alarm-status {
        width: 100%;
        justify-content: flex-end;
    }

    .alarm-footer {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .btn-alarm-history {
        width: 100%;
        text-align: center;
    }
}

/* ==================== MODERN TOGGLE SWITCHES (ESP-style) ==================== */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background-color: #4CAF50;
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(24px);
}

.toggle-switch.disabled .toggle-slider {
    background-color: #999 !important;
    cursor: not-allowed;
}

/* NO/NC Mode Switch */
.mode-switch {
    position: relative;
    display: inline-block;
    width: 70px;
    height: 26px;
}

.mode-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mode-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2196F3;
    /* Blue for NC */
    transition: .3s;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    font-size: 10px;
    font-weight: bold;
    color: white;
}

.mode-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    z-index: 1;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.mode-switch input:checked+.mode-slider {
    background-color: #ff9800;
    /* Orange for NO */
}

.mode-switch input:checked+.mode-slider:before {
    transform: translateX(44px);
}

.mode-switch.disabled .mode-slider {
    background-color: #999 !important;
    cursor: not-allowed;
}

/* ==================== ALARM CONFIG STYLES ==================== */

.alarm-config-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
}

.alarm-config-section.disabled-section {
    opacity: 0.6;
    background: #f0f0f0;
}

.alarm-config-section.alarm-active {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    border-color: #f44336;
    animation: pulse-alarm 1s infinite;
}

@keyframes pulse-alarm {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(244, 67, 54, 0);
    }
}

.alarm-config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.alarm-title {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.mode-hint {
    font-size: 0.75rem;
    color: #666;
    font-style: italic;
}

.alarm-status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.alarm-status-badge.ok {
    background-color: #4CAF50;
    color: white;
}

.alarm-status-badge.triggered {
    background: #f44336;
    color: white;
    animation: blink 0.5s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.alarm-status-badge.disabled {
    background-color: #9e9e9e;
    color: white;
}

.alarm-config-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
}

.alarm-control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.alarm-control-group .control-label {
    font-size: 0.85rem;
    color: #555;
    min-width: 70px;
}

.ofa-live-values {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.live-value {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.live-value span {
    font-size: 0.75rem;
    color: #666;
}

.live-value strong {
    font-size: 1.1rem;
    color: #333;
}

.buzzer-section {
    background: linear-gradient(135deg, #fff8e1 0%, #ffffff 100%);
    border-color: rgba(255, 152, 0, 0.3);
}

.alarm-save-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.btn-save-alarms {
    width: 100%;
    padding: 12px 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-save-alarms:hover {
    background-color: #45a049;
}

/* ==================== PRIME BUTTONS ==================== */

.prime-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.prime-btn.start {
    background-color: #4CAF50;
    color: white;
}

.prime-btn.start:hover {
    background-color: #45a049;
}

.prime-btn.stop {
    background-color: #f44336;
    color: white;
}

.prime-btn.stop:hover {
    background-color: #e53935;
}

.prime-btn:disabled {
    background-color: #ccc !important;
    cursor: not-allowed;
}

.prime-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.prime-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: #666;
}

.prime-button-group {
    display: flex;
    gap: 10px;
}

/* Settings tabs with alarm tab */
.tab-btn.alarm-tab {
    background: linear-gradient(135deg, #ff5722 0%, #ff9800 100%);
    color: white;
}

.tab-btn.alarm-tab.active {
    background: linear-gradient(135deg, #e64a19 0%, #f57c00 100%);
}

@media (max-width: 600px) {
    .alarm-config-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .alarm-control-group {
        justify-content: space-between;
    }

    .ofa-live-values {
        flex-direction: column;
    }

    .prime-button-group {
        flex-direction: column;
    }

    .prime-btn {
        width: 100%;
    }
}

/* ==================== ENHANCED RESPONSIVE DESIGN ==================== */

/* Tablet styles (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .device-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .container {
        padding: 16px;
        max-width: 100%;
    }

    .card {
        padding: 18px;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .tab-buttons {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: 1 1 auto;
        min-width: 100px;
        font-size: 0.85rem;
        padding: 10px 12px;
    }
}

/* Small desktop / narrow window (1024px - 1280px) */
@media (min-width: 1025px) and (max-width: 1280px) {
    .device-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 18px;
    }

    .container {
        max-width: 100%;
        padding: 20px;
    }
}

/* Large desktop (1280px+) */
@media (min-width: 1281px) {
    .device-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 20px;
    }

    .container {
        max-width: 1600px;
        margin: 0 auto;
        padding: 24px;
    }
}

/* Portrait mode phone adjustments */
@media (max-width: 480px) and (orientation: portrait) {
    .card {
        padding: 14px;
        border-radius: 12px;
    }

    .card h2 {
        font-size: 1rem;
        margin-bottom: 8px;
    }

    .status-row {
        padding: 6px 0;
        font-size: 0.85rem;
    }

    .status-row.compact {
        padding: 4px 0;
    }

    /* Reduce white space in cards */
    .status-grid {
        gap: 8px;
    }

    .stats-grid {
        gap: 8px;
    }

    /* Make badges smaller */
    .badge {
        padding: 3px 8px;
        font-size: 0.7rem;
    }

    /* Tab buttons compact */
    .tab-buttons {
        gap: 6px;
        margin-bottom: 10px;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    /* Alarm sections compact */
    .alarm-config-section {
        padding: 10px;
        margin-bottom: 10px;
    }

    .alarm-config-header {
        padding: 8px 10px;
    }

    .alarm-title {
        font-size: 0.85rem;
    }

    /* Input fields compact */
    input[type="text"],
    input[type="number"],
    input[type="password"],
    input[type="email"],
    select {
        padding: 10px 12px;
        font-size: 14px;
    }
}

/* Landscape phone adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .device-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .navbar {
        padding: 8px 16px;
    }

    .container {
        padding: 12px;
    }
}

/* Fix device detail card on all screen sizes */
.device-detail {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.device-detail .card {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Fix chart container */
.chart-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.chart-container canvas {
    max-width: 100%;
    height: auto !important;
}

/* Fix tabs overflow */
.tab-buttons {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.tab-buttons::-webkit-scrollbar {
    height: 4px;
}

.tab-buttons::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

/* Live alarm indicator in device card */
.card.has-alarm {
    border-left: 4px solid #f44336;
    animation: pulse-alarm 2s infinite;
}

@keyframes pulse-alarm {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(244, 67, 54, 0);
    }
}

.alarm-indicator-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #f44336;
    border-radius: 50%;
    margin-left: 8px;
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* Edit Modal Styles */
.edit-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.edit-modal.active {
    display: flex;
}

.edit-modal-content {
    background: white;
    padding: 28px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.edit-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.edit-modal-header h2 {
    margin: 0;
    color: var(--accent-2);
    font-size: 1.4rem;
}

.edit-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
}

.edit-modal-close:hover {
    color: #333;
}

.edit-form-group {
    margin-bottom: 16px;
}

.edit-form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--ink);
    font-size: 0.9rem;
}

.edit-form-group input,
.edit-form-group select {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.edit-form-group input:focus,
.edit-form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(46, 143, 91, 0.1);
}

.edit-modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.edit-modal-actions button {
    flex: 1;
    padding: 14px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-modal-actions .btn-save {
    background: linear-gradient(135deg, #1e6f46, #2f8f5b);
    color: white;
    border: none;
}

.edit-modal-actions .btn-save:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 111, 70, 0.3);
}

.edit-modal-actions .btn-cancel {
    background: #f5f5f5;
    color: #666;
    border: 1px solid #ddd;
}

.edit-modal-actions .btn-cancel:hover {
    background: #eee;
}

/* ==================== LIVE REFRESH INDICATOR ==================== */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* ==================== FOOTER & SCROLL FIXES ==================== */
/* Remove sticky footer behavior */
.app-footer {
    position: relative !important;
    bottom: auto !important;
    width: 100%;
    margin-top: auto;
}

/* Ensure proper scrolling */
body,
html {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
}

#app-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    flex: 1;
    overflow: visible;
}

/* Remove double scroll */
.screen {
    overflow: visible !important;
    height: auto !important;
}

.screen.active {
    overflow: visible !important;
    min-height: calc(100vh - 120px);
}

/* ==================== GLOBAL COMPONENT UNIFICATION ==================== */

/* --- Admin Tables --- */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.admin-table th,
.admin-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.admin-table th {
    background: var(--bg-accent);
    color: var(--ink-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-table tr:hover {
    background: var(--bg-accent);
}

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

/* --- Metric Cards --- */
.metric-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    text-align: center;
    position: relative;
    overflow: hidden;
    min-width: 140px;
}

.metric-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-2);
    line-height: 1.2;
}

.metric-card .label {
    font-size: 0.8125rem;
    color: var(--ink-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Modifiers for metric cards */
.metric-card.success {
    border-left: 4px solid var(--success);
}

.metric-card.warning {
    border-left: 4px solid var(--warning);
}

.metric-card.danger {
    border-left: 4px solid var(--danger);
}

.metric-card.info {
    border-left: 4px solid #3b82f6;
}

.metric-card.success .value {
    color: var(--success);
}

.metric-card.warning .value {
    color: var(--warning);
}

.metric-card.danger .value {
    color: var(--danger);
}


/* --- Filter Bars --- */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    align-items: center;
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.search-input,
.filter-select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--ink);
    min-width: 160px;
}

.search-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* --- Global Modals --- */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 15, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--surface);
    margin: 5% auto;
    padding: 32px;
    border-radius: var(--radius-lg);
    max-width: 600px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    position: relative;
    color: var(--ink);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--ink);
    font-weight: 700;
}

/* --- Badge Consistency --- */
.badge {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.badge.success,
.badge.online {
    background: #e6f4ea;
    color: var(--success);
    border: 1px solid rgba(47, 143, 91, 0.2);
}

.badge.warning,
.badge.pending {
    background: #fff3e0;
    color: var(--warning);
    border: 1px solid rgba(217, 119, 6, 0.2);
}

.badge.danger,
.badge.offline,
.badge.error {
    background: #fee2e2;
    color: var(--danger);
    border: 1px solid rgba(217, 73, 60, 0.2);
}

.badge.info {
    background: #eff6ff;
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge.neutral,
.badge.default {
    background: var(--bg-accent);
    color: var(--ink-muted);
    border: 1px solid var(--border-color);
}

/* --- Status Indicators --- */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background: var(--success);
}

.status-dot.disconnected {
    background: var(--danger);
}

/* --- RSSI Indicators --- */
.rssi-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.rssi-bars {
    display: flex;
    gap: 2px;
    align-items: flex-end;
}

.rssi-bar {
    width: 4px;
    background: #ddd;
    border-radius: 1px;
}

.rssi-bar.active {
    background: var(--success);
}

.rssi-bar.warn {
    background: var(--warning);
}

.rssi-bar.bad {
    background: var(--danger);
}

/* --- Global Button Variants --- */
.btn-danger {
    background: var(--danger);
    color: white;
    border-bottom-color: rgba(0, 0, 0, 0.2);
}

.btn-danger:hover {
    background: #b9372b;
}

.btn-warning {
    background: var(--warning);
    color: white;
    border-bottom-color: rgba(0, 0, 0, 0.2);
}

.btn-warning:hover {
    background: #b45309;
}

.btn-info {
    background: #3b82f6;
    color: white;
    border-bottom-color: rgba(0, 0, 0, 0.2);
}

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

/* --- Chips --- */
.chip-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--bg-accent);
    color: var(--ink-muted);
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.chip:hover {
    background: #e2e8f0;
    color: var(--ink);
}

.chip.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}

.page-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--surface);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--ink-muted);
    font-weight: 500;
}

.page-btn:hover:not(:disabled) {
    background: var(--bg-accent);
    color: var(--ink);
}

.page-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   UI BASELINE  FINAL UNIFIER
   Strict unified tokens for green industrial consistency
   ========================================================================== */

/* 1. BUTTON UNIFICATION */
button,
.btn,
.back-btn,
.device-filter-btn,
.inline-form button,
.modal-footer button {
    border-radius: 8px !important;
    /* Force standard radius, kill pills */
    font-weight: 600 !important;
    letter-spacing: 0.01em;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Primary Actions */
button[type='submit'],
.btn-primary {
    background-color: var(--accent) !important;
    color: white !important;
    border: none !important;
}

button[type='submit']:hover,
.btn-primary:hover {
    background-color: var(--accent-2) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Secondary / Back Actions */
.back-btn,
.btn-secondary {
    background-color: var(--surface) !important;
    color: var(--ink-muted) !important;
    border: 1px solid var(--border-color) !important;
}

.back-btn:hover,
.btn-secondary:hover {
    background-color: var(--bg-accent) !important;
    color: var(--ink) !important;
}

/* Filter Toggles (Dashboard) */
.device-filter-btn {
    border: 1px solid var(--border-color) !important;
    background: var(--surface);
    color: var(--ink-muted);
    padding: 8px 16px !important;
}

.device-filter-btn.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}

/* 2. CARD UNIFICATION */
.card,
.metric-card,
.glass-card,
.panel-card {
    border-radius: 12px !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: var(--shadow-sm) !important;
    background: var(--surface) !important;
}

/* Ensure consistent padding inside text layout cards */
.metric-card {
    padding: 20px !important;
}

/* 3. INPUT UNIFICATION */
input[type='text'],
input[type='number'],
input[type='password'],
input[type='email'],
input[type='date'],
select,
textarea {
    border-radius: 10px !important;
    border: 1px solid var(--border-color) !important;
    height: 42px;
    /* Consistent height */
    padding: 0 12px !important;
    /* Consistent horizontal padding */
    font-size: 0.9rem !important;
}

textarea {
    height: auto !important;
    padding: 12px !important;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(47, 143, 91, 0.1) !important;
    outline: none !important;
}

/* 4. BADGE UNIFICATION */
.badge,
.status-pill {
    border-radius: 6px !important;
    padding: 4px 10px !important;
    font-weight: 600 !important;
    font-size: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Badge variants */
.badge.success,
.badge.connected,
.status-pill.online {
    background-color: #dcfce7 !important;
    color: #166534 !important;
    border: 1px solid #bbf7d0 !important;
}

.badge.warning,
.badge.connecting {
    background-color: #fef9c3 !important;
    color: #854d0e !important;
    border: 1px solid #fde047 !important;
}

.badge.danger,
.badge.error,
.status-pill.offline {
    background-color: #fee2e2 !important;
    color: #991b1b !important;
    border: 1px solid #fecaca !important;
}

.badge.neutral,
.badge.default {
    background-color: #f1f5f9 !important;
    color: #475569 !important;
    border: 1px solid #e2e8f0 !important;
}

/* 5. TABLE UNIFICATION (Backup for plain tables) */
table.admin-table th,
.table-head {
    background-color: #f8fafc !important;
    color: var(--ink-muted) !important;
    font-weight: 600 !important;
    font-size: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px !important;
}


/* Company Header Accent - replaces inline gradient */
.company-header-accent {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 24px;
    margin: -24px -24px 20px -24px;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    border-radius: 12px 12px 0 0;
    /* Matches card 12px */
}

.company-header-accent h3 {
    font-size: 1.8rem;
    margin: 0;
    color: white !important;
}

.company-header-accent .muted {
    margin: 4px 0 0 0;
    color: rgba(255, 255, 255, 0.8);
}


/* 6. MODAL LAYOUT UNIFICATION */
.modal {
    /* Ensure any flexed modal centers its content */
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5) !important;
    /* Unified overlay */
    padding: 20px;
    /* Prevent edge touching on mobile */
}

.modal-content {
    background: var(--surface) !important;
    border-radius: 16px !important;
    box-shadow: var(--shadow-xl) !important;
    border: 1px solid var(--border-color) !important;
    max-width: 500px;
    width: 100%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-header h2 {
    margin: 0;
    color: var(--accent-2);
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--ink-muted);
    padding: 0;
}

.modal-close:hover {
    color: var(--danger);
}


/* === UI BASELINE  FINAL ENFORCER === */

:root {
    /* Manded Tokens */
    --accent: #2d8154;
    --bg-base: #f7faf7;
    --bg-accent: #eff4ef;
    --surface: #ffffff;
    --border-color: #cbd5cb;
    --ink: #1f2a1f;
    --ink-muted: #5a6a5c;

    /* Global Sizing */
    --radius-btn: 8px;
    /* STRICT: No pills */
    --radius-card: 12px;
    --radius-input: 10px;
    --height-input: 42px;
}

/* 1. RESET & BASICS */
body {
    background-color: var(--bg-base);
    color: var(--ink);
}

/* 2. BUTTONS - UNIVERSAL OVERRIDE */
button,
.btn,
.back-btn,
.device-filter-btn,
.btn-ghost,
.btn-primary,
.btn-secondary,
.btn-danger {
    border-radius: var(--radius-btn) !important;
    text-transform: none;
    letter-spacing: 0.01em;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
}

/* Kill pill shapes specifically */
.device-filter-btn {
    border-radius: var(--radius-btn) !important;
    padding: 8px 16px !important;
    border: 1px solid var(--border-color) !important;
    background: var(--surface);
    color: var(--ink-muted);
}

.device-filter-btn.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}

/* 3. CARDS - UNIFORMITY */
.card,
.metric-card,
.glass-card,
.panel-card,
.info-box {
    background: var(--surface) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
    border-radius: var(--radius-card) !important;
}

/* Left-border status pattern for consistency */
.card.status-ok {
    border-left: 4px solid var(--success) !important;
}

.card.status-warn {
    border-left: 4px solid var(--warning) !important;
}

.card.status-err {
    border-left: 4px solid var(--danger) !important;
}

/* 4. INPUTS - UNIFORMITY */
input[type='text'],
input[type='number'],
input[type='password'],
input[type='email'],
input[type='date'],
select,
textarea {
    height: var(--height-input);
    border-radius: var(--radius-input) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0 12px !important;
    background: var(--surface);
    color: var(--ink);
    font-size: 0.9rem;
}

textarea {
    height: auto;
    padding: 12px !important;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(45, 129, 84, 0.1) !important;
}

/* 5. TABLES - UNIFORMITY */
/* Target all table headers possible */
th,
.table-head,
.admin-table th {
    background-color: var(--bg-accent) !important;
    color: var(--ink-muted) !important;
    font-size: 0.75rem !important;
    text-transform: uppercase;
    font-weight: 700 !important;
    letter-spacing: 0.05em;
    padding: 12px 16px !important;
    border-bottom: 1px solid var(--border-color);
}

td,
.table-row {
    border-bottom: 1px solid var(--border-color);
}

/* 6. MODALS - CLEANUP */
.modal {
    background-color: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(2px);
    display: none;
    /* Default hidden */
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
    /* Flex when active */
}

/* Ensure explicit display:flex if inline style overrides it (legacy js) */
.modal[style*='display: block'] {
    display: flex !important;
}

.modal-content {
    background: var(--surface) !important;
    border-radius: 16px !important;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0 !important;
    /* Flex column for sticky footer */
    display: flex !important;
    flex-direction: column !important;
    max-height: 90vh;
    /* Ensure it fits in viewport */
    overflow: hidden;
    /* Clip corners and prevent outer scroll */
}

/* Standardized Modal Header */
.modal-header {
    background: #f8fafc;
    /* Light grey-green tint possible if var available, else surface-accent */
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px 16px 0 0;
    /* Match modal content radius */
    flex: 0 0 auto;
    /* Header doesn't shrink */
}

.modal-header h2 {
    color: var(--accent);
    font-size: 1.15rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.modal-close,
.close {
    color: var(--ink-muted);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
    background: none;
    border: none;
    padding: 0;
}

.modal-close:hover,
.close:hover {
    color: var(--danger);
}

.modal-body {
    padding: 24px;
    /* Strict padding requirement */
    /* Remove fixed max-height, let flex handle it */
    overflow-y: auto;
    background: var(--surface);
    color: var(--ink);
    flex: 1 1 auto;
    /* Grow and shrink, take available space */
}

.modal-footer {
    padding: 16px 24px;
    background: #f8fafc;
    /* Matches header */
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    /* Right align strictly */
    gap: 12px;
    border-radius: 0 0 16px 16px;
    flex: 0 0 auto;
    /* Footer doesn't shrink, stays fixed at bottom */
}

/* User Edit Scope List - Special Fix */
.scope-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
}

.scope-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.scope-item:last-child {
    border-bottom: none;
}

.scope-item:hover {
    background: #f8fafc;
}

.scope-item label {
    margin: 0;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--ink);
    cursor: pointer;
    flex-grow: 1;
}

.scope-item input[type="checkbox"] {
    margin-left: 12px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}


/* 7. TAB UNIFICATION (MICRO-POLISH) */
/* Targets .tab-btn and .company-tab */
.tab-buttons,
.company-tabs {
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 24px;
    gap: 24px;
    padding: 0;
}

.tab-btn,
.company-tab {
    background: transparent !important;
    border: none !important;
    border-bottom: 2px solid transparent !important;
    border-radius: 0 !important;
    padding: 12px 4px !important;
    color: var(--ink-muted) !important;
    font-weight: 500 !important;
    font-size: 0.95rem !important;
    margin-bottom: -2px !important;
    /* Overlap border */
    transition: all 0.2s ease !important;
}

.tab-btn:hover,
.company-tab:hover {
    color: var(--ink) !important;
    background: transparent !important;
}

.tab-btn.active,
.company-tab.active {
    color: var(--accent) !important;
    border-bottom: 2px solid var(--accent) !important;
    font-weight: 700 !important;
    background: transparent !important;
}

/* 8. BADGE MICRO-POLISH */
.badge,
.status-pill {
    font-size: 0.7rem !important;
    padding: 3px 8px !important;
    border-radius: 6px !important;
    line-height: 1;
    letter-spacing: 0.05em;
    font-weight: 700 !important;
}

/* Ensure semantic colors are strictly enforced */
.badge.success,
.badge.connected,
.status-pill.online {
    background: #dcfce7 !important;
    color: #15803d !important;
    border: 1px solid #86efac !important;
}

.badge.warning,
.badge.connecting {
    background: #fef9c3 !important;
    color: #a16207 !important;
    border: 1px solid #fde047 !important;
}

.badge.danger,
.badge.error,
.status-pill.offline {
    background: #fee2e2 !important;
    color: #b91c1c !important;
    border: 1px solid #fca5a5 !important;
}

.badge.neutral,
.badge.default {
    background: #f1f5f9 !important;
    color: #475569 !important;
    border: 1px solid #cbd5e1 !important;
}

/* 9. FOOTER UNIFICATION */
.app-footer {
    background: transparent !important;
    border-top: 1px solid var(--border-color) !important;
    margin-top: auto;
    padding: 32px 0 !important;
    text-align: center;
    color: var(--ink-muted) !important;
    font-size: 0.8rem;
}

.app-footer p {
    margin: 4px 0;
}

.app-footer Strong {
    color: var(--ink);
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
}


/* === GREEN INDUSTRIAL OVERHAUL === */

/* 1. TABS: SEGMENTED CONTROL STYLE */
.tab-buttons,
.company-tabs {
    display: inline-flex;
    background: #e2e8e2;
    /* Muted surface for track */
    padding: 4px;
    border-radius: 8px;
    gap: 0 !important;
    /* No gap in segmented control */
    border: 1px solid var(--border-color);
}

.tab-btn,
.company-tab {
    padding: 6px 16px !important;
    border-radius: 6px !important;
    border: none !important;
    background: transparent !important;
    color: var(--ink-muted) !important;
    font-weight: 500 !important;
    font-size: 0.85rem !important;
    /* Compact industrial text */
    margin: 0 !important;
    transition: all 0.2s ease;
}

.tab-btn:hover,
.company-tab:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.5) !important;
}

.tab-btn.active,
.company-tab.active {
    background: var(--accent) !important;
    /* Solid Green */
    color: white !important;
    font-weight: 600 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* 2. FOOTER: DARK INDUSTRIAL */
/* 2. FOOTER: DARK INDUSTRIAL */
.app-footer {
    background: #111811 !important;
    /* Dark Green/Black */
    color: #8fa38f !important;
    /* Muted Green Text */
    border-top: 1px solid #1f2f1f !important;
    padding: 20px 24px !important;
    /* Compact padding with side spacing */
    margin-top: 24px !important;
    /* Reduced from 48px */
    font-size: 0.8rem;
    font-weight: 500;
}

.app-footer strong {
    color: #d0f0d0;
}

/* Highlight */
.app-footer a {
    color: #d0f0d0;
    text-decoration: none;
    opacity: 0.8;
}

.app-footer a:hover {
    opacity: 1;
    text-decoration: underline;
}

.app-footer div {
    margin-bottom: 4px;
}

/* Spacing for new div structure */

/* 3. MODALS: INDUSTRIAL DIALOGS */
.modal-content {
    border-radius: 8px !important;
    /* Sharper */
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2) !important;
    border: 1px solid var(--border-color);
}

.modal-header {
    background: #f1f5f1;
    /* Light industrial bg */
    border-bottom: 1px solid #e0e6e0;
    padding: 16px 24px;
}

.modal-header h2 {
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink);
    font-weight: 700;
}

.modal-footer {
    background: #f8faf8;
    border-top: 1px solid #e0e6e0;
}

.modal-close {
    background: #e2e8e2;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--ink-muted);
}

.modal-close:hover {
    background: #fee2e2;
    color: var(--danger);
}

/* 4. STATUS: SEMANTIC COLORS */
/* Online/Success */
.badge.success,
.badge.connected,
.status-pill.online,
.badge.online,
.status-dot.online,
.legend-dot.online {
    background-color: #dcfce7 !important;
    color: #14532d !important;
    border: 1px solid #86efac !important;
}

.device-filter-btn.online {
    color: #15803d !important;
    border-color: #86efac !important;
    background: #f0fdf4 !important;
}

.device-filter-btn.online.active {
    background: #15803d !important;
    color: white !important;
    border-color: #15803d !important;
}

/* Offline/Error */
.badge.danger,
.badge.error,
.status-pill.offline,
.badge.offline,
.status-dot.offline,
.legend-dot.offline {
    background-color: #fee2e2 !important;
    color: #7f1d1d !important;
    border: 1px solid #fca5a5 !important;
}

.device-filter-btn.offline {
    color: #b91c1c !important;
    border-color: #fca5a5 !important;
    background: #fef2f2 !important;
}

.device-filter-btn.offline.active {
    background: #b91c1c !important;
    color: white !important;
    border-color: #b91c1c !important;
}

/* Warning/Info */
.badge.warning,
.badge.connecting {
    background-color: #fef9c3 !important;
    color: #713f12 !important;
    border: 1px solid #fde047 !important;
}

/* OFFLINE CARD POLISH (Nice-to-have) */
.card.status-offline h2 {
    color: var(--ink-muted) !important;
    /* Desaturate header */
    border-bottom-color: #e5e7eb;
}

.card.status-offline {
    border-color: #e5e7eb !important;
    box-shadow: none !important;
    /* Visual recession */
}



/* === TABS – UNIFIED SEGMENTED CONTROL (Company + Device) === */
:root {
    --tab-track: #e7efe7;
    --tab-border: #cbd5cb;
    --tab-text: #2f3a2f;
    --tab-text-muted: #556255;
    --tab-active: #2d8154;
}

/* Container: company tabs + device tabs */
.company-tabs,
.tab-buttons {
    background: var(--tab-track);
    border: 1px solid var(--tab-border);
    border-radius: 14px;
    padding: 6px;
    gap: 6px;
    align-items: center;
    border-bottom: 1px solid var(--tab-border);
    /* keep if needed */
}

/* Buttons */
.company-tab,
.tab-btn {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(203, 213, 203, 0.75);
    color: var(--tab-text);
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 600;
    box-shadow: none;
    transition: background .15s ease, border-color .15s ease, transform .05s ease;
}

/* Device Log Filter Buttons - Contrast Fix */
.log-filter-btn {
    opacity: 1 !important;
    background: white;
    color: var(--ink-muted);
    border: 1px solid var(--border-color);
    font-weight: 500;
    transition: all 0.2s ease;
}

.log-filter-btn:hover {
    background: var(--bg-accent);
    color: var(--ink);
    border-color: var(--ink-muted);
}

.log-filter-btn.active {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
    font-weight: 600;
}

/* Fix for Log Action Buttons (Copy/CSV/Print) - enforce contrast */
.log-header .btn-secondary,
.log-header button:not(.btn-primary):not(.btn-danger),
.log-actions button,
.log-filter-bar button {
    background-color: white !important;
    color: #5a6a5c !important;
    border: 1px solid #ccc !important;
}

.log-header .btn-secondary:hover,
.log-header button:not(.btn-primary):not(.btn-danger):hover,
.log-actions button:hover,
.log-filter-bar button:hover {
    background-color: #f5f5f5 !important;
    color: #5a6a5c !important;
}

/* UI Polish: Log Export Buttons */
.log-export-btn {
    padding: 4px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.75rem;
    color: #5a6a5c !important;
    /* Force green text */
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.log-export-btn:hover {
    background: #f5f5f5;
    color: #5a6a5c !important;
    border-color: #bbb;
}

/* UI Polish: Standard Back Button */
.back-btn {
    background: none;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.back-btn:hover {
    background: var(--bg-accent);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* UI Polish: Modern Device Card Grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

/* Modernized Device Card */
.device-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    /* Smoother corners */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    /* Subtle premium shadow */
    padding: 24px;
    /* Larger padding for premium feel */
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* More breathing room */
    position: relative;
    /* For badge positioning if needed */
}

.device-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
    /* Deeper lift effect */
    border-color: #b0bec5;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.device-card-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 8px;
}

.device-info-row {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Login Page Layout Fix */
html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#login-screen {
    /* Styles handled in main block above */
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Removed min-height: 100vh to allow footer to stick properly without overflow */
}

/* Ensure footer sticks to bottom */
.app-footer {
    margin-top: auto;
    background: #111811;
    /* Dark Industrial Green */
    color: #8da38d;
    padding: 15px 0;
    text-align: center;
    font-size: 0.85rem;
}

.system-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.system-info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-base);
    /* Very subtle grey */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s;
}

.system-info-item:hover {
    border-color: var(--accent);
}

.system-info-label {
    color: var(--ink-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.system-info-value {
    color: var(--ink);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    /* Technical feel */
    font-size: 0.9rem;
}

/* Fix Map Container */
.device-mini-map {
    width: 100%;
    min-height: 200px;
    background: #e2e8e2;
    /* Placeholder color before load */
    border-radius: 8px;
    z-index: 1;
    /* Ensure it stays below headers if any */
}

/* Ensure Leaflet attribution doesn't break layout */
.leaflet-container {
    font-family: inherit;
}

background: rgba(255, 255, 255, 0.9);
border-color: var(--tab-border);
}

/* Active */
.company-tab.active,
.tab-btn.active {
    background: var(--tab-active) !important;
    color: #fff !important;
    border-color: transparent !important;
}

/* Remove gradients from tab actives (industrial = solid) */
.company-tab.active,
.tab-btn.alarm-tab.active {
    background-image: none !important;
}

/* Icons in device tabs */
.tab-btn .tab-icon,
.tab-btn span[style*="font-size"] {
    opacity: .9;
}

/* Make inactive device tabs less “washed out” */
.tab-btn:not(.active) {
    color: var(--tab-text-muted);
}

/* Mobile: keep compact */
@media (max-width: 768px) {

    .company-tab,
    .tab-btn {
        padding: 9px 12px;
        font-size: 0.85rem;
    }
}

/* Premium Organization/Company Card */
.org-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    overflow: hidden;
}

.org-header {
    padding: 18px 24px;
    background: linear-gradient(to right, #ffffff, #fcfdfc);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
    user-select: none;
}

.org-header:hover {
    background-color: #f7faf7;
    /* var(--bg-base) */
}

.org-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    flex: 1;
}

.org-body {
    padding: 24px;
    background: #fbfcfb;
    /* Very subtle grey/green tint */
}

/* Site/Location Section */
.site-section {
    margin-bottom: 24px;
}

.site-section:last-child {
    margin-bottom: 0;
}

.site-header {
    padding: 12px 16px;
    margin-bottom: 12px;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
    user-select: none;
    border: 1px solid transparent;
}

.site-header:hover {
    background: rgba(0, 0, 0, 0.03);
}

.site-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink-muted);
    flex: 1;
}

.toggle-icon {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--accent);
    width: 20px;
    text-align: center;
    transition: transform 0.2s;
}

/* Rotate icon based on open state logic handled by text content change currently, 
   but we can enhance with transform if we used class toggle. 
   For now, logic swaps '>' with 'v'. 
   Let's style the text character nicely. 
*/

/* 
========================================
NEW DEVICES SPLIT VIEW & ORG TREE
========================================
*/

/* Layout */
.devices-page-container {
    padding: 20px;
    max-width: 100%;
    /* Flexible width */
    width: 100%;
}

.devices-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    position: relative;
    width: 100%;
}

/* Sidebar (Desktop/Tablet) */
.devices-sidebar {
    width: 320px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    position: sticky;
    top: 90px;
    /* Below navbar */
    height: calc(100vh - 110px);
    overflow-y: auto;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.devices-main {
    flex: 1;
    min-width: 0;
    /* Prevent flex overflow */
}

/* Sidebar Search */
.sidebar-search,
.drawer-search {
    margin-bottom: 16px;
}

.sidebar-search input,
.drawer-search input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    background: var(--bg-base);
    color: var(--ink);
}

.sidebar-search input:focus,
.drawer-search input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}

/* Org Tree */
.org-tree {
    flex: 1;
    overflow-y: auto;
}

/* Base list reset */
.org-tree-list,
.org-locations-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.org-tree-item {
    margin-bottom: 4px;
}

/* Company Row */
.org-company-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.1s;
    user-select: none;
}

.org-company-row:hover {
    background: var(--bg-accent);
}

/* Company toggle icon */
.org-toggle-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
    color: var(--ink-muted);
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.org-toggle-icon.expanded {
    transform: rotate(90deg);
}

.org-company-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.org-company-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--ink);
}

.org-company-meta {
    font-size: 0.75rem;
    color: var(--ink-muted);
    margin-top: 2px;
}

/* Location List (Nested) */
.org-locations-list {
    margin-top: 4px;
    padding-left: 12px;
    /* Indent */
    display: none;
    /* Hidden by default unless expanded */
}

.org-locations-list.expanded {
    display: block;
}

/* Location Row */
.org-location-row {
    display: flex;
    align-items: center;
    padding: 8px 10px 8px 24px;
    /* Extra left padding for hierarchy */
    border-radius: var(--radius-md);
    cursor: pointer;
    border-left: 3px solid transparent;
    /* Accent border */
    transition: all 0.1s;
    margin-bottom: 2px;
}

.org-location-row:hover {
    background: var(--bg-accent);
}

.org-location-row.active {
    background: rgba(47, 143, 91, 0.08);
    /* Subtle green tint */
    border-left-color: var(--accent);
}

.org-location-row.active .org-location-name {
    color: var(--accent-2);
    font-weight: 600;
}

.org-location-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink);
}

.org-location-meta {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--ink-muted);
}

/* Status dots in tree */
.status-pill {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-left: 6px;
    display: inline-block;
}

.status-pill.online {
    background: var(--success);
}

.status-pill.offline {
    background: var(--danger);
    opacity: 0.6;
}

/* Show All Item (top of tree) */
.org-all-row {
    display: flex;
    align-items: center;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: var(--radius-md);
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    border: 1px solid transparent;
}

.org-all-row:hover {
    background: var(--bg-accent);
}

.org-all-row.active {
    background: rgba(47, 143, 91, 0.08);
    border-color: var(--accent);
    color: var(--accent-2);
}


/* Header & Breadcrumbs */
.devices-header-row {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    /* allow wrapping on small screens */
    gap: 16px;
}

.header-left-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-titles h2 {
    margin-bottom: 4px;
    font-size: 1.5rem;
}

.breadcrumb {
    font-size: 0.9rem;
    color: var(--ink-muted);
    font-weight: 500;
}

/* Mobile Drawer */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    background: var(--surface);
    z-index: 2001;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

/* ==================== LAYOUT NORMALIZATION (SINGLE PAGE SCROLL) ==================== */
/* Ensure footer is always AFTER content (no overlay), while still sitting at the bottom
   when content is short (classic sticky-footer via flex). */
html,
body {
    height: auto !important;
    min-height: 100vh;
    overflow-y: auto !important;
}

body {
    display: flex;
    flex-direction: column;
}

#app-screen {
    flex: 1 1 auto;
    min-height: 0;
}

/* Critical: do not create an inner scrolling container for views */
#app-screen > .view {
    overflow: visible !important;
}

/* Footer must be in normal flow (never fixed/sticky) */
footer.app-footer {
    position: relative !important;
    bottom: auto !important;
    margin-top: auto;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-overlay.open {
    display: block;
    opacity: 1;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.drawer-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
}

.close-drawer-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--ink-muted);
    padding: 0 8px;
}

/* Mobile Toggle Button */
.mobile-location-btn {
    display: none;
    /* Desktop hidden */
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    width: fit-content;
    margin-bottom: 12px;
}

/* Device List Grid Override for Flat View */
.device-list-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    /* Standard grid */
    gap: 20px;
    margin-top: 20px;
}

/* Filter counts badge fix */
.filter-count {
    margin-left: 6px;
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 99px;
    font-size: 0.75rem;
}

/* Responsive Breakpoints */
@media (min-width: 1024px) {
    .devices-sidebar {
        width: 300px;
    }
}

@media (max-width: 1023px) {

    /* Tablet */
    .devices-sidebar {
        width: 250px;
    }

    .devices-page-container {
        padding: 15px;
    }

    .device-list-container {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 768px) {

    /* Mobile */
    .devices-sidebar {
        display: none;
        /* Hide sidebar */
    }

    .devices-layout {
        display: block;
        /* Stack */
    }

    .mobile-location-btn {
        display: inline-flex;
    }

    .header-left-group {
        width: 100%;
    }

    .devices-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .devices-header-row #btn-register-device {
        width: 100%;
    }

    /* Device grid mobile */
    .device-list-container {
        grid-template-columns: 1fr;
        /* Single column */
    }
}


/* SIMPLIFICATION & SAFETY OVERRIDES */

/* Hide Option B Elements and Legacy Summaries/Page Titles if present */
/* We keep page-titles hidden if we use our own headers, but we MUST SHOW summary and filters now per request A */
.summary-card,
.view-toggle-container,
.subtle-company-group,
.page-titles {
    display: none !important;
}

/* Ensure these are HIDDEN (We render our own custom stats inside device-list now) */
#device-summary,
.device-filters {
    display: none !important;
}

/* Minimal Header for Simplified View */
.scope-header-minimal {
    margin-bottom: 24px;
    padding-bottom: 0px;
}

.scope-header-minimal h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    line-height: 1.2;
}

.scope-header-minimal .breadcrumb {
    font-size: 0.9rem;
    color: var(--ink-muted);
    margin-top: 4px;
}

/* Sidebar Cleanup */
.org-company-meta,
.org-location-meta {
    display: none !important;
    /* Force hide stats pills */
}

.org-location-row.active {
    background-color: #e8f5e9;
    /* Light green selection */
    color: var(--primary);
    font-weight: 600;
}

/* D: 3-Column Grid Layout */
/* D: 3-Column Grid Layout */
.device-grid,
.device-list-container {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 24px;
    align-items: start;
    justify-content: start;
    justify-items: start;
    /* Ensure cards align left in their tracks */
    width: 100%;
}

/* FIX: #device-list is the WRAPPER. It must be block flow so children can be full width. */
#device-list {
    display: block !important;
}

/* Full Width Stats Grid */
.stats-grid-full-width {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
    width: 100% !important;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--ink-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

/* Full Width Filter Row */
.filter-row-full-width {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    width: 100%;
    flex-wrap: wrap;
}

/* Filter Pills - Restored Custom Styling */
.filter-pill {
    flex: 1;
    min-width: 120px;
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    background: #fff;
    color: var(--ink);
    border-color: #e0e0e0;
}

/* Hover generic */
.filter-pill:hover {
    filter: brightness(0.98);
}

/* TOTAL (Generic Active) */
.filter-pill.active {
    background: #2f7d4c !important;
    color: #ffffff !important;
    border-color: #2f7d4c !important;
}

/* ONLINE (Specific Class) */
.filter-pill.pill-success {
    background: #e9f8ef;
    color: #1f6b45;
    border-color: #6fd49b;
}

/* Online Active Override - Force Green Scheme */
.filter-pill.pill-success.active {
    background: #e9f8ef !important;
    color: #1f6b45 !important;
    border-color: #6fd49b !important;
    border-width: 2px;
}

/* Offline Active Override - Force Red Scheme */
.filter-pill.pill-danger.active {
    background: #fdeaea !important;
    color: #9b1c1c !important;
    border-color: #f5a3a3 !important;
    border-width: 2px;
}

.filter-pill .pill-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.8rem;
}

/* Total Active */
.filter-pill.active .pill-count {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

/* Specific Active - FIX COUNT VISIBILITY */
.filter-pill.pill-success.active .pill-count {
    background: rgba(31, 107, 69, 0.2) !important;
    color: #1f6b45 !important;
}

.filter-pill.pill-danger.active .pill-count {
    background: rgba(155, 28, 28, 0.2) !important;
    color: #9b1c1c !important;
}

/* Specific Static Counts */
.filter-pill.pill-success .pill-count {
    background: rgba(31, 107, 69, 0.1);
    color: #1f6b45;
}

.filter-pill.pill-danger .pill-count {
    background: rgba(155, 28, 28, 0.1);
    color: #9b1c1c;
}


/* Responsive Overrides */
@media (max-width: 1200px) {

    .device-grid,
    .device-list-container {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

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

@media (max-width: 768px) {

    .device-grid,
    .device-list-container {
        grid-template-columns: 1fr !important;
    }

    .stats-grid-full-width {
        grid-template-columns: 1fr;
    }

    .filter-row-full-width {
        flex-direction: column;
    }

    .filter-pill {
        width: 100%;
    }
}