/* ---------------------------------------------------------------------
   Design tokens
--------------------------------------------------------------------- */
:root {
  --bg: #10161c;
  --bg-dotted: radial-gradient(rgba(143, 160, 172, 0.08) 1px, transparent 1px);
  --surface: #161d24;
  --surface-raised: #1c242c;
  --border: #262f38;
  --border-strong: #333e48;

  --text-primary: #e7edf2;
  --text-secondary: #8fa0ac;
  --text-muted: #5c6b76;

  --accent: #f2a93b;
  --accent-hover: #ffc266;
  --accent-ink: #241a05;

  --success: #3ecf8e;
  --success-bg: rgba(62, 207, 142, 0.12);
  --danger: #ef5b4e;
  --danger-bg: rgba(239, 91, 78, 0.12);
  --warning: #f2c94c;
  --warning-bg: rgba(242, 201, 76, 0.12);

  --radius: 8px;
  --radius-sm: 5px;
  --sidebar-w: 244px;

  --font-ui: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px 0;
}

.font-mono { font-family: var(--font-mono); font-size: 0.92em; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Shell layout
--------------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.sidebar__brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}

.sidebar__brand-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  position: relative;
}

.status-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0.35;
  animation: pulse 2s ease-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .status-dot::after { animation: none; }
}

@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.45; }
  100% { transform: scale(2.1); opacity: 0; }
}

.sidebar__status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px 16px 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-left: 2px solid transparent;
}

.nav-link svg { flex-shrink: 0; opacity: 0.85; }

.nav-link:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--surface-raised);
  color: var(--text-primary);
  border-left: 2px solid var(--accent);
}

.sidebar__footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 10px;
}

.sidebar__admin {
  padding: 0 8px;
  margin-bottom: 10px;
}

.sidebar__admin-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar__admin-role {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.sidebar__logout {
  display: block;
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}

.sidebar__logout:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---------------------------------------------------------------------
   Main area
--------------------------------------------------------------------- */
.main {
  background-image: var(--bg-dotted);
  background-size: 22px 22px;
  min-height: 100vh;
}

.main__inner {
  max-width: 1120px;
  padding: 32px 40px 60px 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.topbar__title { font-size: 22px; }

.topbar__subtitle {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin-top: 2px;
}

/* ---------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.2;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn--primary:hover { background: var(--accent-hover); }

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.btn--ghost:hover { background: var(--surface-raised); }

.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn--danger:hover { background: var(--danger-bg); }

.btn--success {
  background: transparent;
  border-color: var(--success);
  color: var(--success);
}
.btn--success:hover { background: var(--success-bg); }

.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; }

/* ---------------------------------------------------------------------
   Panels
--------------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.panel__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel__header h3 { font-size: 15px; }
.panel__body { padding: 20px; }
.panel__body--flush { padding: 0; }

/* ---------------------------------------------------------------------
   Stats
--------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card--success { border-left-color: var(--success); }
.stat-card--danger { border-left-color: var(--danger); }

.stat-card__value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--text-primary);
}

.stat-card__label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

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

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

thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-raised); }

.cell-secondary { color: var(--text-secondary); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------------------------------------------------------------
   Badges
--------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge--active { background: var(--success-bg); color: var(--success); }
.badge--active::before { background: var(--success); }

.badge--blocked { background: var(--danger-bg); color: var(--danger); }
.badge--blocked::before { background: var(--danger); }

.badge--role { background: var(--surface-raised); color: var(--text-secondary); }
.badge--role::before { background: var(--text-secondary); }

/* ---------------------------------------------------------------------
   Forms
--------------------------------------------------------------------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 10px 12px;
}

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

input::placeholder, textarea::placeholder { color: var(--text-muted); }

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

select { appearance: none; cursor: pointer; }

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

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.checkbox-cell { text-align: center; }

/* ---------------------------------------------------------------------
   Search bar
--------------------------------------------------------------------- */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-bar input[type="search"] { flex: 1; min-width: 220px; }
.search-bar select { width: auto; min-width: 140px; }

/* ---------------------------------------------------------------------
   Alerts / flash messages
--------------------------------------------------------------------- */
.alert-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.alert {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  border: 1px solid transparent;
}

.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(62,207,142,0.3); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(239,91,78,0.3); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(242,201,76,0.3); }

/* ---------------------------------------------------------------------
   Empty state
--------------------------------------------------------------------- */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ---------------------------------------------------------------------
   Login page
--------------------------------------------------------------------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: var(--bg-dotted);
  background-size: 22px 22px;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-card h1 { font-size: 17px; }
.login-card__sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 22px; }

/* ---------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------- */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px 16px;
  }
  .sidebar__brand { border-bottom: none; padding-bottom: 0; margin-bottom: 0; margin-right: 10px; }
  .sidebar__status-row { display: none; }
  .sidebar__nav { flex-direction: row; }
  .sidebar__footer { display: none; }
  .main__inner { padding: 22px 18px 40px 18px; }
  .form-grid { grid-template-columns: 1fr; }
}
