* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; }
a { color: inherit; }

.saas-shell {
    display: flex;
    min-height: 100vh;
    background: var(--color-bg);
    font-family: var(--font-sans);
    color: var(--color-text);
    font-size: var(--text-base);
}

.saas-sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform var(--transition);
    z-index: 200;
    border-right: 1px solid var(--color-sidebar-border);
}

.sidebar-header { padding: var(--space-5) var(--space-5) var(--space-4); }
.sidebar-logo { display: flex; align-items: center; text-decoration: none; color: #fff; }
.logo-wordmark { width: 134px; height: auto; display: block; }
.mobile-header-logo { display: flex; align-items: center; color: var(--color-accent); }
.mobile-header-logo .logo-wordmark { width: 112px; }

.sidebar-nav { flex: 1; padding: var(--space-2) var(--space-3); }
.nav-group { margin-bottom: var(--space-4); }
.nav-group-label {
    display: block; padding: var(--space-2) var(--space-3); font-size: 0.6875rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-sidebar-text); opacity: 0.55;
}
.nav-item {
    display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3);
    min-height: 38px; margin-bottom: 1px; border-radius: var(--radius-md); color: var(--color-sidebar-text);
    text-decoration: none; font-size: var(--text-sm); font-weight: 500; position: relative;
    transition: background var(--transition), color var(--transition);
}
.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::before {
    content: ''; position: absolute; left: -1px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 16px; border-radius: var(--radius-full); background: #A78BFA;
}
.nav-item svg, .nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }

.sidebar-footer {
    padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-sidebar-border);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
}
.sidebar-footer #current-user-name { font-size: var(--text-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
    border-radius: var(--radius-md); background: none; border: none; cursor: pointer;
    color: var(--color-sidebar-text); transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; }

.saas-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.page-header {
    padding: var(--space-6) var(--space-8); border-bottom: 1px solid var(--color-border);
    background: var(--color-surface); display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: var(--space-4); position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: var(--text-2xl); font-weight: 700; margin: 0; letter-spacing: -0.015em; }
.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); }
.page-actions { display: flex; align-items: center; gap: var(--space-3); }

.mobile-header { display: none; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    font-size: var(--text-sm); font-weight: 600; font-family: inherit; min-height: 40px;
    padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); border: 1px solid transparent;
    cursor: pointer; transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    white-space: nowrap;
}
.btn svg, .btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--color-accent); color: #fff; box-shadow: 0 1px 2px rgba(109,40,217,0.25); }
.btn-primary:hover { background: var(--color-accent-hover); box-shadow: 0 2px 8px rgba(109,40,217,0.35); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-2); border-color: var(--color-text-subtle); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-sm { min-height: 30px; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-ghost { background: transparent; color: var(--color-text-muted); min-height: 36px; padding: var(--space-2) var(--space-3); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn[disabled]:hover { transform: none; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header { padding: var(--space-5) var(--space-5) var(--space-3); }
.card-title { font-size: var(--text-lg); font-weight: 600; margin: 0; }
.card-subtitle { font-size: var(--text-sm); color: var(--color-text-muted); margin: var(--space-1) 0 0; }
.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); }

.alert { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-warning { background: var(--color-warning-light); color: #92400E; }
.alert-success { background: var(--color-success-light); color: #14532D; }
.alert-danger  { background: var(--color-danger-light); color: #991B1B; }

.empty-state { text-align: center; padding: var(--space-12) var(--space-6); color: var(--color-text-muted); }
.empty-state-icon {
    width: 44px; height: 44px; margin: 0 auto var(--space-3); color: var(--color-text-subtle);
    display: flex; align-items: center; justify-content: center;
}
.empty-state-icon svg { width: 32px; height: 32px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--color-text-muted); margin-bottom: var(--space-2); }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); font-size: var(--text-sm); font-family: inherit;
    background: var(--color-surface); color: var(--color-text); min-height: 40px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: var(--color-border-strong); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--color-accent); box-shadow: var(--focus-ring);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--color-text-subtle); }
.form-hint { font-size: var(--text-xs); color: var(--color-text-subtle); margin-top: var(--space-1); line-height: 1.5; }

.form-toggle { display: flex; align-items: center; gap: var(--space-3); cursor: pointer; user-select: none; }
.form-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--color-accent); cursor: pointer; flex-shrink: 0; }

/* ── Repeater field (repeatable list settings, e.g. announcement items) ──── */
.repeater-list { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-2); }
.repeater-row { display: flex; align-items: flex-start; gap: var(--space-2); background: var(--color-surface-2);
    border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-3); }
.repeater-row-fields { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.repeater-row-fields .repeater-item-input { flex: 1 1 160px; min-width: 0; }
.repeater-remove-btn { flex-shrink: 0; width: 30px; height: 30px; border-radius: var(--radius-md);
    border: 1px solid var(--color-border-strong); background: var(--color-surface); color: var(--color-text-subtle);
    cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: var(--text-sm); line-height: 1; }
.repeater-remove-btn:hover { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }

/* ── Placement snippet (Custom Liquid block) ───────────────────────────── */
.snippet-block { display: flex; align-items: flex-start; gap: var(--space-3); background: var(--color-surface-2);
    border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-3); }
.snippet-pre { flex: 1 1 auto; min-width: 0; margin: 0; overflow-x: auto; font-family: var(--font-mono);
    font-size: var(--text-xs); line-height: 1.6; color: var(--color-text); white-space: pre-wrap; word-break: break-all; }
.snippet-block .btn-sm { flex-shrink: 0; }

/* ── Feature editor + live preview ─────────────────────────────────────── */
/* Right column stays above 480px so the preview iframe never falls under the widgets' own
   `@media (max-width:480px)` mobile breakpoint — otherwise every "desktop" setting (image side-by-
   side layouts, unclamped image sizes, etc.) silently renders as its mobile fallback in preview,
   even though real desktop shoppers would never see that. */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 520px); gap: var(--space-6); align-items: start; }
.preview-panel { position: sticky; top: var(--space-6); }
.preview-frame-wrap { height: 480px; border-top: 1px solid var(--color-border); background: #F1F1F5; }
.preview-frame-wrap iframe { width: 100%; height: 100%; border: none; display: block; }
@media (max-width: 900px) {
    .editor-layout { grid-template-columns: 1fr; }
    .preview-panel { position: static; }
    .preview-frame-wrap { height: 420px; }
}

/* ── Feature grid ───────────────────────────────────────────────────────── */
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-5); }
.feature-card {
    padding: var(--space-5); display: block; text-decoration: none; color: inherit;
    transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
}
.feature-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-strong); transform: translateY(-1px); }
.feature-card-icon {
    width: 40px; height: 40px; border-radius: var(--radius-md); margin-bottom: var(--space-3);
    display: flex; align-items: center; justify-content: center;
    background: var(--color-accent-light); color: var(--color-accent);
}
.feature-card-icon svg { width: 21px; height: 21px; }
/* Non-clickable variant of feature-card — stat tiles, pricing cards — no hover-lift affordance. */
.stat-tile { padding: var(--space-5); }
.stat-tile .feature-card-icon { margin-bottom: var(--space-3); }

.feature-status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-xs); font-weight: 600;
    padding: 3px var(--space-2) 3px 7px; border-radius: var(--radius-full); }
.feature-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.feature-status.on   { background: var(--color-success-light); color: #14532D; }
.feature-status.off  { background: var(--color-surface-2); color: var(--color-text-muted); }
.feature-status.free { background: var(--color-info-light); color: #075985; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
    text-align: left; font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--color-text-muted); padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--color-border);
}
.data-table td { padding: var(--space-3) var(--space-3); border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--color-surface-2); }
.data-table .text-right { text-align: right; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15,14,28,0.55); z-index: 400;
    align-items: center; justify-content: center; padding: var(--space-4);
    backdrop-filter: blur(2px);
}
.modal-overlay.visible { display: flex; animation: overlay-in 160ms ease; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); max-width: 440px; width: 100%; max-height: 90vh; overflow-y: auto;
    padding: var(--space-6); animation: modal-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.modal-title { font-size: var(--text-lg); font-weight: 700; margin: 0; }
.modal-close {
    display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
    background: none; border: none; border-radius: var(--radius-md); cursor: pointer; color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--color-surface-2); color: var(--color-text); }
.modal-close svg { width: 16px; height: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }

.feature-grant-row {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border);
}
.feature-grant-row:last-child { border-bottom: none; }
.feature-grant-row .icon-badge { width: 30px; height: 30px; margin-right: var(--space-1); }

/* Icon size within a badge is set inline via icon(name, px) at the call site — CSS here only
   handles the badge box itself, since inline SVG sizing always wins specificity over a CSS rule. */
.icon-badge {
    display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
    border-radius: var(--radius-sm); background: var(--color-accent-light); color: var(--color-accent); flex-shrink: 0;
}

/* ── Toasts ─────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: var(--space-6); right: var(--space-6); display: flex; flex-direction: column; gap: var(--space-2); z-index: 500; }
.toast {
    display: flex; align-items: center; gap: var(--space-2); 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; min-width: 240px; animation: toast-in 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success { background: #15803D; }
.toast-error   { background: #DC2626; }
.toast-info    { background: #0369A1; }
.toast-warning { background: #B45309; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
    .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); }
    /* .saas-sidebar and #sidebar-overlay are position:fixed (out of flow) so this only affects
       the remaining two flex children — stacks the mobile header above main instead of beside it. */
    .saas-shell { flex-direction: column; }
    .mobile-header {
        display: flex; align-items: center; gap: var(--space-4); height: var(--header-height);
        width: 100%; padding: 0 var(--space-4); background: var(--color-surface); border-bottom: 1px solid var(--color-border);
        position: sticky; top: 0; z-index: 100;
    }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 250; }
    .sidebar-overlay.visible { display: block; }
    .page-content { padding: var(--space-4); }
    .page-header { padding: var(--space-4); position: static; }
}
