/* ============================================================
   Templates Panel — Sidebar + Grouped Card Layout
   Append to app.css or import separately
   ============================================================ */

/* ─── Layout ─────────────────────────────────────────────── */
.templates-layout {
    display: flex;
    gap: 0;
    min-height: calc(100vh - var(--header-height) - 100px);
}

.templates-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    border-radius: 8px 0 0 8px;
    padding: 0;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height) - 100px);
}

.templates-content {
    flex: 1;
    min-width: 0;
    padding: 20px 24px;
}

/* ─── Sidebar Sections ───────────────────────────────────── */
.sidebar-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px 6px;
}

.sidebar-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}

/* ─── Sidebar Items ──────────────────────────────────────── */
.sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sidebar-list-scrollable {
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-list-scrollable::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list-scrollable::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar-list-scrollable::-webkit-scrollbar-track {
    background: transparent;
}

/* Add button pinned below the scrollable list */
.sidebar-section > .sidebar-add-btn,
.sidebar-section > .sidebar-new-item {
    margin: 4px 6px 0;
}

.sidebar-item-wrapper {
    display: flex;
    align-items: center;
    position: relative;
}

.sidebar-item-wrapper .btn-icon-xs {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.15s;
}

.sidebar-item-wrapper:hover .btn-icon-xs {
    opacity: 1;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    text-align: left;
    font-family: inherit;
    transition: background 0.12s;
    border-radius: 0;
}

.sidebar-item:hover {
    background: var(--sidebar-hover);
}

.sidebar-item.active {
    background: var(--sidebar-active);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-item-static {
    cursor: default;
}

.sidebar-item-static:hover {
    background: none;
}

.sidebar-item-icon {
    font-size: 16px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-item-count {
    font-size: 11px;
    color: var(--text-dim);
    background: var(--bg);
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 500;
    flex-shrink: 0;
}

.sidebar-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-left: 6px;
}

.sidebar-add-btn {
    color: var(--accent);
    font-style: italic;
}

.sidebar-new-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 14px;
}

.sidebar-new-item input {
    flex: 1;
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    background: var(--bg);
}

/* ─── Icon & Color Pickers ───────────────────────────────── */
.icon-picker-btn {
    font-size: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.15s;
}

.icon-picker-btn:hover {
    border-color: var(--accent);
}

.icon-picker-popover {
    position: absolute;
    left: 0;
    z-index: 999;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.08);
    overflow: hidden;
    animation: iconPickerIn 0.12s ease-out;
}

.icon-picker-popover em-emoji-picker {
    --em-rgb-background: var(--surface-rgb, 255, 255, 255);
    --em-rgb-input: 241, 245, 249;
    border: none !important;
}

@keyframes iconPickerIn {
    from { opacity: 0; transform: translateY(-3px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.color-picker-btn {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s;
    margin-left: 6px;
    flex-shrink: 0;
}

.color-picker-btn:hover {
    border-color: var(--accent);
}

.color-picker-grid {
    position: absolute;
    left: 0;
    top: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    z-index: 99;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.color-picker-option {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s, transform 0.1s;
}

.color-picker-option:hover {
    transform: scale(1.15);
}

.color-picker-option.active {
    border-color: var(--text);
}

/* ─── Small Button Variants ──────────────────────────────── */
.btn-icon-sm {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.12s;
    padding: 0;
    font-family: inherit;
}

.btn-icon-sm:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.btn-icon-xs {
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    transition: all 0.12s;
    padding: 0;
    font-family: inherit;
}

.btn-icon-xs:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.btn-icon-xs:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-danger-icon:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ─── Template Groups ────────────────────────────────────── */
.template-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.template-group-header {
    padding: 16px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
}

.template-group-info {
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.template-group-meta {
    flex: 1;
    min-width: 0;
}

.template-group-title {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.cat-icon {
    font-size: 18px;
}

.objective-tag,
.header-objective-tag {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    padding: 2px 10px;
    border-radius: 10px;
    margin-left: 6px;
}

.template-group-stats {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.text-success { color: var(--success); font-weight: 600; }
.text-danger  { color: var(--danger); font-weight: 600; }
.text-dim     { color: var(--text-dim); }

/* ─── Channel Bars (mini horizontal bars) ────────────────── */
.template-group-channel-bars {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.channel-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.channel-bar-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.channel-bar-label {
    width: 80px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.channel-bar-pct {
    width: 36px;
    text-align: right;
    font-weight: 600;
    flex-shrink: 0;
}

.channel-bar-track {
    flex: 1;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
    max-width: 200px;
}

.channel-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ─── Template Group Table ───────────────────────────────── */
.template-group .data-table {
    margin: 0;
    border: none;
    border-radius: 0;
}

.template-group .data-table thead th {
    background: var(--surface);
}

/* ─── Channel Legend Bar (top of content) ───────────────── */
.channel-legend-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.channel-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    border-left-width: 3px;
}

.channel-chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ─── Add Channel Button (per group) ────────────────────── */
.btn-add-channel {
    display: block;
    margin: 8px 0 4px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--accent);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-add-channel:hover {
    background: var(--accent-light, #f0f7ff);
    border-color: var(--accent);
}

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1024px) {
    .templates-sidebar {
        width: 200px;
        min-width: 200px;
    }
}

@media (max-width: 768px) {
    .templates-layout {
        flex-direction: column;
    }

    .templates-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 260px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        border-radius: 8px 8px 0 0;
    }

    .template-group-info {
        flex-direction: column;
        align-items: center;
    }
}

/* ── Forecast Validation ── */
.btn-validate {
    background: none;
    border: 1px solid var(--border, #d1d5db);
    color: var(--text-primary, #374151);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-validate:hover:not(:disabled) {
    background: var(--bg-hover, #f3f4f6);
    border-color: #8B5CF6;
    color: #8B5CF6;
}
.btn-validate:disabled {
    opacity: 0.6;
    cursor: wait;
}

.validation-results {
    background: #fafafa;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 8px 0 12px;
    font-size: 13px;
}
.validation-results.validation-error {
    border-color: #fca5a5;
    background: #fef2f2;
}
.validation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 13px;
}
.validation-comparison {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.validation-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.validation-ch {
    min-width: 80px;
    font-size: 12px;
}
.validation-template {
    min-width: 36px;
    text-align: right;
    font-weight: 500;
    color: var(--text-dim, #6b7280);
}
.validation-arrow {
    color: var(--text-dim, #9ca3af);
    font-size: 11px;
}
.validation-api {
    min-width: 36px;
    text-align: right;
    font-weight: 600;
}
.validation-api.validation-divergent {
    color: #d97706;
}
.validation-diff {
    font-size: 11px;
    font-weight: 600;
    min-width: 40px;
}
.validation-error-msg {
    color: #dc2626;
    font-size: 13px;
}
