/* CashHub — Design System */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #60a5fa;
    --primary-subtle: rgba(59, 130, 246, 0.14);
    --primary-muted: rgba(59, 130, 246, 0.28);

    --surface: #ffffff;
    --surface-raised: #f8fafc;
    --background: #eef2f7;
    --background-subtle: #f8fafc;

    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --success-border: rgba(34, 197, 94, 0.28);

    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --warning-border: rgba(245, 158, 11, 0.28);

    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.28);

    --info: #38bdf8;
    --info-bg: rgba(56, 189, 248, 0.12);
    --info-border: rgba(56, 189, 248, 0.28);

    --sidebar-bg: #ffffff;
    --topbar-bg: #ffffff;
    --card-bg: #ffffff;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.1);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.14);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --header-height: 72px;
    --sidebar-width: 250px;
    --transition: 0.2s ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --warning-hover: rgba(245, 158, 11, 0.2);
    --danger-hover: rgba(239, 68, 68, 0.2);
    --info-hover: rgba(56, 189, 248, 0.2);
    --select-arrow: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3e%3cpath d='M4 6l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
    --overlay: rgba(15, 23, 42, 0.55);
    --color-scheme: light;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #60a5fa;
    --primary-subtle: rgba(59, 130, 246, 0.18);
    --primary-muted: rgba(59, 130, 246, 0.32);

    --surface: #151924;
    --surface-raised: #1b2130;
    --background: #0f111a;
    --background-subtle: #12151f;

    --border: #232836;
    --border-strong: #2f3648;

    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --text-inverse: #ffffff;

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.14);
    --success-border: rgba(34, 197, 94, 0.3);

    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.14);
    --warning-border: rgba(245, 158, 11, 0.3);

    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.14);
    --danger-border: rgba(239, 68, 68, 0.3);

    --info: #38bdf8;
    --info-bg: rgba(56, 189, 248, 0.14);
    --info-border: rgba(56, 189, 248, 0.3);

    --sidebar-bg: #12151f;
    --topbar-bg: #12151f;
    --card-bg: #161b26;

    --shadow-xs: none;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.45);

    --warning-hover: rgba(245, 158, 11, 0.22);
    --danger-hover: rgba(239, 68, 68, 0.22);
    --info-hover: rgba(56, 189, 248, 0.22);
    --select-arrow: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3e%3cpath d='M4 6l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
    --overlay: rgba(0, 0, 0, 0.65);
    --color-scheme: dark;
}

html {
    color-scheme: var(--color-scheme);
    scroll-behavior: smooth;
}

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

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

body.modal-open {
    overflow: hidden;
}

/* ─── App shell & sidebar ─── */

.app-body {
    overflow-x: hidden;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 1.25rem 1.25rem;
}

.sidebar-brand .logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-brand .logo-icon svg {
    width: 20px;
    height: 20px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    display: block;
    flex-shrink: 0;
    border-radius: 12px;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0.875rem;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 0.3rem;
}

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

.sidebar-link:hover {
    background: var(--background-subtle);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-link.is-active {
    background: var(--primary-subtle);
    color: var(--primary);
}

.sidebar-footer {
    padding: 0.875rem;
    border-top: 1px solid var(--border);
}

.sidebar-logout-link {
    margin-bottom: 0;
}

.sidebar-backdrop {
    display: none;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.topbar {
    height: var(--header-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    flex: 1;
    min-width: 0;
}

.topbar-search {
    position: relative;
    width: min(420px, 100%);
}

.topbar-search svg {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.topbar-search-input {
    width: 100%;
    height: 42px;
    border: 1px solid var(--border);
    background: var(--background-subtle);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0 1rem 0 2.5rem;
    font: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.topbar-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-shrink: 0;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    padding: 0;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

.icon-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--background-subtle);
}

.icon-btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger-border);
    background: var(--danger-bg);
}

.icon-btn .icon-sun { display: none; }
.icon-btn .icon-moon { display: block; }
[data-theme="dark"] .icon-btn .icon-sun { display: block; }
[data-theme="dark"] .icon-btn .icon-moon { display: none; }

.topbar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.topbar-user-menu {
    position: relative;
}

.topbar-user-btn {
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
}

.topbar-user-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    z-index: 1200;
}

.user-menu-panel[hidden] {
    display: none !important;
}

.user-menu-meta {
    padding: 0.65rem 0.75rem 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.35rem;
}

.user-menu-meta strong {
    display: block;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.15rem;
}

.user-menu-meta span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.75rem;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.user-menu-item svg {
    width: 16px;
    height: 16px;
}

.user-menu-item:hover {
    background: var(--background-subtle);
    color: var(--text-primary);
    text-decoration: none;
}

.user-menu-logout:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.bottom-nav {
    display: none;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 12px;
    cursor: pointer;
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.panel-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin: 0 0 0.35rem;
}

.panel-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.panel-actions {
    display: flex;
    gap: 0.625rem;
    align-items: center;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.35rem;
    box-shadow: var(--shadow-sm);
}

.metric-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.85rem;
    font-weight: 500;
}

.metric-value-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--text-primary);
}

.metric-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
}

.metric-badge-success {
    background: var(--success-bg);
    color: var(--success);
}

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

.metric-badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

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

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

.panel-section-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--text-primary);
}

.panel-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.inline-search {
    position: relative;
    width: 180px;
}

.inline-search svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.inline-search .form-control {
    height: 38px;
    padding-left: 2.1rem;
    border-radius: 10px;
    font-size: 0.8125rem;
}

.filter-compact {
    width: 170px;
    height: 38px;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 0.8125rem;
}

.data-table-wrap {
    border: none;
    border-radius: 0;
}

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

.data-table th {
    text-align: left;
    padding: 0.85rem 1.15rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    background: transparent;
}

.data-table td {
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

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

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

/* Mobile: tabelle → card verticali (niente scroll orizzontale) */
@media (max-width: 900px) {
    .table-responsive.data-table-wrap,
    .data-table-wrap.table-responsive {
        overflow: visible;
        border: none;
        border-radius: 0;
        background: transparent;
    }

    .data-table {
        display: block;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .data-table tbody tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 14px;
        padding: 0.9rem 1rem;
        margin: 0;
    }

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

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

    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border);
        text-align: right;
        color: var(--text-primary);
    }

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

    .data-table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 42%;
        text-align: left;
        font-size: 0.6875rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
    }

    .data-table td.td-primary {
        display: block;
        text-align: left;
        padding: 0 0 0.75rem;
        margin-bottom: 0.15rem;
        border-bottom: 1px solid var(--border);
    }

    .data-table td.td-primary::before {
        display: none;
    }

    .data-table td.td-actions {
        display: block;
        text-align: left;
        padding-top: 0.75rem;
        padding-bottom: 0;
    }

    .data-table td.td-actions::before {
        display: none;
    }

    .data-table td.td-actions .table-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .data-table td.td-actions .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 36px;
    }

    .data-table .hide-on-mobile {
        display: none !important;
    }

    .data-table .device-cell {
        width: 100%;
    }

    .data-table td .device-status,
    .data-table td .badge,
    .data-table td .mono-text,
    .data-table td .device-model {
        text-align: right;
    }

    .data-table td {
        word-break: break-word;
    }

    .data-table td > *:not(div.device-cell):not(div.table-actions) {
        min-width: 0;
    }
}

.device-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.device-cell-thumb {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--background-subtle);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.device-cell-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.device-cell .device-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0;
}

.device-cell-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mono-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

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

.users-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 1.5rem;
    align-items: start;
}

.users-count {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

.app-main .main-content {
    padding: 1.75rem 0 2.5rem;
}

.app-main .container {
    max-width: none;
    padding: 0 1.75rem;
}

.app-main .page-header {
    display: none;
}

/* ─── Layout ─── */

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.main-content {
    padding: 2rem 0 3rem;
}

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

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

/* ─── Header ─── */

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-xs);
}

.header .container {
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--text-inverse);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.logo-text {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-tagline {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary-subtle);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-admin {
    background: var(--primary-subtle);
    color: var(--primary);
    border: 1px solid var(--primary-muted);
}

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

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all var(--transition);
}

.btn-logout:hover {
    background: var(--background);
    border-color: var(--border-strong);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-logout svg {
    width: 16px;
    height: 16px;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
}

.theme-toggle:hover {
    background: var(--background);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

.theme-toggle-login {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 20;
}

[data-theme="dark"] .device-item-thumb,
[data-theme="dark"] .model-preview {
    background: #0b1220;
}

[data-theme="dark"] .login-brand {
    background: linear-gradient(145deg, #0f172a 0%, #1e3a8a 55%, #1e40af 100%);
}

/* ─── Stats ─── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), border-color var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--border-strong);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.stat-icon.devices {
    background: var(--primary-subtle);
    color: var(--primary);
}

.stat-icon.active {
    background: var(--success-bg);
    color: var(--success);
}

.stat-icon.inactive {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-icon.maintenance {
    background: var(--danger-bg);
    color: var(--danger);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-number {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-top: 0.125rem;
}

/* ─── Cards ─── */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

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

.card-header h3,
.card-header .card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.card-body {
    padding: 1.5rem;
}

/* ─── Toolbar ─── */

.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-box svg {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-box .form-control {
    padding-left: 2.5rem;
}

.filter-select {
    min-width: 200px;
}

/* ─── Forms ─── */

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

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.form-control.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.invalid-feedback {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--danger);
}

.form-select {
    appearance: none;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px;
    padding-right: 2.5rem;
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 1.25rem;
}

.form-grid .form-group-full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.625rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

/* ─── Buttons ─── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5625rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font);
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.4;
    white-space: nowrap;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--text-inverse);
    text-decoration: none;
}

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

.btn-secondary:hover {
    background: var(--background);
    border-color: var(--border-strong);
    color: var(--text-primary);
    text-decoration: none;
}

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

.btn-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning-border);
}

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

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-border);
}

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

.btn-info {
    background: var(--info-bg);
    color: var(--info);
    border-color: var(--info-border);
}

.btn-info:hover {
    background: var(--info-hover);
    color: var(--info);
    text-decoration: none;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-sm svg {
    width: 14px;
    height: 14px;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
}

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

/* ─── Devices Section ─── */

.devices-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.devices-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem 1.5rem 0;
    flex-wrap: wrap;
}

.devices-section-intro {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.devices-section-icon {
    width: 48px;
    height: 48px;
    background: var(--primary-subtle);
    color: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.devices-section-icon svg {
    width: 24px;
    height: 24px;
}

.devices-section-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin: 0;
}

.devices-section-subtitle {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0.125rem 0 0;
}

.devices-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem 0;
}

.devices-filter-bar .search-box {
    flex: 1;
    min-width: 220px;
}

.devices-filter-bar .filter-select {
    min-width: 180px;
}

.status-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    background: var(--background-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.25rem;
}

.status-chip {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.status-chip:hover {
    color: var(--text-primary);
    background: var(--surface);
}

.status-chip.is-active {
    background: var(--primary-subtle);
    color: var(--primary);
    box-shadow: none;
    font-weight: 600;
}

.devices-results-meta {
    padding: 0.85rem 1.35rem 1.15rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    border-top: 1px solid var(--border);
}

.panel .devices-empty,
.panel .devices-no-results {
    padding: 3rem 1.5rem;
}

.devices-results-meta strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.devices-section-body {
    padding: 1rem 1.5rem 1.5rem;
}

.devices-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.device-item {
    display: grid;
    grid-template-columns: 88px 1fr auto;
    gap: 1.25rem;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--background-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.device-item:hover {
    background: var(--surface);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.device-item-thumb {
    width: 88px;
    height: 72px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    flex-shrink: 0;
}

.device-item-thumb .device-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.device-item-main {
    min-width: 0;
}

.device-item-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
}

.device-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.device-model-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    background: var(--primary-subtle);
    color: var(--primary);
    border: 1px solid var(--primary-muted);
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.device-item-location {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0 0 0.625rem;
}

.device-item-location svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.device-item-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin: 0;
}

.device-spec {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
    font-size: 0.75rem;
}

.device-spec dt {
    color: var(--text-muted);
    font-weight: 500;
    margin: 0;
}

.device-spec dd {
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
}

.device-spec-mono {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.6875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.0625rem 0.375rem;
}

.device-item-aside {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

.device-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-attivo {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.status-inattivo {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid var(--warning-border);
}

.status-manutenzione {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.live-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.22rem 0.55rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid var(--border);
    background: var(--background-subtle);
    color: var(--text-muted);
}

.live-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.live-status.is-online {
    color: var(--success);
    background: var(--success-bg);
    border-color: var(--success-border);
}

.live-status.is-offline {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: var(--danger-border);
}

.live-status.is-checking {
    color: var(--primary);
    background: var(--primary-subtle);
    border-color: var(--primary-muted);
}

.live-status.is-checking .live-status-dot {
    animation: livePulse 0.9s ease-in-out infinite;
}

.live-status.is-unknown {
    color: var(--text-muted);
}

@keyframes livePulse {
    0%, 100% { opacity: 0.35; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.15); }
}

#checkDevicesOnline svg {
    vertical-align: -3px;
    margin-right: 0.25rem;
}
    border-radius: 50%;
    background: currentColor;
}

.device-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    justify-content: flex-end;
}

.btn.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Empty & no-results */

.devices-empty,
.devices-no-results {
    text-align: center;
    padding: 3rem 1.5rem;
}

.devices-empty-visual {
    width: 72px;
    height: 72px;
    margin: 0 auto 1.25rem;
    background: var(--background-subtle);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.devices-empty-visual svg {
    width: 36px;
    height: 36px;
}

.devices-empty h3,
.devices-no-results h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.devices-empty p,
.devices-no-results p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    max-width: 360px;
    margin: 0 auto 1.25rem;
}

.devices-no-results svg {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Legacy aliases (modals, JS) */
.devices-grid { display: flex; flex-direction: column; gap: 0.625rem; }
.device-card { /* inherits .device-item */ }
.device-image { object-fit: contain; }
.device-location span { /* search compat */ }

/* ─── Tables ─── */

.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.875rem;
}

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

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

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

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

.table-actions {
    display: flex;
    gap: 0.375rem;
}

/* ─── Alerts ─── */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: 0.875rem;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success);
}

.alert-danger {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
}

.alert-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
}

.alert-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info);
}

.btn-close {
    background: none;
    border: none;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    margin-left: auto;
    padding: 0;
}

.btn-close:hover {
    opacity: 1;
}

/* ─── Modals ─── */

.modal {
    display: flex;
    position: fixed;
    z-index: 2000;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(8, 10, 18, 0.62);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-dialog {
    width: 100%;
    max-width: 560px;
    max-height: calc(100dvh - 2.5rem);
    margin: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transform: translateY(14px) scale(0.98);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
}

.modal.is-open .modal-dialog {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-dialog-lg {
    max-width: 640px;
}

.modal-content {
    background: var(--surface);
    border-radius: 18px;
    width: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 24px 64px rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
}

.modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.modal-header {
    background: linear-gradient(180deg, var(--surface-raised) 0%, var(--surface) 100%);
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1.35rem 1.15rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-shrink: 0;
}

.modal-header-text {
    min-width: 0;
}

.modal-eyebrow {
    margin: 0 0 0.3rem;
    font-size: 0.6875rem;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
}

.modal-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.25;
}

.modal-subtitle {
    margin: 0.35rem 0 0;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--text-secondary);
}

.modal-close {
    flex-shrink: 0;
    background: var(--background-subtle);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    padding: 0;
}

.modal-close svg {
    width: 16px;
    height: 16px;
}

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

.modal-body {
    padding: 1.25rem 1.35rem 0.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    flex: 1 1 auto;
    min-height: 0;
}

.modal-section {
    margin-bottom: 1.35rem;
    padding-bottom: 1.15rem;
    border-bottom: 1px solid var(--border);
}

.modal-section:last-child {
    margin-bottom: 0.5rem;
    padding-bottom: 0;
    border-bottom: none;
}

.modal-section-title {
    margin: 0 0 0.9rem;
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    padding: 1rem 1.35rem 1.2rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.modal-footer .btn {
    min-width: 7.5rem;
}

.modal-body .form-actions {
    display: none;
}

.model-preview-wrap {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    padding: 0.85rem;
    border: 1px dashed var(--border-strong);
    border-radius: 14px;
    background: var(--background-subtle);
}

.model-preview-wrap.is-visible {
    display: flex;
}

.model-preview {
    display: block;
    max-width: 100%;
    max-height: 140px;
    width: auto;
    height: auto;
    object-fit: contain;
    border: none;
    border-radius: 8px;
}

.model-preview.visible {
    display: block;
}

/* ─── Login ─── */

.login-body {
    margin: 0;
    overscroll-behavior: none;
}

.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: relative;
}

.login-brand {
    background: linear-gradient(145deg, var(--primary) 0%, #1e3a8a 50%, #172554 100%);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.login-brand::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(59, 130, 246, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(147, 197, 253, 0.15) 0%, transparent 40%);
}

.login-brand-content {
    position: relative;
    z-index: 1;
    max-width: 420px;
}

.login-brand-logo {
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
}

.login-brand-logo-img {
    width: 64px;
    height: 64px;
    display: block;
    margin-bottom: 1.5rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.login-brand-eyebrow {
    display: inline-block;
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(191, 219, 254, 0.9);
}

.login-brand h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 0.75rem;
    line-height: 1.2;
}

.login-brand-lead {
    margin: 0;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.6;
}

.login-brand-features {
    margin-top: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.85);
}

.login-feature-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.login-feature-icon svg {
    width: 16px;
    height: 16px;
}

.login-panel {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--background-subtle);
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-card-header {
    margin-bottom: 2rem;
}

.login-card-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.375rem;
}

.login-card-header p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.login-form .form-group.focused .form-label {
    color: var(--primary);
}

.btn-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.btn.is-loading .btn-spinner {
    display: inline-block;
}

.btn.is-loading .btn-label {
    opacity: 0.9;
}

.login-loader {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.login-loader.is-visible {
    display: flex;
}

.login-loader-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 2rem 2.5rem;
    text-align: center;
    min-width: 220px;
}

.login-loader-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--primary-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.login-loader-panel p {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Section divider ─── */

.section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* ─── Animations ─── */

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

.fade-in {
    animation: fadeIn 0.4s ease-out both;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.2s; }

/* ─── Utilities ─── */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1.5rem; }
.d-flex { display: flex; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.gap-2 { gap: 1rem; }
.w-100 { width: 100%; }
.hidden { display: none; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ─── Responsive ─── */

@media (max-width: 1024px) {
    .stats-grid,
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .users-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .sidebar,
    .sidebar-backdrop,
    .sidebar-toggle {
        display: none !important;
    }

    body.sidebar-open {
        overflow: auto;
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        left: 1rem;
        right: 1rem;
        bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
        z-index: 1100;
        align-items: center;
        justify-content: space-around;
        gap: 0.25rem;
        width: auto;
        min-height: 0;
        height: 52px;
        padding: 0.3rem;
        background: var(--surface);
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border: 1px solid var(--border);
        border-radius: 18px;
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.1rem;
        min-width: 0;
        height: 100%;
        padding: 0.25rem 0.35rem;
        border-radius: 14px;
        color: var(--text-muted);
        text-decoration: none;
        font-size: 0.625rem;
        font-weight: 600;
        letter-spacing: 0.01em;
        transition: color var(--transition), background var(--transition);
    }

    .bottom-nav-item svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    .bottom-nav-item span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.1;
    }

    .bottom-nav-item:hover {
        color: var(--text-secondary);
        text-decoration: none;
        background: transparent;
    }

    .bottom-nav-item.is-active {
        color: var(--primary);
        background: var(--primary-subtle);
    }

    .app-main {
        padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }

    .topbar-user .user-details {
        display: none;
    }

    .topbar {
        padding: 0 1rem;
    }

    .app-main .container {
        padding: 0 1rem;
    }

    .pwa-install-toast {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 768px) {
    html:has(.login-body) {
        height: 100%;
        overflow: hidden;
    }

    .login-body {
        height: 100%;
        min-height: 100dvh;
        overflow: hidden;
    }

    .login-page {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    .login-brand {
        display: flex;
        padding: 1.5rem 1.35rem 1.75rem;
        padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
        min-height: 0;
        justify-content: flex-end;
        flex-shrink: 0;
    }

    .login-brand::after {
        display: none;
    }

    .login-brand-content {
        max-width: none;
        width: 100%;
    }

    .login-brand-logo-img {
        width: 48px;
        height: 48px;
        margin-bottom: 0.85rem;
        border-radius: 12px;
    }

    .login-brand-eyebrow {
        margin-bottom: 0.35rem;
        font-size: 0.6875rem;
    }

    .login-brand h1 {
        font-size: 1.65rem;
        margin-bottom: 0.5rem;
    }

    .login-brand-lead {
        font-size: 0.875rem;
        max-width: 22rem;
        line-height: 1.45;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .login-brand-features {
        display: none;
    }

    .login-panel {
        min-height: 0;
        height: 100%;
        align-items: stretch;
        justify-content: flex-start;
        padding: 1.5rem 1.35rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
        margin-top: 0;
        position: relative;
        z-index: 3;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .login-card {
        max-width: none;
        width: 100%;
        background: transparent;
        border: none;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
        margin: 0;
    }

    .login-card-header {
        margin-bottom: 1.5rem;
    }

    .login-card-header h2 {
        font-size: 1.35rem;
        margin-bottom: 0.4rem;
    }

    .login-card-header p {
        font-size: 0.9rem;
        line-height: 1.45;
    }

    .login-form .form-group {
        margin-bottom: 1.15rem;
    }

    .login-form .form-group:last-child {
        margin-bottom: 0;
        margin-top: 0.35rem;
    }

    .theme-toggle-login {
        top: calc(0.85rem + env(safe-area-inset-top, 0px));
        right: 0.85rem;
        background: rgba(15, 23, 42, 0.35);
        border-color: rgba(255, 255, 255, 0.18);
        color: #fff;
    }

    .header .container {
        flex-wrap: wrap;
        height: auto;
        padding-top: 0.875rem;
        padding-bottom: 0.875rem;
    }

    .topbar .user-details,
    .header .user-details {
        display: none;
    }

    .topbar-user {
        display: none;
    }

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

    .devices-grid,
    .devices-list {
        gap: 0.5rem;
    }

    .device-item {
        grid-template-columns: 1fr;
        gap: 0.875rem;
        padding: 1rem;
    }

    .device-item-thumb {
        width: 100%;
        height: 120px;
    }

    .device-item-aside {
        align-items: stretch;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        padding-top: 0.75rem;
        border-top: 1px solid var(--border);
    }

    .device-actions {
        justify-content: flex-start;
    }

    .device-actions .btn {
        flex: 1;
        min-width: 0;
    }

    .devices-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .status-chips {
        justify-content: center;
    }

    .filter-select {
        width: 100%;
    }

    .devices-section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal {
        padding: 0.75rem;
        align-items: flex-end;
    }

    .modal-dialog {
        max-width: none;
        max-height: calc(100dvh - 1.5rem);
        width: 100%;
    }

    .modal-content {
        max-height: 100%;
        border-radius: 18px 18px 14px 14px;
    }

    .modal-footer {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 0;
    }

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

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.625rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }

    .card-body {
        padding: 1.25rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }
}

/* ——— PWA install toast (mobile) ——— */
.pwa-install-toast {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4000;
    padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
    opacity: 0;
    transform: translateY(110%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

.pwa-install-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.pwa-install-toast__inner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    max-width: 28rem;
    margin: 0 auto;
    padding: 0.875rem 0.875rem 0.875rem 0.75rem;
    background: #161a27;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.pwa-install-toast__logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}

.pwa-install-toast__body {
    flex: 1;
    min-width: 0;
}

.pwa-install-toast__title {
    display: block;
    font-size: 0.95rem;
    font-weight: 650;
    color: #f8fafc;
    margin-bottom: 0.2rem;
}

.pwa-install-toast__text {
    margin: 0 0 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: #94a3b8;
}

.pwa-install-toast__text strong {
    color: #e2e8f0;
    font-weight: 600;
}

.pwa-install-toast__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pwa-install-toast__btn {
    appearance: none;
    border: none;
    border-radius: 10px;
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}

.pwa-install-toast__btn--ghost {
    background: transparent;
    color: #94a3b8;
}

.pwa-install-toast__btn--ghost:hover {
    color: #e2e8f0;
}

.pwa-install-toast__btn--primary {
    background: #2563eb;
    color: #fff;
}

.pwa-install-toast__btn--primary:hover {
    background: #1d4ed8;
}

.pwa-install-toast__close {
    appearance: none;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 1.35rem;
    line-height: 1;
    padding: 0 0.15rem;
    cursor: pointer;
    flex-shrink: 0;
}

.pwa-install-toast__close:hover {
    color: #e2e8f0;
}

@media (min-width: 769px) {
    .pwa-install-toast {
        display: none !important;
    }
}
