@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Poppins:wght@500;600;700&display=swap');

/* ===================================================================
   AutoMail · v5 Design System
   Light / Dark via [data-theme] attribute on <html>

   Warm palette. The neutrals carry a slight bias toward the accent
   rather than the cool blue-grey they used to, so white surfaces read
   as paper against the ground instead of as a separate colour family.

   Every text token below was checked against its own background:
   primary ~13:1, secondary ~6.7:1, muted ~4.6:1, and each semantic
   colour at least 4.9:1. The accent used for filled buttons is a
   deepened terracotta rather than the brand's lighter #d97757, which
   would only have reached 4.2:1 behind white label text.
   =================================================================== */

:root,
[data-theme="light"] {
    --bg-app: #fcfbf7;
    --bg-surface: #ffffff;
    --bg-surface-2: #f7f4ec;
    --bg-input: #ffffff;
    --bg-hover: #f7f4ec;
    --bg-sidebar: #ffffff;
    --bg-elevated: #ffffff;

    --text-primary: #2b2924;
    --text-secondary: #5c594f;
    --text-muted: #6f6c62;
    --text-on-primary: #ffffff;

    --primary: #b4552f;
    --primary-hover: #9c4728;
    --primary-soft: #fdf1eb;
    --primary-soft-hover: #f8e2d7;

    --accent: #446f9f;
    --success: #5f7448;
    --success-soft: #f1f4ea;
    --danger: #a8452a;
    --danger-soft: #fdeee9;
    --warning: #8f6414;
    --warning-soft: #faf3e2;

    --border: #ece8dd;
    --border-strong: #ddd8c9;
    --border-focus: #b4552f;

    --shadow-sm: 0 1px 2px rgba(43, 41, 36, 0.04), 0 1px 1px rgba(43, 41, 36, 0.03);
    --shadow-md: 0 4px 6px -1px rgba(43, 41, 36, 0.05), 0 2px 4px -2px rgba(43, 41, 36, 0.04);
    --shadow-lg: 0 12px 26px -10px rgba(43, 41, 36, 0.14), 0 4px 8px -4px rgba(43, 41, 36, 0.06);
    --shadow-glow: 0 0 0 3px rgba(217, 119, 87, 0.16);

    --overlay: rgba(43, 41, 36, 0.55);

    /* Brand marks and progress fills. Deliberately a warm ramp rather
       than primary -> accent: terracotta into blue passes through grey
       and reads as a muddy smear at small sizes. */
    --brand-gradient: linear-gradient(135deg, #e08a68, #b4552f);
    --brand-gradient-h: linear-gradient(90deg, #d97757, #b4552f);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    /* Width of the fixed theme switcher plus its offset, reserved by any
       header row whose controls would otherwise sit underneath it. */
    --theme-switcher-space: 140px;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);

    --bg-radial:
        radial-gradient(circle at 12% 8%, rgba(217, 119, 87, 0.07), transparent 35%),
        radial-gradient(circle at 88% 92%, rgba(106, 155, 204, 0.05), transparent 40%);
}

[data-theme="dark"] {
    --bg-app: #1a1917;
    --bg-surface: #232120;
    --bg-surface-2: #2a2826;
    --bg-input: #211f1d;
    --bg-hover: #2f2c29;
    --bg-sidebar: #211f1d;
    --bg-elevated: #2a2826;

    --text-primary: #f2efe8;
    --text-secondary: #b3b0a6;
    --text-muted: #8b887f;
    /* Dark mode uses the brand orange at full strength for fills, which
       is too light for white text -- so labels on it go dark instead. */
    --text-on-primary: #1f1a17;

    --primary: #d97757;
    --primary-hover: #e79a7c;
    --primary-soft: rgba(217, 119, 87, 0.16);
    --primary-soft-hover: rgba(217, 119, 87, 0.26);

    --accent: #92b8dd;
    --success: #a3b886;
    --success-soft: rgba(163, 184, 134, 0.15);
    --danger: #e08064;
    --danger-soft: rgba(224, 128, 100, 0.15);
    --warning: #d6a94a;
    --warning-soft: rgba(214, 169, 74, 0.15);

    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.17);
    --border-focus: #d97757;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 38px -10px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 0 3px rgba(217, 119, 87, 0.32);

    --overlay: rgba(12, 11, 10, 0.66);

    --brand-gradient: linear-gradient(135deg, #e79a7c, #c9603c);
    --brand-gradient-h: linear-gradient(90deg, #e79a7c, #d97757);

    --bg-radial:
        radial-gradient(circle at 12% 8%, rgba(217, 119, 87, 0.16), transparent 38%),
        radial-gradient(circle at 88% 92%, rgba(106, 155, 204, 0.10), transparent 40%);
}

/* Poppins carries the brand marks and headings; Inter stays on the
   dense interface text, where a geometric face is harder to read. */
.brand-text,
.page-header h1,
.surface-title {
    font-family: 'Poppins', 'Inter', system-ui, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg-app);
    background-image: var(--bg-radial);
    background-attachment: fixed;
    color: var(--text-primary);
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    max-width: 1920px;
    margin: 0 auto;
}

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    z-index: 10;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px 24px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--brand-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    box-shadow: var(--shadow-md);
}

.brand-text {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.nav-links {
    list-style: none;
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}

.nav-item a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item a.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.nav-item a i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 12px 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
    letter-spacing: 0.04em;
}

/* ===== Main content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-app);
}

/* ===== Alerts ===== */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 24px 0;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
}
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.btn-soft {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: transparent;
}
.btn-soft:hover {
    background: var(--primary-soft-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}
.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-large {
    padding: 12px 28px;
    font-size: 0.95rem;
    border-radius: var(--radius-md);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== Form fields ===== */
.field-group {
    margin-bottom: 14px;
}

.field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.field-label i {
    color: var(--primary);
    font-size: 0.85rem;
}

.field-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: var(--transition);
}

.field-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}

.field-input::placeholder { color: var(--text-muted); }

textarea.field-input {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    line-height: 1.5;
}

select.field-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 38px;
    cursor: pointer;
}

[data-theme="dark"] select.field-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23c5cee0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.field-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== Surface cards ===== */
.surface-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    overflow: hidden;
}

.surface-card:hover {
    box-shadow: var(--shadow-md);
}

.surface-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.surface-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.surface-title i {
    color: var(--primary);
    font-size: 0.95rem;
}

.surface-body { padding: 18px; }

/* ===== Pills / badges ===== */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.4;
}
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-info { background: var(--primary-soft); color: var(--primary); }
.pill-muted { background: var(--bg-hover); color: var(--text-secondary); }

.pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent);
}

/* ===== Theme switcher (3-option) ===== */
.theme-switcher {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-md);
}

.theme-switcher button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.theme-switcher button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.theme-switcher button.active {
    background: var(--primary-soft);
    color: var(--primary);
}

/* ===== History page ===== */
.page-header {
    padding: 24px 32px;
    /* The theme switcher is position:fixed at z-index 9999, so it floats over
       this row and was covering the right-most action -- "Clear all" on the
       History page sat underneath it. Reserve its footprint. */
    padding-right: calc(32px + var(--theme-switcher-space));
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    /* Narrow screens wrap the header, so the actions drop below the switcher
       and no longer need the reserved gutter. */
    .page-header { padding-right: 24px; }
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 32px 32px;
}

.data-table {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* ===== Modal / Progress ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(8px);
    z-index: 9000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop.open { display: flex; }

.modal-card {
    width: 100%;
    max-width: 560px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

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

.modal-card-body { padding: 24px; }

/* Progress bar */
.progress-track {
    width: 100%;
    height: 8px;
    background: var(--bg-hover);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin: 12px 0 16px;
}
.progress-fill {
    height: 100%;
    width: 0;
    background: var(--brand-gradient-h);
    border-radius: var(--radius-pill);
    transition: width 0.4s ease;
}

.progress-stats {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
}

.progress-stat {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.progress-stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.progress-stat .value {
    font-size: 1.3rem;
    font-weight: 700;
    margin-top: 2px;
}

.recipient-feed {
    margin-top: 16px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
}

.recipient-feed-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.recipient-feed-row:last-child { border-bottom: none; }

.recipient-feed-row .icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.7rem;
    flex-shrink: 0;
}
.recipient-feed-row.sent .icon { background: var(--success); }
.recipient-feed-row.failed .icon { background: var(--danger); }

.recipient-feed-row .name {
    color: var(--text-primary);
    font-weight: 500;
    flex-shrink: 0;
}
.recipient-feed-row .email {
    color: var(--text-muted);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.recipient-feed-row .err {
    color: var(--danger);
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 18px;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    transform: translateY(120%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 420px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}
.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-info { border-left: 4px solid var(--primary); }

/* ===== Responsive ===== */
@media (max-width: 992px) {
    .sidebar { width: 72px; padding: 16px 8px; }
    .brand-text, .nav-item span, .sidebar-footer { display: none; }
    .nav-item a { justify-content: center; padding: 10px; }
}
