/* ==============================================================
   Goranikurdi admin panel — light dashboard theme.
   Inter on a soft slate background, indigo accent, rounded cards.
   ============================================================== */

:root {
    /* surfaces */
    --bg:           #F4F6FB;
    --surface:      #FFFFFF;
    --surface-2:    #F8FAFC;
    --surface-hover:#F1F5F9;

    /* text */
    --text:         #0F172A;
    --text-2:       #334155;
    --muted:        #64748B;
    --muted-2:      #94A3B8;

    /* lines */
    --line:         #E5E9F0;
    --line-strong:  #CBD5E1;

    /* accents */
    --accent:       #4F46E5;
    --accent-hover: #4338CA;
    --accent-soft:  #EEF2FF;
    --accent-soft-2:#E0E7FF;

    --green:        #10B981;
    --green-soft:   #D1FAE5;
    --red:          #EF4444;
    --red-soft:     #FEE2E2;
    --amber:        #F59E0B;

    /* depth */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 4px 16px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.06);
    --ring:      0 0 0 3px var(--accent-soft);

    /* radii */
    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;
    --r-xl: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
    /* Inter for Latin glyphs, Vazirmatn for Arabic/Kurdish glyphs (browser
       falls back per-glyph automatically). System sans last. */
    font-family: 'Inter', 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}
.muted { color: var(--muted); }

/* ============================================================== app shell */

.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ---------- sidebar nav ---------- */

.app-nav {
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    padding: 18px 14px;
    position: sticky; top: 0;
    height: 100vh;
}

.app-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 8px 18px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.logo-mark {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, #7C3AED 100%);
    color: white;
    display: grid; place-items: center;
    font-weight: 700; font-size: 18px;
    box-shadow: var(--shadow-sm);
}
.logo-text {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}
.logo-sub {
    font-weight: 400;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-top: 2px;
}

.nav-list {
    display: flex; flex-direction: column; gap: 2px;
    flex: 1;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 10px 12px;
    border-radius: var(--r);
    cursor: pointer;
    text-align: left;
    font-weight: 500;
    transition: background 120ms, color 120ms;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}
.nav-item.active svg { color: var(--accent); }

.nav-foot {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}
.health-pill {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r);
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.health-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
}

/* ---------- main column ---------- */

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

.page-head {
    height: 64px;
    display: flex; align-items: center;
    padding: 0 28px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.page-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.page-body {
    flex: 1;
    min-height: 0;
}

/* ============================================================== views */

.view { display: none; }
.view.active { display: flex; }

.two-pane {
    height: calc(100vh - 64px);
    padding: 20px;
    gap: 16px;
}

.stats-view { display: none; }
.stats-view.active { display: block; overflow-y: auto; }

/* ============================================================== card */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

/* ============================================================== list pane */

.list-pane {
    width: 360px;
    flex-shrink: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}

.search-row {
    display: flex; gap: 8px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}
.search-input {
    position: relative;
    flex: 1;
}
.search-input svg {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--muted-2);
    pointer-events: none;
}
.search-input input[type="search"] {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--r);
    padding: 9px 10px 9px 34px;
    outline: none;
    transition: border-color 120ms, box-shadow 120ms, background 120ms;
}
.search-input input[type="search"]:focus {
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.list-meta {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

/* ---------- filter toggle + collapsible filter panel ---------- */

.icon-btn {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px;
    padding: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.has-active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}
.filter-count {
    position: absolute;
    top: -4px; right: -4px;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 10px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    line-height: 1;
}

.filters-panel {
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 10px;
}
.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
}
.f-cell {
    display: flex; flex-direction: column; gap: 3px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.f-cell select {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 6px 8px;
    font-size: 13px;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    outline: none;
}
.f-cell select:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}
.link-btn {
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    align-self: flex-start;
}
.link-btn:hover { text-decoration: underline; }

.track-list, .artist-list {
    list-style: none; margin: 0; padding: 4px 0;
    overflow-y: auto;
    flex: 1;
}
.track-list li, .artist-list li {
    padding: 10px 14px;
    margin: 2px 6px;
    border-radius: var(--r);
    cursor: pointer;
    display: flex; align-items: baseline; gap: 10px;
    border: 1px solid transparent;
    transition: background 100ms, border-color 100ms;
}
.track-list li:hover, .artist-list li:hover {
    background: var(--surface-hover);
}
.track-list li.selected, .artist-list li.selected {
    background: var(--accent-soft);
    border-color: var(--accent-soft-2);
}

/* Kurdish-letter section heading inside the artist list. */
.artist-list li.letter-heading {
    display: block;
    cursor: default;
    background: transparent;
    border: 0;
    border-radius: 0;
    margin: 8px 6px 2px 6px;
    padding: 4px 12px;
    font-family: 'Vazirmatn', 'Inter', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--accent-soft-2);
    line-height: 1.4;
    text-align: right;
    direction: rtl;
}
.artist-list li.letter-heading:hover { background: transparent; }
.track-list li.selected .row-id,
.artist-list li.selected .row-id { color: var(--accent); }

.row-id {
    color: var(--muted-2);
    font-variant-numeric: tabular-nums;
    min-width: 56px;
    font-size: 11px;
    font-weight: 500;
}
.row-title {
    flex: 1;
    color: var(--text);
    font-weight: 500;
}
.row-sub {
    color: var(--muted);
    font-size: 12px;
}
.row-content { flex: 1; min-width: 0; }
.row-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.pager {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.pager button {
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 4px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background 100ms;
}
.pager button:hover:not(:disabled) { background: var(--surface-hover); }
.pager button:disabled { opacity: 0.4; cursor: default; }

/* ============================================================== editor */

.editor {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    min-width: 0;
}

.empty-state {
    color: var(--muted);
    margin-top: 80px;
    text-align: center;
    font-size: 14px;
}
.empty-state b { color: var(--text); }

.editor h2 {
    margin: 0 0 4px 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.editor .editor-sub {
    color: var(--muted);
    margin-bottom: 24px;
    font-size: 13px;
}

.field { display: flex; flex-direction: column; margin-bottom: 16px; }
.field label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.field input, .field select, .field textarea {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 9px 12px;
    outline: none;
    transition: border-color 120ms, box-shadow 120ms;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}
.field textarea {
    resize: vertical;
    min-height: 260px;
    /* Vazirmatn handles Sorani properly. Mono fonts mangle Arabic-script
       letter shaping; do not use ui-monospace here. */
    font-family: 'Vazirmatn', 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.85;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.section-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    margin: 18px 0 12px 0;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

/* ---------- artist editor — tracks list ---------- */

.artist-tracks-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
    background: var(--surface);
}
.artist-tracks-list li {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    transition: background 100ms;
}
.artist-tracks-list li:last-child { border-bottom: 0; }
.artist-tracks-list li:hover { background: var(--surface-hover); }
.artist-tracks-list .row-id {
    color: var(--muted-2);
    font-size: 11px;
    font-weight: 500;
    min-width: 60px;
    font-variant-numeric: tabular-nums;
}
.artist-tracks-list .at-title {
    flex: 1;
    color: var(--text);
    font-weight: 500;
}
.artist-tracks-list .at-meta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.at-tag-audio {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent-soft-2);
}

/* "Tracks" header row with sort + new-track actions on the right. */
.section-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.section-label-row .link-btn {
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
    font-weight: 600;
}
.section-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}
.mini-sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}
.mini-sort select {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    outline: none;
    cursor: pointer;
}
.mini-sort select:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* Color-coded classification tags on the artist's track rows. */
.tag-genre {
    color: #4338CA;
    background: #EEF2FF;
    border-color: #E0E7FF;
}
.tag-mood {
    color: #B45309;
    background: #FFFBEB;
    border-color: #FEF3C7;
}
.tag-era {
    color: #047857;
    background: #ECFDF5;
    border-color: #D1FAE5;
}

/* Per-row play button. Stays inline on the left of each track row. */
.row-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--accent-soft-2);
    background: var(--accent-soft);
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: background 120ms, transform 120ms, color 120ms;
}
.row-play .ico { width: 12px; height: 12px; }
.row-play .ico-play  { margin-left: 1px; /* visual nudge — triangle's centroid sits left of its bbox */ }
.row-play .ico-pause { display: none; }
/* When the audio element is actively emitting sound for THIS track,
   swap the icon to ⏸. .playing alone (without .is-playing-now) means
   "current but paused" — keep showing ▶ so the user knows clicking
   resumes. */
.row-play.is-playing-now .ico-play  { display: none; }
.row-play.is-playing-now .ico-pause { display: inline-block; margin: 0; }
.row-play:hover { background: var(--accent); color: white; }
.row-play:active { transform: scale(0.92); }
.row-play.playing {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 0 4px var(--accent-soft-2);
}
.row-play.disabled {
    background: var(--surface-2);
    border-color: var(--line);
    color: var(--muted-2);
    cursor: not-allowed;
}

/* Persistent player bar. Pinned to the bottom so playback continues across
   tab switches and re-renders of the track editor. */
.player-bar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
}
.player-bar[hidden] { display: none; }
.player-info {
    flex: 0 0 auto;
    min-width: 220px;
    max-width: 360px;
    overflow: hidden;
}
.player-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-sub {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.player-bar audio {
    flex: 1 1 auto;
    height: 36px;
    border-radius: var(--r-sm);
}
.player-close {
    flex: 0 0 auto;
    width: 32px; height: 32px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    border-radius: 50%;
    font-size: 18px;
    color: var(--muted);
    cursor: pointer;
}
.player-close:hover { background: var(--surface-hover); color: var(--text); }

/* Reserve room at the bottom of the scrollable page so the fixed player
   bar never covers the last row of content. */
body.has-player .page-body { padding-bottom: 80px; }

.actions {
    display: flex; gap: 8px; margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

button.primary {
    background: var(--accent);
    color: white;
    border: 0;
    padding: 9px 16px;
    border-radius: var(--r);
    cursor: pointer;
    font-weight: 600;
    transition: background 120ms, box-shadow 120ms;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

button.secondary {
    background: var(--surface);
    color: var(--text-2);
    border: 1px solid var(--line);
    padding: 9px 16px;
    border-radius: var(--r);
    cursor: pointer;
    font-weight: 500;
    transition: background 120ms, border-color 120ms;
}
button.secondary:hover { background: var(--surface-hover); border-color: var(--line-strong); }

button.danger {
    background: var(--surface);
    color: var(--red);
    border: 1px solid var(--red-soft);
    padding: 9px 16px;
    border-radius: var(--r);
    cursor: pointer;
    font-weight: 500;
    margin-left: auto;
    transition: background 120ms, border-color 120ms;
}
button.danger:hover { background: var(--red-soft); border-color: var(--red); }

.audio-info {
    background: var(--surface-2);
    border: 1px dashed var(--line-strong);
    border-radius: var(--r);
    padding: 10px 14px;
    margin-bottom: 18px;
    font-size: 13px;
    color: var(--muted);
}

.audio-player {
    background: var(--accent-soft);
    border: 1px solid var(--accent-soft-2);
    border-radius: var(--r);
    padding: 12px 14px;
    margin-bottom: 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.audio-player audio {
    width: 100%;
    height: 38px;
    border-radius: var(--r-sm);
}
.audio-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    align-self: flex-start;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: var(--r-sm);
    font-weight: 600;
    cursor: pointer;
}
.audio-play-btn:hover { background: var(--accent-hover); }
.audio-play-btn svg { width: 16px; height: 16px; }
.audio-play-btn.playing { background: var(--green); }
.audio-play-btn.playing::after { content: '· playing'; font-size: 11px; opacity: .85; }
.row-play.playing { color: var(--green); }
.audio-meta {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px;
}
.audio-dl {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: var(--r-sm);
    background: var(--surface);
    border: 1px solid var(--accent-soft-2);
    transition: background 120ms;
}
.audio-dl:hover { background: var(--accent-soft-2); }

.audio-replace {
    margin-left: auto;
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--accent-soft-2);
    border-radius: var(--r-sm);
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms;
}
.audio-replace:hover { background: var(--accent-soft-2); }

/* Drop-zone shown when a track has no MP3 yet. */
.audio-uploader {
    display: flex; align-items: center; gap: 14px;
    padding: 18px 18px;
    margin-bottom: 18px;
    background: var(--surface-2);
    border: 2px dashed var(--line-strong);
    border-radius: var(--r-lg);
    cursor: pointer;
    transition: background 120ms, border-color 120ms;
    outline: none;
}
.audio-uploader:hover, .audio-uploader:focus {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.audio-uploader.drag {
    background: var(--accent-soft);
    border-color: var(--accent);
    border-style: solid;
}
.audio-uploader .up-icon {
    width: 32px; height: 32px;
    color: var(--accent);
    flex-shrink: 0;
}
.audio-uploader .up-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}
.audio-uploader .up-link {
    color: var(--accent);
    text-decoration: underline;
}
.audio-uploader .up-sub {
    font-size: 12px;
    margin-top: 2px;
}

/* ============================================================== stats */

.stats-wrap {
    padding: 24px 28px 32px;
    max-width: 1400px;
    margin: 0 auto;
}

.stats-header {
    display: flex; align-items: baseline; gap: 12px; margin-bottom: 24px;
}
.stats-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    background: var(--green);
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0   rgba(16, 185, 129, 0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0   rgba(16, 185, 129, 0); }
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 160ms, transform 160ms;
}
.kpi:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.kpi-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.kpi-value {
    font-size: 28px;
    font-weight: 700;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--text);
}

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 1000px) { .stats-row { grid-template-columns: 1fr; } }

.card {
    /* card already defined above; stats override padding */
}
#view-stats .card {
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}
#view-stats .card h3 {
    margin: 0 0 14px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th, .data-table td {
    text-align: left;
    padding: 8px 8px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}
.data-table th {
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* ---------- daily activity bars ---------- */

.bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    height: 180px;
    padding: 24px 0;
}
.bar {
    flex: 1;
    background: linear-gradient(to top, var(--accent) 0%, #818CF8 100%);
    border-radius: 6px 6px 0 0;
    position: relative;
    min-height: 4px;
    transition: filter 160ms, transform 160ms;
}
.bar:hover {
    filter: brightness(1.08);
    transform: translateY(-2px);
}
.bar .bar-value {
    position: absolute;
    top: -20px; left: 0; right: 0;
    text-align: center;
    font-size: 11px;
    color: var(--text-2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.bar .bar-label {
    position: absolute;
    bottom: -20px; left: 0; right: 0;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
}

.tag {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 2px 7px;
    font-size: 11px;
    color: var(--muted);
    margin-right: 4px;
    font-weight: 500;
}

/* ============================================================== toast */

.toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--text);
    border: 1px solid var(--text);
    color: white;
    padding: 10px 18px;
    border-radius: var(--r);
    opacity: 0;
    transition: opacity 200ms, transform 200ms;
    pointer-events: none;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    font-size: 13px;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.error {
    background: var(--red);
    border-color: var(--red);
    color: white;
}
.toast.ok {
    background: var(--green);
    border-color: var(--green);
    color: white;
}

/* ============================================================== scrollbars */

.track-list::-webkit-scrollbar,
.artist-list::-webkit-scrollbar,
.editor::-webkit-scrollbar,
.stats-view::-webkit-scrollbar { width: 10px; height: 10px; }
.track-list::-webkit-scrollbar-thumb,
.artist-list::-webkit-scrollbar-thumb,
.editor::-webkit-scrollbar-thumb,
.stats-view::-webkit-scrollbar-thumb {
    background: #D8DEE9;
    border-radius: 8px;
    border: 2px solid var(--surface);
}
.track-list::-webkit-scrollbar-thumb:hover,
.artist-list::-webkit-scrollbar-thumb:hover,
.editor::-webkit-scrollbar-thumb:hover,
.stats-view::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }
.track-list::-webkit-scrollbar-track,
.artist-list::-webkit-scrollbar-track,
.editor::-webkit-scrollbar-track,
.stats-view::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   SCRAPER tab — Telegram channel ingest
   Layered cards: session → controls → queue. Two-pane queue
   reuses the same .track-list / .editor styles where possible.
   ============================================================ */
/* Override the .view.active flex display so the wrap actually fills
   the page width — otherwise it shrinks to its content and the bulk
   bar's buttons overflow. Mirrors how .stats-view is set up. */
.scraper-view { display: none; padding: 0; }
.scraper-view.active { display: block; overflow-y: auto; }
.scraper-wrap {
    display: flex; flex-direction: column; gap: 1.2em;
    padding: 24px 28px 32px;
    max-width: 1400px; margin: 0 auto;
}
.scraper-card { padding: 1.1em 1.3em; }
.scraper-card h3 { margin: 0 0 .6em; }
.scraper-login-stage { display: grid; gap: .4em; max-width: 26em; margin-top: .6em; }
.scraper-login-stage label { font-size: .85em; color: var(--muted); }
.scraper-login-stage input { padding: .55em .7em; border: 1px solid var(--line); border-radius: 6px; font-size: 1em; }
.scraper-login-stage button { justify-self: start; }
.form-err { color: #BF616A; margin-top: .6em; font-size: .9em; }

.scraper-controls { display: flex; gap: .6em; align-items: center; flex-wrap: wrap; }
.scraper-controls input[type="text"] { flex: 1; min-width: 16em; padding: .55em .7em; border: 1px solid var(--line); border-radius: 6px; }
.scraper-controls input[type="number"] { width: 6em; padding: .35em .5em; border: 1px solid var(--line); border-radius: 6px; }
.scraper-controls label { display: flex; align-items: center; gap: .4em; font-size: .9em; color: var(--muted); }
.scraper-controls .scraper-fresh-lbl input { width: 16px; height: 16px; }
.scraper-hint { margin-top: .7em; font-size: .82em; line-height: 1.4; }
.scraper-hint.resume {
    color: #1B5E20; background: #E8F5E9;
    border: 1px solid #A5D6A7; border-radius: 6px;
    padding: .5em .7em;
}

.scraper-progress { margin-top: .9em; font-size: .9em; padding: .6em .8em; border-radius: 8px; }
.scraper-progress.running {
    background: #EBF5FF;
    border: 1px solid #5E81AC;
    color: var(--text);
    font-size: 1em;
}
.scraper-progress.failed {
    background: #FBEBEB;
    border: 1px solid #BF616A;
    color: #5C2A30;
    font-size: 1em;
}
.prog-head { display: flex; align-items: center; gap: .5em; margin-bottom: .5em; }
.prog-spinner {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid #5E81AC; border-top-color: transparent;
    animation: spin 0.9s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.prog-bar {
    height: 6px; background: #D8DEE9; border-radius: 3px; overflow: hidden;
    margin-bottom: .6em;
}
.prog-fill {
    height: 100%; background: #5E81AC; border-radius: 3px;
    transition: width .3s ease;
}
.prog-stats { display: flex; gap: 1.2em; flex-wrap: wrap; margin-bottom: .4em; }
.prog-stats span { display: flex; flex-direction: column; line-height: 1.1; }
.prog-stats span b { font-size: 1.4em; }
.prog-stats span small { color: var(--muted); font-size: .75em; }
.prog-stats span.ok b { color: #A3BE8C; }
.prog-latest {
    padding: .4em .6em; background: rgba(255,255,255,.6);
    border-radius: 4px; font-size: .9em; margin-top: .3em;
}

.scraper-tabs { display: flex; gap: .4em; margin-bottom: .8em; border-bottom: 1px solid var(--line); }
.scraper-subtab {
    background: none; border: none; padding: .55em 1em;
    cursor: pointer; font-size: .92em; color: var(--muted);
    border-bottom: 2px solid transparent;
}
.scraper-subtab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.scraper-subtab span { display: inline-block; min-width: 1.4em; padding: 0 .35em;
    background: var(--line); border-radius: 999px; font-size: .8em; margin-left: .3em; }

/* ---- pending list (full-width rows, no two-pane editor) ---- */
/* No internal scroll: the whole scraper-view scrolls as one page,
   so the list grows naturally as new rows arrive during a live
   scrape and the sticky bulk-bar pins to the top of the viewport. */
.scraper-list {
    list-style: none; padding: 0; margin: 0;
    border-top: 1px solid var(--line);
}
.scraper-list .empty-row {
    padding: 2em; text-align: center; color: var(--muted);
}
.srow {
    border-bottom: 1px solid var(--line);
    transition: background .15s;
}
.srow:hover { background: #F8F9FB; }
.srow.expanded { background: #F4F6FA; }
.srow-main {
    display: flex; align-items: center; gap: .8em;
    padding: .6em .8em;
    min-width: 0; /* lets flex children wrap text instead of overflow */
}
.srow-tick { width: 18px; height: 18px; cursor: pointer; flex: 0 0 auto; }
.srow-tick-spacer { width: 18px; flex: 0 0 auto; }
.srow-text {
    flex: 1 1 auto; min-width: 0;
    display: flex; flex-direction: column; gap: .15em;
}
.srow-title {
    font-weight: 600; font-size: .98em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.srow-sub {
    font-size: .82em; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.srow-sub .muted { color: var(--muted); }
.srow-controls {
    display: flex; gap: .35em; flex: 0 0 auto;
    align-items: center;
}
.iconbtn {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 6px; padding: .35em .6em;
    cursor: pointer; font-size: .85em; line-height: 1;
    color: var(--text);
    transition: background .12s, border-color .12s;
}
.iconbtn:hover { background: #ECEFF4; border-color: var(--line-strong); }
.iconbtn.add    { color: #2E7D32; border-color: #C8E6C9; }
.iconbtn.add:hover    { background: #E8F5E9; }
.iconbtn.delete { color: #BF616A; }
.iconbtn.delete:hover { background: #FCE4E4; border-color: #BF616A; }
.iconbtn.expand.no-info { opacity: .4; }
.pill.ok {
    background: #E8F5E9; color: #2E7D32; border-radius: 999px;
    padding: .1em .55em; font-size: .8em; margin-left: .4em;
}

/* ---- expanded detail panel ---- */
.srow-detail {
    padding: .4em 1em 1em 2.6em;
    display: flex; flex-direction: column; gap: .7em;
    border-top: 1px dashed var(--line);
}
.srow-audio { width: 100%; height: 36px; }
.detail-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: .5em;
}
.detail-grid label, .srow-detail label.full {
    display: flex; flex-direction: column; gap: .2em;
    font-size: .8em; color: var(--muted);
}
.detail-grid input, .srow-detail textarea {
    padding: .35em .5em; border: 1px solid var(--line);
    border-radius: 5px; font-size: .9em; color: var(--text);
}
.srow-detail textarea { resize: vertical; min-height: 5em; }
.lyrics-source {
    font-size: .8em; color: #2E5783;
    background: #EBF5FF; border: 1px solid #B6D4F2;
    padding: .35em .6em; border-radius: 4px;
    margin-bottom: .35em;
}
.lyrics-source.pair-reply    { border-color: #2E7D32; background: #E8F5E9; color: #1B5E20; }
.lyrics-source.pair-group    { border-color: #2E7D32; background: #E8F5E9; color: #1B5E20; }
.lyrics-source.pair-adjacent { border-color: #B6D4F2; background: #EBF5FF; color: #2E5783; }
.lyrics-source.pair-caption  { border-color: #D8DEE9; background: #ECEFF4; color: #4C566A; }
/* Tiny "has lyrics" indicator on the collapsed row title. */
.lyrics-dot {
    display: inline-block; font-size: .8em; line-height: 1;
    margin-left: .35em; padding: .1em .4em; border-radius: 999px;
    vertical-align: middle;
}
.lyrics-dot.pair-reply,
.lyrics-dot.pair-group    { background: #E8F5E9; color: #1B5E20; }
.lyrics-dot.pair-adjacent { background: #EBF5FF; color: #2E5783; }
.lyrics-dot.pair-caption  { background: #ECEFF4; color: #4C566A; }
.save-edits { align-self: flex-start; }
.caption-collapse summary { cursor: pointer; color: var(--muted); font-size: .85em; }
.caption-pre {
    background: #ECEFF4; padding: .6em .8em; border-radius: 5px;
    white-space: pre-wrap; font-family: inherit; font-size: .85em;
    max-height: 14em; overflow-y: auto;
}

/* ---- sticky bulk-action bar ----
   Always visible while there are rows. Idle state is muted so it
   doesn't dominate; once 1+ rows are ticked, .has-selection flips
   the bar to vivid blue and reveals the action buttons. */
.scraper-bulkbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .6em .9em;
    padding: .65em .9em; background: #ECEFF4; color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px 6px 0 0;
    margin-bottom: 0;
    transition: background .15s, color .15s;
}
.scraper-bulkbar.has-selection {
    background: #5E81AC; color: white; border-color: #5E81AC;
}
.scraper-bulkbar:not(.has-selection) .bulk-actions { display: none; }
.scraper-bulkbar:not(.has-selection) .select-all input { accent-color: #5E81AC; }
.scraper-bulkbar .select-all {
    display: flex; align-items: center; gap: .5em; cursor: pointer;
    flex: 0 0 auto;
}
.scraper-bulkbar .select-all input { width: 18px; height: 18px; }
.scraper-bulkbar .bulk-actions {
    display: flex; gap: .5em; flex-wrap: wrap; justify-content: flex-end;
    flex: 1 1 auto;
}
.scraper-bulkbar .bulk-actions button { white-space: nowrap; }
.scraper-bulkbar .danger { background: #BF616A; color: white; border: none; }
.scraper-bulkbar .danger:hover { background: #A54D55; }
.scraper-bulkbar .link-btn { color: white; opacity: .85; }
.scraper-bulkbar .link-btn:hover { opacity: 1; }

/* ---- shared confirm modal ---- */
.modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
/* `display: flex` above wins over the UA's [hidden] { display:none },
   so the modal would show on first load until openConfirm() opens
   it for real. Force it back. */
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(46, 52, 64, 0.55);
}
.modal-card {
    position: relative; z-index: 1;
    background: var(--surface); border-radius: 10px;
    padding: 1.4em 1.6em; max-width: 32em; width: 90vw;
    box-shadow: 0 16px 60px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 .8em; }
.modal-body { margin-bottom: 1em; }
.confirm-list {
    margin: .6em 0 0; padding-left: 1.2em;
    max-height: 18em; overflow-y: auto; font-size: .9em;
}
.modal-actions { display: flex; justify-content: flex-end; gap: .6em; }
.modal-actions .danger { background: #BF616A; color: white; border: none; }
.modal-actions .danger:hover { background: #A54D55; }
/* Dup-check UI inside the single-Add modal. */
.confirm-track-pill {
    background: #ECEFF4; padding: .5em .8em;
    border-radius: 6px; margin: .4em 0 1em;
}
.dup-area { margin-bottom: .8em; }
.dup-clean { color: #2E7D32; background: #E8F5E9; border: 1px solid #A5D6A7;
             padding: .55em .8em; border-radius: 6px; font-size: .9em; }
.dup-warn  { color: #8B5A00; background: #FFF8E1; border: 1px solid #FFE0A3;
             padding: .5em .8em; border-radius: 6px; font-size: .9em; margin-bottom: .5em; }
.dup-hint  { font-size: .8em; margin-top: .5em; }
.dup-list  { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .35em; }
.dup-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: .8em; padding: .5em .7em;
    background: #F8F9FB; border: 1px solid var(--line); border-radius: 6px;
}
.dup-meta   { min-width: 0; flex: 1 1 auto; }
.dup-line   { font-size: .9em; line-height: 1.3; }
.dup-badge  { color: var(--muted); font-size: .8em; margin-left: .35em; }
.dup-conf   { color: var(--muted); font-size: .8em; margin-left: .55em; }
.dup-actions { display: flex; gap: .35em; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.dup-actions button { font-size: .82em; padding: .3em .6em; }

/* Bulk-Add dup-check UI. Same color palette as the single-Add equivalents
   above, but a side-by-side "pending → existing match" layout so the
   admin can scan many rows at once and decide skip-vs-override. */
.bulk-prog {
    margin: .6em 0; font-size: .85em; color: var(--muted);
    text-align: center;
}
.dup-warn-line {
    color: #8B5A00; background: #FFF8E1; border: 1px solid #FFE0A3;
    padding: .55em .8em; border-radius: 6px; font-size: .9em;
    margin-bottom: .5em;
}
.bulk-dup-details {
    margin-top: .5em;
    border: 1px solid var(--line); border-radius: 6px;
    background: #FAFBFD;
}
.bulk-dup-details > summary {
    cursor: pointer; padding: .55em .8em;
    font-size: .88em; font-weight: 500; color: var(--text-2);
    user-select: none;
}
.bulk-dup-details > summary:hover { background: var(--surface-hover); }
.bulk-dup-list {
    list-style: none; margin: 0; padding: .2em .4em .5em;
    max-height: 22em; overflow-y: auto;
    display: flex; flex-direction: column; gap: .3em;
}
.bulk-dup-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center; gap: .6em;
    padding: .45em .65em;
    background: white; border: 1px solid var(--line); border-radius: 5px;
    font-size: .85em;
}
.bulk-dup-pending,
.bulk-dup-existing {
    min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bulk-dup-arrow {
    color: var(--muted-2); font-size: 1.1em; flex: 0 0 auto;
}
.bulk-add-override {
    margin-top: .9em; text-align: center;
    padding-top: .8em; border-top: 1px dashed var(--line);
}
.link-btn.danger-link {
    color: #BF616A; font-size: .85em;
}
.link-btn.danger-link:hover { color: #A54D55; }

/* ============================================================
   DATABASE EXPLORER
   Three-column finder layout: DBs | Tables | Rows.
   ============================================================ */
.db-view {
    padding: 0 1.4em 1.4em;
    /* .view.active is `display:flex` (default row); we want column so
       the mode-bar stacks above the columns and the columns fill the
       rest of .page-body. */
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Mode toggle (Library / Tables) — sits above the columns. */
.db-mode-bar {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: flex-start;
    padding: .9em 0 .8em;
}
.db-mode-toggle {
    display: inline-flex; gap: 2px;
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 999px; padding: 3px;
}
.db-mode-btn {
    border: none; background: transparent; cursor: pointer;
    padding: .42em 1em; border-radius: 999px;
    font-size: .85em; font-weight: 500; color: var(--muted);
    font-family: inherit;
}
.db-mode-btn:hover { color: var(--text); }
.db-mode-btn.active {
    background: var(--surface); color: var(--accent);
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.db-cols {
    display: grid;
    grid-template-columns: 240px 280px 1fr;
    gap: 1em;
    /* Fill remaining vertical space inside .db-view (which itself fills
       .page-body). min-height:0 lets the grid actually shrink instead of
       overflowing — without it the children's intrinsic content size
       wins and the columns push past the bottom of the screen. */
    flex: 1 1 auto;
    min-height: 0;
}
.db-cols[hidden] { display: none; }   /* defeat the grid display when toggled off */
.db-col {
    display: flex; flex-direction: column;
    overflow: hidden;
    padding: 0;
}
.db-col-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: .9em 1em; border-bottom: 1px solid var(--line);
    font-weight: 600; font-size: .92em; color: var(--text-2);
    background: var(--surface-2);
    flex: 0 0 auto;
}
.db-mini-search {
    border: 1px solid var(--line); border-radius: 6px;
    padding: .25em .55em; font-size: .82em; width: 8em;
}
.db-list, .db-tables { list-style: none; margin: 0; padding: .4em; overflow-y: auto; flex: 1 1 auto; }

/* Column 1 — databases */
.db-list-item {
    padding: .7em .8em; border-radius: 8px; cursor: pointer;
    margin-bottom: .25em; border: 1px solid transparent;
}
.db-list-item:hover { background: var(--surface-hover); }
.db-list-item.selected {
    background: var(--accent-soft); border-color: var(--accent-soft-2);
}
.db-list-item.missing { opacity: .5; cursor: not-allowed; }
.db-list-name { font-weight: 600; font-size: .95em; color: var(--text); }
.db-list-meta { font-size: .78em; color: var(--muted); margin-top: .15em; }
.db-list-note { font-size: .76em; margin-top: .15em; line-height: 1.3; }
.missing-tag {
    color: #BF616A; background: #FFEBEE; padding: .1em .4em; border-radius: 4px;
    font-size: .85em;
}

/* Column 2 — tables */
.db-table-item {
    display: grid; grid-template-columns: 1.4em 1fr auto;
    align-items: center; gap: .5em;
    padding: .45em .6em; border-radius: 6px; cursor: pointer;
    font-size: .88em;
}
.db-table-item:hover { background: var(--surface-hover); }
.db-table-item.selected { background: var(--accent-soft); color: var(--accent); }
.db-table-item.shadow { color: var(--muted); font-style: italic; }
.db-table-icon { color: var(--muted-2); font-size: .9em; text-align: center; }
.db-table-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, 'SF Mono', Menlo, monospace, 'Vazirmatn'; }
.db-table-count { font-size: .78em; color: var(--muted); }
.db-table-sep {
    margin-top: .8em; padding: .4em .6em .2em;
    font-size: .72em; text-transform: uppercase; color: var(--muted-2);
    letter-spacing: .05em;
}
.db-empty { padding: 1em; text-align: center; }

/* Column 3 — rows */
.db-rows-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1em; padding: .9em 1em; border-bottom: 1px solid var(--line);
    background: var(--surface-2); flex: 0 0 auto;
}
.db-rows-title { display: flex; flex-direction: column; }
.db-rows-title #db-rows-title,
.db-rows-title #lib-tracks-title { font-weight: 600; font-family: 'Inter', 'Vazirmatn', sans-serif; }
.db-rows-title #db-rows-meta { font-size: .78em; }
.db-rows-tools { display: flex; align-items: center; gap: .5em; }
.db-search input { font-size: .85em; padding: .35em .5em .35em 2em; width: 14em; }
#db-schema-toggle { font-size: .82em; padding: .35em .8em; }
#db-schema-toggle.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-2); }

.db-rows-wrap { flex: 1 1 auto; overflow: auto; }
.db-rows-table {
    width: 100%; border-collapse: collapse; font-size: .85em;
    /* Inter for Latin, Vazirmatn for Arabic glyphs (per-glyph fallback by
       the browser). Mono fonts mangle Sorani — same fix we use elsewhere
       in the panel for any field that holds Kurdish text. */
    font-family: 'Inter', 'Vazirmatn', sans-serif;
}
.db-rows-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--surface); border-bottom: 1px solid var(--line-strong);
    padding: .55em .7em; text-align: left; cursor: pointer; user-select: none;
    white-space: nowrap; font-weight: 600; color: var(--text-2);
}
.db-rows-table thead th:hover { background: var(--surface-hover); }
.db-rows-table tbody td {
    padding: .45em .7em; border-bottom: 1px solid var(--line);
    max-width: 32em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    vertical-align: top;
}
.db-rows-table tbody tr:hover td { background: var(--surface-2); }
.db-null { color: var(--muted-2); font-style: italic; }

/* Schema panel */
.db-schema {
    padding: 1em 1.2em; background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    max-height: 40vh; overflow-y: auto; flex: 0 0 auto;
}
.db-schema-table {
    width: 100%; border-collapse: collapse; font-size: .82em;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    margin-bottom: .8em;
}
.db-schema-table th, .db-schema-table td {
    padding: .3em .6em; border-bottom: 1px solid var(--line);
    text-align: left;
}
.db-schema-sub { margin-top: .8em; font-size: .85em; }
.db-schema-sub b { display: block; margin-bottom: .3em; }
.db-schema-sub ul { margin: 0; padding-left: 1.2em; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .82em; }
.db-schema-sql {
    background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
    padding: .6em .8em; font-size: .8em; white-space: pre-wrap; word-break: break-word;
    max-height: 14em; overflow-y: auto;
}

/* Pager */
.db-pager {
    display: flex; align-items: center; justify-content: center;
    gap: .8em; padding: .6em; border-top: 1px solid var(--line);
    background: var(--surface-2); flex: 0 0 auto; font-size: .85em;
}
.db-pager button {
    border: 1px solid var(--line); background: var(--surface);
    border-radius: 6px; padding: .25em .7em; cursor: pointer;
}
.db-pager button:disabled { opacity: .4; cursor: not-allowed; }

/* Tiny refresh button used in all three column heads. Subtle when idle,
   spins for one rotation when clicked so the click registers visually. */
.db-refresh-btn {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--muted); border-radius: 6px;
    width: 1.9em; height: 1.9em; padding: 0;
    font-size: 1em; line-height: 1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.db-refresh-btn:hover { background: var(--surface-hover); color: var(--text); }
.db-refresh-btn:disabled { opacity: .5; cursor: wait; }
.db-refresh-btn.spinning { animation: db-spin .6s linear; }
@keyframes db-spin { to { transform: rotate(360deg); } }

/* BLOB cells — distinct colour so they don't look like garbled text. */
.db-blob { color: var(--accent); font-style: italic; }

/* Hover affordance: tells the user a row is clickable for full details. */
.db-rows-table tbody tr { cursor: pointer; }

/* Row-detail modal: wider than the standard confirm modal because we need
   to show full lyrics / JSON values without horizontal scroll. */
.db-row-modal-card {
    max-width: 56em; width: 92vw;
    max-height: 86vh; display: flex; flex-direction: column;
}
.db-row-modal-body {
    overflow-y: auto; flex: 1 1 auto;
    margin-bottom: 1em;
}
.db-row-detail { margin: 0; }
.db-row-detail-row {
    display: grid; grid-template-columns: 11em 1fr auto;
    align-items: start; gap: .6em;
    padding: .55em 0; border-bottom: 1px solid var(--line);
}
.db-row-detail-row:last-child { border-bottom: none; }
.db-row-detail-key {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: .85em; color: var(--muted);
    word-break: break-word;
}
.db-row-detail-val {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: .85em; white-space: pre-wrap; word-break: break-word;
    color: var(--text);
}
.db-row-detail-val.is-null  { color: var(--muted-2); font-style: italic; }
.db-row-detail-val.is-blob  { color: var(--accent);  font-style: italic; }
.db-row-detail-copy {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--muted-2); border-radius: 5px;
    font-size: .72em; padding: .2em .55em; cursor: pointer;
    align-self: flex-start;
}
.db-row-detail-copy:hover { background: var(--surface-hover); color: var(--text); }
.db-row-detail-copy.copied { color: #2E7D32; border-color: #A5D6A7; }

/* ============================================================
   LIBRARY mode (categorised browse) — three-column layout
   reusing .db-col / .db-list / .db-rows-* skeletons but with
   its own track list (no SQL grid) and Vazirmatn-friendly text
   so Sorani titles + artist names render cleanly.
   ============================================================ */

/* Column 2 values: { label … count } per row. */
.lib-val-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: .6em;
}
.lib-val-label {
    font-weight: 500; font-size: .9em; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-family: 'Inter', 'Vazirmatn', sans-serif;
}
.lib-val-count {
    flex: 0 0 auto;
    font-size: .76em; color: var(--muted);
    background: var(--surface-2); border-radius: 999px;
    padding: .1em .55em;
}
.lib-val-item.selected .lib-val-count {
    background: var(--surface); color: var(--accent);
}

/* Column 3 track list. Grid columns: ▶, #id, title, artist, tags. */
.lib-tracks-wrap { padding: .2em 0; }
.lib-tracks-list {
    list-style: none; margin: 0; padding: .3em .4em;
}
.lib-track-row {
    display: grid;
    grid-template-columns: 28px 64px 1fr 1fr auto;
    align-items: center; gap: .7em;
    padding: .5em .7em;
    border-radius: 8px;
    border-bottom: 1px solid var(--line);
    font-family: 'Inter', 'Vazirmatn', sans-serif;
    font-size: .9em;
}
.lib-track-row:last-child { border-bottom: 0; }
.lib-track-row:hover { background: var(--surface-hover); }
.lib-track-row.can-play { cursor: pointer; }
.lib-track-row .row-id {
    color: var(--muted); font-size: .78em;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.lib-track-title {
    font-weight: 500; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-track-artist {
    color: var(--muted); font-size: .88em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Artist name renders as a clickable link → jumps to the Artist category
   with that artist preselected. Underline only on hover so the row stays
   visually calm when scanning a long list. */
a.lib-track-artist.lib-link {
    color: var(--accent); cursor: pointer; text-decoration: none;
}
a.lib-track-artist.lib-link:hover {
    color: var(--accent); text-decoration: underline;
}
.lib-track-tags {
    display: flex; flex-wrap: wrap; gap: .25em; justify-content: flex-end;
}
.lib-pager { border-top: 1px solid var(--line); }



/* ============================================================
   RECOMMENDATIONS tab
   Single full-width list of user-submitted messages / songs.
   Each row shows the user, the message body (text or inline
   <audio>), status pills, and block / delete actions.
   ============================================================ */
.rec-view  { padding: 0 1.4em 1.4em; }
.rec-wrap  { display: flex; flex-direction: column; gap: 1em; padding-top: 1em; }

/* Top toolbar — status filter pills + search + actions */
.rec-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1em; padding: .8em 1em; flex-wrap: wrap;
}
.rec-status-pills { display: flex; gap: .35em; flex-wrap: wrap; }
.rec-pill {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--text-2); padding: .35em .85em; border-radius: 999px;
    font-size: .82em; cursor: pointer; font-family: inherit;
}
.rec-pill:hover  { background: var(--surface-hover); }
.rec-pill.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-2); }
.rec-pill span   { margin-left: .35em; opacity: .7; font-size: .9em; }
.rec-tools       { display: flex; gap: .5em; align-items: center; }
.rec-tools .search-input input { width: 16em; }

/* Blocked-users panel (collapsible) */
.rec-blocked-panel { padding: 1em 1.2em; }
.rec-blocked-panel h3 { margin: 0 0 .6em; font-size: .95em; }
.rec-blocked-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .35em; }
.rec-blocked-list li {
    display: flex; align-items: center; justify-content: space-between;
    padding: .4em .6em; background: var(--surface-2); border-radius: 6px;
    font-size: .88em;
}

/* Recommendation list */
.rec-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .8em; }
.rec-row  {
    padding: 1em 1.2em;
    display: flex; flex-direction: column; gap: .7em;
    border-left: 3px solid transparent;
}
.rec-row.is-new      { border-left-color: var(--accent); background: var(--accent-soft); }
.rec-row.is-blocked  { opacity: .8; }
.rec-row-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: .8em;
}
.rec-user       { display: flex; align-items: center; gap: .5em; min-width: 0; }
.rec-kind       { font-size: 1.1em; }
.rec-user-name  { font-weight: 600; font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-blocked-tag {
    background: #FFEBEE; color: #BF616A; border: 1px solid #FFCDD2;
    padding: .1em .5em; border-radius: 4px; font-size: .72em;
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.rec-time { font-size: .78em; flex: 0 0 auto; }

.rec-row-body { padding: .2em 0; }
.rec-text {
    font-size: .95em; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
    /* Inter for Latin, Vazirmatn for Arabic glyphs (per-glyph fallback). */
    font-family: 'Inter', 'Vazirmatn', sans-serif;
}
.rec-row-body audio { width: 100%; max-width: 32em; }
.rec-audio-meta { font-size: .82em; margin-top: .35em; }
.rec-audio-missing { font-size: .85em; color: #BF616A; }

.rec-row-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: .8em; flex-wrap: wrap; padding-top: .4em;
    border-top: 1px solid var(--line);
}
.rec-status-group { display: flex; gap: .25em; }
.rec-status-btn {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--muted); padding: .25em .65em; border-radius: 5px;
    font-size: .76em; cursor: pointer; text-transform: capitalize;
    font-family: inherit;
}
.rec-status-btn:hover  { background: var(--surface-hover); color: var(--text); }
.rec-status-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft-2); }

.rec-action-group { display: flex; gap: .5em; }
.rec-action-group button { font-size: .82em; padding: .35em .8em; }
.rec-block { color: #BF616A; }
.rec-block:hover { background: #FFEBEE; border-color: #FFCDD2; }

.rec-empty { padding: 2em; text-align: center; }

/* Approve-recommendation modal — wider than the standard confirm modal
   because we render a full track-fields form. Two-column grid for the
   short fields, full-width row for the lyrics textarea. */
.rec-approve-card {
    max-width: 48em; width: 92vw;
    max-height: 88vh; display: flex; flex-direction: column;
}
.rec-approve-card h2 { margin-bottom: .2em; }
#rec-approve-summary { margin-bottom: 1em; font-size: .85em; }
.rec-approve-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: .55em .8em;
    overflow-y: auto;
    padding-right: .2em;
    margin-bottom: 1em;
}
.ra-cell { display: flex; flex-direction: column; gap: .2em; }
.ra-cell > span { font-size: .78em; color: var(--muted); font-weight: 500; }
.ra-cell > span em { color: #BF616A; font-style: normal; }
.ra-cell input,
.ra-cell textarea {
    border: 1px solid var(--line); border-radius: 6px;
    padding: .45em .6em; font-size: .92em;
    font-family: 'Inter', 'Vazirmatn', sans-serif;
    background: var(--surface);
}
.ra-cell input:focus,
.ra-cell textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft-2);
}
.ra-lyrics { grid-column: 1 / -1; }
.ra-lyrics textarea { resize: vertical; min-height: 6em; }

.ra-dup {
    border: 1px solid #FFE0A3; background: #FFF8E1; border-radius: 6px;
    padding: .8em 1em; margin-bottom: .8em;
}
.ra-dup-actions { display: flex; gap: .5em; margin-top: .6em; }

.rec-approved-tag {
    background: #E8F5E9; color: #2E7D32; border: 1px solid #A5D6A7;
    padding: .3em .8em; border-radius: 5px;
    font-size: .82em; font-weight: 500;
}

/* Approve-modal "not MP3" error variant — red palette to make it
   clear this is a hard rejection, not the amber "duplicate" warning. */
.ra-dup.ra-error {
    border-color: #FFCDD2; background: #FFEBEE;
}
.ra-dup.ra-error .dup-warn-line {
    background: transparent; border: none; padding: 0;
    color: #BF616A; font-size: 1em; margin-bottom: .35em;
}
.ra-fmt { font-size: .85em; margin-top: .25em; }
.ra-fmt code {
    background: var(--surface); border: 1px solid var(--line);
    padding: .1em .4em; border-radius: 4px; font-size: .9em;
}

/* User-activity card (Bot stats tab) */
.users-activity-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: .3em;
}
.users-activity-head h3 { margin: 0; }
#users-activity { font-size: .88em; }
#users-activity tr.ua-idle td { color: var(--muted-2); }
#users-activity .ua-misses { color: #BF616A; font-weight: 500; }

/* ====================================================== EXTERNAL (SoundCloud) tab */
.ext-view              { padding: 0; }
.ext-wrap              { display: flex; flex-direction: column; gap: 12px; }
.ext-toolbar           { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.ext-status-pills      { display: flex; gap: 6px; }
.ext-pill              { background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; cursor: pointer; color: var(--text); font-size: 13px; }
.ext-pill.active       { background: var(--accent-soft); border-color: var(--accent); }
.ext-pill span         { margin-left: 4px; opacity: .7; font-size: 12px; }
.ext-tools             { display: flex; gap: 6px; }
.ext-list              { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ext-row               { padding: 12px 14px; }
.ext-row-head          { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ext-row-title b       { font-size: 15px; }
.ext-row-meta          { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ext-row-body          { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.ext-audio             { width: 100%; max-width: 480px; }
.ext-row-sub           { font-size: 12px; }
.ext-edit-grid         { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ext-edit-grid label   { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ext-edit-grid input   { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 13px; }
.ext-row-actions       { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ext-empty             { padding: 24px; text-align: center; }

/* Status pills inside row meta */
.pill.ext-status-pending           { background: var(--accent-soft); color: var(--accent); }
.pill.ext-status-approved_external { background: #d6efc7; color: #2c5e1a; }
.pill.ext-status-approved_main     { background: #c5e1f9; color: #1d4f7a; }
.pill.ext-status-rejected          { background: #f6d4d4; color: #7a1d1d; }

/* ==============================================================
   DARK MODE
   ==============================================================
   Activated by `data-theme="dark"` on <html>. The pre-paint
   script in index.html applies it before CSS loads so there is
   no flash of light theme on a dark-mode reload.

   Strategy: override the same CSS custom properties the light
   theme defines, then patch the handful of components that
   hardcode their own colors below this block.
   ============================================================== */

html[data-theme="dark"] {
    /* surfaces — slate-900 / -800 / -950 ladder */
    --bg:           #0F172A;
    --surface:      #1E293B;
    --surface-2:    #111827;
    --surface-hover:#334155;

    /* text — light slate so it stays readable against the dark fill */
    --text:         #F1F5F9;
    --text-2:       #CBD5E1;
    --muted:        #94A3B8;
    --muted-2:      #64748B;

    /* lines — subtle separators on dark backgrounds */
    --line:         #334155;
    --line-strong:  #475569;

    /* accents — lighten the indigo so it doesn't disappear */
    --accent:       #818CF8;
    --accent-hover: #A5B4FC;
    --accent-soft:  #312E81;
    --accent-soft-2:#3730A3;

    --green:        #34D399;
    --green-soft:   #064E3B;
    --red:          #F87171;
    --red-soft:     #7F1D1D;
    --amber:        #FBBF24;

    /* depth — heavier shadows are invisible on dark; soften them */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.30), 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.40), 0 1px 3px rgba(0, 0, 0, 0.30);
    --ring:      0 0 0 3px rgba(129, 140, 248, 0.30);

    color-scheme: dark;
}

/* Form fields — the browser default fill on dark UAs gives white text
   on white background otherwise; force the panel's slate. */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--line-strong);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: var(--muted-2);
}

/* Hardcoded-color patches. Original light values live in the
   sections above this block; the rules below rewrite just the
   pieces that aren't variable-driven. Selectors mirror the
   original ones so specificity wins on default insertion order. */

/* Iconbutton color variants (lines 590-606 region of light CSS). */
html[data-theme="dark"] .iconbtn.color-accent { color: #C7D2FE; background: rgba(99,102,241,0.15);  border-color: rgba(99,102,241,0.40); }
html[data-theme="dark"] .iconbtn.color-amber  { color: #FCD34D; background: rgba(245,158,11,0.12);  border-color: rgba(245,158,11,0.35); }
html[data-theme="dark"] .iconbtn.color-green  { color: #6EE7B7; background: rgba(16,185,129,0.12);  border-color: rgba(16,185,129,0.35); }

/* Scraper progress widget — explicitly white-on-dark slate. */
html[data-theme="dark"] .form-err           { color: #FCA5A5; }
html[data-theme="dark"] .form-success       { color: #BBF7D0; background: rgba(16,185,129,0.10); border-color: rgba(16,185,129,0.40); }
html[data-theme="dark"] .form-info          { color: #BFDBFE; background: rgba(94,129,172,0.15); border-color: rgba(94,129,172,0.45); }
html[data-theme="dark"] .form-error         { color: #FCA5A5; background: rgba(239,68,68,0.12);  border-color: rgba(239,68,68,0.40); }
html[data-theme="dark"] .spinner            { border-color: rgba(94,129,172,0.40); border-top-color: transparent; }
html[data-theme="dark"] .prog-bar           { background: var(--line-strong); }
html[data-theme="dark"] .prog-bar > div     { background: var(--accent); }
html[data-theme="dark"] .prog-stats span.ok b { color: #BBF7D0; }
html[data-theme="dark"] .prog-stats span.dup b{ color: var(--muted); }

/* Scraper row hover (lines 1184-1185 region). */
html[data-theme="dark"] .srow:hover         { background: var(--surface-hover); }
html[data-theme="dark"] .srow.expanded      { background: var(--surface-hover); }

/* Add/delete inline icon buttons (1218-1224). */
html[data-theme="dark"] .iconbtn.add        { color: #6EE7B7; border-color: rgba(16,185,129,0.40); }
html[data-theme="dark"] .iconbtn.add:hover  { background: rgba(16,185,129,0.12); }
html[data-theme="dark"] .iconbtn.delete     { color: #FCA5A5; }
html[data-theme="dark"] .iconbtn.delete:hover { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.45); }
html[data-theme="dark"] .iconbtn-pill       { background: rgba(16,185,129,0.18); color: #BBF7D0; }

/* Lyrics-source pairing badges (1248-1266). */
html[data-theme="dark"] .lyrics-source              { color: #BFDBFE; background: rgba(94,129,172,0.18); border-color: rgba(94,129,172,0.45); }
html[data-theme="dark"] .lyrics-source.pair-reply    { border-color: rgba(16,185,129,0.50); background: rgba(16,185,129,0.15); color: #BBF7D0; }
html[data-theme="dark"] .lyrics-source.pair-group    { border-color: rgba(16,185,129,0.50); background: rgba(16,185,129,0.15); color: #BBF7D0; }
html[data-theme="dark"] .lyrics-source.pair-adjacent { border-color: rgba(94,129,172,0.50); background: rgba(94,129,172,0.18); color: #BFDBFE; }
html[data-theme="dark"] .lyrics-source.pair-caption  { border-color: var(--line-strong);  background: var(--surface-hover);    color: var(--muted); }

html[data-theme="dark"] .lyrics-dot.pair-group       { background: rgba(16,185,129,0.18); color: #BBF7D0; }
html[data-theme="dark"] .lyrics-dot.pair-adjacent    { background: rgba(94,129,172,0.20); color: #BFDBFE; }
html[data-theme="dark"] .lyrics-dot.pair-caption     { background: var(--surface-hover);   color: var(--muted); }

/* External-tier status pills (last few lines of light CSS). */
html[data-theme="dark"] .pill.ext-status-pending           { background: rgba(245,158,11,0.20); color: #FDE68A; }
html[data-theme="dark"] .pill.ext-status-approved_external { background: rgba(16,185,129,0.20); color: #BBF7D0; }
html[data-theme="dark"] .pill.ext-status-approved_main     { background: rgba(94,129,172,0.25); color: #BFDBFE; }
html[data-theme="dark"] .pill.ext-status-rejected          { background: rgba(239,68,68,0.20);  color: #FCA5A5; }

/* Approval-queue / submission status pills (used in editor + admin). */
html[data-theme="dark"] .pill.pending  { background: rgba(245,158,11,0.20); color: #FDE68A; }
html[data-theme="dark"] .pill.approved { background: rgba(16,185,129,0.20); color: #BBF7D0; }
html[data-theme="dark"] .pill.rejected { background: rgba(239,68,68,0.20);  color: #FCA5A5; }

/* Modal backdrop — lift opacity on dark so the underlying app dims further. */
html[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.65); }

/* ==============================================================
   THEME TOGGLE BUTTON
   ============================================================== */
.theme-toggle {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    padding: 8px 10px;
    border-radius: var(--r);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    margin-top: 8px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); border-color: var(--line-strong); }
.theme-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Show only the icon matching the *next* theme — clicking always
   switches, so the icon represents what you'll get when you click. */
.theme-toggle .icon-dark, .theme-toggle .label-dark { display: inline-flex; }
.theme-toggle .icon-light, .theme-toggle .label-light { display: none; }
html[data-theme="dark"] .theme-toggle .icon-dark, html[data-theme="dark"] .theme-toggle .label-dark { display: none; }
html[data-theme="dark"] .theme-toggle .icon-light, html[data-theme="dark"] .theme-toggle .label-light { display: inline-flex; }

/* ==============================================================
   RESPONSIVE — phone + tablet
   ==============================================================
   Two breakpoints:
     ≤ 900px  Tablet / phone landscape — sidebar becomes a slide-
              out drawer behind a backdrop; two-pane views stack
              vertically; tap targets enlarged.
     ≤ 600px  Phone portrait — form rows drop to one column,
              page padding tightens, KPI grid drops to two cols,
              cards horizontal-scroll any wider content (tables).
   The drawer is opened by a .nav-toggle button injected into
   .page-head. The backdrop element catches outside taps.
   ============================================================== */

/* Hamburger button — hidden on desktop, revealed on mobile via
   the @media block below. Lives in .page-head, ahead of .page-title. */
.nav-toggle {
    display: none;
    align-items: center; justify-content: center;
    width: 40px; height: 40px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--r);
    color: var(--text);
    cursor: pointer;
    margin-right: 12px;
    flex-shrink: 0;
}
.nav-toggle:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.nav-toggle svg { width: 20px; height: 20px; }

/* Backdrop — only visible when .app.nav-open. Sits at z-index 49,
   below the drawer (50) but above all main-area content. */
.nav-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 49;
}

/* ----- ≤ 900px : drawer + stacked two-pane ----- */
@media (max-width: 900px) {
    /* App shell becomes single-column. */
    .app { grid-template-columns: 1fr; }

    /* Sidebar = off-canvas drawer. */
    .app-nav {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px; max-width: 80vw;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s ease-out;
        box-shadow: var(--shadow-lg);
    }
    .app.nav-open .app-nav { transform: translateX(0); }
    .app.nav-open .nav-backdrop { display: block; }

    /* Hamburger visible. */
    .nav-toggle { display: inline-flex; }

    /* Tighter page padding on small screens. */
    .page-head { padding: 0 14px; height: 56px; }
    .page-title { font-size: 18px; }

    /* Stack two-pane views: list above, editor below. Existing
       .two-pane { display:grid } gets overridden here. */
    .two-pane { display: block !important; }
    .two-pane > .list-pane,
    .two-pane > .editor {
        width: 100%;
        max-width: 100%;
        margin-bottom: 12px;
    }
    /* When both rendered side-by-side they had separate scrolling
       contexts; flat-stacked, the page itself scrolls — drop the
       inner overflows so a long lyrics textarea can grow naturally. */
    .two-pane > .list-pane { max-height: 60vh; overflow: auto; }

    /* Larger tap targets for nav items. */
    .nav-item, .tab.nav-item { padding: 14px 12px; min-height: 44px; }

    /* Multi-column form rows used by the admin editor + scraper. */
    .row-2,
    .row-3 { grid-template-columns: 1fr; }
    .ext-edit-grid { grid-template-columns: 1fr; }

    /* Database explorer's three panes — stack vertically on mobile.
       Each pane gets a sensible max-height so the user can scroll
       within one without the whole page becoming a single huge list. */
    .db-cols { grid-template-columns: 1fr; }
    .db-cols > * { max-height: 50vh; overflow: auto; }

    /* iOS Safari zooms when an input's computed font-size is < 16px
       on focus. Clamp to 16px in the mobile breakpoint to prevent
       the page from yanking around mid-interaction. */
    input[type="text"], input[type="search"], input[type="password"],
    input[type="number"], input[type="email"], input[type="tel"],
    textarea, select { font-size: 16px; }

    /* Stats KPI grid already uses auto-fit minmax(190px, 1fr) — fine
       on mobile. Stats-row already collapses at 1000px (existing rule). */
}

/* ----- ≤ 600px : phone portrait ----- */
@media (max-width: 600px) {
    .page-body { padding: 0 8px; }
    .card { padding: 12px; }

    /* Search rows: input fills the row, buttons wrap below. */
    .search-row { flex-wrap: wrap; gap: 8px; }
    .search-row > .search-input { flex: 1 1 100%; }

    /* KPI grid → 2 cols (was auto-fit 190px which tries to fit 3 on
       a 360px screen and clips). */
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }

    /* Cards holding wide tables get horizontal scroll on mobile so
       table columns don't overflow off-screen. */
    .card { overflow-x: auto; }

    /* Modals — full width with small inset. */
    .modal-card { width: calc(100vw - 24px); max-width: 100vw; padding: 1em 1em; }

    /* Table cell padding tightens. */
    .data-table th, .data-table td { padding: 6px 8px; font-size: 12px; }
}

/* ----- ≤ 380px : extra-small phones (iPhone SE / Mini) ----- */
@media (max-width: 380px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .nav-toggle { width: 36px; height: 36px; margin-right: 8px; }
}
