/* =========================================================================
   Zema Studio — admin theme
   Light/dark tokens, app shell (top bar + sidebar), and restyling of the
   Bootstrap 4 components used by the scaffolded admin views.
   ========================================================================= */

:root {
    --bg: #f9f9f9;
    --surface: #ffffff;
    --surface-2: #f2f2f2;
    --hover: rgba(0, 0, 0, .05);
    --active: rgba(0, 0, 0, .1);
    --text: #0f0f0f;
    --text-2: #606060;
    --text-3: #909090;
    --border: #e5e5e5;
    --accent: #065fd4;
    --accent-soft: #def1ff;
    --brand: #ff0033;
    --success: #0f8a3c;
    --danger: #cc0000;
    --warning: #b06000;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 3px rgba(0, 0, 0, .08);
    --radius: 12px;
    --topbar-h: 56px;
    --sidebar-w: 248px;
    --sidebar-mini-w: 72px;
    --chart-1: #065fd4;
    --chart-2: #ff0033;
    --chart-3: #0f8a3c;
    --chart-4: #b06000;
    --chart-5: #7b3fe4;
    --chart-6: #00838f;
    --chart-grid: rgba(0, 0, 0, .08);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #1f1f1f;
    --surface: #282828;
    --surface-2: #323232;
    --hover: rgba(255, 255, 255, .08);
    --active: rgba(255, 255, 255, .14);
    --text: #f1f1f1;
    --text-2: #aaaaaa;
    --text-3: #717171;
    --border: #3f3f3f;
    --accent: #3ea6ff;
    --accent-soft: rgba(62, 166, 255, .16);
    --brand: #ff4e45;
    --success: #2ba640;
    --danger: #ff4e45;
    --warning: #f9a825;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --chart-1: #3ea6ff;
    --chart-2: #ff4e45;
    --chart-3: #2ba640;
    --chart-4: #f9a825;
    --chart-5: #b388ff;
    --chart-6: #4dd0e1;
    --chart-grid: rgba(255, 255, 255, .08);
    color-scheme: dark;
}

/* ---------- base ---------- */
html, body.studio {
    background: var(--bg);
}

body.studio {
    margin: 0;
    color: var(--text);
    font-family: "Roboto", "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

body.studio a { color: var(--accent); }
body.studio a:hover { text-decoration: none; opacity: .85; }

.msi {
    font-family: "Material Symbols Outlined";
    font-weight: normal;
    font-style: normal;
    font-size: 22px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    direction: ltr;
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
    vertical-align: middle;
    user-select: none;
}

.msi.fill { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }

/* ---------- top bar ---------- */
.studio-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--topbar-h);
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.studio-topbar .brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text) !important;
    font-weight: 500;
    font-size: 18px;
    letter-spacing: -.3px;
    white-space: nowrap;
}

.logo {
    position: relative;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border-radius: 50%;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.logo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.logo.lg {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    font-size: 40px;
    margin-bottom: 10px;
}

.studio-topbar .brand .tag {
    color: var(--brand);
    font-weight: 700;
}

.icon-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn:hover { background: var(--hover); }
.icon-btn:focus-visible, .studio-btn:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.studio-search {
    flex: 1 1 auto;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
}

.studio-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.studio-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 15px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
}

/* ---------- buttons ---------- */
.studio-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text) !important;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.studio-btn:hover { background: var(--hover); opacity: 1 !important; }
.studio-btn .msi { font-size: 20px; }

.studio-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff !important;
}

:root[data-theme="dark"] .studio-btn.primary { color: #0f0f0f !important; }
.studio-btn.primary:hover { filter: brightness(1.08); background: var(--accent); }

.studio-btn.ghost { border-color: transparent; background: transparent; }
.studio-btn.danger { color: var(--danger) !important; }

/* ---------- dropdowns ---------- */
.studio .dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 32px rgba(0, 0, 0, .16);
    padding: 8px 0;
    min-width: 240px;
    color: var(--text);
}

.studio .dropdown-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 9px 18px;
    color: var(--text) !important;
    font-size: 14px;
}

.studio .dropdown-item:hover, .studio .dropdown-item:focus { background: var(--hover); color: var(--text); }
.studio .dropdown-item .msi { color: var(--text-2); }
.studio .dropdown-divider { border-top-color: var(--border); }
.studio .dropdown-header { color: var(--text-2); font-size: 12px; }

/* ---------- sidebar ---------- */
.studio-sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    z-index: 1020;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px 0 24px;
    transition: width .18s ease, transform .2s ease;
    scrollbar-width: thin;
}

.channel-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12px 16px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.channel-card .name { font-weight: 500; font-size: 15px; }
.channel-card .role { color: var(--text-2); font-size: 12px; }

.nav-section {
    padding: 14px 24px 6px;
    color: var(--text-2);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: .6px;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 20px;
    height: 44px;
    padding: 0 24px;
    color: var(--text-2) !important;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    white-space: nowrap;
}

.nav-item .msi { color: var(--text-2); font-size: 22px; }
.nav-item:hover { background: var(--hover); opacity: 1 !important; }

.nav-item.active { color: var(--brand) !important; background: var(--surface-2); }
.nav-item.active .msi { color: var(--brand); font-variation-settings: "FILL" 1; }
.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--brand);
}

body.sidebar-mini .studio-sidebar { width: var(--sidebar-mini-w); }
body.sidebar-mini .studio-sidebar .channel-card,
body.sidebar-mini .studio-sidebar .nav-section,
body.sidebar-mini .studio-sidebar .nav-label { display: none; }
body.sidebar-mini .studio-sidebar .nav-item { justify-content: center; padding: 0; }
body.sidebar-mini .studio-main { margin-left: var(--sidebar-mini-w); }

.sidebar-scrim {
    display: none;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, .4);
    z-index: 1015;
}

/* ---------- main ---------- */
.studio-main {
    margin-left: var(--sidebar-w);
    padding: calc(var(--topbar-h) + 24px) 32px 48px;
    min-height: 100vh;
    transition: margin-left .18s ease;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-head h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 500;
    letter-spacing: -.2px;
    color: var(--text);
}

.page-head .sub { color: var(--text-2); margin-top: 2px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel-pad { padding: 20px 24px; }

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

.panel-title .hint { color: var(--text-2); font-size: 12px; font-weight: 400; }
.muted { color: var(--text-2); }
.small-muted { color: var(--text-2); font-size: 12px; }

/* ---------- dashboard ---------- */
.range-tabs {
    display: inline-flex;
    padding: 3px;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.range-tabs a {
    padding: 6px 14px;
    border-radius: 16px;
    color: var(--text-2) !important;
    font-weight: 500;
    font-size: 13px;
}

.range-tabs a.on { background: var(--surface); color: var(--text) !important; box-shadow: var(--shadow); }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kpi .label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
}

.kpi .label .msi { font-size: 18px; }
.kpi .value { font-size: 28px; font-weight: 500; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }

.delta {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    font-weight: 500;
}

.delta .msi { font-size: 16px; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--text-2); }

.dash-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 16px;
}

.dash-grid > *, .kpi-grid > * { min-width: 0; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 230px; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 12px;
    color: var(--text-2);
}

.legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: -1px;
}

.mix {
    display: flex;
    height: 10px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface-2);
    margin: 10px 0 14px;
}

.mix span { display: block; height: 100%; }

.stat-list { list-style: none; margin: 0; padding: 0; }

.stat-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0;
    border-top: 1px solid var(--border);
}

.stat-list li:first-child { border-top: 0; }
.stat-list .num { font-weight: 500; font-variant-numeric: tabular-nums; }

.media-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    min-width: 0;
}

.media-row:first-child { border-top: 0; }
.media-row .meta { min-width: 0; flex: 1; }

.media-row .title {
    color: var(--text);
    font-weight: 500;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank {
    width: 18px;
    color: var(--text-2);
    font-weight: 500;
    text-align: right;
    flex: 0 0 18px;
}

.thumb {
    position: relative;
    flex: 0 0 auto;
    width: 120px;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
}

.thumb.sm { width: 88px; }
.thumb.square { width: 56px; aspect-ratio: 1 / 1; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge-kind {
    position: absolute;
    right: 4px;
    bottom: 4px;
    background: rgba(0, 0, 0, .78);
    color: #fff;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
}

.thumb .badge-kind .msi { font-size: 14px; }

.empty {
    text-align: center;
    color: var(--text-2);
    padding: 36px 16px;
}

.empty .msi { font-size: 40px; color: var(--text-3); display: block; margin: 0 auto 8px; }

.note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
}

.note .msi { color: var(--accent); font-size: 20px; }

/* ---------- content page ---------- */
.studio-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    overflow-x: auto;
}

.studio-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 12px 18px;
    color: var(--text-2) !important;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.studio-tabs a.on { color: var(--text) !important; border-bottom-color: var(--text); }

.count-pill {
    background: var(--surface-2);
    color: var(--text-2);
    border-radius: 10px;
    padding: 0 7px;
    font-size: 12px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.filter-bar .grow { flex: 1 1 220px; }

.chip-select, .chip-input {
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 17px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    max-width: 100%;
}

.chip-input { width: 100%; }
.chip-check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; margin: 0; cursor: pointer; }

.table-wrap { overflow-x: auto; }

.studio-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text);
}

.studio-table th {
    position: sticky;
    top: 0;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 500;
    text-align: left;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.studio-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.studio-table tr:hover td { background: var(--hover); }
.studio-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.studio-table th.num { text-align: right; }

.item-cell { display: flex; gap: 14px; align-items: center; min-width: 280px; }
.item-cell .meta { min-width: 0; }
.item-cell .title { color: var(--text); font-weight: 500; }
.item-cell .desc {
    color: var(--text-2);
    font-size: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 420px;
}

.row-actions { display: flex; gap: 2px; opacity: .55; transition: opacity .12s; }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
.row-actions .icon-btn { width: 34px; height: 34px; flex-basis: 34px; color: var(--text-2); }
.row-actions .icon-btn .msi { font-size: 20px; }
.row-actions form { display: inline; margin: 0; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--text-2);
    white-space: nowrap;
}

.pill .msi { font-size: 14px; }
.pill.on { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: rgba(15, 138, 60, .12); color: var(--success); }
.pill.off { background: rgba(204, 0, 0, .1); color: var(--danger); }

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text-2);
    font-size: 13px;
}

/* =========================================================================
   Scaffolded views (Bootstrap 4 markup) restyled to match the studio
   ========================================================================= */

.studio-page.auto-head > h1:first-child,
.studio-page.auto-head > h2:first-child,
.studio-page.auto-head > h1:first-child + h4,
.studio-page.auto-head > h2:first-child + h4,
.studio-page.auto-head > h1:first-child + h4 + hr,
.studio-page.auto-head > h2:first-child + h4 + hr,
.studio-page.auto-head > h1:first-child + hr,
.studio-page.auto-head > h2:first-child + hr { display: none; }

.studio-page.scaffold {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.studio-page h1, .studio-page h2, .studio-page h3, .studio-page h4, .studio-page h5 { color: var(--text); font-weight: 500; }
.studio-page h4 { font-size: 17px; }
.studio-page hr { border-top-color: var(--border); }

/* scaffolded forms live in .col-md-4: give them room */
.studio-page.scaffold > .row > .col-md-4 {
    flex: 0 0 100%;
    max-width: 680px;
}

.studio-page .form-group { margin-bottom: 18px; }

.studio-page label, .studio-page .control-label {
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.studio-page .form-control {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 42px;
    font-size: 14px;
}

.studio-page textarea.form-control { min-height: 110px; }
.studio-page .form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--surface); color: var(--text); }
.studio-page .form-control::placeholder { color: var(--text-3); }
.studio-page select.form-control option { background: var(--surface); color: var(--text); }

.studio-page input[type="file"].form-control {
    padding: 18px;
    min-height: 72px;
    border-style: dashed;
    border-width: 2px;
    background: var(--surface-2);
    cursor: pointer;
}

.studio-page input[type="checkbox"], .studio-page input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }
.studio-page .checkbox label, .studio-page .form-check-label { color: var(--text); font-weight: 400; font-size: 14px; }

.studio-page .text-danger, .studio-page .field-validation-error { color: var(--danger) !important; font-size: 12px; }
.studio-page .validation-summary-errors ul { padding-left: 18px; margin: 0 0 12px; }

.studio-page .btn {
    border-radius: 18px;
    height: 36px;
    padding: 0 18px;
    font-weight: 500;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.studio-page .btn-default, .studio-page .btn-secondary, .studio-page .btn-light {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
}

:root[data-theme="dark"] .studio-page .btn-default,
:root[data-theme="dark"] .studio-page .btn-primary { color: #0f0f0f; }

.studio-page .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.studio-page .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.studio-page .btn-outline-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.studio-page .btn:hover { filter: brightness(1.08); }

.studio-page .table {
    color: var(--text);
    margin-bottom: 0;
}

.studio-page .table th {
    color: var(--text-2);
    font-size: 12px;
    font-weight: 500;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.studio-page .table td { border-top: 1px solid var(--border); vertical-align: middle; }
.studio-page .table tbody tr:hover td { background: var(--hover); }
.studio-page .table-scroll { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }

.studio-page dl.dl-horizontal, .studio-page dl.row {
    display: grid;
    grid-template-columns: minmax(140px, 220px) 1fr;
    gap: 0;
    margin: 0;
}

.studio-page dl.dl-horizontal dt, .studio-page dl.row dt,
.studio-page dl.dl-horizontal dd, .studio-page dl.row dd {
    padding: 10px 0;
    border-top: 1px solid var(--border);
    margin: 0;
    max-width: none;
    flex: none;
    word-break: break-word;
}

.studio-page dl dt { color: var(--text-2); font-weight: 500; font-size: 13px; }

.studio-page .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}

.studio-page .card-header { background: var(--surface-2); border-bottom-color: var(--border); }
.studio-page .page-link { background: var(--surface); border-color: var(--border); color: var(--accent); }
.studio-page .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.studio-page .input-group-text { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }

/* The page header already has a "New" button; hide the scaffold's "Create New" link.
   "Back to List" style links become pill buttons. */
.studio-page.scaffold > p:has(> a[href$="/Create"]:only-child) { display: none; }

.studio-page.scaffold > div:last-of-type > a:not([class]) {
    display: inline-flex;
    align-items: center;
    height: 34px;
    padding: 0 16px;
    border-radius: 17px;
    border: 1px solid var(--border);
    color: var(--text) !important;
    font-weight: 500;
    margin-top: 6px;
}

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
    .span-8, .span-6, .span-4 { grid-column: span 12; }
    .span-4.half, .span-6.half { grid-column: span 6; }
}

@media (max-width: 1024px) {
    .studio-sidebar { transform: translateX(-100%); width: var(--sidebar-w); box-shadow: 0 0 24px rgba(0, 0, 0, .2); }
    body.sidebar-open .studio-sidebar { transform: none; }
    body.sidebar-open .sidebar-scrim { display: block; }
    .studio-main, body.sidebar-mini .studio-main { margin-left: 0; }
    body.sidebar-mini .studio-sidebar { width: var(--sidebar-w); }
    body.sidebar-mini .studio-sidebar .channel-card,
    body.sidebar-mini .studio-sidebar .nav-section { display: block; }
    body.sidebar-mini .studio-sidebar .channel-card { display: flex; }
    body.sidebar-mini .studio-sidebar .nav-label { display: inline; }
    body.sidebar-mini .studio-sidebar .nav-item { justify-content: flex-start; padding: 0 24px; }
}

@media (max-width: 720px) {
    .studio-topbar { padding: 0 8px; gap: 4px; }
    .studio-topbar .brand .text, .studio-btn .btn-text { display: none; }
    .studio-search { display: none; }
    .studio-search.open {
        display: flex;
        position: absolute;
        left: 8px;
        right: 8px;
        top: 8px;
        max-width: none;
        z-index: 2;
    }
    .studio-main { padding: calc(var(--topbar-h) + 16px) 16px 40px; }
    .span-4.half, .span-6.half { grid-column: span 12; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .kpi { padding: 14px; }
    .kpi .value { font-size: 22px; }
    .panel-pad, .studio-page.scaffold { padding: 16px; }
    .studio-page .table-scroll { margin: 0 -16px; padding: 0 16px; }
    .thumb { width: 96px; }
    .item-cell { min-width: 220px; }
    .studio-page dl.dl-horizontal, .studio-page dl.row { grid-template-columns: 1fr; }
    .studio-page dl dd { border-top: 0; padding-top: 0; }
}

@media (min-width: 721px) {
    .search-toggle { display: none; }
}

/* ---------- uploader (drag and drop, progress, preview) ---------- */
.uploader { display: flex; flex-direction: column; gap: 12px; }

.uploader-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 28px 20px;
    text-align: center;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.uploader-drop:hover, .uploader-drop:focus-visible, .uploader-drop.over {
    border-color: var(--accent);
    background: var(--accent-soft);
    outline: none;
}

.uploader-icon {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--hover);
    color: var(--text-2);
}

.uploader-icon .msi { font-size: 36px; }
.uploader-drop.over .uploader-icon { color: var(--accent); }
.uploader-title { font-size: 15px; font-weight: 500; color: var(--text); }
.uploader-sub { font-size: 12px; color: var(--text-2); }
.uploader-drop .studio-btn { margin-top: 6px; }

/* a single slot shows what was uploaded instead of the drop zone */
.uploader[data-multiple="false"].has-value .uploader-drop { padding: 12px; flex-direction: row; justify-content: center; }
.uploader[data-multiple="false"].has-value .uploader-icon,
.uploader[data-multiple="false"].has-value .uploader-sub { display: none; }
.uploader[data-multiple="false"].has-value .uploader-title { font-size: 13px; font-weight: 400; color: var(--text-2); }
.uploader[data-multiple="false"].has-value .uploader-drop .studio-btn { margin-top: 0; }

.uploader-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--hover);
    text-align: center;
}

.uploader-preview img { display: block; max-width: 100%; max-height: 320px; margin: 0 auto; object-fit: contain; }
.uploader-player { width: 100%; border-radius: var(--radius); background: #000; }
audio.uploader-player { background: transparent; }

.uploader-list { display: flex; flex-direction: column; gap: 8px; }
.uploader-list:empty { display: none; }

.uploader-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.uploader-thumb {
    flex: 0 0 48px;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--hover);
    color: var(--text-2);
}

.uploader-thumb img { width: 100%; height: 100%; object-fit: cover; }
.uploader-body { flex: 1; min-width: 0; }
.uploader-file { font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uploader-row .uploader-name { height: 32px; padding: 4px 8px; font-weight: 500; }
.uploader-status { margin-top: 2px; font-size: 12px; color: var(--text-2); }

.uploader-bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--hover); overflow: hidden; }
.uploader-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s; }
.uploader-row.done .uploader-bar span { background: var(--success); }
.uploader-row.done .uploader-status { color: var(--success); }
.uploader-row.error { border-color: var(--danger); }
.uploader-row.error .uploader-status { color: var(--danger); }
.uploader-row.error .uploader-bar { display: none; }
.uploader-notice { font-size: 13px; color: var(--danger); }

.upload-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .upload-layout { grid-template-columns: 1fr; } }

/* ---------- dropdown (picker.js) ---------- */
.picker { position: relative; min-width: 0; }
.picker.chip { display: inline-block; max-width: 100%; }
.picker-native { position: absolute !important; left: 0; bottom: 0; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; opacity: 0; pointer-events: none; }

.picker-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 5px 8px 5px 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: border-color .15s, box-shadow .15s;
}

.picker-toggle:hover { border-color: var(--text-3); }
.picker-toggle:focus-visible, .picker.open .picker-toggle { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.picker.disabled .picker-toggle { opacity: .55; cursor: not-allowed; }
.picker-value { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.picker-value > span:not(.picker-chip) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-placeholder { color: var(--text-3); }
.picker-caret { flex: none; font-size: 20px; color: var(--text-2); transition: transform .15s; }
.picker.open .picker-caret { transform: rotate(180deg); }

.picker.chip .picker-toggle { min-height: 34px; padding: 0 6px 0 12px; border-radius: 17px; font-size: 13px; }

.picker-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 100%;
    padding: 2px 2px 2px 10px;
    border-radius: 14px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
    line-height: 20px;
}

.picker-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-chip-remove { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text-2); cursor: pointer; }
.picker-chip-remove:hover, .picker-chip-remove:focus-visible { background: var(--active); color: var(--text); outline: none; }
.picker-chip-remove .msi { font-size: 16px; }

.picker-panel {
    position: fixed;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .18), 0 2px 6px rgba(0, 0, 0, .08);
    overflow: hidden;
    outline: none;
}

.picker-panel[hidden] { display: none; }
:root[data-theme="dark"] .picker-panel { box-shadow: 0 8px 28px rgba(0, 0, 0, .6); }
.picker-search-box { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.picker-search-box[hidden] { display: none; }
.picker-search-box .msi { font-size: 20px; }
.picker-search { flex: 1; min-width: 0; height: 28px; padding: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 14px; }
.picker-search::placeholder { color: var(--text-3); }
.picker-options { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }

.picker-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

.picker-option.active { background: var(--hover); }
.picker-option.selected { font-weight: 500; }
.picker-option .picker-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-option .msi { flex: none; font-size: 20px; color: var(--text-2); }
.picker-option.selected .picker-box, .picker-option .picker-check { color: var(--accent); }
.picker-option.picker-create { color: var(--accent); font-weight: 500; }
.picker-option.picker-create .msi { color: var(--accent); }
.picker-option + .picker-create, .picker-empty + .picker-create { margin-top: 6px; position: relative; }
.picker-option + .picker-create::before, .picker-empty + .picker-create::before { content: ""; position: absolute; left: -6px; right: -6px; top: -4px; border-top: 1px solid var(--border); }
.picker-empty { padding: 10px; color: var(--text-2); font-size: 13px; }
.picker-error { color: var(--danger); }
.picker.busy .picker-options { opacity: .6; pointer-events: none; }

/* ---------- dialog (quick-create.js) ---------- */
.studio-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
    overflow: hidden;
}

.studio-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.studio-dialog[open] { display: flex; }
.studio-dialog:not([open]) { display: none; }
.studio-dialog form { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 12px 24px; border-bottom: 1px solid var(--border); }
.dialog-head h3 { margin: 0; font-size: 18px; font-weight: 500; }
.dialog-body { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 8px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 24px; border-top: 1px solid var(--border); }
.dialog-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(200px, 2fr); gap: 0 24px; }
.dialog-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.studio-dialog .control-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.studio-dialog .form-group { margin-bottom: 16px; }
.studio-dialog .form-control { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; min-height: 42px; font-size: 14px; }
.studio-dialog .form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.studio-dialog .uploader-drop { padding: 20px 12px; }
.studio-dialog .uploader-icon { width: 52px; height: 52px; }
.studio-dialog .uploader-icon .msi { font-size: 28px; }
.studio-dialog .uploader-preview img { max-height: 180px; }
@media (max-width: 640px) { .dialog-grid { grid-template-columns: 1fr; } }

/* ---------- validation ---------- */
body.studio .text-danger, .field-validation-error { color: var(--danger) !important; }
.field-validation-error { display: block; margin-top: 4px; font-size: 12px; }
.field-validation-error::first-letter { text-transform: uppercase; }
.field-validation-valid { display: none; }
.validation-summary-valid { display: none; }
.validation-summary-errors { margin-bottom: 16px; padding: 10px 14px; border: 1px solid var(--danger); border-radius: 8px; font-size: 13px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.validation-summary-errors li::first-letter { text-transform: uppercase; }
.studio-page .form-control.input-validation-error,
.studio-dialog .form-control.input-validation-error,
.picker:has(.input-validation-error) .picker-toggle { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.uploader-notice { margin-top: 6px; }

/* =========================================================================
   CRUD components: the few pieces every list / form / detail / delete page shares.
   Pages compose these classes (and Views/Shared/Crud partials); nothing page-specific lives here.
   ========================================================================= */

/* list pages: the table sits flush in its card, not padded inside it */
.studio-page.scaffold:has(> .table-wrap) { padding: 0; overflow: hidden; }
.studio-page.scaffold > .table-wrap .studio-table th:first-child,
.studio-page.scaffold > .table-wrap .studio-table td:first-child { padding-left: 24px; }
.studio-page.scaffold > .table-wrap .studio-table th:last-child,
.studio-page.scaffold > .table-wrap .studio-table td:last-child { padding-right: 24px; width: 1%; }
.studio-table td img { border-radius: 8px; vertical-align: middle; }

/* row buttons: quiet until the row is hovered, delete turns red on its own hover */
.icon-btn.danger:hover { color: var(--danger); background: rgba(204, 0, 0, .1); }
.row-actions .icon-btn { border-radius: 10px; }

/* the bar that closes a form or a detail page */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.studio-btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff !important; }
.studio-btn.danger-solid:hover { background: var(--danger); filter: brightness(1.08); }

/* delete confirmation */
.callout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin: 0 0 20px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
}
.callout.danger { background: rgba(204, 0, 0, .08); color: var(--danger); }
.callout .msi { font-size: 20px; }

/* forms: two columns on wide screens, one on phones */
.studio-page form > .form-group { max-width: 680px; }
.studio-page .form-control, .studio-page select.form-control { width: 100%; }

/* detail / delete summaries as a card list */
.studio-page dl.dl-horizontal { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.studio-page dl.dl-horizontal dt, .studio-page dl.dl-horizontal dd { padding: 12px 16px; margin: 0; border-bottom: 1px solid var(--border); }
.studio-page dl.dl-horizontal dt { color: var(--text-2); font-weight: 500; font-size: 13px; background: var(--surface-2); }
.studio-page dl.dl-horizontal dd { color: var(--text); }
.studio-page dl.dl-horizontal dt:last-of-type, .studio-page dl.dl-horizontal dd:last-of-type { border-bottom: 0; }
