/* ── Reset / base ─────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei",
                 "PingFang TC", Roboto, sans-serif;
    background: #f4f6fa;
    color: #1f2937;
    font-size: 11px;
    line-height: 1.25;
    display: flex;
    flex-direction: column;
}

.muted { color: #6b7280; font-size: 10px; }

/* ── Header ────────────────────────────────────────────────── */
header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    background: #ffffff;
    padding: 2px 16px;
    border-bottom: 2px solid #744ec2;
    gap: 16px;
    flex-shrink: 0;
}

.logo-img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    display: block;
}

.header-center { text-align: center; }
.header-center h1 {
    font-size: 28px;
    color: #744ec2;
    font-weight: 700;
    line-height: 1.1;
}
.header-center h2 {
    font-size: 18px;
    color: #744ec2;
    font-weight: 500;
    line-height: 1.1;
    margin-top: 2px;
}

.header-right .last-update { text-align: right; font-size: 10px; line-height: 1.3; }

/* ── Location bar ─────────────────────────────────────────── */
.location-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 16px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.location-bar label { font-weight: 600; color: #c2185b; font-size: 11px; }
.location-bar select {
    padding: 2px 6px;
    font-size: 11px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    min-width: 130px;
}
.status-pill {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 12px;
    background: #d1fae5;
    color: #065f46;
    font-size: 10px;
    font-weight: 600;
}
.status-pill.error { background: #fee2e2; color: #991b1b; }
.status-pill.warn  { background: #fef3c7; color: #92400e; }

/* ── Main: viewport flex container ─────────────────────────── */
main {
    flex: 1 1 auto;
    overflow: hidden;
    padding: 4px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

/* ── Inactive devices: fixed height (5 rows max + header), blue border ──── */
.inactive-section {
    background: #fff;
    border-radius: 4px;
    border: 2px solid #1976d2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 4px 8px;
    flex: 0 0 auto;
}
.inactive-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}
.inactive-section h3 { color: #1976d2; font-size: 12px; }
.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
}
.page-btn {
    background: #fff;
    border: 1px solid #1976d2;
    color: #1976d2;
    padding: 1px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
}
.page-btn:hover:not(:disabled) { background: #e3f2fd; }
.page-btn:disabled { color: #9ca3af; border-color: #d1d5db; cursor: not-allowed; }
#page-indicator { color: #6b7280; font-weight: 600; }

#inactive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    table-layout: fixed;
}
#inactive-table th {
    text-align: left;
    background: #eff6ff;
    padding: 2px 6px;
    font-weight: 600;
    color: #1e40af;
    font-size: 9px;
    line-height: 1.15;
    border-bottom: 1px solid #bfdbfe;
}
#inactive-table td {
    padding: 2px 6px;
    border-bottom: 1px solid #f3f4f6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.silent-cell { color: #ef4444; font-weight: 600; }

/* ── Rooms: take remaining vertical space ─────────────────── */
.rooms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* Only collapse to single column on actual mobile phones (< 600px).
   Anything wider — laptop, tablet, narrow desktop — keeps the 3-column row. */
@media (max-width: 600px) {
    .rooms-grid { grid-template-columns: 1fr; }
    html, body { overflow: auto; }
}

/* ── Room cards ───────────────────────────────────────────── */
.room-card {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.room-title {
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}
.room-title.male       { background: #1976d2; }
.room-title.female     { background: #ec407a; }
.room-title.disability { background: #00897b; }

.room-panels {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px;
    overflow-y: auto;        /* per-room scroll if a single room has too much; page itself stays put */
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    scrollbar-width: thin;
}
.room-panels::-webkit-scrollbar { width: 4px; }
.room-panels::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* ── Sub-panel inside each room ───────────────────────────── */
.panel {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.panel-title {
    padding: 2px 6px;
    background: #FFF3C4;          /* AEON-logo pale yellow */
    font-weight: 600;
    color: #744ec2;               /* keep heading purple for contrast */
    font-size: 10px;
    border-bottom: 1px solid #FACC15;
}

.panel-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;           /* respect explicit column widths so panels align */
}
.panel-table th,
.panel-table td {
    width: 25%;                    /* 4 equal columns (25% each); 3-col tables use first 3 slots */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.panel-table th {
    text-align: left;
    padding: 1px 5px;
    background: #f3f4f6;
    font-weight: 500;
    font-size: 9px;
    color: #6b7280;
    line-height: 1.2;
}
.panel-table td {
    padding: 1px 5px;
    border-top: 1px solid #f3f4f6;
    font-size: 10px;
    line-height: 1.2;
}

/* Center any cell that contains a status dot, plus its header */
.panel-table td:has(.dot),
.panel-table th.status-col { text-align: center; }

/* Status dot */
.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9ca3af;
    vertical-align: middle;
}
.dot.ok    { background: #10b981; }
.dot.alert { background: #ef4444; }
.dot.warn  { background: #f59e0b; }

/* AQ tiles — single row of 4 across */
.aq-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    padding: 3px 4px;
}
.aq-tile {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 3px;
    padding: 2px 1px;
    text-align: center;
    min-width: 0;
}
.aq-label {
    font-size: 8px;
    color: #6b7280;
    margin-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aq-value {
    font-size: 12px;
    font-weight: 700;
    color: #d97706;
    white-space: nowrap;
    line-height: 1;
}
.aq-unit {
    font-size: 8px;
    color: #6b7280;
    margin-left: 1px;
    font-weight: 500;
}

.empty {
    padding: 4px 8px;
    color: #9ca3af;
    font-style: italic;
    font-size: 10px;
}

/* ── Tab nav (shared between Smart Toilet + Device Management) ─── */
.tab-nav {
    display: flex;
    gap: 0;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 16px;
    flex-shrink: 0;
}
.tab-link {
    padding: 6px 18px;
    color: #6b7280;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.tab-link:hover  { color: #744ec2; }
.tab-link.active {
    color: #744ec2;
    border-bottom-color: #744ec2;
}

/* ── Device Management page — locked viewport, no page scroll ──── */
.page-devmgmt { overflow: hidden; }

.page-devmgmt main {
    flex: 1 1 auto;
    overflow: hidden;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

/* Category filter pills bar (only filters laptops) */
.category-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.category-bar label { font-weight: 600; color: #744ec2; font-size: 11px; flex-shrink: 0; }
.category-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.category-pill {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #4b5563;
    padding: 2px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    transition: all 0.15s;
}
.category-pill:hover { background: #f3e8ff; border-color: #744ec2; color: #744ec2; }
.category-pill.active {
    background: #744ec2;
    color: #fff;
    border-color: #744ec2;
}
.pill-count {
    display: inline-block;
    margin-left: 4px;
    padding: 0 4px;
    background: rgba(0,0,0,0.08);
    border-radius: 8px;
    font-weight: 700;
    font-size: 9px;
}
.category-pill.active .pill-count { background: rgba(255,255,255,0.25); }

/* Each section: 3 columns — icon (narrow) | stats (compact) | table (fills rest) */
.dm-section {
    background: #fff;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: grid;
    grid-template-columns: 90px 220px 1fr;
    gap: 8px;
    padding: 8px 10px;
    flex: 1 1 0;             /* both sections share remaining viewport equally */
    min-height: 0;
    overflow: hidden;
}

/* Responsive: collapse icon/stats next to each other on narrow viewports */
@media (max-width: 1300px) {
    .dm-section { grid-template-columns: 80px 180px 1fr; gap: 6px; }
}
@media (max-width: 1050px) {
    .dm-section { grid-template-columns: 70px 160px 1fr; gap: 4px; }
}

/* Left col: icon + section label */
.dm-icon-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #faf5ff, #f3e8ff);
    border-radius: 6px;
    padding: 6px;
    min-width: 0;
}
.dm-big-icon {
    font-size: 56px;
    line-height: 1;
    margin-bottom: 6px;
}
.dm-big-icon-img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin-bottom: 4px;
}
.dm-section-title {
    text-align: center;
    font-size: 11px;
    color: #744ec2;
    font-weight: 700;
    line-height: 1.2;
}

/* Middle col: compact stat cards + optional spared list */
.dm-stats-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
/* Two stat tiles side-by-side in a row */
.stat-row-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    flex-shrink: 0;
}
/* Each tile is a single horizontal row: label on LEFT, big number on RIGHT */
.stat-card {
    background: linear-gradient(135deg, #f3e8ff, #e9d5ff);
    border-radius: 5px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;   /* label left, count right */
    gap: 6px;
    overflow: hidden;
    min-width: 0;
}
.stat-card.spared   { background: linear-gradient(135deg, #fef3c7, #fde68a); }
.stat-card.expiring { background: linear-gradient(135deg, #fee2e2, #fecaca); }
/* DOM order is value first, label second → flip visually so label appears on left */
.stat-card .stat-value { order: 2; }
.stat-card .stat-label { order: 1; }
.stat-value {
    font-size: 20px;
    font-weight: 800;
    color: #744ec2;
    line-height: 1;
    flex-shrink: 0;
}
.stat-label {
    font-size: 9px;
    color: #4b5563;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;       /* allow Chinese to wrap to 2 lines if needed */
    word-break: keep-all;
}
.stat-card.spared   .stat-value { color: #b45309; }
.stat-card.expiring .stat-value { color: #b91c1c; }

.spared-list-wrap {
    border: 1px solid #fde68a;
    border-radius: 4px;
    background: #fffbeb;
    padding: 3px 6px;
    overflow-y: auto;          /* THE only scroll on the spared list */
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    scrollbar-width: thin;
}
.spared-list-wrap::-webkit-scrollbar { width: 5px; }
.spared-list-wrap::-webkit-scrollbar-thumb { background: #fcd34d; border-radius: 2px; }
.spared-list-title {
    font-size: 9px;
    color: #b45309;
    font-weight: 700;
    margin-bottom: 2px;
    position: sticky;
    top: 0;
    background: #fffbeb;       /* covers content scrolling underneath */
}
.spared-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 9px;
    table-layout: fixed;       /* no manual block/flex hackery — just a normal table */
}
.spared-list th, .spared-list td {
    padding: 2px 4px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.spared-list th { color: #b45309; font-weight: 600; }
/* Column widths: Brand small, Model wide (wraps), Serial medium */
.spared-list th:nth-child(1), .spared-list td:nth-child(1) { width: 18%; }
.spared-list th:nth-child(2), .spared-list td:nth-child(2) {
    width: 52%;
    white-space: normal;       /* allow Model to wrap to 2 lines if needed */
    line-height: 1.15;
}
.spared-list th:nth-child(3), .spared-list td:nth-child(3) { width: 30%; }

/* Right col: main data table (scrolls internally) */
.dm-table-col {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.dm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    table-layout: auto;
}
.dm-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #faf5ff;
}
.dm-table th {
    text-align: left;
    background: #faf5ff;
    color: #6d28d9;
    padding: 3px 6px;
    font-size: 10px;
    font-weight: 700;
    border-bottom: 2px solid #ddd6fe;
    white-space: nowrap;
}
.dm-table td {
    padding: 2px 6px;
    border-bottom: 1px solid #f3f4f6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}
.dm-table tr:hover { background: #fafafa; }

/* Wrap the table in its own scroll container */
.dm-table-col {
    overflow-y: auto;
    scrollbar-width: thin;
}
.dm-table-col::-webkit-scrollbar { width: 5px; }
.dm-table-col::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.alert-text { color: #b91c1c; font-weight: 700; }
.warn-text  { color: #b45309; font-weight: 600; }
.empty-row {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 8px !important;
}
