:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --sidebar-bg: #fbfbfb;
  --text: #0a0a0a;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --black: #111827;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #c2410c;
  --warn-soft: #fff7ed;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Auth pages ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }

.brand-icon {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-icon svg { width: 20px; height: 20px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--text-muted); line-height: 1.2; }

.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card .sub { font-size: 13.5px; color: var(--text-muted); margin: 0 0 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-subtle); outline: none; transition: border-color .15s ease, background .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); background: var(--bg); }
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.field .error { font-size: 12.5px; color: var(--danger); margin-top: 5px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }

.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px; }
.alert-error { background: var(--danger-soft); color: #991b1b; }
.alert-success { background: var(--accent-soft); color: #0f5f57; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Buttons ---------- */

.btn {
  border: none; border-radius: 999px; padding: 10px 18px; font-size: 13.5px; font-weight: 650;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .1s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--black); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #000; }
.btn-outline { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-faint); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 13px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- App shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; }
.sidebar-nav { flex: 1; padding: 8px 12px; overflow-y: auto; }

.nav-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding: 16px 12px 6px; }

.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 550; color: var(--text-muted); margin-bottom: 2px;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: var(--border); color: var(--text); }
.nav-link.active { background: var(--black); color: #fff; }

.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 650; line-height: 1.3; }
.user-role { font-size: 11.5px; color: var(--text-muted); text-transform: capitalize; }

.main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 32px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px); z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.content { padding: 28px 32px 64px; max-width: 1180px; }

/* ---------- Cards / stats ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; background: var(--bg); }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.panel { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); margin-bottom: 24px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 22px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
  font-weight: 650; padding: 10px 22px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 13px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-subtle); }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; text-transform: capitalize;
}
.badge-teal { background: var(--accent-soft); color: #0f5f57; }
.badge-gray { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: #991b1b; }

.empty-row td { text-align: center; color: var(--text-faint); padding: 40px 20px; }

/* ---------- Misc ---------- */

.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.search-input {
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-subtle);
  font-size: 13.5px; min-width: 220px; outline: none;
}
.search-input:focus { border-color: var(--accent); background: var(--bg); }

.ai-panel { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius-md); padding: 16px; margin-top: 10px; }
.ai-panel-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #0f5f57; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,10,10,.35); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: var(--bg); border-radius: var(--radius-lg); max-width: 480px; width: 100%; box-shadow: var(--shadow-md); max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 15px; margin: 0; }
.modal-body { padding: 22px; }
.modal-close { border: none; background: var(--bg-subtle); width: 28px; height: 28px; border-radius: 999px; cursor: pointer; color: var(--text-muted); }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .content, .topbar { padding-left: 20px; padding-right: 20px; }
}
