/**
 * Email Reports Admin Styles
 * Uses existing Switchboard CSS classes from switchboard-admin.css
 * Only contains email-reports specific styles
 */

/* ========================================
   CSS Variable Fallbacks (in case main CSS not loaded)
   ======================================== */
.sb-er-wrap {
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-500-rgb: 59, 130, 246;
}

/* ========================================
   Wrapper Override
   ======================================== */
.sb-er-wrap {
    max-width: 1200px;
}

/* ========================================
   Status Dot Indicators
   ======================================== */
.sb-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.sb-status-dot-green {
    background-color: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.sb-status-dot-red {
    background-color: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* ========================================
   Tabs (in header)
   ======================================== */
.sb-er-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 16px;
    height: 36px;
    background: white;
    border: 1px solid var(--gray-200, #e2e8f0);
    border-radius: 6px;
    color: var(--gray-600, #475569);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
}

.sb-er-tab:hover {
    background: var(--gray-50, #f8fafc);
    border-color: var(--gray-300, #cbd5e1);
    color: var(--gray-700, #334155);
}

.sb-er-tab.active {
    background: var(--primary-500, #3b82f6);
    border-color: var(--primary-500, #3b82f6);
    color: white;
}

/* ========================================
   Two-Column Layout (Sidebar Navigation + Main Content)
   ======================================== */
.sb-er-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    align-items: start;
}

/* Sidebar - Navigation Only */
.sb-er-sidebar {
    position: sticky;
    top: 32px;
}

.sb-er-sidebar .sb-module-card {
    margin-bottom: 0;
}

/* Main content area */
.sb-er-main {
    min-width: 0;
}

.sb-er-main .sb-module-card {
    margin-bottom: 0;
}

/* ========================================
   Sections List in Sidebar
   ======================================== */
.sb-er-sections-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sb-er-section-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border: 1px solid var(--gray-200, #e2e8f0);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600, #475569);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sb-er-section-item:hover {
    background: var(--gray-50, #f8fafc);
    border-color: var(--gray-300, #cbd5e1);
}

.sb-er-section-item.active {
    background: var(--primary-50, #eff6ff);
    border-color: var(--primary-500, #3b82f6);
    color: var(--primary-600, #2563eb);
}

.sb-er-section-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sb-er-section-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Settings item in sidebar - has icon */
.sb-er-settings-item {
    background: var(--gray-50, #f8fafc);
}

.sb-er-settings-item svg {
    color: var(--gray-400, #94a3b8);
    transition: color 0.15s ease;
}

.sb-er-settings-item.active svg,
.sb-er-settings-item:hover svg {
    color: var(--primary-500, #3b82f6);
}

/* Sidebar Divider */
.sb-er-sidebar-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0 6px;
    padding: 0 4px;
}

.sb-er-sidebar-divider span {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-400, #94a3b8);
    white-space: nowrap;
}

.sb-er-sidebar-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-200, #e2e8f0);
}

/* Small toggle for sidebar */
.sb-module-toggle-sm {
    transform: scale(0.85);
    transform-origin: left center;
}

/* ========================================
   Panels (Settings vs Section)
   ======================================== */
.sb-er-panel {
    /* Shown/hidden via JS */
}

.sb-er-section-panel {
    display: none;
}

/* ========================================
   Settings Grid (Branding + Schedule side by side)
   ======================================== */
.sb-er-settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 32px;
}

.sb-er-settings-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700, #334155);
    margin: 0 0 16px;
    padding-bottom: 0;
    border-bottom: none;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ========================================
   Main Panel Form Fields
   ======================================== */
.sb-er-field {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    align-items: start;
    margin-bottom: 20px;
}

.sb-er-field:last-child {
    margin-bottom: 0;
}

.sb-er-field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700, #334155);
    padding-top: 8px;
}

.sb-er-field-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sb-er-field-control select,
.sb-er-field-control input[type="text"],
.sb-er-field-control input[type="email"],
.sb-er-field-control input[type="time"],
.sb-er-field-control input[type="number"],
.sb-er-field-control textarea {
    width: 100%;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid var(--gray-300, #cbd5e1);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: var(--gray-700, #334155);
    background: white;
    transition: border-color 0.15s ease;
    line-height: 1.4;
}

.sb-er-field-control select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M10.293 3.293L6 7.586 1.707 3.293A1 1 0 00.293 4.707l5 5a1 1 0 001.414 0l5-5a1 1 0 10-1.414-1.414z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.sb-er-field-control textarea {
    min-height: 60px;
    resize: vertical;
    max-width: 100%;
}

.sb-er-field-control select:focus,
.sb-er-field-control input:focus,
.sb-er-field-control textarea:focus {
    outline: none;
    border-color: var(--primary-500, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.sb-er-field-help {
    font-size: 12px;
    color: var(--gray-500, #64748b);
}

/* Toggle with label inline */
.sb-er-field-control:has(.sb-module-toggle) {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

/* Section config panel */
.sb-er-section-config-panel {
    /* Shown/hidden via JS */
}

/* Section unavailable message */
.sb-er-section-unavailable {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 30px 20px;
    text-align: center;
    color: var(--gray-500, #64748b);
}

.sb-er-section-unavailable-icon {
    color: var(--gray-400, #94a3b8);
}

.sb-er-section-unavailable p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* ========================================
   Logo Upload
   ======================================== */
.sb-er-logo-upload {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.sb-er-logo-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    max-width: 160px;
    min-height: 45px;
    max-height: 60px;
    border: 2px dashed var(--gray-300, #cbd5e1);
    border-radius: 6px;
    padding: 8px;
    background: var(--gray-50, #f8fafc);
}

.sb-er-logo-preview img {
    max-width: 100%;
    max-height: 44px;
    display: block;
}

.sb-er-logo-buttons {
    display: flex;
    gap: 6px;
}

/* ========================================
   Simple Color Picker
   ======================================== */
.sb-er-color-field {
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
}

.sb-er-color-field input[type="color"] {
    width: 40px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--gray-300, #cbd5e1);
    border-radius: 6px;
    cursor: pointer;
    background: white;
}

.sb-er-color-field input[type="text"] {
    width: 90px !important;
    max-width: 90px !important;
    font-family: monospace;
}

/* ========================================
   Empty Message
   ======================================== */
.sb-er-empty-msg {
    text-align: center;
    padding: 20px 16px;
    color: var(--gray-500, #64748b);
    font-size: 12px;
    line-height: 1.5;
}

/* ========================================
   Feedback Messages
   ======================================== */
.sb-er-feedback {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    margin-right: auto;
}

.sb-er-feedback.success {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #166534;
}

.sb-er-feedback.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.sb-er-feedback.warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #92400e;
}

/* ========================================
   Preview Frame
   ======================================== */
.sb-er-preview-frame {
    background: #f9fafb;
    border-top: 1px solid var(--gray-100, #f1f5f9);
    min-height: 300px;
    overflow: hidden;
}

.sb-er-preview-frame iframe {
    width: 100%;
    min-height: 400px;
    border: none;
    display: block;
    background: white;
}

.sb-er-preview-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--gray-500, #64748b);
    gap: 10px;
    font-size: 13px;
}

.sb-er-preview-loading .spinner {
    float: none;
    margin: 0;
}

.sb-er-preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--gray-400, #94a3b8);
    font-size: 13px;
}

/* ========================================
   History Filter Buttons (Sidebar)
   ======================================== */
.sb-er-history-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border: 1px solid var(--gray-200, #e2e8f0);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600, #475569);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
}

.sb-er-history-filter:hover {
    background: var(--gray-50, #f8fafc);
    border-color: var(--gray-300, #cbd5e1);
}

.sb-er-history-filter.active,
.sb-er-status-filter.active {
    background: var(--primary-50, #eff6ff);
    border-color: var(--primary-500, #3b82f6);
    color: var(--primary-600, #2563eb);
}

/* Status filter buttons use same style as history filter */
.sb-er-status-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border: 1px solid var(--gray-200, #e2e8f0);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-600, #475569);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
    width: 100%;
}

.sb-er-status-filter:hover {
    background: var(--gray-50, #f8fafc);
    border-color: var(--gray-300, #cbd5e1);
}

.sb-er-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 600;
    background: var(--gray-100, #f1f5f9);
    color: var(--gray-600, #475569);
    border-radius: 10px;
}

.sb-er-filter-count-success {
    background: #dcfce7;
    color: #166534;
}

.sb-er-filter-count-error {
    background: #fef2f2;
    color: #991b1b;
}

/* History Stats in Sidebar */
.sb-er-history-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sb-er-history-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100, #f1f5f9);
}

.sb-er-history-stat:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.sb-er-history-stat-label {
    font-size: 12px;
    color: var(--gray-500, #64748b);
}

.sb-er-history-stat-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700, #334155);
}

/* Empty State for History */
.sb-er-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.sb-er-empty-state-icon {
    color: var(--gray-300, #cbd5e1);
    margin-bottom: 16px;
}

.sb-er-empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-700, #334155);
    margin: 0 0 8px;
}

.sb-er-empty-state-desc {
    font-size: 13px;
    color: var(--gray-500, #64748b);
    margin: 0;
    max-width: 280px;
}

/* Pagination */
.sb-er-page-info {
    font-size: 13px;
    color: var(--gray-500, #64748b);
}

.sb-er-pagination {
    display: flex;
    gap: 8px;
}

/* ========================================
   History Table Enhancements
   ======================================== */
.sb-er-type-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    background: var(--gray-100, #f1f5f9);
    color: var(--gray-600, #475569);
    border-radius: 4px;
    text-transform: capitalize;
}

.sb-er-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.sb-er-status-sent {
    background: #dcfce7;
    color: #166534;
}

.sb-er-status-failed {
    background: #fef2f2;
    color: #991b1b;
}

.sb-er-date-cell {
    font-size: 12px;
}

.sb-er-date-relative {
    font-weight: 500;
    color: var(--gray-700, #334155);
}

.sb-er-date-absolute {
    font-size: 11px;
    color: var(--gray-400, #94a3b8);
    margin-top: 2px;
}

.sb-er-row-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

tr:hover .sb-er-row-actions {
    opacity: 1;
}

.delete-history-btn {
    padding: 4px 8px;
    font-size: 12px;
    color: #ef4444;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.delete-history-btn:hover {
    background: #fef2f2;
    border-color: #fecaca;
}

/* ========================================
   Disabled Recipients (Combined Mode)
   ======================================== */
.sb-er-section-recipients.sb-er-recipients-disabled {
    opacity: 0.5;
    pointer-events: none;
    position: relative;
}

.sb-er-section-recipients.sb-er-recipients-disabled::after {
    content: 'Using global recipients';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--gray-100, #f1f5f9);
    color: var(--gray-500, #64748b);
    font-size: 11px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 1;
}

/* ========================================
   Footer Buttons Alignment
   ======================================== */
.sb-er-wrap .sb-module-card-footer {
    justify-content: flex-end;
}

.sb-er-wrap .sb-module-card-footer .sb-er-feedback {
    margin-right: auto;
}

/* ========================================
   Settings Grid - Half-width stacked sections
   ======================================== */
.sb-er-settings-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sb-er-settings-section {
    background: var(--gray-50, #f8fafc);
    border: 1px solid var(--gray-100, #f1f5f9);
    border-radius: 8px;
    padding: 20px 24px;
}

/* ========================================
   Responsive
   ======================================== */

@media screen and (max-width: 900px) {
    .sb-er-layout {
        grid-template-columns: 1fr;
    }

    .sb-er-sidebar {
        position: static;
    }
}

@media screen and (max-width: 782px) {
    .sb-er-field {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .sb-er-field-label {
        padding-top: 0;
    }

    .sb-er-field-control select,
    .sb-er-field-control input[type="text"],
    .sb-er-field-control input[type="email"],
    .sb-er-field-control input[type="time"],
    .sb-er-field-control input[type="number"] {
        max-width: 100%;
    }

    .sb-er-logo-upload {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ========================================
   Toast Notifications
   ======================================== */
.sb-er-toast {
    position: fixed;
    top: 50px;
    right: 20px;
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 2px 10px rgba(0, 0, 0, 0.1);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    max-width: 400px;
}

.sb-er-toast.show {
    transform: translateX(0);
}

.sb-er-toast-success {
    border-left: 4px solid #22c55e;
}

.sb-er-toast-success .sb-er-toast-icon {
    color: #22c55e;
}

.sb-er-toast-error {
    border-left: 4px solid #ef4444;
}

.sb-er-toast-error .sb-er-toast-icon {
    color: #ef4444;
}

.sb-er-toast-icon {
    flex-shrink: 0;
}

.sb-er-toast-message {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700, #334155);
}

.sb-er-toast-close {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 18px;
    color: var(--gray-400, #94a3b8);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.sb-er-toast-close:hover {
    background: var(--gray-100, #f1f5f9);
    color: var(--gray-600, #475569);
}

/* ========================================
   Unsaved Changes Badge
   ======================================== */
.sb-er-unsaved-badge {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    color: #92400e;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.sb-er-unsaved-badge::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #f59e0b;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========================================
   Tooltip
   ======================================== */
/* Allow tooltip to overflow ALL parent containers */
.sb-er-sections-list,
.sb-er-sections-list .sb-er-section-item,
.sb-er-sidebar,
.sb-er-sidebar .sb-module-card,
.sb-er-sidebar .sb-module-card-body {
    overflow: visible !important;
}

.sb-er-tooltip {
    position: relative;
    cursor: help;
}

.sb-er-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    padding: 6px 10px;
    background: var(--gray-800, #1e293b);
    color: white;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.4;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    z-index: 99999;
    pointer-events: none;
}

.sb-er-tooltip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    right: 10px;
    border: 4px solid transparent;
    border-top-color: var(--gray-800, #1e293b);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    z-index: 9999;
}

.sb-er-tooltip:hover::after,
.sb-er-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}
