/* Edara Storefront — Admin SPA styles (MD3-flavoured) */

:root {
    --bg: #f7f7fb;
    --surface: #ffffff;
    --surface-2: #f0f1f6;
    --border: #e1e3ec;
    --text: #1a1c22;
    --muted: #5d6378;
    --accent: #6750a4;
    --accent-2: #00b894;
    --danger: #b3261e;
    --success: #2e7d32;
    --warning: #b26a00;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 17, 21, 0.06), 0 4px 12px rgba(15, 17, 21, 0.04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.55; }
html[dir="rtl"] body { font-family: "Noto Sans Arabic", var(--font); }

.loading-state, .auth-view {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
}
.auth-view h1 { margin: 0 0 8px; font-size: 1.8rem; }
.muted { color: var(--muted); }

/* Accessibility utilities ---------------------------------------------- */
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.skip-link {
    position: absolute;
    left: 8px;
    top: -48px;
    z-index: 10000;
    background: var(--accent);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 600;
    transition: top .15s ease;
}
.skip-link:focus {
    top: 8px;
    outline: 2px solid var(--text);
    outline-offset: 2px;
}
html[dir="rtl"] .skip-link { left: auto; right: 8px; }

/* Global focus-visible ring (O1) --------------------------------------- */
.btn:focus-visible,
.main-nav a:focus-visible,
.theme-card-select:focus-visible,
.theme-card-preview:focus-visible,
.data-list-row:focus-visible,
.reorder-btn:focus-visible,
[data-secret-toggle]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.main-nav a.active:focus-visible { outline-color: var(--text); }
#content:focus { outline: none; }

/* Buttons --------------------------------------------------------------- */
.btn {
    appearance: none;
    border: 0;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 500;
    transition: filter .15s ease, background .15s ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.ghost-sm { background: var(--surface-2); color: var(--text); padding: 6px 12px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn.ghost-sm:hover { background: var(--border); }

/* Top bar --------------------------------------------------------------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 6px; font-weight: 700; letter-spacing: 0.04em; }
.brand-mark { color: var(--accent); font-size: 1.2rem; }
.brand-sub { font-size: 0.8rem; color: var(--muted); }

.main-nav { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.main-nav a { color: var(--text); text-decoration: none; padding: 6px 12px; border-radius: var(--radius-sm); font-size: 0.95rem; }
.main-nav a:hover { background: var(--surface-2); }
.main-nav a.active { background: var(--accent); color: #fff; }

main { padding: 32px 24px; max-width: 1100px; margin: 0 auto; }

/* Section headings ------------------------------------------------------ */
.admin-section { margin-bottom: 48px; }
.admin-section .section-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.admin-section .section-head h2 { margin: 0; flex: 1 1 auto; }
.admin-section .section-head .muted { flex: 1 1 100%; margin: 0; }

/* Form grid ------------------------------------------------------------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.field > span { font-weight: 500; color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.field-inline input[type="checkbox"] { width: 18px; height: 18px; }

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field input[type="url"],
.field input[type="password"],
.field input[type="number"],
.field input:not([type]),
.field select,
.field textarea {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}
.field input[type="color"] {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    height: 40px;
    padding: 4px;
}
.field input[type="file"] {
    padding: 6px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}
.hint { color: var(--muted); font-size: 0.8rem; }

.form-actions { grid-column: 1 / -1; display: flex; gap: 12px; justify-content: flex-end; }
.onboarding-success {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: rgba(46, 125, 50, 0.10);
    border: 1px solid rgba(46, 125, 50, 0.35);
    border-radius: var(--radius);
}
.onboarding-success-msg { font-weight: 600; color: var(--success); flex: 1 1 auto; }
.form-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0; grid-column: 1 / -1; }
.form-block legend { font-weight: 600; padding: 0 6px; }

.form-inline { display: flex; gap: 8px; margin-bottom: 16px; }
.form-inline input { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }

.upload-preview img.thumb { max-width: 96px; max-height: 96px; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-top: 6px; }

.secret-input { display: flex; gap: 6px; }
.secret-input input { flex: 1; }

/* Tables ---------------------------------------------------------------- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    text-align: start;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 0.9rem;
}
.data-table th { background: var(--surface-2); font-weight: 600; color: var(--muted); }
.data-table tbody tr:hover { background: rgba(103, 80, 164, 0.04); }
.data-table input[type="checkbox"] { width: auto; }
.data-table input:not([type="checkbox"]) {
    width: 100%;
    border: 1px solid transparent;
    border-bottom: 1px dashed var(--muted);
    padding: 6px 24px 6px 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    background-image: linear-gradient(transparent, transparent);
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 12px;
    font: inherit;
    transition: background .25s ease, border-color .15s ease;
}
html[dir="rtl"] .data-table input:not([type="checkbox"]) {
    padding: 6px 8px 6px 24px;
    background-position: left 6px center;
}
/* Pencil affordance so editable cells don't look static. */
.data-table td:has(> input:not([type="checkbox"])) { position: relative; }
.data-table td:has(> input:not([type="checkbox"]))::after {
    content: "✎";
    position: absolute;
    inset-inline-end: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0.6;
}
.data-table td:has(> input:focus)::after { opacity: 0; }
.data-table input:not([type="checkbox"]):hover { border-bottom-color: var(--accent); }
.data-table input:not([type="checkbox"]):focus {
    background-color: var(--surface);
    border: 1px solid var(--accent);
    outline: none;
}
/* Transient in-cell saved cue (#9) — in addition to the toast. */
.data-table input.cell-saved {
    border-bottom-color: var(--success);
    background-color: rgba(46, 125, 50, 0.12);
}
.data-table td.cell-saved::after { content: "✓"; color: var(--success); opacity: 1; }
.data-table select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px; }

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--muted);
}

/* Lists ----------------------------------------------------------------- */
.data-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.data-list li {
    border-bottom: 1px solid var(--border);
}
.data-list li:last-child { border-bottom: 0; }
/* Non-interactive rows (e.g. domains list) keep the old flex layout. */
.data-list li:not(:has(.data-list-row)) {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}
.data-list .data-list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.data-list .data-list-row:hover { background: var(--surface-2); }
.data-list .page-slug { font-family: ui-monospace, "Courier New", monospace; color: var(--muted); font-size: 0.85rem; min-width: 120px; }
.data-list .page-title { flex: 1; font-weight: 500; }

.status { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.status.is-on { background: rgba(46, 125, 50, 0.12); color: var(--success); }
.status.is-off { background: rgba(178, 106, 0, 0.12); color: var(--warning); }

.split { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.split-list, .split-edit { display: flex; flex-direction: column; gap: 12px; }

/* Theme picker ---------------------------------------------------------- */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.theme-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border .15s ease, transform .15s ease;
    display: flex;
    flex-direction: column;
}
.theme-card:hover { transform: translateY(-2px); }
.theme-card.selected { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(103, 80, 164, 0.15); }
.theme-card-select {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}
.theme-card-name { font-weight: 600; text-align: center; }
.theme-card-preview {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    padding: 8px;
    color: var(--accent);
    text-decoration: none;
    border-top: 1px solid var(--border);
}
.theme-card-preview:hover { background: var(--surface-2); text-decoration: underline; }

/* Mini storefront mock --------------------------------------------------- */
.theme-mini {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    height: 96px;
}
.theme-mini-header { height: 14px; border-radius: 3px; }
.theme-mini-body { display: flex; gap: 6px; flex: 1; }
.theme-mini-tile {
    flex: 1;
    background: rgba(255, 255, 255, 0.7);
    border: 2px solid;
    border-radius: 3px;
}
.theme-mini-btn { height: 12px; width: 50%; border-radius: 999px; align-self: center; }

/* Sortable section list ------------------------------------------------- */
.sortable-list { list-style: none; padding: 0; margin: 0 0 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.sortable-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.sortable-list li:last-child { border-bottom: 0; }
.sortable-list .drag-handle { cursor: grab; color: var(--muted); font-size: 1.1rem; }
.sortable-list .section-label { flex: 1; font-weight: 500; }
.reorder-controls { display: inline-flex; gap: 4px; }
.reorder-btn {
    min-width: 32px;
    padding: 4px 8px;
    line-height: 1;
    font-size: 0.95rem;
}
.reorder-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Switch ---------------------------------------------------------------- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0;
    background: var(--border);
    border-radius: 24px;
    transition: background .15s ease;
}
.switch .slider:before {
    content: "";
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform .15s ease;
}
html[dir="rtl"] .switch .slider:before { left: auto; right: 3px; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(18px); }
html[dir="rtl"] .switch input:checked + .slider:before { transform: translateX(-18px); }

/* Info panel ------------------------------------------------------------ */
.info-panel {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 16px;
}
.info-panel summary { cursor: pointer; font-weight: 500; }
.info-panel code { background: var(--surface); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

/* Toast ----------------------------------------------------------------- */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
html[dir="rtl"] #toast-container { right: auto; left: 24px; }
.toast {
    pointer-events: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    max-width: 360px;
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    animation: toast-in .2s ease;
}
html[dir="rtl"] .toast { border-left: 1px solid var(--border); border-right: 4px solid var(--accent); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transition: opacity .4s ease; }
@keyframes toast-in {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* U2 — persistent form-level error (AA: #b00020 on #fff ~6:1). Distinct from
   the transient toast; stays until the next submit. */
.form-error {
    grid-column: 1 / -1;
    margin: 0 0 12px;
    padding: 10px 14px;
    border: 1px solid #f3c2c2;
    border-left: 4px solid #b00020;
    border-radius: var(--radius-sm);
    background: #fdf0f0;
    color: #b00020;
    font-size: 0.9rem;
    font-weight: 600;
}
.form-error[hidden] { display: none; }
