:root {
  --background: #f5f5f7;
  --surface: #ffffff;
  --foreground: #1d1d1f;
  --muted: #6e6e73;
  --border: #e5e5ea;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #d70015;
  --success: #1a7f37;
  --radius: 14px;
  --overlay-track: rgba(0, 0, 0, 0.04);
  --overlay-hover: rgba(0, 0, 0, 0.03);
  --overlay-weak: rgba(0, 0, 0, 0.05);
  --overlay-strong: rgba(0, 0, 0, 0.08);
  --pill: #ffffff;
  --card-shadow: none;
  --brand: #1d1d1f;
}

html[data-theme="dark"] {
  --background: #000000;
  --surface: #232326;
  --foreground: #f5f5f7;
  --muted: #a1a1a6;
  --border: #48484c;
  --accent: #0a84ff;
  --accent-hover: #3a9bff;
  --danger: #ff453a;
  --success: #32d74b;
  --overlay-track: rgba(255, 255, 255, 0.06);
  --overlay-hover: rgba(255, 255, 255, 0.05);
  --overlay-weak: rgba(255, 255, 255, 0.08);
  --overlay-strong: rgba(255, 255, 255, 0.12);
  --pill: #38383a;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.02);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; padding: 32px; max-width: 1100px; margin: 0 auto; width: 100%; }
.stack { display: flex; flex-direction: column; }
.g-4 { gap: 4px; } .g-8 { gap: 8px; } .g-12 { gap: 12px; } .g-16 { gap: 16px; } .g-24 { gap: 24px; }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.section { margin-bottom: 32px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.text-sm { font-size: 13px; } .text-xs { font-size: 12px; }
.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.font-semibold { font-weight: 600; }
.title { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.subtitle { font-size: 14px; color: var(--muted); margin-top: 4px; }
.max-w-sm { max-width: 380px; } .max-w-md { max-width: 520px; } .max-w-lg { max-width: 680px; } .max-w-xl { max-width: 860px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 700px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } .main { padding: 16px; } }

/* ---- Sidebar ---- */
.sidebar { width: 240px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; }
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 10px; }
.sidebar-logo { height: 32px; width: 32px; border-radius: 10px; background: var(--brand); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-nav { flex: 1; padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--muted); }
.nav-link:hover { background: var(--overlay-hover); color: var(--foreground); }
.nav-link.active { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }
.sidebar-footer { padding: 8px 12px 16px; border-top: 1px solid var(--border); }
.sidebar-email { padding: 8px 12px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-btn { height: 32px; width: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: none; border: none; cursor: pointer; color: var(--muted); margin-left: auto; }
.theme-btn:hover { background: var(--overlay-hover); }

/* ---- Card / surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--card-shadow); }
.card-pad { padding: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--card-shadow); }
.stat-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-size: 30px; font-weight: 600; letter-spacing: -0.01em; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 980px; padding: 9px 18px; font-size: 14px; font-weight: 500; border: none; cursor: pointer; text-decoration: none; white-space: nowrap; font-family: inherit; transition: background-color .15s ease, opacity .15s ease; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--overlay-weak); color: var(--foreground); }
.btn-secondary:hover:not(:disabled) { background: var(--overlay-strong); }
.btn-danger { background: rgba(215,0,21,.1); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(215,0,21,.17); }
.btn-block { width: 100%; }
.btn-xs { padding: 6px 12px; font-size: 12px; }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; display: block; }
.field-input, .field-select, .field-textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
  font-size: 14px; background: var(--surface); color: var(--foreground); font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field-input:focus, .field-select:focus, .field-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,132,255,.2); }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* ---- Badge ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 980px; padding: 3px 10px; font-size: 12px; font-weight: 500; border: none; cursor: pointer; font-family: inherit; }
.badge-active { background: rgba(26,127,55,.14); color: var(--success); }
.badge-inactive { background: var(--overlay-strong); color: var(--muted); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead tr { border-bottom: 1px solid var(--border); text-align: left; color: var(--muted); }
th { padding: 10px 18px; font-weight: 500; font-size: 13px; }
td { padding: 10px 18px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--overlay-hover); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

/* ---- Pill toggle ---- */
.pill-group { display: inline-flex; gap: 4px; background: var(--overlay-track); border-radius: 980px; padding: 4px; }
.pill-item { padding: 7px 16px; border-radius: 980px; font-size: 13px; font-weight: 500; color: var(--muted); border: none; background: none; cursor: pointer; font-family: inherit; }
.pill-item.active { background: var(--pill); color: var(--foreground); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

/* ---- QR preview ---- */
.qr-frame { background: #fff; border-radius: 10px; padding: 12px; border: 1px solid var(--border); }
html[data-theme="dark"] .qr-frame.qr-frame-invert { background: #000; }

/* ---- Misc ---- */
.alert { border-radius: 10px; padding: 12px 16px; font-size: 14px; }
.alert-info { background: color-mix(in srgb, var(--accent) 8%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent); }
.divider { border-top: 1px solid var(--border); margin: 16px 0; }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
