/**
 * brands.css — Styles for the Brand & Campaign Management page (v0.39.0)
 *
 * Depends on design-system.css for --ds-* variables.
 */

/* ── ds-input-sm (not in design-system.css) ─────────────────────── */
.ds-input-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}

/* ── Auth gate ───────────────────────────────────────────────────── */
.auth-gate {
    position: fixed;
    inset: 0;
    background: var(--ds-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.auth-gate.ds-hidden { display: none; }

.auth-gate-dialog {
    width: 360px;
    padding: 2rem;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-gate-icon  { font-size: 2.5rem; }
.auth-gate-title { font-size: 1.25rem; font-weight: 600; margin: 0; }
.auth-gate-desc  { color: var(--ds-text-muted); font-size: 0.875rem; margin: 0; }

/* ── App shell ───────────────────────────────────────────────────── */
.brands-app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 44px);
    background: var(--ds-bg);
    color: var(--ds-text);
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────── */
.brands-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--ds-surface);
    border-bottom: 1px solid var(--ds-border);
    flex-shrink: 0;
}

.brands-header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    color: var(--ds-text-muted);
    text-decoration: none;
    font-size: 0.8125rem;
}

.nav-link:hover { color: var(--ds-accent); }

/* ── Body: sidebar + main ────────────────────────────────────────── */
.brands-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.brands-body.ds-hidden { display: none; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.brands-sidebar {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--ds-surface);
    border-right: 1px solid var(--ds-border);
    overflow: hidden;
    transition: width 0.22s ease;
}

.brands-sidebar.collapsed {
    width: 48px;
}

.brands-sidebar.collapsed .sidebar-search,
.brands-sidebar.collapsed .brand-list,
.brands-sidebar.collapsed .sidebar-footer {
    display: none;
}

/* Shared .sidebar-header / .sidebar-collapse-btn come from style.css.
   Override border color to use ds-tokens in this context. */
.brands-sidebar .sidebar-header {
    border-bottom-color: var(--ds-border);
}

.sidebar-search {
    padding: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--ds-border);
}

/* ── Brand list ──────────────────────────────────────────────────── */
.brand-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ── Sidebar footer ──────────────────────────────────────────────── */
.sidebar-footer {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--ds-border);
}

.sidebar-footer-btn {
    width: 100%;
    justify-content: center;
}

.brand-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--ds-radius-md, 6px);
    cursor: pointer;
    transition: background 0.1s;
}

.brand-item:hover { background: var(--ds-surface-raised); }

.brand-item.active {
    background: var(--ds-accent-subtle, rgba(99,102,241,0.12));
}

.brand-item-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0;
}

.brand-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.0625rem;
}

.brand-item-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ds-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-item-count {
    font-size: 0.625rem;
    color: var(--ds-text-muted);
}

.brand-item-actions { display: none; gap: 0.25rem; flex-shrink: 0; }
.brand-item:hover .brand-item-actions { display: flex; }

/* ── Main content ────────────────────────────────────────────────── */
.brands-main {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    background: var(--ds-bg);
}

/* ── Placeholder ─────────────────────────────────────────────────── */
.main-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: var(--ds-text-muted);
    text-align: center;
    gap: 0.75rem;
    padding: 2rem;
}

.placeholder-icon { font-size: 3rem; margin-bottom: 0.25rem; opacity: 0.6; }
.main-placeholder h3 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--ds-text); }
.main-placeholder p  { margin: 0; font-size: 0.875rem; max-width: 320px; line-height: 1.6; }
.placeholder-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; }

/* ── Brand panel ─────────────────────────────────────────────────── */
.brand-panel { padding: 1.5rem; }
.brand-panel.ds-hidden { display: none; }

.brand-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.brand-panel-name   { margin: 0; font-size: 1.5rem; font-weight: 700; }
.brand-panel-actions { display: flex; gap: 0.5rem; }

/* ── Back navigation link ────────────────────────────────────────── */
.back-link { display: none; } /* superseded by header-back-btn */

.header-back-btn {
    background: none;
    border: none;
    color: var(--ds-text-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px 0 0;
    flex-shrink: 0;
    transition: color 0.12s;
}
.header-back-btn:hover { color: var(--ds-text); }

/* ── Brand content layout ────────────────────────────────────────── */
.brand-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Creatives grid ──────────────────────────────────────────────── */
.creatives-section { }

.creatives-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

.creative-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.creative-card:hover {
    border-color: var(--ds-accent);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

.creative-card-thumb {
    aspect-ratio: 16/9;
    background: var(--ds-bg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.creative-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.creative-card-thumb-placeholder {
    font-size: 1.5rem;
    color: var(--ds-text-muted);
}
.creative-card-info {
    padding: 0.5rem 0.625rem 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
.creative-card-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ds-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.creative-card-count {
    font-size: 0.6875rem;
    color: var(--ds-text-muted);
}

/* ── Stats chips ─────────────────────────────────────────────────── */
.stat-groups {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    align-items: flex-start;
}

.stat-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0 1.5rem;
    border-right: 1px solid var(--ds-border);
}

.stat-group:first-child { padding-left: 0; }
.stat-group:last-child  { padding-right: 0; border-right: none; }

.stat-group-title {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ds-text-muted);
    text-align: center;
}

.stat-group-items {
    display: flex;
    justify-content: space-evenly;
    align-items: baseline;
    width: 100%;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-item-value {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--ds-accent);
    line-height: 1.1;
}

.stat-item-label {
    font-size: 0.625rem;
    color: var(--ds-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
}

.stat-footer {
    font-size: 0.75rem;
    color: var(--ds-text-muted);
    text-align: center;
    margin-top: 1.25rem;
    margin-bottom: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--ds-border);
}

/* ── Distribution bars ───────────────────────────────────────────── */
.distrib-section { margin-bottom: 1.5rem; }

.distrib-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ds-text-muted);
    margin-bottom: 0.75rem;
}

.distrib-bar-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 4px;
    margin-left: -4px;
    transition: background 0.15s;
}

.distrib-bar-row:hover {
    background: var(--ds-bg-raised, rgba(255,255,255,0.05));
}

.distrib-bar-row.distrib-bar-active {
    background: rgba(99, 102, 241, 0.15);
}

.distrib-bar-row.distrib-bar-active .distrib-bar-label {
    color: var(--ds-text);
}

.distrib-bar-row.distrib-bar-active .distrib-bar-fill {
    background: #818cf8;
}

.distrib-clear-btn {
    background: none;
    border: none;
    color: var(--ds-accent);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0 0 0 0.5rem;
    opacity: 0.8;
}

.distrib-clear-btn:hover { opacity: 1; }

.distrib-bar-label {
    width: 90px;
    flex-shrink: 0;
    color: var(--ds-text-muted);
}

.distrib-bar-track {
    flex: 1;
    height: 6px;
    background: var(--ds-border);
    border-radius: 3px;
    overflow: hidden;
}

.distrib-bar-fill {
    height: 100%;
    background: var(--ds-accent);
    border-radius: 3px;
    transition: width 0.3s;
}

/* SOV per-channel group: channel name left, three metric rows right */
.sov-channel-group {
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.sov-channel-name {
    padding-top: 2px;
}

.sov-metrics {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sov-metric-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.sov-metric-label {
    width: 110px;
    flex-shrink: 0;
    color: var(--ds-text-muted);
    font-size: 0.7rem;
}

.distrib-bar-count {
    width: 24px;
    text-align: right;
    color: var(--ds-text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Ad panel ────────────────────────────────────────────────────── */
.ad-panel {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.ad-panel.ds-hidden { display: none; }

.ad-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--ds-surface);
    border-bottom: 1px solid var(--ds-border);
    flex-shrink: 0;
}

/* ── Ad player ───────────────────────────────────────────────────── */
.ad-player-wrap {
    position: relative;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: var(--ds-radius-md);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--ds-border);
    align-self: flex-start;
}

.ad-player-canvas {
    display: block;
    width: 256px;
    height: 144px;
}

.ad-player-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.25rem;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
    color: #fff;
}

.ad-player-wrap:hover .ad-player-overlay,
.ad-player-wrap.paused .ad-player-overlay { opacity: 1; }

.ad-header-info { flex: 1; min-width: 0; }

.ad-header-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1rem;
}

.ad-header-full { grid-column: 1 / -1; }

.ad-header-actions {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    grid-column: 1 / -1;
    margin-top: 0.25rem;
}

/* ── Ad content ──────────────────────────────────────────────────── */
.ad-content {
    flex: 1;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Occurrences ─────────────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.875rem;
}

.section-title { font-size: 0.875rem; font-weight: 600; color: var(--ds-text); }
.section-count { font-size: 0.75rem; color: var(--ds-text-muted); }

.occ-row {
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md);
    margin-bottom: 0.5rem;
    overflow: hidden;
    background: var(--ds-surface);
}

.occ-row-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    transition: background 0.1s;
}

.occ-row-header:hover { background: var(--ds-surface-raised); }

.occ-row.expanded .occ-row-header {
    background: var(--ds-surface-raised);
    border-bottom: 1px solid var(--ds-border);
}

.occ-thumb {
    width: 64px;
    height: 36px;
    flex-shrink: 0;
    background: #000;
    border-radius: 3px;
    object-fit: cover;
}

.occ-thumb-placeholder {
    width: 64px;
    height: 36px;
    flex-shrink: 0;
    background: var(--ds-surface-raised);
    border-radius: 3px;
    border: 1px solid var(--ds-border);
}

.occ-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem 0.75rem;
}

.occ-channel {
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--ds-surface-raised);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid var(--ds-border);
}

.occ-date   { font-size: 0.8125rem; color: var(--ds-text); font-variant-numeric: tabular-nums; }
.occ-time   { font-size: 0.8125rem; color: var(--ds-text-muted); font-variant-numeric: tabular-nums; }
.occ-slot   { font-size: 0.75rem; color: var(--ds-text-muted); }
.occ-frames { font-size: 0.75rem; color: var(--ds-text-muted); font-variant-numeric: tabular-nums; font-family: monospace; }

.occ-corrected-badge {
    font-size: 0.6875rem;
    color: var(--ds-warning, #f59e0b);
    background: rgba(245,158,11,0.12);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid rgba(245,158,11,0.3);
}

.occ-viewers-badge {
    font-size: 0.6875rem;
    color: #38bdf8;
    background: rgba(56,189,248,0.10);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid rgba(56,189,248,0.25);
}

.occ-expand-btn { font-size: 0.75rem; color: var(--ds-text-muted); flex-shrink: 0; }

/* ── Occurrence inline editor ────────────────────────────────────── */
/* ── Occurrence inline editor ────────────────────────────────────── */
.occ-editor {
    padding: 0.75rem 1rem;
    background: var(--ds-bg);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 700px;
    margin: 0 auto;
}

/* Player image + Start/End thumbnails in a row */
.occ-editor-body {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
}

.occ-player-img {
    flex: 0 0 60%;
    min-width: 0;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid #2e2e48;
    background: #0a0a18;
    display: block;
}

/* Scrubber row */
.occ-editor .mini-player-controls { display: flex; align-items: center; gap: 8px; }
.occ-editor .mini-play-btn {
    background: none;
    border: 1px solid #2e2e48;
    border-radius: 4px;
    color: #c0c0d8;
    font-size: 13px;
    cursor: pointer;
    padding: 3px 9px;
    flex-shrink: 0;
}
.occ-editor .mini-play-btn:hover { background: #2a2a42; color: #e2e2f0; }
.occ-editor #occ-scrubber { flex: 1; height: 3px; accent-color: #5a8dee; cursor: pointer; }
.occ-editor .mini-counter { font-size: 11px; color: #555; white-space: nowrap; flex-shrink: 0; }
.occ-editor #occ-fps {
    background: #0e0e1e;
    border: 1px solid #2e2e48;
    border-radius: 4px;
    color: #888;
    font-size: 11px;
    padding: 2px 5px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Start / End thumbnail panel */
.occ-editor .frame-range-controls {
    flex: 1;
    min-width: 0;
    background: #0e0e1e;
    border: 1px solid #2e2e48;
    border-radius: 6px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.occ-editor .frame-endpoint { flex: 1; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.occ-editor .frame-endpoint-header { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.occ-editor .frame-endpoint-label { font-size: 9px; font-weight: 800; color: #666; text-transform: uppercase; letter-spacing: 0.08em; flex-shrink: 0; }
.occ-editor .frame-endpoint-time { font-size: 11px; font-variant-numeric: tabular-nums; color: #8898cc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.occ-editor .frame-thumb { flex: 1; min-height: 0; width: 100%; object-fit: cover; border-radius: 4px; border: 1px solid #2e2e48; background: #0a0a18; display: block; }
.occ-editor .frame-thumb.active-seek { border-color: #5a8dee; box-shadow: 0 0 0 2px rgba(90,141,238,.3); }
.occ-editor .frame-adj-row { display: flex; gap: 4px; }
.occ-editor .frame-adj-btn {
    flex: 1;
    background: #1a1a30;
    border: 1px solid #2e2e48;
    border-radius: 4px;
    color: #888;
    font-size: 11px;
    cursor: pointer;
    padding: 4px 0;
    line-height: 1;
    transition: color 0.1s, background 0.1s, border-color 0.1s;
}
.occ-editor .frame-adj-btn:hover  { background: #2a2a42; color: #e2e2f0; border-color: #5a8dee; }
.occ-editor .frame-adj-btn:active { background: #5a8dee; color: #fff; border-color: #5a8dee; }

/* Save/Abort actions — hidden until dirty */
.occ-editor-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
}
.occ-editor-actions.ds-hidden { display: none; }

.occ-editor-note {
    font-size: 0.6875rem;
    color: var(--ds-text-muted);
    text-align: center;
    font-style: italic;
    margin: 0;
}

/* ── Skeleton / loading states ───────────────────────────────────── */
.sidebar-skeleton {
    padding: 0.75rem;
    font-size: 0.8125rem;
    color: var(--ds-text-muted);
    text-align: center;
}

.sidebar-loading {
    padding: 1rem;
    text-align: center;
    color: var(--ds-text-muted);
    font-size: 0.8125rem;
}

/* ── Identity chip: defined in style.css ─────────────────────────── */
/* ── Modal ───────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.ds-hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

.modal-dialog {
    position: relative;
    width: min(500px, 90vw);
    background: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-xl);
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--ds-space-lg) var(--ds-space-xl);
    border-bottom: 1px solid var(--ds-border);
}

.modal-title {
    margin: 0;
    font-size: var(--ds-font-size-lg);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--ds-text-muted);
    font-size: var(--ds-font-size-lg);
    cursor: pointer;
    padding: var(--ds-space-xs);
    line-height: 1;
    transition: color var(--ds-transition-fast);
}

.modal-close:hover { color: var(--ds-text); }

.modal-body   { padding: var(--ds-space-xl); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--ds-space-sm);
    padding: var(--ds-space-lg) var(--ds-space-xl);
    border-top: 1px solid var(--ds-border);
}

/* ── Toast ───────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: var(--ds-space-2xl, 2rem);
    right: var(--ds-space-2xl, 2rem);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-md, 0.75rem);
    pointer-events: none;
}

#toast-container > * { pointer-events: auto; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .brands-body    { flex-direction: column; }
    .brands-sidebar { width: 100%; max-height: 40vh; flex-shrink: 0; }
}
