/* =========================================================
   Portal CSS — Emergency Lighting IoT Management
   ========================================================= */

:root {
  --bg: #eef2f8;
  --panel: #ffffff;
  --line: #d6deea;
  --text: #1a2638;
  --muted: #5b6d84;
  --nav-bg: #0d1929;
  --nav-panel: #15243a;
  --nav-active: #1e3455;
  --nav-border: #243a5a;
  --nav-text: #dce7ff;
  --nav-muted: #7a94b8;
  --accent: #2a78ff;
  --accent-2: #46c5ff;
  --accent-grad: linear-gradient(90deg, #2a78ff, #46c5ff);
  --ok: #1ea97a;
  --ok-bg: #e8faf3;
  --warn: #d97706;
  --warn-bg: #fef3e2;
  --danger: #e03e3e;
  --danger-bg: #fdeaea;
  --info: #2a78ff;
  --info-bg: #eaf0ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(31,52,85,.08);
  --shadow-md: 0 8px 32px rgba(31,52,85,.13);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--nav-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow: hidden;
  z-index: 100;
  transition: width .2s ease;
}

.sidebar-brand {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--nav-border);
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 36px; height: 36px;
  background: var(--accent-grad);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
  line-height: 1.2;
}

.brand-text p {
  font-size: 11px;
  color: var(--nav-muted);
  margin-top: 2px;
}

.sidebar-toolbar {
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--nav-border);
}

.sidebar-toolbar .btn-icon {
  flex: 1;
  background: var(--nav-panel);
  border: 1px solid var(--nav-border);
  color: var(--nav-text);
  border-radius: var(--radius-sm);
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}

.sidebar-toolbar .btn-icon:hover {
  background: var(--nav-active);
}

.sidebar-tree-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px 16px;
}

.sidebar-tree-wrap::-webkit-scrollbar { width: 4px; }
.sidebar-tree-wrap::-webkit-scrollbar-track { background: transparent; }
.sidebar-tree-wrap::-webkit-scrollbar-thumb { background: #2a3e5e; border-radius: 2px; }

/* ── Tree ── */
.tree { list-style: none; }
.tree li { margin-bottom: 2px; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
  overflow: hidden;
}

.tree-row:hover { background: var(--nav-panel); }
.tree-row.active { background: var(--nav-active); color: #fff; }
.tree-row.active .tree-icon { color: var(--accent-2); }

.tree-toggle {
  font-size: 10px;
  color: var(--nav-muted);
  flex-shrink: 0;
  width: 12px;
  transition: transform .15s;
}

.tree-toggle.open { transform: rotate(90deg); }

.tree-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  color: var(--nav-text);
  flex: 1;
}

.tree-badge {
  font-size: 10px;
  background: #233554;
  color: var(--nav-muted);
  border-radius: 999px;
  padding: 1px 6px;
  flex-shrink: 0;
}

.tree-row.active .tree-badge {
  background: #2d4d7a;
  color: var(--accent-2);
}

.tree-children {
  list-style: none;
  margin-left: 20px;
  border-left: 1px dashed #2a3e5e;
  padding-left: 8px;
  display: none;
}

.tree-children.open { display: block; }

/* ── Main ── */
.main-wrap {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 var(--line);
}

.topbar-breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-breadcrumb .crumb-sep { color: var(--line); }
.topbar-breadcrumb .crumb-active { color: var(--text); font-weight: 600; }

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.main-content {
  flex: 1;
  padding: 20px 24px 32px;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.page-header-left h2 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.page-header-left p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.page-header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ── Stats Row ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card .stat-icon {
  font-size: 24px;
  line-height: 1;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--muted);
}

.stat-card.ok .stat-value { color: var(--ok); }
.stat-card.warn .stat-value { color: var(--warn); }
.stat-card.info .stat-value { color: var(--info); }

/* ── Grid Layout ── */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }

/* ── Card ── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
}

.card-body {
  padding: 14px 16px;
}

.card-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #fafbfd;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  font-weight: 600;
  color: #355581;
  background: #f6f9ff;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

tr:hover td { background: #f8faff; }

td.mono { font-family: "Consolas", monospace; font-size: 12px; color: var(--muted); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: #f0f3f8; color: var(--muted); }

/* Dot indicator */
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-danger { background: var(--danger); }
.dot-muted { background: #c8d5e8; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { filter: brightness(1.07); }
.btn:active { filter: brightness(.93); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.btn-primary { background: var(--accent-grad); color: #fff; }
.btn-success { background: linear-gradient(90deg, #1ea97a, #29c98b); color: #fff; }
.btn-danger  { background: linear-gradient(90deg, #e03e3e, #f56565); color: #fff; }
.btn-warn    { background: linear-gradient(90deg, #d97706, #f59e0b); color: #fff; }
.btn-outline { background: #fff; border: 1px solid #c5d4ec; color: #2b4f87; }
.btn-ghost   { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-sm      { padding: 5px 10px; font-size: 12px; }
.btn-xs      { padding: 3px 8px; font-size: 11px; }
.btn-icon    { padding: 7px; }

/* ── Form ── */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.form-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cfd9e8;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42,120,255,.1);
}

.form-row textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.form-inline {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-inline .form-row { flex: 1; margin-bottom: 0; }

/* ── Checkbox / Radio ── */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 8px;
}

.check-row input[type="checkbox"],
.check-row input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Chart container ── */
.chart-container {
  position: relative;
}

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: min(520px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { transform: scale(.96) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #fafbfd;
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
  max-width: 320px;
  pointer-events: auto;
}

.toast.ok   { background: var(--ok); }
.toast.warn { background: var(--warn); }
.toast.error { background: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); height: 0; padding: 0; margin: 0; }
}

.toast.out { animation: toastOut .2s ease forwards; }

/* ── Progress bar ── */
.progress {
  width: 100%;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent-grad);
  border-radius: 999px;
  transition: width .3s ease;
}

/* ── Test status table ── */
.test-status-row td { font-size: 12px; }
.test-status-row td:first-child { font-weight: 600; }

/* ── Batch select toolbar ── */
.selection-bar {
  background: #ebf2ff;
  border: 1px solid #c0d6ff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 10px;
}

.selection-bar .sel-count {
  font-weight: 600;
  color: var(--accent);
  flex: 1;
}

.device-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.device-filter-bar .dev-search,
.device-filter-bar .dev-select {
  height: 34px;
  border: 1px solid #cfd9e8;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  padding: 0 10px;
}

.device-filter-bar .dev-search {
  min-width: 220px;
  flex: 1 1 260px;
}

.device-filter-bar .dev-select {
  min-width: 140px;
}

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}

/* ── Scrollable table wrap ── */
.table-scroll {
  max-height: 400px;
  overflow-y: auto;
}

.table-scroll::-webkit-scrollbar { width: 4px; }
.table-scroll::-webkit-scrollbar-thumb { background: #d0ddef; border-radius: 2px; }

/* ── Inline status ── */
.status-text { font-size: 12px; color: var(--muted); margin-top: 6px; }
.status-text.ok   { color: var(--ok); }
.status-text.warn { color: var(--warn); }
.status-text.error { color: var(--danger); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }

/* ── Tab nav ── */
.tab-nav {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 16px;
}

.tab-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .col-4, .col-5 { grid-column: span 6; }
}

@media (max-width: 800px) {
  .sidebar { width: 220px; min-width: 220px; }
  .main-wrap { margin-left: 220px; }
  .col-4, .col-5, .col-6, .col-7, .col-8 { grid-column: span 12; }
}

/* ── Hamburger button (mobile only) ── */
.btn-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Mobile sidebar overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 600px) {
  .btn-hamburger { display: flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    width: 82vw;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .main-content { padding: 14px 12px 28px; }
  .topbar { padding: 0 12px; }
}
