/* ============================================================
 * Smart AED IoT — Modern UI theme
 * Custom gradient palette + refined tokens
 * ============================================================ */

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

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --accent: #f093fb;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --info: #4299e1;
    --dark: #1a202c;
    --ink: #2d3748;
    --muted: #718096;
    --soft: #a0aec0;
    --line: #e2e8f0;
    --bg: #f1f3f9;
    --surface: #ffffff;

    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-primary-soft: linear-gradient(135deg, rgba(102, 126, 234, .1) 0%, rgba(118, 75, 162, .1) 100%);

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 25px -3px rgba(15, 23, 42, .08), 0 4px 6px -4px rgba(15, 23, 42, .04);
    --shadow-xl: 0 20px 40px -12px rgba(15, 23, 42, .12);
    --shadow-glow: 0 0 0 3px rgba(102, 126, 234, .15);

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

    --ease: cubic-bezier(.4, 0, .2, 1);
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', 'Sarabun', 'Noto Sans Thai', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.005em;
}

a { color: var(--primary); }

/* ============================================================
 * Sidebar
 * ============================================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 268px;
    height: 100vh;
    background: var(--gradient-primary);
    color: white;
    padding: 24px 18px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .08);
}

/* subtle decorative glow */
.sidebar::before {
    content: '';
    position: absolute;
    top: -80px;
    right: -80px;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, rgba(255, 255, 255, .18), transparent 70%);
    pointer-events: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .15);
    position: relative;
}

.logo i {
    font-size: 30px;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .2));
}

.logo h2 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-menu { list-style: none; }

.nav-item { margin-bottom: 4px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    color: rgba(255, 255, 255, .85);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all .25s var(--ease);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    position: relative;
}

.nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: white;
    border-radius: 0 4px 4px 0;
    transition: height .2s var(--ease);
}

.nav-link:hover {
    background: rgba(255, 255, 255, .1);
    color: white;
    text-decoration: none;
    padding-left: 18px;
}

.nav-link.active {
    background: rgba(255, 255, 255, .22);
    color: white;
    text-decoration: none;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2);
}

.nav-link.active::before { height: 60%; }

.nav-link i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.user-info {
    position: absolute;
    bottom: 20px;
    left: 18px;
    right: 18px;
    padding: 14px;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: var(--radius-md);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.user-info h4 {
    font-size: 14px;
    margin-bottom: 4px;
    font-weight: 600;
}

.user-info p {
    font-size: 12px;
    opacity: .85;
}

/* ============================================================
 * Main content
 * ============================================================ */
.main-content {
    margin-left: 268px;
    padding: 24px;
    min-height: 100vh;
}

.top-bar {
    background: var(--surface);
    padding: 16px 24px;
    border-radius: var(--radius-md);
    margin-bottom: 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

/* Organization chip in top bar — shows owner/staff affiliation prominently */
.org-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px 8px 10px;
    background: linear-gradient(135deg, rgba(102, 126, 234, .1), rgba(118, 75, 162, .08));
    border: 1px solid rgba(102, 126, 234, .25);
    border-radius: 999px;
    max-width: 380px;
    min-width: 0;
    flex: 0 1 auto;
    margin-left: auto;
    margin-right: 8px;
}
.org-chip-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    box-shadow: 0 4px 10px rgba(102, 126, 234, .3);
}
.org-chip-body {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    overflow: hidden;
}
.org-chip-body small {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 600;
}
.org-chip-body strong {
    font-size: 13px;
    color: var(--dark);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 960px) {
    .org-chip {
        max-width: 200px;
    }
    .org-chip-body strong { font-size: 12px; }
}
@media (max-width: 640px) {
    .org-chip { display: none; }
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.01em;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 18px;
}

.notif-dropdown {
    position: relative;
}

.notification-bell {
    position: relative;
    font-size: 18px;
    color: var(--ink);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background .2s var(--ease);
    text-decoration: none;
    background: transparent;
    border: none;
    padding: 0;
}
.notification-bell:hover {
    background: var(--bg);
    text-decoration: none;
}

/* Bell dropdown panel */
.notif-panel {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--line);
    z-index: 2500;
    overflow: hidden;
    animation: slideUp .2s var(--ease);
}
.notif-panel.show { display: block; }

.notif-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}
.notif-panel-header strong {
    color: var(--dark);
    font-size: 14px;
}

.notif-panel-list {
    max-height: 380px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: inherit;
    transition: background .15s var(--ease);
}
.notif-item:hover {
    background: var(--bg);
    text-decoration: none;
    color: inherit;
}
.notif-item:last-child { border-bottom: none; }

.notif-item-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    flex-shrink: 0;
}
.notif-critical .notif-item-icon { background: linear-gradient(135deg, #f56565, #e53e3e); }
.notif-warning  .notif-item-icon { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.notif-info     .notif-item-icon { background: linear-gradient(135deg, #4299e1, #3182ce); }

.notif-item-body { flex: 1; min-width: 0; }

.notif-item-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
    font-size: 13px;
    color: var(--dark);
}

.notif-item-msg {
    font-size: 12px;
    color: var(--ink);
    line-height: 1.5;
    margin-bottom: 4px;
}

.notif-item-time {
    font-size: 11px;
    color: var(--soft);
}
.notif-item-time i { margin-right: 4px; }

.notif-empty {
    padding: 36px 20px;
    text-align: center;
    color: var(--soft);
}
.notif-empty i { font-size: 36px; margin-bottom: 10px; opacity: .6; }
.notif-empty p { font-size: 13px; }

.notif-panel-footer {
    display: block;
    padding: 12px 18px;
    text-align: center;
    border-top: 1px solid var(--line);
    background: var(--bg);
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    transition: background .15s var(--ease);
}
.notif-panel-footer:hover {
    background: var(--line);
    color: var(--primary);
    text-decoration: none;
}

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 0 0 2px white;
}

.current-time {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

/* ============================================================
 * Stats cards
 * ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(226, 232, 240, .7);
    position: relative;
    overflow: hidden;
    transition: all .25s var(--ease);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    border-radius: 4px 0 0 4px;
}

.stat-card.success::before { background: var(--success); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before  { background: var(--danger); }
.stat-card.info::before    { background: var(--info); }

.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(102, 126, 234, .3);
}

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

.stat-title {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 600;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    box-shadow: 0 6px 14px rgba(0, 0, 0, .1);
}

.stat-icon.primary { background: var(--gradient-primary); }
.stat-icon.success { background: linear-gradient(135deg, #48bb78, #38a169); }
.stat-icon.warning { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.stat-icon.danger  { background: linear-gradient(135deg, #f56565, #e53e3e); }
.stat-icon.info    { background: linear-gradient(135deg, #4299e1, #3182ce); }

.stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-change {
    font-size: 12px;
    color: var(--success);
    margin-top: 6px;
    font-weight: 500;
}

/* ============================================================
 * Cards
 * ============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(226, 232, 240, .7);
    margin-bottom: 22px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
    gap: 12px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.01em;
}
.card-title i { color: var(--primary); margin-right: 4px; }

/* ============================================================
 * Tables
 * ============================================================ */
.table-container { overflow-x: auto; }

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

table.data-table thead {
    background: var(--bg);
}

table.data-table th,
table.data-table td {
    padding: 13px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: 14px;
}

table.data-table th {
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

table.data-table tbody tr {
    transition: background .15s var(--ease);
}
table.data-table tbody tr:hover { background: rgba(102, 126, 234, .04); }

/* ============================================================
 * Badges
 * ============================================================ */
.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
}

.badge-pill.success   { background: #c6f6d5; color: #22543d; }
.badge-pill.warning   { background: #feebc8; color: #7c2d12; }
.badge-pill.danger    { background: #fed7d7; color: #742a2a; }
.badge-pill.info      { background: #bee3f8; color: #2c5282; }
.badge-pill.secondary { background: #e2e8f0; color: #4a5568; }

/* ============================================================
 * Buttons
 * ============================================================ */
.btn-action {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all .2s var(--ease);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    letter-spacing: .01em;
    line-height: 1;
}

.btn-action.primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, .35);
}
.btn-action.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, .45);
    color: white;
    text-decoration: none;
}

.btn-action.success {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
    box-shadow: 0 4px 12px rgba(72, 187, 120, .35);
}
.btn-action.success:hover {
    transform: translateY(-1px);
    color: white;
    text-decoration: none;
}

.btn-action.danger {
    background: linear-gradient(135deg, #f56565, #e53e3e);
    color: white;
    box-shadow: 0 4px 12px rgba(245, 101, 101, .35);
}
.btn-action.danger:hover { transform: translateY(-1px); }

.btn-action.info {
    background: linear-gradient(135deg, #4299e1, #3182ce);
    color: white;
    box-shadow: 0 4px 12px rgba(66, 153, 225, .35);
}
.btn-action.info:hover { transform: translateY(-1px); color: white; }

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

.btn-action.sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-action:active { transform: translateY(0); }

/* ============================================================
 * Search & Filter
 * ============================================================ */
.search-filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

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

.search-box input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    transition: all .2s var(--ease);
    font-family: inherit;
    line-height: 1.7;
    min-height: 48px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--soft);
    font-size: 14px;
}

.filter-select {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    cursor: pointer;
    font-family: inherit;
    color: var(--ink);
    transition: all .2s var(--ease);
    line-height: 1.7;
    min-height: 48px;
}
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

/* ============================================================
 * Modal
 * ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn .2s var(--ease);
}
.modal-overlay.show { display: flex; }

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideUp .25s var(--ease);
}

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

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
}

.modal-close {
    font-size: 24px;
    cursor: pointer;
    color: var(--soft);
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all .2s var(--ease);
}
.modal-close:hover {
    background: var(--bg);
    color: var(--ink);
}

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

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

.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--ink);
    transition: all .2s var(--ease);
    font-family: inherit;
    /* Thai tone marks + descenders need extra vertical room. 1.5 clips them. */
    line-height: 1.7;
    min-height: 46px;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.form-control:disabled, .form-control[readonly] {
    background: var(--bg);
    color: var(--muted);
}

/* Native <select> looks like a plain input in some browsers (no chevron).
 * Force a consistent style + custom arrow SVG on the right so it's obvious
 * these are dropdowns, and add room on the right so long Thai option text
 * doesn't get clipped by the arrow. */
select.form-control,
select.filter-select,
.filter-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23718096' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
    padding-right: 40px;
    cursor: pointer;
    /* Native <select> renders closed value with tight line-height by default.
     * Give it room so Thai descenders / tone marks don't get clipped. */
    line-height: 1.7;
    min-height: 48px;
    padding-top: 12px;
    padding-bottom: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Option rows inside the open dropdown — some browsers honor these
 * (Firefox, Chrome on Linux/Windows). Safari largely ignores them. */
select.form-control option,
.filter-select option {
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--ink);
    line-height: 1.6;
    white-space: normal;
}

/* ============================================================
 * Timeline
 * ============================================================ */
.timeline {
    position: relative;
    padding-left: 30px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 4px;
    bottom: 0;
    width: 2px;
    background: var(--line);
}

.timeline-item {
    position: relative;
    margin-bottom: 16px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -25px;
    top: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, .2);
}

.timeline-item.alert::before {
    background: var(--danger);
    box-shadow: 0 0 0 3px rgba(245, 101, 101, .2);
}

.timeline-time {
    font-size: 11px;
    color: var(--soft);
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.timeline-content {
    background: var(--bg);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid var(--line);
    line-height: 1.5;
}

/* ============================================================
 * Alert notifications
 * ============================================================ */
.alert-notification {
    position: fixed;
    top: 24px;
    right: 24px;
    background: var(--surface);
    padding: 18px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    z-index: 3000;
    min-width: 340px;
    max-width: 400px;
    display: none;
    animation: slideInRight .35s var(--ease);
    border-left: 4px solid var(--info);
}

@keyframes slideInRight {
    from { transform: translateX(420px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.alert-notification.show { display: block; }
.alert-notification.danger  { border-left-color: var(--danger); }
.alert-notification.warning { border-left-color: var(--warning); }
.alert-notification.info    { border-left-color: var(--info); }

/* ============================================================
 * QR Code + battery + health chips
 * ============================================================ */
.qr-code-container {
    text-align: center;
    padding: 20px;
}

.qr-code-box {
    width: 220px;
    margin: 0 auto;
    background: white;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

.battery-health {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.battery-bar {
    flex: 1;
    height: 8px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    min-width: 60px;
}

.battery-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .3s var(--ease);
}

.battery-fill.high   { background: linear-gradient(90deg, #48bb78, #38a169); }
.battery-fill.medium { background: linear-gradient(90deg, #ed8936, #dd6b20); }
.battery-fill.low    { background: linear-gradient(90deg, #f56565, #e53e3e); }

.health-score {
    display: inline-block;
    padding: 5px 13px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: .02em;
}

.health-score.excellent { background: #c6f6d5; color: #22543d; }
.health-score.good      { background: #bee3f8; color: #2c5282; }
.health-score.fair      { background: #feebc8; color: #7c2d12; }
.health-score.poor      { background: #fed7d7; color: #742a2a; }

/* ============================================================
 * Device cards (monitoring)
 * ============================================================ */
.device-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--success);
    transition: all .25s var(--ease);
}
.device-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
}

.device-card.alert {
    border-left-color: var(--danger);
    animation: pulse 2.5s infinite;
}

.device-card.offline {
    border-left-color: var(--soft);
    opacity: .75;
}

.device-card.maintenance { border-left-color: var(--soft); }

@keyframes pulse {
    0%, 100% { box-shadow: var(--shadow-sm); }
    50%      { box-shadow: 0 8px 24px rgba(245, 101, 101, .25); }
}

/* ============================================================
 * Charts & misc
 * ============================================================ */
.chart-container {
    position: relative;
    height: 300px;
    margin-top: 14px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

@media (max-width: 1200px) {
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; padding: 16px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .top-bar { padding: 12px 16px; }
    .page-title { font-size: 18px; }
}

.action-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--soft);
}

.empty-state i {
    font-size: 60px;
    margin-bottom: 18px;
    color: var(--line);
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 16px;
    font-weight: 600;
}

.mqtt-status {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

.mqtt-dot {
    width: 10px;
    height: 10px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(72, 187, 120, .2);
    animation: breathe 2s infinite;
}

@keyframes breathe {
    0%, 100% { box-shadow: 0 0 0 4px rgba(72, 187, 120, .2); }
    50%      { box-shadow: 0 0 0 8px rgba(72, 187, 120, .1); }
}

.map-legend {
    margin-top: 15px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
}
.map-legend h4 {
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.map-legend-items {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--ink);
}

.flash-success {
    background: linear-gradient(135deg, rgba(72, 187, 120, .15), rgba(56, 161, 105, .08));
    color: #22543d;
    border: 1px solid rgba(72, 187, 120, .3);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideDown .3s var(--ease);
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
