:root {
  --navy:   #0B1B3A;
  --navy-soft: #33415C;
  --blue:   #1D4ED8;
  --blue-deep: #14306B;
  --blue-bg: #EEF3FE;
  --gold:   #B8860B;
  --green:  #16A34A;
  --green-bg: #E9F8EF;
  --red:    #DC2626;
  --red-bg: #FDEEEE;
  --amber:  #B45309;
  --amber-bg: #FEF3E2;
  --paper:  #F7F8FA;
  --card:   #FFFFFF;
  --line:   #E3E6EC;
  --muted:  #667085;

  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--navy);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
:focus-visible { outline: 2.5px solid var(--blue); outline-offset: 2px; }

/* =========================================================================
   BUTTONS
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 14px; padding: 10px 18px;
  border-radius: 8px; border: 1.5px solid transparent; cursor: pointer;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--navy); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: default; }

/* =========================================================================
   LOGIN
   ========================================================================= */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 36px 32px; text-align: center;
  box-shadow: 0 20px 50px -20px rgba(11,27,58,.15);
}
.login-mark { border-radius: 9px; margin-bottom: 14px; }
.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 8px;
  margin-bottom: 14px; font-size: 14px;
}
.login-card .btn { width: 100%; justify-content: center; }
.login-err { color: var(--red); font-size: 13px; margin: 14px 0 0; }
.login-note { color: var(--muted); font-size: 12px; margin: 18px 0 0; }

/* =========================================================================
   SHELL
   ========================================================================= */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  background: var(--navy); color: #fff; padding: 22px 16px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  width: 232px; flex: 0 0 232px;
}
.side-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; padding: 0 8px 26px; }
.side-brand img { border-radius: 7px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a {
  color: rgba(255,255,255,.68); text-decoration: none; font-size: 14px; font-weight: 500;
  padding: 10px 12px; border-radius: 8px; transition: background .15s ease, color .15s ease;
}
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.side-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12); }
.env-tag { font-family: var(--font-mono); font-size: 10.5px; color: rgba(255,255,255,.4); word-break: break-all; padding: 0 8px; }
.side-foot .btn-ghost { border-color: rgba(255,255,255,.25); color: #fff; }
.side-foot .btn-ghost:hover { border-color: #fff; }

.main { padding: 28px 36px 60px; max-width: 1080px; flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.topbar h1 { font-size: 24px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.toast {
  font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 999px;
  background: var(--green-bg); color: var(--green);
}
.toast.err { background: var(--red-bg); color: var(--red); }

.view { display: flex; flex-direction: column; gap: 22px; }

/* =========================================================================
   STAT GRID
   ========================================================================= */
.stat-grid { display: flex; flex-wrap: wrap; gap: 14px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; flex: 1 1 160px; min-width: 160px; }
.stat-card .n { font-family: var(--font-mono); font-size: 26px; font-weight: 600; display: block; }
.stat-card .l { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: block; }

/* =========================================================================
   PANELS
   ========================================================================= */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush .table { margin: 0; }
.panel h2 { font-size: 16px; font-weight: 700; }
.panel-desc { font-size: 13px; color: var(--muted); margin: 5px 0 0; }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.panel-danger { border-color: #F3D9D9; }

/* =========================================================================
   FIELDS
   ========================================================================= */
.field { margin-top: 16px; display: flex; flex-direction: column; gap: 7px; }
.field:first-child { margin-top: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--navy-soft); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 8px; width: 100%; background: #fff;
}
.field textarea { resize: vertical; font-family: inherit; }
.field-actions { display: flex; gap: 10px; }
.field-row { flex-direction: row; align-items: center; }
.field-row input { flex: 1; }
.field-grid { display: flex; gap: 14px; margin-top: 16px; }
.field-grid .field { flex: 1; min-width: 0; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: var(--line); border-radius: 999px; cursor: pointer;
  transition: background .15s ease;
}
.switch-track::before {
  content: ''; position: absolute; width: 19px; height: 19px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s ease; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::before { transform: translateX(19px); }
.panel-danger .switch input:checked + .switch-track { background: var(--red); }

/* =========================================================================
   TOOLBAR (users page)
   ========================================================================= */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar input[type=search] {
  flex: 1; min-width: 220px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 8px;
}
.toolbar select { padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; }
.spacer { flex: 1; }

/* =========================================================================
   TABLES
   ========================================================================= */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(29,78,216,.03); }
.table .mono { font-family: var(--font-mono); font-size: 12.5px; }
.table-empty { padding: 30px; text-align: center; color: var(--muted); font-size: 13.5px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-banned { background: var(--red-bg); color: var(--red); }
.badge-muted { background: var(--amber-bg); color: var(--amber); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.pager { display: flex; justify-content: center; gap: 10px; }

/* =========================================================================
   MODALS
   ========================================================================= */
.modal-backdrop {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(11,27,58,.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100;
}
.modal {
  background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 460px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 30px 70px -20px rgba(11,27,58,.35);
}
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.device-list { display: flex; flex-direction: column; gap: 6px; }
.device-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; background: var(--paper); border-radius: 7px; font-size: 12.5px;
}
.device-row .mono { color: var(--muted); }
.device-empty { font-size: 13px; color: var(--muted); padding: 8px 0; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; width: 100%; flex: 0 0 auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 20px; }
  .field-grid { flex-direction: column; }
}
