* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; font-family: var(--font-sans); color: var(--color-text);
    background: var(--color-bg-gradient), var(--color-bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }
svg { display: block; }

/* Accessible, visible focus ring everywhere — never remove without a replacement */
:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}
button, [role="button"], .nav-item, a { cursor: pointer; }

/* ── App shell ────────────────────────────────────────────────────────────── */
.saas-shell { display: flex; min-height: 100vh; }
.saas-sidebar {
    width: var(--sidebar-width); background: var(--color-sidebar-bg);
    -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--color-sidebar-border);
    display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; overflow-y: auto;
    flex-shrink: 0; transition: transform var(--transition-slow); z-index: 200;
}
.sidebar-header { padding: var(--space-6) var(--space-5) var(--space-4); }
.sidebar-logo {
    display: flex; align-items: center; gap: var(--space-2); text-decoration: none;
    color: #fff; font-weight: 800; font-size: var(--text-lg); letter-spacing: -.01em;
}
.logo-img { height: 52px; width: auto; display: block; }
.logo-img-lg { height: 80px; width: auto; display: block; }
.sidebar-nav { flex: 1; padding: var(--space-2) var(--space-3); }
.nav-group { margin-bottom: var(--space-5); }
/* Permission-gated nav groups: hidden by default so there's no flash of a
   super-admin/role-gated section before applyPermissionVisibility() runs —
   JS explicitly reveals these for users who qualify, it never needs to hide
   them (that's already the resting state). */
[data-requires-permission], [data-requires-super-admin] { display: none; }
.nav-group-label {
    display: block; padding: var(--space-2) var(--space-3); font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em; color: var(--color-sidebar-text); opacity: .55;
}
.nav-item {
    display: flex; align-items: center; gap: var(--space-3); min-height: 44px;
    padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
    color: var(--color-sidebar-text); text-decoration: none; font-size: var(--text-sm); font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--color-sidebar-active-bg); color: var(--color-sidebar-active); }
.nav-item.active svg { opacity: 1; color: var(--color-sidebar-accent); }
.sidebar-footer {
    padding: var(--space-4); border-top: 1px solid var(--color-sidebar-border);
    display: flex; align-items: center; gap: var(--space-2);
}

.saas-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* ── Impersonation banner ─────────────────────────────────────────────────── */
.impersonation-banner {
    display: none; align-items: center; justify-content: center; gap: var(--space-4); flex-wrap: wrap;
    height: 44px; background: var(--color-warning); color: #211a06; font-size: var(--text-sm); font-weight: 700;
    padding: 0 var(--space-4); position: sticky; top: 0; z-index: 60; text-align: center;
}
.impersonation-banner .btn {
    background: #211a06; color: var(--color-warning); border-color: transparent; min-height: 30px; padding: var(--space-1) var(--space-3);
}
.impersonation-banner .btn:hover { background: #372c0d; }
body.impersonating .impersonation-banner { display: flex; }
body.impersonating .page-header { top: 44px; }

.page-header {
    padding: var(--space-6) var(--space-8); border-bottom: 1px solid var(--color-border);
    background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-4);
}
.page-title { font-size: var(--text-2xl); font-weight: 800; margin: 0; letter-spacing: -.01em; }
.page-subtitle { font-size: var(--text-sm); color: var(--color-text-muted); margin: var(--space-1) 0 0; }
.page-content { padding: var(--space-8); flex: 1; max-width: var(--content-max-width); }

/* ── User menu (header profile dropdown) ─────────────────────────────────── */
.user-menu { position: relative; }
.user-menu-trigger {
    display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
    border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-surface);
    cursor: pointer; transition: var(--transition); font-family: inherit; min-height: 44px;
}
.user-menu-trigger:hover { background: var(--color-surface-2); }
.user-menu-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--color-accent), var(--color-accent-strong));
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--text-sm);
    flex-shrink: 0;
}
.user-menu-name { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-trigger svg { width: 16px; height: 16px; color: var(--color-text-muted); transition: transform var(--transition); flex-shrink: 0; }
.user-menu.open .user-menu-trigger svg { transform: rotate(180deg); }

.user-menu-dropdown {
    display: none; position: absolute; top: calc(100% + var(--space-2)); right: 0; min-width: 200px;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); padding: var(--space-2); z-index: 200;
}
.user-menu.open .user-menu-dropdown { display: block; }
.user-menu-item {
    display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
    color: var(--color-text); text-decoration: none; font-size: var(--text-sm); cursor: pointer; background: none; border: none;
    width: 100%; text-align: left; font-family: inherit; min-height: 40px;
}
.user-menu-item:hover { background: var(--color-surface-2); text-decoration: none; }
.user-menu-item svg { width: 18px; height: 18px; color: var(--color-text-muted); flex-shrink: 0; }
.user-menu-item.danger { color: var(--color-danger); }
.user-menu-item.danger svg { color: var(--color-danger); }
.user-menu-divider { height: 1px; background: var(--color-border); margin: var(--space-2) 0; }

.mobile-header { display: none; }
@media (max-width: 1023px) {
    /* .mobile-header becomes an in-flow flex sibling of .saas-main once
       visible — without this, saas-shell's default row direction puts them
       side by side instead of stacked (the fixed-position sidebar/overlay
       are unaffected either way since they're out of normal flow). */
    .saas-shell { flex-direction: column; }
    .saas-sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); z-index: 300; }
    .saas-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .mobile-header {
        display: flex; align-items: center; gap: var(--space-4); height: var(--header-height); padding: 0 var(--space-4);
        background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
        border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 100;
    }
    /* JS (app.v6.js) relocates #user-menu into .mobile-header on this
       breakpoint so there's a single top bar instead of the sticky
       .page-header stacking directly under the sticky .mobile-header. */
    .page-header { display: none; }
    .mobile-header .user-menu { margin-left: auto; }
    .mobile-header .user-menu-trigger { padding: 2px; border: none; background: transparent; min-height: auto; }
    .mobile-header .user-menu-trigger:hover { background: var(--color-surface-2); border-radius: 50%; }
    .mobile-header .user-menu-name, .mobile-header .user-menu-trigger svg { display: none; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(10,9,20,.55); z-index: 250; }
    .sidebar-overlay.visible { display: block; }
    .page-content { padding: var(--space-5); }
    .page-header { padding: var(--space-5); }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    font-family: inherit; font-size: var(--text-sm); font-weight: 600; min-height: 44px;
    padding: var(--space-2) var(--space-5); border-radius: var(--radius-md); border: 1px solid transparent;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    transition: background var(--transition), color var(--transition), border-color var(--transition),
                box-shadow var(--transition), transform var(--transition);
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary {
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover)); color: var(--color-on-accent);
    box-shadow: 0 4px 14px rgba(var(--color-accent-rgb),.35);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(var(--color-accent-rgb),.45); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(var(--color-accent-rgb),.35); }
.btn-secondary { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-surface); border-color: var(--color-border-strong); }
.btn-danger { background: var(--color-danger); color: var(--color-on-accent); }
.btn-danger:hover { background: #DC2626; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.spinner {
    width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    margin-bottom: var(--space-6); box-shadow: var(--shadow-sm); transition: box-shadow var(--transition), transform var(--transition);
}
.card-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--color-border); }
.card-title { font-size: var(--text-lg); font-weight: 700; margin: 0; letter-spacing: -.005em; }
.card-subtitle { font-size: var(--text-sm); color: var(--color-text-muted); margin: var(--space-1) 0 0; }
.card-body { padding: var(--space-6); }
.card-footer { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border); display: flex; gap: var(--space-3); justify-content: flex-end; flex-wrap: wrap; }
.card-clickable { cursor: pointer; }
.card-clickable:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-strong); }

.card-glass {
    background: var(--glass-bg); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border); box-shadow: var(--shadow-glass);
}

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); margin-bottom: var(--space-4); border: 1px solid transparent; line-height: 1.5; }
.alert-warning { background: var(--color-warning-light); color: #92400E; border-color: rgba(245,158,11,.25); }
.alert-success { background: var(--color-success-light); color: #065F46; border-color: rgba(16,185,129,.25); }
.alert-danger  { background: var(--color-danger-light); color: #991B1B; border-color: rgba(239,68,68,.25); }
.alert-info    { background: var(--color-info-light); color: #075985; border-color: rgba(14,165,233,.25); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: var(--radius-full);
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; line-height: 1.6;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-success { background: var(--color-success-light); color: #047857; }
.badge-warning { background: var(--color-warning-light); color: #B45309; }
.badge-danger  { background: var(--color-danger-light); color: #B91C1C; }
.badge-info    { background: var(--color-info-light); color: #0369A1; }
.badge-neutral { background: var(--color-surface-2); color: var(--color-text-muted); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-5); }
label { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--color-text); margin-bottom: var(--space-2); }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], textarea, select {
    width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3); border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md); background: var(--color-surface); color: var(--color-text);
    font-family: inherit; font-size: var(--text-sm); transition: border-color var(--transition), box-shadow var(--transition);
}
textarea { min-height: 88px; resize: vertical; font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--color-text-subtle); }
input:hover, textarea:hover, select:hover { border-color: var(--color-border-strong); }
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--color-accent); box-shadow: var(--shadow-focus);
}
code { font-family: var(--font-mono); background: var(--color-surface-2); padding: 2px 6px; border-radius: 6px; font-size: .9em; }

/* Custom toggle switch — built on the native checkbox, no extra markup needed */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; min-height: 44px; font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }
.switch input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; margin: 0; flex-shrink: 0; position: relative;
    width: 42px; height: 24px; min-height: 0; border-radius: var(--radius-full);
    background: var(--color-border-strong); cursor: pointer; transition: background var(--transition);
}
.switch input[type="checkbox"]::before {
    content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--transition);
}
.switch input[type="checkbox"]:checked { background: var(--color-accent); }
.switch input[type="checkbox"]:checked::before { transform: translateX(18px); }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--color-text-muted); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2); position: sticky; top: 0;
}
.data-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); font-size: var(--text-sm); }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--color-accent-light); }
.data-table tbody tr:last-child td { border-bottom: none; }
/* A bare <select width:100%> inside an auto-layout table cell can't resolve
   its own width (the column's width comes FROM the select's intrinsic
   content, which is nearly nothing) — collapses to a few px in some
   browsers, hiding the selected text entirely. Floor it. */
.data-table select { min-width: 110px; width: auto; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--color-text-muted); }
.empty-state-icon {
    width: 56px; height: 56px; margin: 0 auto var(--space-4); border-radius: var(--radius-full);
    background: var(--color-accent-light); color: var(--color-accent);
    display: flex; align-items: center; justify-content: center;
}
.empty-state-icon svg { width: 26px; height: 26px; }
.empty-state h3 { color: var(--color-text); margin: 0 0 var(--space-2); font-size: var(--text-lg); }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: 999; display: flex; flex-direction: column; gap: var(--space-2); max-width: calc(100vw - 2 * var(--space-6)); }
.toast {
    padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    font-size: var(--text-sm); font-weight: 500; color: #fff; animation: toast-in var(--transition-slow) ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.toast-success { background: #059669; }
.toast-error   { background: #DC2626; }
.toast-info    { background: #0284C7; }
.toast-warning { background: #D97706; }

/* ── Dashboard: onboarding checklist ─────────────────────────────────────── */
.checklist-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.checklist-item:last-child { border-bottom: none; }
.checklist-icon {
    width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.checklist-icon svg { width: 15px; height: 15px; }
.checklist-icon.done { background: var(--color-success-light); color: var(--color-success); }
.checklist-icon.pending { background: var(--color-surface-2); color: var(--color-text-subtle); border: 2px solid var(--color-border-strong); }
.checklist-text { flex: 1; min-width: 0; }
.checklist-text .title { font-weight: 600; font-size: var(--text-sm); }
.checklist-text .desc { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }

/* ── Dashboard: plan usage bars ──────────────────────────────────────────── */
.usage-row { margin-bottom: var(--space-4); }
.usage-row:last-child { margin-bottom: 0; }
.usage-row-label { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--text-sm); margin-bottom: var(--space-2); gap: var(--space-3); }
.usage-row-label .value { color: var(--color-text-muted); font-size: var(--text-xs); flex-shrink: 0; }
.usage-bar-track { height: 8px; border-radius: var(--radius-full); background: var(--color-surface-2); overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: var(--radius-full); background: var(--color-accent); transition: width var(--transition-slow); }
.usage-bar-fill.warning { background: var(--color-warning); }
.usage-bar-fill.danger { background: var(--color-danger); }

/* ── Dashboard: account/store status rows ────────────────────────────────── */
.status-row {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
    padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border);
}
.status-row:last-child { border-bottom: none; }
.status-row-badges { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ── Auth pages ───────────────────────────────────────────────────────────── */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-6); }
.auth-card { width: 100%; max-width: 408px; }
