/* ── CSS Variables ─────────────────────────────────────────────────────────── */

:root {
  --bg:             #0b0f1a;
  --surface:        #161b2e;
  --surface2:       #1a2035;
  --border:         #1e2537;
  --primary:        #89b4fa;
  --text:           #cdd6f4;
  --text-secondary: #a6adc8;
  --muted:          #6c7086;
  --green:          #a6e3a1;
  --red:            #f38ba8;
  --yellow:         #f9e2af;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */

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

/* ── Sidebar ────────────────────────────────────────────────────────────────── */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #11151f;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0 0;
}

.brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
}

.brand-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.06em;
}

.brand-sub {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar nav {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
}

.nav-section {
  font-size: 0.60rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 10px;
  margin: 16px 0 6px;
}

.nav-section:first-child { margin-top: 0; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  margin-bottom: 1px;
  transition: background 0.12s, color 0.12s;
}

.sidebar nav a:hover {
  background: rgba(137, 180, 250, 0.08);
  color: var(--text);
}

.sidebar nav a.active {
  background: rgba(137, 180, 250, 0.12);
  color: var(--primary);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}

.sidebar-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
}

.sidebar-footer a:hover { color: var(--text); }

/* ── Main area ──────────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  min-height: 54px;
  border-bottom: 1px solid var(--border);
  background: #11151f;
  display: flex;
  align-items: center;
  padding: 0 24px;
  flex-shrink: 0;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.content {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Stat cards ─────────────────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  min-width: 0;
}

.card-label {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ── Status indicators ──────────────────────────────────────────────────────── */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

.dot-green  { background: var(--green); }
.dot-red    { background: var(--red); }
.dot-yellow { background: var(--yellow); }
.dot-muted  { background: var(--muted); }

/* ── Section title ──────────────────────────────────────────────────────────── */

.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Empty state ────────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
  font-size: 0.83rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.empty-state p { margin-top: 8px; font-size: 0.75rem; }

/* ── Table ──────────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;          /* horizontal scroll instead of clipping */
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 600px;          /* prevents table from collapsing on narrow screens */
  border-collapse: collapse;
  font-size: 0.81rem;
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

tbody tr:hover { background: rgba(137, 180, 250, 0.03); }

/* ── Badges ─────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green  { background: rgba(166,227,161,0.15); color: var(--green); }
.badge-red    { background: rgba(243,139,168,0.15); color: var(--red); }
.badge-yellow { background: rgba(249,226,175,0.15); color: var(--yellow); }
.badge-blue   { background: rgba(137,180,250,0.15); color: var(--primary); }
.badge-muted  { background: rgba(108,112,134,0.15); color: var(--muted); }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.alert-success { background: rgba(166,227,161,0.10); border: 1px solid rgba(166,227,161,0.25); color: var(--green); }
.alert-warning { background: rgba(249,226,175,0.10); border: 1px solid rgba(249,226,175,0.25); color: var(--yellow); }
.alert-danger  { background: rgba(243,139,168,0.10); border: 1px solid rgba(243,139,168,0.25); color: var(--red); }

/* ── Forms ──────────────────────────────────────────────────────────────────── */

.form-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  max-width: 520px;
  width: 100%;
}

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

label {
  display: block;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.83rem;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

input:focus,
select:focus { outline: none; border-color: var(--primary); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236c7086' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.btn {
  padding: 9px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s;
  white-space: nowrap;
}

.btn:hover    { opacity: 0.84; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--primary); color: #0b0f1a; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--muted); }

/* ── Utility ────────────────────────────────────────────────────────────────── */

.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.text-muted   { color: var(--muted); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.text-primary { color: var(--primary); }

/* ── Hamburger (hidden on desktop) ─────────────────────────────────────────── */

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.hamburger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

/* ── Sidebar overlay (mobile) ───────────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
}

/* ── Responsive: tablet (≤900px) ───────────────────────────────────────────── */

@media (max-width: 900px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .content {
    padding: 20px;
  }
}

/* ── Responsive: mobile (≤768px) ───────────────────────────────────────────── */

@media (max-width: 768px) {

  /* Show hamburger button */
  .hamburger { display: flex; }

  /* Sidebar becomes a fixed drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 220px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-overlay.sidebar-open {
    display: block;
  }

  /* Main area fills full width */
  .main {
    width: 100%;
    overflow: hidden;
  }

  /* Topbar adjustments */
  .topbar {
    padding: 0 14px;
    min-height: 50px;
  }

  .topbar-right {
    gap: 10px;
    font-size: 0.70rem;
  }

  /* Hide "Engine Online" status in topbar on mobile to save space */
  .topbar-right > span:first-child {
    display: none;
  }

  /* Content padding */
  .content {
    padding: 14px;
  }

  /* Cards: 2 columns on tablet, 1 on very small */
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
  }

  .card {
    padding: 14px;
  }

  .card-value {
    font-size: 1.3rem;
  }

  /* Tables: horizontal scroll */
  .table-wrap {
    border-radius: 8px;
    margin-left: -14px;
    margin-right: -14px;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  /* Form block: full width on mobile */
  .form-block {
    max-width: 100%;
    padding: 16px;
  }

  /* Section title wrapping */
  .section-title {
    flex-wrap: wrap;
  }

  /* Scan action bar */
  .section-title .btn {
    font-size: 0.75rem;
    padding: 5px 12px;
  }
}

/* ── Responsive: small phones (≤480px) ─────────────────────────────────────── */

@media (max-width: 480px) {

  .card-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .card-value {
    font-size: 1.1rem;
  }

  .topbar-right span,
  .topbar-right a {
    font-size: 0.68rem;
  }

  /* Hide username in topbar, keep sign-out only */
  .topbar-right > span:nth-child(2) {
    display: none;
  }

  .content {
    padding: 10px;
  }

  table {
    font-size: 0.75rem;
  }

  thead th,
  tbody td {
    padding: 9px 10px;
  }
}
