/* ─── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: #0f172a;
  min-height: 100vh;
  display: flex;
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #0b3c5d;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.4rem 1.25rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand-name {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.sidebar-brand-sub {
  color: rgba(255,255,255,.45);
  font-size: .72rem;
  margin-top: .15rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.sidebar-nav {
  flex: 1;
  padding: .75rem 0;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.sidebar-nav a:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}
.sidebar-nav a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-left-color: #0f6b66;
}
.sidebar-nav .nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: .8;
}
.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: .75rem .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .75rem;
  color: rgba(255,255,255,.5);
  text-decoration: none;
  font-size: .8rem;
  border-radius: 8px;
  transition: background .12s, color .12s;
}
.sidebar-footer a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

/* ─── App shell ───────────────────────────────────────── */
.app-layout { display: flex; flex: 1; }
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  min-width: 0;
}
.page-header {
  padding: 1.5rem 2rem .25rem;
}
.page-header h1 {
  margin: 0 0 .2rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: #0f172a;
}
.page-header p {
  margin: 0;
  color: #64748b;
  font-size: .85rem;
}
.layout {
  padding: 1.25rem 2rem 2rem;
  flex: 1;
}

/* ─── Auth wrap (no sidebar) ──────────────────────────── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f1f5f9;
  width: 100%;
  padding: 2rem;
}
.auth-card {
  max-width: 380px;
  width: 100%;
}
.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-logo-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: #0b3c5d;
}
.auth-logo-sub {
  font-size: .8rem;
  color: #64748b;
}

/* ─── Flash messages ──────────────────────────────────── */
.flash-stack { margin-bottom: 1rem; }
.flash {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem 1rem;
  border-radius: 8px;
  margin-bottom: .5rem;
  font-size: .875rem;
  font-weight: 500;
}
.flash.success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.flash.error   { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.flash.info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ─── Cards ───────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  border: 1px solid #e2e8f0;
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
}

/* ─── Metrics ─────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 1.25rem;
}
.metric {
  background: #fff;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border: 1px solid #e2e8f0;
}
.metric-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: .3rem;
  color: #0f172a;
}
.metric-label {
  font-size: .75rem;
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.metric.clr-green .metric-value { color: #16a34a; }
.metric.clr-orange .metric-value { color: #ea580c; }
.metric.clr-red .metric-value { color: #dc2626; }

/* ─── Tables ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.table th {
  text-align: left;
  padding: .55rem .75rem;
  color: #64748b;
  font-weight: 600;
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
.table td {
  padding: .7rem .75rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.table td a {
  color: #0b3c5d;
  text-decoration: none;
  font-weight: 500;
}
.table td a:hover { color: #0f6b66; text-decoration: underline; }
.table .empty-row td {
  text-align: center;
  color: #94a3b8;
  padding: 2rem;
  font-size: .875rem;
}

/* ─── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .65rem;
  border-radius: 999px;
  font-size: .73rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.pending     { background: #fef3c7; color: #92400e; }
.badge.commissioned { background: #dcfce7; color: #15803d; }
.badge.blocked     { background: #fee2e2; color: #991b1b; }
.badge.super_admin { background: #ede9fe; color: #5b21b6; }
.badge.org_admin   { background: #dbeafe; color: #1e40af; }
.badge.org_member  { background: #f1f5f9; color: #475569; }

/* ─── Online indicator ────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online  { background: #22c55e; box-shadow: 0 0 0 2px #dcfce7; }
.status-dot.offline { background: #cbd5e1; }
.device-name-cell {
  display: flex;
  align-items: center;
  gap: .55rem;
}

/* ─── Filter tabs ─────────────────────────────────────── */
.filter-tabs {
  display: flex;
  gap: .4rem;
  margin-bottom: .9rem;
  flex-wrap: wrap;
}
.filter-tab {
  padding: .35rem .85rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #64748b;
  transition: all .12s;
  user-select: none;
}
.filter-tab:hover  { border-color: #0b3c5d; color: #0b3c5d; }
.filter-tab.active { background: #0b3c5d; color: #fff; border-color: #0b3c5d; }
.filter-tab .tab-count {
  display: inline-block;
  background: rgba(0,0,0,.1);
  border-radius: 999px;
  padding: 0 .4rem;
  font-size: .7rem;
  margin-left: .3rem;
}
.filter-tab.active .tab-count { background: rgba(255,255,255,.2); }

/* ─── Battery icon ────────────────────────────────────── */
.bat-icon { display: inline-block; vertical-align: middle; }
.bat-wrap {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 500;
  color: #374151;
}
.bat-wrap.low  { color: #dc2626; }
.bat-wrap.mid  { color: #ea580c; }
.bat-wrap.good { color: #16a34a; }

/* ─── RSSI icon ───────────────────────────────────────── */
.rssi-wrap {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 500;
  color: #374151;
}
.rssi-wrap.rssi-none { color: #94a3b8; }
.rssi-wrap.rssi-low  { color: #dc2626; }
.rssi-wrap.rssi-mid  { color: #ea580c; }
.rssi-wrap.rssi-good { color: #16a34a; }

/* ─── Forms ───────────────────────────────────────────── */
.form-grid { display: grid; gap: .75rem; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-label {
  font-size: .78rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: .04em;
}
input, select, textarea {
  font: inherit;
  padding: .6rem .8rem;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  width: 100%;
  background: #fff;
  color: #0f172a;
  font-size: .875rem;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #0b3c5d;
  box-shadow: 0 0 0 3px rgba(11,60,93,.12);
}
textarea { min-height: 80px; resize: vertical; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: 8px;
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .12s;
  white-space: nowrap;
}
.btn-primary  { background: #0b3c5d; color: #fff; border-color: #0b3c5d; }
.btn-primary:hover { background: #0d4f7c; border-color: #0d4f7c; }
.btn-teal     { background: #0f6b66; color: #fff; border-color: #0f6b66; }
.btn-teal:hover { background: #0c5954; }
.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover { background: #f9fafb; border-color: #9ca3af; }
.btn-danger   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-warning  { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.btn-warning:hover { background: #ffedd5; }
.btn-ghost    { background: transparent; color: #374151; border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; border-color: #e2e8f0; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 6px; }
.btn-full { width: 100%; }

/* ─── Action list (device detail sidebar) ─────────────── */
.action-list { display: flex; flex-direction: column; gap: .5rem; }
.action-list .btn { justify-content: flex-start; }

/* ─── Two-column detail grid ──────────────────────────── */
.detail-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr 300px;
  align-items: start;
}
@media (max-width: 820px) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* ─── Two-column side-by-side ─────────────────────────── */
.two-col {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr 340px;
  align-items: start;
}
@media (max-width: 820px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ─── Info grid (device detail facts) ─────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem 1rem;
  margin-bottom: 1rem;
}
.info-item {}
.info-item .info-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  margin-bottom: .15rem;
}
.info-item .info-value {
  font-size: .9rem;
  font-weight: 500;
  color: #0f172a;
}

/* ─── Section divider ─────────────────────────────────── */
.section-sep { height: 1px; background: #e2e8f0; margin: 1rem 0; }

/* ─── Org device list ─────────────────────────────────── */
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li {
  padding: .6rem .25rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.device-list li:last-child { border-bottom: none; }
.device-list a { color: #0b3c5d; text-decoration: none; font-weight: 500; font-size: .875rem; }
.device-list a:hover { color: #0f6b66; }
