/* ==============================================
   CampaignHub - Global App Styles
   Light Enterprise Theme
   ============================================== */

/* ---- CSS Variables / Design Tokens ---- */
:root {
    --bg-root: #f1f5f9;
    --bg-sidebar: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-solid: #ffffff;
    --bg-card-hover: rgba(248, 250, 252, 0.98);
    --bg-input: rgba(248, 250, 252, 0.9);
    --bg-modal: #ffffff;

    --border-color: rgba(0, 0, 0, 0.09);
    --border-focus: rgba(99, 102, 241, 0.5);

    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-glow: rgba(99, 102, 241, 0.2);
    --color-success: #059669;
    --color-success-bg: rgba(5, 150, 105, 0.1);
    --color-warning: #d97706;
    --color-warning-bg: rgba(217, 119, 6, 0.1);
    --color-danger: #dc2626;
    --color-danger-bg: rgba(220, 38, 38, 0.1);
    --color-info: #0891b2;
    --color-info-bg: rgba(8, 145, 178, 0.1);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --sidebar-width: 260px;
    --topbar-height: 60px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.12);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background-color: var(--bg-root);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- App Loading Screen ---- */
.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    letter-spacing: 0.025em;
}

/* ---- Blazor Error UI ---- */
.blazor-error-ui {
    background: #ffffff;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    display: none;
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
    gap: 0.5rem;
    align-items: center;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.blazor-error-ui.blazor-error-ui-show {
    display: flex;
}
.blazor-error-ui .reload {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    margin-left: 0.5rem;
}
.blazor-error-ui .dismiss {
    cursor: pointer;
    margin-left: auto;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ========================
   LAYOUT
   ======================== */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    position: relative;
    z-index: 50;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-logo-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.sidebar-logo-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-section-title {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.75rem 0.5rem 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.nav-link:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--color-primary);
    border-color: rgba(99, 102, 241, 0.2);
}

.nav-link .nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--border-color);
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.user-pill:hover { background: rgba(0,0,0,0.05); }

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.65rem; color: var(--text-muted); }

/* ---- Main Content Area ---- */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.topbar-spacer { flex: 1; }

.topbar-badge {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(0,0,0,0.04);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    padding: 0.25rem 0.75rem;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* ========================
   COMPONENTS
   ======================== */

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.75rem;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* ---- Stat Cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: rgba(255,255,255,0.12);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-icon.primary { background: rgba(99,102,241,0.15); }
.stat-icon.success { background: var(--color-success-bg); }
.stat-icon.warning { background: var(--color-warning-bg); }
.stat-icon.danger { background: var(--color-danger-bg); }
.stat-icon.info { background: var(--color-info-bg); }

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 0.125rem;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    font-family: var(--font-sans);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-outline:hover:not(:disabled) {
    background: rgba(0,0,0,0.05);
    border-color: rgba(0,0,0,0.15);
    color: var(--text-primary);
}

.btn-success {
    background: var(--color-success);
    color: #fff;
}
.btn-success:hover:not(:disabled) {
    background: #059669;
    box-shadow: 0 0 20px rgba(16,185,129,0.3);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 0 20px rgba(239,68,68,0.3);
    transform: translateY(-1px);
}

.btn-warning {
    background: var(--color-warning);
    color: #000;
}
.btn-warning:hover:not(:disabled) {
    background: #d97706;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 0.9375rem;
    border-radius: var(--radius-md);
}

.btn-icon {
    padding: 0.4rem;
    border-radius: var(--radius-sm);
}

/* ---- Forms ---- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    background: var(--bg-input) !important;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.75rem;
    color: var(--text-primary) !important;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    width: 100%;
    transition: var(--transition);
    outline: none;
    -webkit-text-fill-color: var(--text-primary) !important;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
    background: var(--bg-input) !important;
}

.form-control::placeholder {
    color: var(--text-muted) !important;
}

.form-control option {
    background: var(--bg-card-solid);
    color: var(--text-primary);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 0.75rem center !important;
    background-size: 12px !important;
    padding-right: 2.25rem !important;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    accent-color: var(--color-primary);
    width: 16px;
    height: 16px;
}

/* ---- Table ---- */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table thead {
    background: rgba(0,0,0,0.03);
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: var(--transition);
}

.data-table tbody tr:hover td {
    background: rgba(0,0,0,0.03);
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.025em;
    border: 1px solid;
}

.badge-pending { background: var(--color-warning-bg); color: var(--color-warning); border-color: rgba(245,158,11,0.25); }
.badge-processing { background: var(--color-info-bg); color: var(--color-info); border-color: rgba(6,182,212,0.25); }
.badge-success, .badge-completed, .badge-read { background: var(--color-success-bg); color: var(--color-success); border-color: rgba(16,185,129,0.25); }
.badge-danger, .badge-failed { background: var(--color-danger-bg); color: var(--color-danger); border-color: rgba(239,68,68,0.25); }
.badge-paused { background: rgba(148,163,184,0.12); color: #94a3b8; border-color: rgba(148,163,184,0.25); }
.badge-sent { background: rgba(99,102,241,0.12); color: var(--color-primary); border-color: rgba(99,102,241,0.25); }
.badge-delivered { background: var(--color-success-bg); color: var(--color-success); border-color: rgba(16,185,129,0.25); }

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: slideUp 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-lg { max-width: 720px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.modal-close:hover { background: rgba(0,0,0,0.07); color: var(--text-primary); }

.modal-body { padding: 1.5rem; }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header-left {}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.page-subtitle {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid;
    font-size: 0.8125rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.alert-error { background: var(--color-danger-bg); border-color: rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: var(--color-success-bg); border-color: rgba(16,185,129,0.3); color: #6ee7b7; }
.alert-info { background: var(--color-info-bg); border-color: rgba(6,182,212,0.3); color: #67e8f9; }
.alert-warning { background: var(--color-warning-bg); border-color: rgba(245,158,11,0.3); color: #fde68a; }

/* ---- Empty State ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
    gap: 0.75rem;
}

.empty-icon { font-size: 2.5rem; opacity: 0.5; }
.empty-title { font-size: 0.9375rem; font-weight: 600; color: var(--text-secondary); }
.empty-desc { font-size: 0.8125rem; }

/* ---- Divider ---- */
.divider {
    height: 1px;
    background: var(--border-color);
    margin: 1.25rem 0;
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(99,102,241,0.2);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ---- Auth Layout ---- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 60%), var(--bg-root);
    padding: 1rem;
}

.auth-card {
    background: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.auth-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.auth-logo-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
}

.auth-logo-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.auth-logo-sub {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Status dot ---- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.online { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.busy { background: var(--color-warning); }

/* ---- Utilities ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); font-size: 0.75rem; }
.text-sm { font-size: 0.8125rem; }
.font-bold { font-weight: 700; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Pulse animation for running state ---- */
.pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }