/* ============================================
   OmegaMailer Dashboard Styles
   ============================================ */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    padding: 1.5rem;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
}

.logo h1 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.nav-item:hover, .nav-item.active {
    background: var(--gray-800);
    color: white;
}

.nav-item .icon {
    font-size: 1.25rem;
}

.rate-limit-info {
    margin-top: 2rem;
    padding: 1rem;
    background: var(--gray-800);
    border-radius: 0.5rem;
}

.rate-limit-info h4 {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--gray-400);
}

.rate-limit-info .small {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: white;
    border-bottom: 1px solid var(--gray-200);
}

.top-bar h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.top-bar-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.75rem;
    border-radius: 9999px;
    background: var(--gray-100);
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 600;
}

.content-wrapper {
    padding: 2rem;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.5;
}

.close-btn:hover {
    opacity: 1;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-content h3 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-content p {
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.card-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
    overflow-x: auto;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.data-table th {
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tr:hover {
    background: var(--gray-50);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-active, .badge-sent, .badge-completed {
    background: #d1fae5;
    color: #065f46;
}

.badge-inactive, .badge-failed, .badge-cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.badge-queued, .badge-pending {
    background: #fef3c7;
    color: #92400e;
}

.badge-valid {
    background: #d1fae5;
    color: #065f46;
}

.badge-risky, .badge-unknown {
    background: #fef3c7;
    color: #92400e;
}

.badge-invalid {
    background: #fee2e2;
    color: #991b1b;
}

.badge-sending {
    background: #dbeafe;
    color: #1e40af;
}

.badge-draft {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    background: white;
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    max-width: 100%;
}

.btn:hover {
    background: var(--gray-50);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.menu-toggle {
    display: none;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.75rem;
    background: white;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.25rem;
    cursor: pointer;
}

.menu-toggle span {
    width: 1rem;
    height: 2px;
    background: var(--gray-800);
    border-radius: 9999px;
}

.sidebar-scrim {
    display: none;
}

.omegamailer-swal {
    border-radius: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--gray-500);
    font-size: 0.75rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* Progress Bars */
.progress-bar {
    height: 0.5rem;
    background: var(--gray-200);
    border-radius: 9999px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar .progress {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}

.progress-bar-small {
    height: 0.375rem;
    background: var(--gray-200);
    border-radius: 9999px;
    overflow: hidden;
    display: inline-block;
    width: 100px;
    vertical-align: middle;
    margin-right: 0.5rem;
}

/* Page Actions */
.page-actions {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.validator-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.validator-summary-grid {
    margin-bottom: 1.5rem;
}

#validator-progress {
    margin-bottom: 1.5rem;
}

.validator-table {
    min-width: unset;
}

.progress-complete .progress {
    background: var(--success, #10b981);
}

.progress-complete .progress-text {
    color: var(--success, #10b981);
    font-weight: 600;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.checkbox-row input {
    width: auto;
}

.muted-text {
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
}

.modal-container {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 0.75rem;
    max-width: 500px;
    width: 90%;
    z-index: 1001;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active,
.modal-container.active {
    display: block;
}

.modal-container h2 {
    margin-bottom: 1rem;
}

.live-progress-widget {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: min(100%, 380px);
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 1rem;
    box-shadow: 0 22px 48px rgba(15, 23, 42, 0.16);
    z-index: 1003;
    overflow: hidden;
}

.live-progress-widget.minimized .live-progress-widget-body {
    display: none;
}

.live-progress-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(16, 185, 129, 0.08));
    border-bottom: 1px solid var(--gray-200);
}

.live-progress-widget-title {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.live-progress-widget-title strong {
    font-size: 0.95rem;
    color: var(--gray-900);
}

.live-progress-widget-title small {
    color: var(--gray-500);
}

.live-progress-widget-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.live-progress-toggle {
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--gray-300);
    border-radius: 9999px;
    background: white;
    color: var(--gray-700);
    cursor: pointer;
}

.live-progress-widget-body {
    padding: 1rem;
}

.live-progress-summary {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    color: var(--gray-600);
    font-size: 0.875rem;
}

.live-progress-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.live-progress-metric {
    padding: 0.75rem;
    border-radius: 0.75rem;
    background: var(--gray-50);
    text-align: center;
}

.live-progress-metric strong {
    display: block;
    font-size: 1.1rem;
    color: var(--gray-900);
}

.live-progress-metric span {
    color: var(--gray-500);
    font-size: 0.75rem;
}

.live-progress-log {
    margin-top: 1rem;
}

.live-progress-log h4 {
    font-size: 0.85rem;
    margin-bottom: 0.6rem;
    color: var(--gray-800);
}

.live-progress-log-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 220px;
    overflow-y: auto;
}

.live-progress-log-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    background: var(--gray-50);
    border-radius: 0.75rem;
    font-size: 0.85rem;
}

.live-progress-log-list li small {
    color: var(--gray-500);
    white-space: nowrap;
}

.live-progress-empty {
    padding: 0.9rem;
    background: var(--gray-50);
    border-radius: 0.75rem;
    color: var(--gray-500);
    font-size: 0.85rem;
}

.table-inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.table-empty-state {
    text-align: center;
    color: var(--gray-500);
    padding: 1.5rem 1rem;
}

/* Tabs */
.campaign-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.tab-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* HTML Editor */
.html-editor {
    border: 1px solid var(--gray-300);
    border-radius: 0.5rem;
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-300);
    flex-wrap: wrap;
}

.editor-toolbar button {
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.75rem;
}

.editor-toolbar button:hover {
    background: var(--gray-100);
}

#emailBody {
    width: 100%;
    min-height: 300px;
    border: none;
    padding: 1rem;
    font-family: monospace;
    resize: vertical;
}

/* Queue Status */
.queue-status {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.queue-item {
    text-align: center;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 0.5rem;
}

.queue-item .label {
    font-size: 0.75rem;
    color: var(--gray-500);
    display: block;
}

.queue-item .value {
    font-size: 1.5rem;
    font-weight: 700;
}

.queue-item .value.pending { color: var(--warning); }
.queue-item .value.sent { color: var(--success); }
.queue-item .value.failed { color: var(--danger); }

.worker-status {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

#worker-status {
    font-weight: 600;
}

.status-running {
    color: var(--success);
}

/* Performance Metrics */
.performance-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.metric {
    text-align: center;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 0.5rem;
}

.metric label {
    font-size: 0.75rem;
    color: var(--gray-500);
    display: block;
}

.metric .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* Rate Limit Detail */
.rate-limit-detail {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rate-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.rate-item span:first-child {
    width: 60px;
    font-weight: 500;
}

.rate-item progress {
    flex: 1;
    height: 0.5rem;
}

.rate-item span:last-child {
    width: 80px;
    text-align: right;
    font-size: 0.875rem;
}

/* Import Results */
.import-results {
    padding: 1.5rem;
    background: var(--gray-50);
    border-radius: 0.5rem;
    margin: 1rem 0;
}

.import-results p {
    margin: 0.5rem 0;
}

.login-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.14), transparent 34%),
        radial-gradient(circle at bottom right, rgba(16, 185, 129, 0.12), transparent 30%),
        #f8fafc;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    width: 100%;
}

.login-card {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    background: white;
    border: 1px solid rgba(229, 231, 235, 0.9);
    border-radius: 1.25rem;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
    padding: 2rem;
}

.login-form,
.login-form .form-group {
    width: 100%;
}

.login-brand {
    margin-bottom: 1.5rem;
}

.login-brand h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--gray-900);
}

.login-brand p {
    color: var(--gray-600);
}

.login-kicker {
    display: inline-block;
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
}

/* Responsive */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        display: block;
    }

    body.nav-open {
        overflow: hidden;
    }

    .sidebar {
        width: min(86vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1002;
        padding: 1.25rem;
    }
    
    .main-content {
        margin-left: 0;
    }

    body.nav-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-scrim {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.48);
        z-index: 1001;
    }

    body.nav-open .sidebar-scrim {
        display: block;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .validator-grid {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }

    .queue-status,
    .performance-metrics {
        grid-template-columns: 1fr;
    }

    .top-bar {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .top-bar h2 {
        font-size: 1.25rem;
    }

    .top-bar-title,
    .user-info {
        width: 100%;
    }

    .user-info {
        justify-content: space-between;
        gap: 0.75rem;
    }

    .content-wrapper {
        padding: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .rate-limit-info {
        display: none;
    }

    .data-table {
        min-width: 560px;
    }

    .login-card {
        padding: 1.5rem;
    }

    .page-actions,
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .page-actions .btn,
    .form-actions .btn {
        width: 100%;
        text-align: center;
    }

    .progress-bar-small {
        width: 100%;
        display: block;
        margin-right: 0;
        margin-bottom: 0.5rem;
    }

    .rate-item {
        flex-direction: column;
        align-items: stretch;
    }

    .rate-item span:first-child,
    .rate-item span:last-child {
        width: auto;
        text-align: left;
    }

    .modal-container {
        top: auto;
        left: 12px;
        right: 12px;
        bottom: 12px;
        transform: none;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 24px);
        padding: 1.25rem;
        border-radius: 1rem;
    }

    .editor-toolbar button {
        flex: 1 1 calc(50% - 0.25rem);
    }

    #emailBody {
        min-height: 240px;
    }

    .live-progress-widget {
        left: 0.75rem;
        right: 0.75rem;
        bottom: 0.75rem;
        width: auto;
    }

    .live-progress-metrics {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .content-wrapper,
    .top-bar,
    .sidebar,
    .card-body,
    .card-header {
        padding-left: 0.875rem;
        padding-right: 0.875rem;
    }

    .data-table {
        min-width: 520px;
    }

    .user-chip {
        width: 100%;
        justify-content: center;
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}

.btn.loading::after {
    content: '';
    position: absolute;
    right: 0.75rem;
    top: 50%;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    transform: translateY(-50%);
    animation: spin 0.6s linear infinite;
}
