:root {
  --bg: #0b1020;
  --surface: #12192e;
  --surface-2: #192340;
  --border: #253257;
  --text: #e6ecf8;
  --muted: #93a4c8;
  --primary: #4f7cff;
  --primary-hover: #3e6bf5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #172347 0%, var(--bg) 60%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.auth-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

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

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4f7cff, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
}

.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.bot-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  margin-bottom: 14px;
  font-size: 12px;
}

.bot-pill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.dot-on { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot-off { background: var(--danger); }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 140ms ease, color 140ms ease;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: rgba(79, 124, 255, 0.16); color: #8cb0ff; font-weight: 600; }

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Main Content */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 25, 46, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.menu-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}

.page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.content {
  padding: 20px 22px 40px;
  max-width: 1320px;
  width: 100%;
}

/* Cards & Grids */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

/* Forms & Buttons */
.form-group { margin-bottom: 12px; }
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

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

textarea {
  resize: vertical;
  min-height: 90px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 120ms ease, background 120ms ease;
}
.btn:hover { background: #223055; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.4); color: #4ade80; }
.btn-success:hover { background: rgba(34, 197, 94, 0.28); }
.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #f87171; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

tr:hover td { background: rgba(255, 255, 255, 0.02); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.badge-yellow { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
.badge-red { background: rgba(239, 68, 68, 0.16); color: #f87171; }
.badge-blue { background: rgba(79, 124, 255, 0.18); color: #8cb0ff; }
.badge-gray { background: rgba(148, 163, 184, 0.15); color: #cbd5e1; }

/* Code box */
.code-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  word-break: break-all;
  white-space: pre-wrap;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Toast */
#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 80;
  max-width: 380px;
}

.qr-preview {
  max-width: 220px;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  display: block;
}

.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.flex-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

@media (max-width: 980px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    z-index: 50;
    transition: left 180ms ease;
  }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-4 { grid-template-columns: 1fr; }
}
