/* Fatoura Admin Control Center v2 — design system.
   Stripe-clarity / Shopify-hierarchy / Linear-polish inspired, not a copy of any of them. */
:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e5e5e9;
  --border-strong: #d7d7dd;
  --text: #16161a;
  --text-2: #55555f;
  --text-3: #8a8a94;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-tint: #eef0fe;
  --good: #16a34a; --good-tint: #eafaf0;
  --bad: #dc2626; --bad-tint: #fdeeee;
  --warn: #d97706; --warn-tint: #fef3e6;
  --info: #2563eb; --info-tint: #eaf1fe;
  --neutral-tint: #f0f0f2;
  --c-free: #8a8a94; --c-starter: #2563eb; --c-pro: #4f46e5; --c-business: #d97706;
  --shadow-sm: 0 1px 2px rgba(20,20,30,.06);
  --shadow-md: 0 4px 16px rgba(20,20,30,.08);
  --shadow-lg: 0 12px 40px rgba(20,20,30,.14);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 244px;
  --topbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 13.5px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--primary-tint); }

/* ---- Boot / login / denied ---- */
#boot, #loginScreen, #deniedScreen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.hidden { display: none !important; }
.logo-mark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; color: var(--text); }
.logo-mark .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--primary); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; width: 360px; text-align: center; box-shadow: var(--shadow-md); }
.auth-card p { color: var(--text-2); margin: 8px 0 24px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #c31c1c; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn { background: transparent; border: none; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 6px; font-size: 13px; }
.icon-btn:hover { background: var(--neutral-tint); color: var(--text); }

/* ---- Shell layout ---- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 8px; padding: 18px 20px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border); }
.sidebar-nav { padding: 10px; flex: 1; }
.nav-section { margin-top: 16px; }
.nav-section:first-child { margin-top: 4px; }
.nav-section-label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); padding: 0 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-tint); color: var(--primary); font-weight: 600; }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: .8; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 20px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.search-trigger {
  flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-3); cursor: pointer; background: var(--surface-2);
}
.search-trigger kbd { margin-left: auto; font-size: 11px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 5px; color: var(--text-3); }
.topbar-spacer { flex: 1; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-tint); }
.live-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.admin-pill { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 20px; font-size: 12.5px; cursor: pointer; }
.admin-pill .avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--primary-tint); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 10.5px; }

.main-content { flex: 1; padding: 24px 28px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--text-2); font-size: 13px; margin: 0; }
.breadcrumbs { font-size: 12.5px; color: var(--text-3); margin-bottom: 6px; }
.breadcrumbs a:hover { color: var(--primary); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Cards / KPIs ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 18px 20px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 11.5px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi-value.muted { font-size: 13px; font-weight: 500; color: var(--text-3); }
.kpi-delta { font-size: 12px; margin-top: 4px; color: var(--text-3); }
.kpi-delta.good { color: var(--good); } .kpi-delta.bad { color: var(--bad); }

.section-title { font-size: 14px; font-weight: 700; margin: 26px 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.data-table thead th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: default; white-space: nowrap;
}
.data-table thead th.sortable { cursor: pointer; user-select: none; }
.data-table thead th.sortable:hover { color: var(--text); }
.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.cell-primary { font-weight: 600; }
.cell-sub { color: var(--text-3); font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }

.table-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.input { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px; background: var(--surface); color: var(--text); font-family: inherit; }
.input:focus { outline: 2px solid var(--primary-tint); border-color: var(--primary); }
select.input { cursor: pointer; }
.search-input { flex: 1; max-width: 280px; }
.filter-chip { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border); font-size: 12.5px; cursor: pointer; color: var(--text-2); background: var(--surface); }
.filter-chip.active { background: var(--primary-tint); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: 12.5px; color: var(--text-3); }

/* ---- Badges / chips ---- */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; }
.badge-good { background: var(--good-tint); color: var(--good); }
.badge-bad { background: var(--bad-tint); color: var(--bad); }
.badge-warn { background: var(--warn-tint); color: var(--warn); }
.badge-info { background: var(--info-tint); color: var(--info); }
.badge-neutral { background: var(--neutral-tint); color: var(--text-2); }
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; text-transform: capitalize; background: color-mix(in srgb, var(--chip-color) 14%, white); color: var(--chip-color); }

/* ---- Tabs (detail pages) ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab-btn { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--text-3); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-color: var(--primary); }

/* ---- Drawer / modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,20,30,.42); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 420px; max-width: 100%; box-shadow: var(--shadow-lg); }
.modal h3 { margin: 0 0 8px; font-size: 15px; }
.modal p { color: var(--text-2); font-size: 13px; margin: 0 0 10px; }
.danger-hint { font-size: 12.5px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin: 10px 0 5px; }
.modal .input { width: 100%; margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(20,20,30,.35); z-index: 90; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 92vw; background: var(--surface); box-shadow: var(--shadow-lg); z-index: 91; overflow-y: auto; padding: 22px; }

/* ---- Command palette ---- */
.cmdk-overlay { position: fixed; inset: 0; background: rgba(20,20,30,.42); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.cmdk-box { width: 560px; max-width: 92vw; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; }
.cmdk-input { width: 100%; border: none; border-bottom: 1px solid var(--border); padding: 16px 18px; font-size: 15px; outline: none; font-family: inherit; }
.cmdk-results { max-height: 50vh; overflow-y: auto; padding: 8px; }
.cmdk-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-3); padding: 8px 10px 4px; }
.cmdk-item { padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.cmdk-item:hover, .cmdk-item.sel { background: var(--primary-tint); }
.cmdk-item-sub { color: var(--text-3); font-size: 12px; }

/* ---- Toasts ---- */
#toastHost { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; opacity: 0; transform: translateY(6px); transition: all .2s; box-shadow: var(--shadow-md); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--bad); }
.toast-good { background: var(--good); }

/* ---- Alerts ---- */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer; }
.alert-item:hover { background: var(--surface-2); }
.alert-sev { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.alert-sev-critical { background: var(--bad); }
.alert-sev-warning { background: var(--warn); }
.alert-sev-info { background: var(--info); }
.alert-badge-count { position: absolute; top: 2px; right: 2px; background: var(--bad); color: #fff; font-size: 9.5px; font-weight: 700; border-radius: 10px; min-width: 15px; height: 15px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }

/* ---- Empty/error/skeleton states ---- */
.empty-state, .error-state { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty-state-title, .error-state-title { font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty-state-sub, .error-state-sub { font-size: 12.5px; margin-bottom: 12px; }
.skeleton-block { padding: 6px; }
.skeleton-row { height: 38px; border-radius: 6px; margin: 6px 0; background: linear-gradient(90deg, var(--surface-2) 25%, var(--neutral-tint) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---- Activity feed ---- */
.activity-item { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--text-3); }
.activity-main { flex: 1; }
.activity-time { color: var(--text-3); font-size: 11.5px; white-space: nowrap; }

/* ---- Misc ---- */
.text-muted { color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid.full { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.money { font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }

@media (max-width: 860px) {
  :root { --sidebar-w: 200px; }
  .main-content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
