/* ── Variables ────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #0f172a;
  --sidebar-w:  220px;
  --accent:     #4ade80;
  --accent-dk:  #22c55e;
  --text:       #1e293b;
  --muted:      #64748b;
  --border:     #e2e8f0;
  --bg:         #f8fafc;
  --card-bg:    #ffffff;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --info:       #3b82f6;
  --radius:     8px;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px;
       color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }

/* ── Auth layout ──────────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
}
.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-card .logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-card .logo span {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-dk);
}
.auth-card h2 { text-align: center; margin-bottom: 1.5rem; font-size: 1.1rem; color: var(--muted); }

/* ── App layout ───────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 1.5rem 1.25rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
  border-bottom: 1px solid #1e293b;
}
.sidebar .brand small { display: block; font-weight: 400; font-size: .7rem; color: #475569; margin-top: 2px; }
.sidebar nav { flex: 1; padding: .75rem 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1.25rem;
  font-size: .85rem;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #1e293b; color: #e2e8f0; }
.sidebar nav a.active { background: #1e293b; color: var(--accent); border-left-color: var(--accent); }
.sidebar nav .nav-section {
  padding: .8rem 1.25rem .3rem;
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #475569;
}
.sidebar .user-info {
  padding: 1rem 1.25rem;
  border-top: 1px solid #1e293b;
  font-size: .78rem;
}
.sidebar .user-info strong { display: block; color: #e2e8f0; }
.sidebar .user-info .badge-admin { color: var(--accent); font-size: .7rem; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2rem;
  min-width: 0;
}
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 600; }
.page-header p  { color: var(--muted); margin-top: .25rem; font-size: .85rem; }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h3 { font-size: .9rem; font-weight: 600; margin-bottom: .75rem; }

/* Stat cards */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  text-align: center;
}
.stat-card .stat-num { font-size: 2rem; font-weight: 700; color: var(--accent-dk); }
.stat-card .stat-lbl { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/* Device cards grid */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.device-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: box-shadow .15s;
}
.device-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.07); }
.device-card .device-name { font-weight: 600; font-size: .95rem; }
.device-card .device-mac  { font-size: .75rem; color: var(--muted); font-family: monospace; }
.device-card .device-meta { font-size: .75rem; color: var(--muted); }
.device-card .device-actions { margin-top: auto; padding-top: .5rem; display: flex; gap: .5rem; }

/* ── Table ────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; padding: .6rem .75rem; border-bottom: 2px solid var(--border);
     font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f1f5f9; }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .85rem;
  border-left: 4px solid transparent;
}
.alert-success { background: #f0fdf4; border-color: var(--accent-dk); color: #166534; }
.alert-danger  { background: #fff1f2; border-color: var(--danger);    color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: var(--warning);   color: #92400e; }
.alert-info    { background: #eff6ff; border-color: var(--info);      color: #1e40af; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .8rem; font-weight: 600;
                    margin-bottom: .35rem; color: var(--text); }
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  transition: border-color .15s;
  outline: none;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--accent-dk); box-shadow: 0 0 0 3px rgba(74,222,128,.15); }
.form-hint { font-size: .73rem; color: var(--muted); margin-top: .3rem; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn-primary  { background: var(--accent-dk); color: #fff; }
.btn-danger   { background: var(--danger);    color: #fff; }
.btn-secondary{ background: #e2e8f0;          color: var(--text); }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

/* ── API key box ──────────────────────────────────────────────── */
.api-key-box {
  font-family: monospace;
  font-size: .8rem;
  background: #0f172a;
  color: var(--accent);
  padding: .75rem 1rem;
  border-radius: var(--radius);
  word-break: break-all;
  margin: .5rem 0;
}
.code-block {
  font-family: monospace;
  font-size: .78rem;
  background: #0f172a;
  color: #94a3b8;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre;
  line-height: 1.6;
}
.code-block .kw  { color: #f472b6; }
.code-block .str { color: var(--accent); }
.code-block .cmt { color: #475569; }

/* ── Search bar ───────────────────────────────────────────────── */
.search-bar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search-bar input { flex: 1; padding: .5rem .75rem; border: 1px solid var(--border);
                    border-radius: var(--radius); font-size: .85rem; outline: none; }
.search-bar input:focus { border-color: var(--accent-dk); }

/* ── Date filter row ──────────────────────────────────────────── */
.filter-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filter-row .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }

/* ── Payload pills ────────────────────────────────────────────── */
.p-pill {
  display: inline-flex;
  align-items: center;
  gap: .28rem;
  background: #f1f5f9;
  border-radius: 99px;
  padding: .18rem .65rem .18rem .4rem;
  font-size: .78rem;
  margin: .15rem .15rem .15rem 0;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.p-icon { font-size: .85rem; line-height: 1; }
.p-lbl  { color: var(--muted); }
.p-val  { font-weight: 600; color: var(--text); margin-left: .1rem; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; }
  .main-content { margin-left: 0; padding: 1rem; }
  .stats-row { flex-direction: column; }
}
