/* /settings — standalone hub page. Layout is a centred column with
   tool-grouped sections. Uses the site.css design tokens (no new
   colors). Future tools (Clipped, etc.) drop in as additional
   .settings-group sections. */

.settings-page {
    max-width: 760px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

.settings-page-head { margin-bottom: 1.5rem; }
.settings-page-head h1 {
    margin: 0 0 0.35rem;
    font-size: 1.5rem;
    font-weight: 600;
}
.settings-page-lead {
    margin: 0;
    color: var(--fg-muted);
    font-size: 0.9rem;
}

.settings-group { margin-top: 1.75rem; }
.settings-group h2 {
    margin: 0 0 0.65rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-muted);
}

/* The card is a panel that wraps multiple rows. Rows are separated by
   a thin border-coloured divider so the section reads as one grouped
   list rather than independent tiles. */
.settings-card {
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel-bg);
    overflow: hidden;
}
.settings-divider {
    border: 0;
    border-top: 1px solid var(--panel-border);
    margin: 0;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1rem 1.1rem;
}
.settings-row-text {
    flex: 1;
    min-width: 0;
}
.settings-row-text h3 {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
}
.settings-row-text p {
    margin: 0;
    color: var(--fg-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}

/* Buttons — match the visual weight of .ms-btn (used inside /musiced)
   but live in the global stylesheet so the settings page doesn't
   depend on music.css. */
/* read-only storage figure on the right of a row (Storage used / Browser storage) */
.settings-stat {
    flex-shrink: 0;
    font-family: var(--font-mono, monospace);
    font-size: 0.85rem;
    color: var(--fg-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
/* per-folder OPFS breakdown (under "Files on disk") — name · owner-tag · size */
.settings-opfs-list {
    list-style: none;
    margin: 0.65rem 0 0;
    padding: 0;
    max-width: 28rem;
    font-family: var(--font-mono, monospace);
    font-size: 0.8rem;
}
.settings-opfs-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.35rem 0;
    border-top: 1px solid var(--panel-border);
}
.settings-opfs-list li:first-child { border-top: none; }
.settings-opfs-name { color: var(--fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.settings-opfs-owner {
    margin-left: 0.55rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fg-dim);
}
.settings-opfs-owner[data-owner="other"] { color: var(--status-warn, #d9a441); }
.settings-opfs-size { color: var(--fg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.settings-opfs-empty { color: var(--fg-dim); padding: 0.35rem 0; }
.settings-btn {
    flex-shrink: 0;
    padding: 0.55rem 1rem;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: var(--bg-raised, var(--bg));
    color: var(--fg);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease-smooth),
                color var(--dur-fast) var(--ease-smooth),
                background var(--dur-fast) var(--ease-smooth);
}
.settings-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.settings-btn:disabled {
    opacity: 0.55;
    cursor: progress;
}
/* Permanently locked control — distinct from the transient in-flight
   :disabled state above (which keeps cursor: progress as a "wait"
   signal while a fetch is mid-flight). Markup signals "permanently
   dead" by carrying BOTH `disabled` AND `aria-disabled="true"`; the
   JS-driven transient state only flips the `disabled` property, so
   the two cases don't collide. */
.settings-btn[disabled][aria-disabled="true"] {
    cursor: not-allowed;
}
.settings-btn[disabled][aria-disabled="true"]:hover {
    border-color: var(--panel-border);
    color: var(--fg);
    background: var(--bg-raised, var(--bg));
}
.settings-btn-danger {
    color: #f87171;
    border-color: #7f1d1d;
}
.settings-btn-danger:hover {
    color: #fca5a5;
    border-color: #fca5a5;
    background: color-mix(in srgb, #7f1d1d 14%, transparent);
}

/* Custom palette — list of color tokens, each a row with a name, a
   color swatch (the native <input type="color"> styled as a square
   chip), and the resolved hex string for read-only reference.
   Tapping the swatch opens the native picker; live `input` event
   pipes back into settings.js → localStorage → live re-render of
   the page palette. */
.settings-palette-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}
.settings-palette-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 1.1rem;
    border-bottom: 1px solid var(--panel-border);
    cursor: pointer;
}
.settings-palette-row:last-child {
    border-bottom: none;
}
.settings-palette-row:hover {
    background: var(--row-hover);
}
.settings-palette-name {
    color: var(--fg);
    font-size: 0.9rem;
}
.settings-palette-hex {
    color: var(--fg-muted);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    min-width: 70px;
    text-align: right;
}

/* Native color picker styled as a square swatch chip. Removing the
   default chrome (border, padding) lets the inner color preview fill
   the box edge to edge. The webkit/moz pseudo-selectors target the
   inner swatch element where supported. */
.settings-palette-input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 40px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease-smooth),
                transform var(--dur-fast) var(--ease-smooth);
}
.settings-palette-input:hover {
    border-color: var(--accent);
    transform: scale(1.04);
}
.settings-palette-input:focus { outline: none; }
.settings-palette-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.settings-palette-input::-webkit-color-swatch-wrapper {
    padding: 0;
}
.settings-palette-input::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}
.settings-palette-input::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

@media (max-width: 600px) {
    .settings-page { padding: 1.25rem 1rem 3rem; }
    .settings-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    /* On narrow screens the button drops below the description text and
       fills the row width — matches the stacked card pattern used on
       /musiced's mobile list rows. */
    .settings-btn { width: 100%; }

    /* Palette rows keep their inline 3-column layout on mobile — the
       chip + hex string are compact enough that wrapping them under
       the label feels worse than the tight row. */
    .settings-palette-row {
        gap: 0.6rem;
        padding: 0.7rem 0.9rem;
    }
    .settings-palette-hex { min-width: 64px; }
}

/* ---- Account & sync section ---- */
.settings-card-lead {
    color: var(--fg-muted);
    font-size: 0.88rem;
    line-height: 1.55;
    margin: 0 0 1.2rem;
    max-width: 44rem;
}
.settings-btn-primary {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-weight: 500;
}
.settings-btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--bg);
}
.settings-btn-primary:disabled { opacity: 0.6; cursor: progress; }
/* The shared .settings-card has NO padding (so the palette/row dividers span
   edge-to-edge). The account card has no rows — just a form/status — so it must
   pad its own content, matching the ~1.1rem inset the rows give their text. */
#settings-account { padding: 1.25rem 1.1rem; }
.acct-form[data-show="false"], .acct-status[data-show="false"] { display: none; }

/* signed-out: lead + email|password side-by-side (fills the card width) + hint
   + buttons. The 2-up fields wrap to stacked on a narrow viewport. */
.acct-lead {
    color: var(--fg-muted);
    font-size: 0.86rem;
    line-height: 1.55;
    margin: 0 0 1.25rem;
}
.acct-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem 1rem;
    margin-bottom: 0.7rem;
}
.acct-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1 1 14rem;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--fg-dim);
}
.acct-field input {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    text-transform: none;
    letter-spacing: 0;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    transition: border-color var(--dur-fast) var(--ease-smooth),
                box-shadow var(--dur-fast) var(--ease-smooth);
}
.acct-field input::placeholder { color: var(--fg-dim); }
.acct-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}
.acct-hint {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0;
    text-transform: none;
    color: var(--fg-dim);
    line-height: 1.4;
}
.acct-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.5rem; }
.acct-error { color: var(--status-err, #e06c6c); font-size: 0.82rem; margin: 0.2rem 0 0.7rem; min-height: 0; }
.acct-error:empty { margin: 0; }
.acct-error.ok { color: var(--accent); }

/* signed-in: status + sync controls */
.acct-who {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--fg);
    font-size: 0.95rem;
    margin: 0 0 0.5rem;
}
.acct-who::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}
.acct-who strong { font-family: var(--font-mono); font-weight: 500; }
.acct-sync-state { color: var(--fg-muted); font-size: 0.85rem; margin: 0 0 1.05rem; }
