@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Syne:wght@400;600;700;800&display=swap');

:root {
  --bg:          #0a0c0f;
  --bg2:         #0f1318;
  --bg3:         #141920;
  --border:      #1e2730;
  --border2:     #2a3540;
  --text:        #e8edf2;
  --text-muted:  #5a6a78;
  --text-dim:    #3a4a58;
  --accent:      #00e5ff;
  --accent-dim:  rgba(0,229,255,0.12);
  --accent-glow: rgba(0,229,255,0.3);
  --success:     #00e676;
  --danger:      #ff3d57;
  --warn:        #ffb300;
  --sidebar-w:   240px;
  --radius:      8px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text);
}

.brand-sub {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s;
  position: relative;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon { font-size: 16px; }

.notif-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  display: none;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.mqtt-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.3s;
}

.dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.offline { background: var(--danger); }
.dot.connecting { background: var(--warn); animation: blink 1s infinite; }

@keyframes blink { 50% { opacity: 0.3; } }

/* ── Main ────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

.page-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.device-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
}

.device-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.device-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.device-dot.offline { background: var(--danger); }

.btn-ping {
  padding: 7px 16px;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
}

.btn-ping:hover { border-color: var(--accent); color: var(--accent); }

/* ── Content / Pages ─────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.page { display: none; }
.page.active { display: block; }

/* ── Stats ───────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--text-dim);
}

.stat-card.accent::after { background: var(--accent); }
.stat-card.danger::after { background: var(--danger); }

.stat-card:hover { border-color: var(--border2); }

.stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  margin-bottom: 6px;
}

.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.danger .stat-value { color: var(--danger); }

.stat-sub {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Cards ───────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card.mt { margin-top: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.card-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

/* ── Live Status ─────────────────────────────── */
.live-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  gap: 12px;
  min-height: 220px;
}

.fingerprint-anim {
  width: 90px; height: 90px;
  position: relative;
}

.fingerprint-anim svg { width: 100%; height: 100%; }

.fp-line {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: draw 2s ease-in-out infinite;
}

@keyframes draw {
  0% { stroke-dashoffset: 60; }
  50% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -60; }
}

.live-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.live-sub {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.fingerprint-anim.granted { filter: drop-shadow(0 0 12px var(--success)); }
.fingerprint-anim.denied { filter: drop-shadow(0 0 12px var(--danger)); }

.pulse-ring {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: pulse 1.5s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--accent-glow); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Mini Log ────────────────────────────────── */
.mini-log { padding: 8px 0; }

.mini-log-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  transition: background 0.15s;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.mini-log-item:last-child { border-bottom: none; }
.mini-log-item:hover { background: var(--bg3); }

.log-status {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.log-status.granted { background: var(--success); }
.log-status.denied { background: var(--danger); }

.log-name { font-weight: 700; flex: 1; }
.log-time { font-family: 'Space Mono', monospace; font-size: 10px; color: var(--text-muted); }

/* ── Device Info Grid ────────────────────────── */
.device-info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}

.info-item {
  padding: 18px 20px;
  border-right: 1px solid var(--border);
}

.info-item:last-child { border-right: none; }

.info-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.info-val {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: var(--accent);
}

/* ── Log Table ───────────────────────────────── */
.table-wrap { overflow-x: auto; }

.log-table {
  width: 100%;
  border-collapse: collapse;
}

.log-table th {
  padding: 12px 20px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.log-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.log-table tbody tr:hover { background: var(--bg3); }
.log-table tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'Space Mono', monospace;
}

.badge.granted { background: rgba(0,230,118,0.12); color: var(--success); }
.badge.denied { background: rgba(255,61,87,0.12); color: var(--danger); }

/* ── Filter Buttons ──────────────────────────── */
.filter-group { display: flex; gap: 4px; }

.filter-btn {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'Syne', sans-serif;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.15s;
}

.filter-btn.active, .filter-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Users ───────────────────────────────────── */
.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 20px;
}

.user-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: border-color 0.2s;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-card:hover { border-color: var(--border2); }

.user-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
}

.user-name { font-weight: 700; font-size: 14px; }

.user-meta {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.user-role {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  width: fit-content;
}

.user-role.admin { border-color: var(--accent); color: var(--accent); }

.btn-del {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
  transition: color 0.15s;
}

.btn-del:hover { color: var(--danger); }

/* ── Add User Form ───────────────────────────── */
.add-user-form {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }

.form-actions { display: flex; gap: 8px; }

.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

/* ── Notifications ───────────────────────────── */
.notif-list { padding: 8px 0; }

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}

.notif-item:last-child { border-bottom: none; }

.notif-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.notif-dot.success { background: var(--success); box-shadow: 0 0 6px var(--success); }
.notif-dot.danger { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.notif-dot.info { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

.notif-msg { font-size: 13px; font-weight: 600; flex: 1; }

.notif-time {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Empty / Utils ───────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: 'Space Mono', monospace;
}

/* ── Toast ───────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  animation: toastIn 0.3s ease;
  border-left: 3px solid;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.success { background: rgba(0,230,118,0.12); border-color: var(--success); color: var(--success); }
.toast.danger  { background: rgba(255,61,87,0.12);  border-color: var(--danger);  color: var(--danger); }
.toast.info    { background: var(--accent-dim);      border-color: var(--accent);  color: var(--accent); }

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Responsive / Mobile ─────────────────────── */

/* Tablet (max 1024px) */
@media (max-width: 1024px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .device-info-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .info-item:nth-child(2) { border-right: none; }
  .info-item:nth-child(3) { border-right: 1px solid var(--border); }
  .info-item:nth-child(3),
  .info-item:nth-child(4) { border-top: 1px solid var(--border); }
}

/* Mobile (max 768px) */
@media (max-width: 768px) {

  /* Sidebar jadi bottom nav */
  :root { --sidebar-w: 0px; }

  html, body { overflow: hidden; }

  .sidebar {
    width: 100%;
    height: 60px;
    top: auto;
    bottom: 0;
    left: 0;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 200;
  }

  .sidebar-brand { display: none; }
  .sidebar-footer { display: none; }

  .sidebar-nav {
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 0;
    flex: 1;
    gap: 0;
  }

  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    font-size: 10px;
    border-radius: 0;
    flex: 1;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  .nav-item.active::before { display: none; }

  .nav-item.active {
    background: transparent;
    border-top: 2px solid var(--accent);
    color: var(--accent);
  }

  .nav-icon { font-size: 18px; }

  .notif-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
  }

  /* Main content */
  .main {
    margin-left: 0;
    margin-bottom: 60px;
    height: calc(100% - 60px);
  }

  /* Topbar */
  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-title { font-size: 16px; }

  .topbar-right { gap: 8px; }

  .device-pill { font-size: 10px; padding: 5px 10px; }

  .btn-ping {
    font-size: 11px;
    padding: 6px 12px;
  }

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

  /* Stats: 2 kolom di mobile */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }

  .stat-value { font-size: 28px; }

  /* Two col jadi satu kolom */
  .two-col {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Device info grid */
  .device-info-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .info-item {
    padding: 14px 16px;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }

  .info-item:nth-child(odd) { border-right: 1px solid var(--border) !important; }
  .info-item:last-child,
  .info-item:nth-last-child(2):nth-child(odd) { border-bottom: none; }

  /* Log table scroll horizontal */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .log-table { min-width: 480px; }

  .log-table th,
  .log-table td { padding: 10px 14px; font-size: 12px; }

  /* User grid */
  .user-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 14px;
  }

  /* Add user form */
  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .add-user-form { padding: 14px; }

  /* Card header */
  .card-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .filter-group { width: 100%; }
  .filter-btn { flex: 1; text-align: center; }

  /* Live status */
  .live-status { padding: 20px; min-height: 180px; }

  .fingerprint-anim { width: 70px; height: 70px; }

  /* Toast */
  .toast-container {
    bottom: 70px;
    right: 12px;
    left: 12px;
  }

  .toast { min-width: unset; width: 100%; }

  /* Notif list */
  .notif-item { padding: 12px 16px; gap: 10px; }

  /* Mini log */
  .mini-log-item { padding: 10px 16px; }
}

/* Small mobile (max 400px) */
@media (max-width: 400px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 24px; }
  .user-grid { grid-template-columns: 1fr; }
  .nav-item { font-size: 9px; padding: 8px 6px; }
}