/* ============================================================
   Accounts Admin — Design System
   ============================================================ */
:root {
  color-scheme: light;

  /* Surfaces (light, layered) */
  --bg:        #f4f3f9;
  --surface:   #ffffff;
  --surface-2: #f5f4fa;
  --elevated:  #ffffff;
  --hover:     #f2f1f9;

  /* Lines */
  --border:        #ecebf3;
  --border-strong: #dcdbe8;

  /* Text */
  --text:   #1b1d2a;
  --text-2: #5c5f72;
  --text-3: #9195a6;

  /* Brand + status */
  --brand:        #2563eb;
  --brand-hover:  #1d4fd0;
  --brand-ink:    #ffffff;
  --brand-soft:   rgba(37,99,235,0.12);
  --brand-ring:   rgba(37,99,235,0.30);

  --ok:      #22b07a;
  --ok-soft: rgba(34,176,122,0.12);
  --danger:  #ef5c6e;
  --danger-soft: rgba(239,92,110,0.12);
  --warn:    #e0982f;
  --warn-soft: rgba(224,152,47,0.14);

  /* Radii */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  /* Shadows (soft, light theme) */
  --shadow-sm: 0 1px 2px rgba(30,30,60,0.06);
  --shadow-md: 0 10px 28px -12px rgba(40,40,90,0.14);
  --shadow-lg: 0 24px 60px -20px rgba(40,40,90,0.20);

  /* Layout */
  --sidebar-w: 256px;
  --topbar-h: 60px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 85% -5%, rgba(37,99,235,0.07), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(37,99,235,0.04), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.only-mobile { display: none; }

/* ============================ Buttons ============================ */
.btn {
  --_bg: var(--surface-2); --_fg: var(--text); --_bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 500; line-height: 1;
  padding: 0 14px; height: 38px;
  border: 1px solid var(--_bd); border-radius: var(--r-sm);
  background: var(--_bg); color: var(--_fg);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s, opacity .15s;
}
.btn svg { flex: none; }
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }

.btn--primary { --_bg: var(--brand); --_fg: var(--brand-ink); --_bd: transparent; box-shadow: var(--shadow-sm); }
.btn--primary:hover { --_bg: var(--brand-hover); background: var(--brand-hover); }
.btn--ghost { --_bg: transparent; --_bd: var(--border); }
.btn--danger { --_bg: var(--danger-soft); --_fg: var(--danger); --_bd: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
.btn--lg { height: 44px; font-size: 15px; }
.btn--sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--r-xs); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }

/* ============================ Inputs ============================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0 12px; height: 40px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { height: auto; padding: 10px 12px; }
input::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
input[type="search"] { -webkit-appearance: none; }
select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f788d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px;
}

/* ============================ Brand ============================ */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  color: #fff; border-radius: 9px;
  background: linear-gradient(145deg, #4f86f0, var(--brand));
  box-shadow: var(--shadow-sm);
}
.brand-name { font-size: 15px; }

/* ============================ Auth ============================ */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(37,99,235,0.08), transparent 60%),
    var(--bg);
}
.auth-panel { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.auth-card {
  width: 100%; display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 28px; box-shadow: var(--shadow-lg);
}
.brand--auth { margin-bottom: 4px; }
.auth-card h1 { font-size: 22px; margin-top: 2px; }
.auth-card .muted { margin: -8px 0 6px; }
.auth-foot { font-size: 12.5px; }

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

.sidebar {
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100dvh;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; height: var(--topbar-h); }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left; font: inherit; font-weight: 500;
  padding: 9px 12px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .14s, color .14s;
}
.nav-item svg { flex: none; opacity: .85; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--text); }
.nav-item.active svg { color: var(--brand); opacity: 1; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 4px 4px 2px; min-width: 0; }
.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: var(--r-full); font-weight: 600; color: #fff; text-transform: uppercase;
  background: linear-gradient(145deg, #4f86f0, var(--brand));
}
.user-meta { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.drawer-overlay { display: none; }

/* ============================ Main ============================ */
.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; }
.content { padding: 24px; display: flex; flex-direction: column; gap: 20px; max-width: 1360px; width: 100%; }

/* ============================ KPI cards ============================ */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-md);
}
.kpi-icon {
  display: grid; place-items: center; width: 46px; height: 46px;
  border-radius: 14px; color: var(--brand);
  background: var(--brand-soft); border: 1px solid var(--border);
}
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 2px; }
.kpi-label { font-size: 13px; color: var(--text-3); font-weight: 500; }

/* ============================ Charts ============================ */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card { padding: 20px; box-shadow: var(--shadow-md); }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.chart-head h2 { font-size: 15px; }
.chart-head p { margin: 2px 0 0; font-size: 12.5px; }
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 12px; }
.bar-name { font-size: 12.5px; color: var(--text-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; }
.bar-fill {
  height: 100%; border-radius: var(--r-full); min-width: 6px;
  background: linear-gradient(90deg, #6ea0f5, var(--brand));
  transition: width .5s cubic-bezier(.2,.8,.2,1);
}
.bar-val { font-size: 13px; font-weight: 600; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.bars .empty-state { padding: 20px; }

/* ============================ Panel ============================ */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.toolbar-title h2 { font-size: 16px; }
.toolbar-title p { margin: 2px 0 0; font-size: 12.5px; }
.toolbar-actions { display: flex; gap: 8px; margin-left: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-select {
  height: 40px; min-width: 130px; max-width: 190px; font-size: 13px;
  color: var(--text-2); font-weight: 500;
  background-color: var(--surface);
  border-color: var(--border);
  cursor: pointer;
}
.filter-select:hover { border-color: var(--border-strong); background-color: var(--hover); }
.filter-select:focus { color: var(--text); }
.search { position: relative; flex: 1; min-width: 180px; max-width: 360px; display: flex; align-items: center; }

/* Status toggle switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch.readonly { cursor: default; }
.switch-track {
  position: relative; width: 38px; height: 22px; flex: none;
  background: var(--danger-soft); border: 1px solid var(--border-strong); border-radius: 999px;
  transition: background .18s, border-color .18s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: var(--danger); border-radius: 50%; transition: transform .18s, background .18s;
}
.switch.on .switch-track { background: var(--ok-soft); border-color: transparent; }
.switch.on .switch-track::after { transform: translateX(16px); background: var(--ok); }
.switch.busy { opacity: .5; pointer-events: none; }
.switch-label { font-size: 12.5px; color: var(--text-2); min-width: 54px; }
.search svg { position: absolute; left: 12px; color: var(--text-3); pointer-events: none; }
.search input { padding-left: 36px; height: 40px; }

/* ============================ Table ============================ */
.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; white-space: nowrap; }
.table th, .table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-3);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td { font-variant-numeric: tabular-nums; }
.col-actions { text-align: right; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 500; line-height: 1.3;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.yes { background: var(--ok-soft); color: var(--ok); }
.pill.no  { background: var(--danger-soft); color: var(--danger); }
.secret { color: var(--text-3); font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; letter-spacing: 1px; }

.cell-actions { display: inline-flex; gap: 6px; justify-content: flex-end; width: 100%; }

/* Empty + loading states */
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-3); }
.empty-state svg { color: var(--text-3); opacity: .5; margin-bottom: 10px; }
.empty-state h3 { font-size: 15px; color: var(--text-2); font-weight: 600; }
.empty-state p { margin: 4px 0 0; font-size: 13px; }

.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-xs); height: 12px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.05), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

.status-line { padding: 10px 16px; font-size: 12.5px; color: var(--text-3); border-top: 1px solid var(--border); min-height: 38px; display: flex; align-items: center; }
.status-line.ok { color: var(--ok); }
.status-line.err { color: var(--danger); }
.status-line:empty { display: none; }

/* ============================ Modal ============================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 20px;
  background: rgba(5,7,12,0.6); backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
.modal {
  width: min(560px, 100%); max-height: 88dvh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: pop .16s cubic-bezier(.2,.8,.2,1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }

.form-error { color: var(--danger); font-size: 13px; min-height: 0; margin: 0; padding: 0 20px; }
.form-error:not(:empty) { padding-bottom: 8px; }
.auth-card .form-error, .modal-body + .form-error { padding: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.perm-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.perm-list label {
  flex-direction: row; align-items: center; gap: 10px; color: var(--text);
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-weight: 450; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.perm-list label:hover { background: var(--hover); }
.perm-list input[type="checkbox"] { width: 16px; height: 16px; flex: none; accent-color: var(--brand); cursor: pointer; }

/* ============================ Toasts ============================ */
.toast-root { position: fixed; z-index: 90; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 36px); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 380px; padding: 12px 14px;
  background: var(--elevated); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--brand); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); color: var(--text); font-size: 13px;
  animation: toast-in .2s cubic-bezier(.2,.8,.2,1);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.leaving { animation: toast-out .2s ease forwards; }
.toast svg { flex: none; margin-top: 1px; }
.toast.ok svg { color: var(--ok); } .toast.err svg { color: var(--danger); }
.toast-msg { word-break: break-word; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ============================ Responsive ============================ */
@media (max-width: 1024px) {
  .kpi-value { font-size: 26px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  .only-mobile { display: inline-flex; }
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 70;
    width: 272px; height: 100dvh;
    transform: translateX(-100%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
    box-shadow: var(--shadow-lg);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .drawer-overlay {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(5,7,12,0.55); backdrop-filter: blur(2px); animation: fade .2s;
  }
  .content { padding: 16px; gap: 16px; }
  .topbar { padding: 0 14px; }
}

@media (max-width: 640px) {
  .kpi-row { grid-template-columns: 1fr; }
  .toolbar { gap: 10px; }
  .search { max-width: none; flex: 1 1 100%; order: 2; }
  .filters { width: 100%; order: 3; }
  .filter-select { flex: 1 1 42%; min-width: 0; max-width: none; }
  .toolbar-actions { margin-left: 0; width: 100%; order: 1; }
  .toolbar-actions .btn { flex: 1; }
  .toolbar-title { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-foot .btn { flex: 1; }
}

@media (max-width: 380px) {
  .content { padding: 12px; }
  .btn span { font-size: 13px; }
}
