/* ================================================================
   AI CLINIC DASHBOARD — Appearance Customizer
   Per-user colour picker panel (sidebar / background / accent …)

   The panel deliberately styles itself from its OWN tokens instead of
   the global --surface / --text variables: those are exactly the values
   the user is editing, so borrowing them would let a bad pick make the
   editor itself unreadable.
   ================================================================ */

/* ── Trigger button (topbar) ─────────────────────────────────────
   Sized to sit level with the user pill it stands next to (30px avatar +
   6px padding + 1px border = 44px), so the topbar reads as one row of
   controls rather than a small box parked beside a taller one. */
.ac-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--border, rgba(15, 23, 42, .1));
    background: var(--surface, #fff);
    color: var(--text-2, #475569);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .15s;
}

/* The glyph is decorative — the button carries its own aria-label — and
   line-height 1 keeps it optically centred whatever the topbar inherits. */
.ac-trigger i {
    line-height: 1;
    pointer-events: none;
}

.ac-trigger:hover {
    background: var(--primary-soft, rgba(81, 121, 168, .12));
    border-color: var(--primary, #5179a8);
    color: var(--primary, #5179a8);
    transform: translateY(-1px);
}

/* Held open while the drawer is: the button is the only thing left on
   screen showing where the panel came from. */
.ac-trigger[aria-expanded="true"] {
    background: var(--primary-soft, rgba(81, 121, 168, .12));
    border-color: var(--primary, #5179a8);
    color: var(--primary, #5179a8);
}

.ac-trigger:focus-visible {
    outline: 2px solid var(--primary, #5179a8);
    outline-offset: 2px;
}

/* ── Panel tokens ────────────────────────────────────────────── */
.ac-panel,
.ac-overlay {
    --ac-bg: #ffffff;
    --ac-bg-2: #f8fafc;
    --ac-fg: #0f172a;
    --ac-fg-2: #475569;
    --ac-fg-3: #94a3b8;
    --ac-line: rgba(15, 23, 42, .1);
    --ac-line-2: rgba(15, 23, 42, .16);
    --ac-accent: #5179a8;
    --ac-danger: #dc2626;
    --ac-danger-soft: #fef2f2;
    --ac-danger-line: #fecaca;
    --ac-shadow: -18px 0 50px rgba(15, 23, 42, .18);
}

html[data-theme="dark"] .ac-panel,
html[data-theme="dark"] .ac-overlay {
    --ac-bg: #131a2a;
    --ac-bg-2: #1c2438;
    --ac-fg: #f1f5f9;
    --ac-fg-2: #cbd5e1;
    --ac-fg-3: #94a3b8;
    --ac-line: rgba(148, 163, 184, .16);
    --ac-line-2: rgba(148, 163, 184, .28);
    --ac-accent: #6ea8fe;
    --ac-danger: #f87171;
    --ac-danger-soft: rgba(248, 113, 113, .14);
    --ac-danger-line: rgba(248, 113, 113, .38);
    --ac-shadow: -18px 0 50px rgba(0, 0, 0, .55);
}

/* ── Overlay ─────────────────────────────────────────────────── */
.ac-overlay {
    position: fixed;
    inset: 0;
    z-index: 1090;
    background: rgba(15, 23, 42, .42);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}

.ac-overlay.ac-open {
    opacity: 1;
    visibility: visible;
}

/* ── Drawer ──────────────────────────────────────────────────── */
.ac-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1091;
    width: 340px;
    max-width: 92vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--ac-bg);
    color: var(--ac-fg);
    border-left: 1px solid var(--ac-line);
    box-shadow: var(--ac-shadow);
    font-family: var(--font, 'Plus Jakarta Sans', -apple-system, sans-serif);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .26s cubic-bezier(.4, 0, .2, 1), visibility .26s;
}

.ac-panel.ac-open {
    transform: none;
    visibility: visible;
}

/* ── Header ──────────────────────────────────────────────────── */
.ac-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--ac-line);
    flex-shrink: 0;
}

.ac-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--ac-fg);
}

.ac-mode-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--ac-bg-2);
    border: 1px solid var(--ac-line);
    font-size: 10.5px;
    font-weight: 600;
    color: var(--ac-fg-3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.ac-close {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    border: 1px solid var(--ac-line);
    background: var(--ac-bg);
    color: var(--ac-fg-2);
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.ac-close:hover {
    background: var(--ac-danger-soft);
    border-color: var(--ac-danger-line);
    color: var(--ac-danger);
}

/* ── Body ────────────────────────────────────────────────────── */
.ac-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 22px;
}

.ac-body::-webkit-scrollbar { width: 6px; }
.ac-body::-webkit-scrollbar-thumb { background: var(--ac-line-2); border-radius: 3px; }

.ac-sect + .ac-sect { margin-top: 22px; }

.ac-sect-title {
    margin: 0 0 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ac-fg-3);
}

/* ── Presets ─────────────────────────────────────────────────── */
.ac-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.ac-preset {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 11px;
    border: 1px solid var(--ac-line);
    background: var(--ac-bg-2);
    color: var(--ac-fg-2);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, transform .15s, box-shadow .15s;
}

.ac-preset:hover {
    border-color: var(--ac-line-2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, .08);
}

.ac-preset.ac-active {
    border-color: var(--ac-accent);
    box-shadow: 0 0 0 2px rgba(81, 121, 168, .22);
}

/* Mini three-band preview of the preset */
.ac-swatch {
    width: 30px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    border: 1px solid var(--ac-line-2);
}

.ac-swatch span:nth-child(1) { width: 34%; }
.ac-swatch span:nth-child(2) { width: 44%; }
.ac-swatch span:nth-child(3) { width: 22%; }

/* ── Colour fields ───────────────────────────────────────────── */
.ac-field {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 0;
}

.ac-field + .ac-field { border-top: 1px solid var(--ac-line); }

.ac-field-text {
    flex: 1;
    min-width: 0;
}

.ac-field-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ac-fg);
}

.ac-field-hint {
    margin-top: 1px;
    font-size: 10.5px;
    color: var(--ac-fg-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hex text box */
.ac-hex {
    width: 74px;
    flex-shrink: 0;
    padding: 6px 7px;
    border-radius: 8px;
    border: 1px solid var(--ac-line);
    background: var(--ac-bg-2);
    color: var(--ac-fg-2);
    font-family: var(--mono, 'JetBrains Mono', monospace);
    font-size: 11px;
    text-transform: uppercase;
}

.ac-hex:focus {
    outline: none;
    border-color: var(--ac-accent);
}

.ac-hex.ac-invalid {
    border-color: #dc2626;
    color: #dc2626;
}

/* Native colour input, dressed up as a round swatch */
.ac-dot {
    position: relative;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--ac-bg);
    box-shadow: 0 0 0 1px var(--ac-line-2), 0 2px 6px rgba(15, 23, 42, .12);
    cursor: pointer;
    transition: transform .15s;
}

.ac-dot:hover { transform: scale(1.08); }

.ac-dot input[type="color"] {
    position: absolute;
    inset: -25%;
    width: 150%;
    height: 150%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.ac-dot input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.ac-dot input[type="color"]::-webkit-color-swatch { border: none; }
.ac-dot input[type="color"]::-moz-color-swatch { border: none; }

/* Per-field revert */
.ac-revert {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid transparent;
    background: none;
    color: var(--ac-fg-3);
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s, background .15s, color .15s;
}

/* Only offered once the field actually differs from the default */
.ac-field.ac-changed .ac-revert {
    opacity: 1;
    pointer-events: auto;
}

.ac-revert:hover {
    background: var(--ac-bg-2);
    border-color: var(--ac-line);
    color: var(--ac-fg);
}

/* ── Footer ──────────────────────────────────────────────────── */
.ac-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 13px 18px;
    border-top: 1px solid var(--ac-line);
    background: var(--ac-bg-2);
    flex-shrink: 0;
}

.ac-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 13px;
    border-radius: 9px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.ac-btn-ghost {
    flex: 1;
    border: 1px solid var(--ac-line-2);
    background: var(--ac-bg);
    color: var(--ac-fg-2);
}

.ac-btn-ghost:hover {
    border-color: var(--ac-danger-line);
    background: var(--ac-danger-soft);
    color: var(--ac-danger);
}

.ac-btn-primary {
    border: 1px solid var(--ac-accent);
    background: var(--ac-accent);
    color: #fff;
}

.ac-btn-primary:hover { filter: brightness(.94); }

/* ── Confirm dialog ──────────────────────────────────────────────
   SweetAlert2 containers default to z-index 1060, which puts them under
   the drawer (1091). Only the customizer's own dialogs opt into this, so
   SweetAlerts elsewhere in the dashboard keep their normal stacking. */
.swal2-container.ac-swal {
    z-index: 1100;
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .ac-panel {
        width: 100%;
        max-width: 100%;
    }

    .ac-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
