:root {
    --background: #fafafa;
    --foreground: #0a0a0a;
    --card: #ffffff;
    --card-foreground: #0a0a0a;
    --popover: #ffffff;
    --popover-foreground: #0a0a0a;
    --primary: #171717;
    --primary-foreground: #fafafa;
    --secondary: #f5f5f5;
    --secondary-foreground: #171717;
    --muted: #f5f5f5;
    --muted-foreground: #737373;
    --accent: #f5f5f5;
    --accent-foreground: #171717;
    --destructive: #ef4444;
    --destructive-foreground: #fafafa;
    --border: #e5e5e5;
    --input: #e5e5e5;
    --ring: #0a0a0a;
    --radius: 6px;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --error-bg: #fef2f2;
}

/* ── Reset & base ── */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--background);
    color: var(--foreground);
    line-height: 1.5;
    font-size: 13px;
    padding: 12px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Card ── */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}

/* ── Typography helpers ── */

label, .label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--foreground);
    margin-bottom: 6px;
}

/* ── Inputs ── */

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"] {
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--input);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: transparent;
    color: var(--foreground);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgba(10, 10, 10, 0.08);
}

input::placeholder {
    color: var(--muted-foreground);
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    white-space: nowrap;
    user-select: none;
}

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

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

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-outline {
    background: transparent;
    color: var(--foreground);
    border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--foreground);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--accent);
}

.btn-destructive {
    background: transparent;
    color: var(--destructive);
    border-color: var(--destructive);
}

.btn-destructive:hover:not(:disabled) {
    background: var(--destructive);
    color: var(--destructive-foreground);
}

.btn-sm {
    height: 26px;
    padding: 0 8px;
    font-size: 11px;
}

/* ── Top bar / gear ── */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.gear-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted-foreground);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}

.gear-btn:hover {
    background: var(--accent);
    color: var(--foreground);
}

.gear-btn svg {
    width: 14px;
    height: 14px;
}

/* ── Setup card ── */

.setup-card {
    text-align: center;
    padding: 24px 12px;
}

.setup-card h2 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.setup-card p {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-bottom: 14px;
}

.setup-card .api-input-group {
    max-width: 100%;
}

.setup-card .alert {
    text-align: left;
    margin-bottom: 10px;
}

.api-input-group {
    display: flex;
    gap: 6px;
}

.api-input-group input {
    flex: 1;
}

/* ── Settings ── */

.settings-section {
    margin-bottom: 16px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
    margin-bottom: 8px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.settings-row-label {
    font-size: 12px;
    font-weight: 500;
}

.settings-row-desc {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-top: 1px;
}

.settings-row select {
    height: 28px;
    padding: 0 6px;
    border: 1px solid var(--input);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: inherit;
    background: var(--card);
    color: var(--foreground);
    outline: none;
    cursor: pointer;
}

.settings-row select:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgba(10, 10, 10, 0.08);
}

.toggle {
    position: relative;
    width: 34px;
    height: 20px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--input);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.toggle input:checked + .toggle-track {
    background: var(--primary);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(14px);
}

.api-key-value {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
    font-size: 12px;
    color: var(--muted-foreground);
    background: var(--muted);
    padding: 4px 8px;
    border-radius: var(--radius);
    letter-spacing: 1px;
}

.confirm-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--muted-foreground);
}

/* ── Alerts ── */

.alert {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-error {
    color: var(--destructive);
    background: var(--error-bg);
    border: 1px solid #fecaca;
}

.alert-success {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid #bbf7d0;
}

.alert-success.toast {
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 200;
    animation: slideUp 0.2s ease-out, fadeOut 0.3s 2.7s ease-out forwards;
}

/* ── Stats bar ── */

.stats-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.stat-item {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: var(--foreground);
    line-height: 1.2;
}

.stat-label {
    font-size: 10px;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ── Groups section ── */

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.section-heading h3 {
    font-size: 13px;
    font-weight: 600;
}

.groups-actions {
    display: flex;
    gap: 4px;
}

.search-wrapper {
    margin-bottom: 8px;
}

.search-wrapper input {
    height: 28px;
    font-size: 12px;
}

.checkbox-list {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    transition: background 0.1s;
}

.checkbox-item:last-child {
    border-bottom: none;
}

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

.checkbox-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin-right: 8px;
    border-radius: 3px;
    accent-color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
}

.checkbox-item label {
    cursor: pointer;
    flex: 1;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
}

.checkbox-item .group-label-text {
    flex: 1;
    min-width: 0;
}

.group-id {
    color: var(--muted-foreground);
    font-size: 10px;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

.unsub-count {
    display: inline-flex;
    align-items: center;
    height: 16px;
    padding: 0 5px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    background: var(--muted);
    color: var(--muted-foreground);
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
    margin-left: 2px;
}

/* ── Badges ── */

.badge {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 5px;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.badge-default {
    background: var(--primary);
    color: var(--primary-foreground);
}

/* ── Info button / popover ── */

.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted-foreground);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    line-height: 1;
    padding: 0;
}

.info-btn:hover {
    background: var(--foreground);
    color: var(--primary-foreground);
    border-color: var(--foreground);
}

.popover {
    position: fixed;
    width: 200px;
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    z-index: 50;
    animation: popoverIn 0.12s ease-out;
}

.popover::after {
    content: '';
    position: absolute;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--popover);
    transform: rotate(45deg);
}

.popover.popover-above::after {
    bottom: -5px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.popover.popover-below::after {
    top: -5px;
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
}

.popover-title {
    font-weight: 600;
    font-size: 11px;
    margin-bottom: 2px;
}

.popover-desc {
    color: var(--muted-foreground);
}

/* ── Selected count ── */

.selected-count {
    font-size: 11px;
    color: var(--muted-foreground);
    margin-top: 6px;
}

/* ── Actions ── */

.actions {
    margin-top: 10px;
}

.actions .btn {
    width: 100%;
}

/* ── Loading / empty states ── */

.loading {
    text-align: center;
    padding: 20px;
    color: var(--muted-foreground);
    font-size: 12px;
}

.loading-dots::after {
    content: '';
    animation: dots 1.2s steps(4, end) infinite;
}

.no-groups {
    text-align: center;
    padding: 20px;
    color: var(--muted-foreground);
    font-size: 12px;
}

/* ── Utility ── */

.hidden {
    display: none !important;
}

.separator {
    height: 1px;
    background: var(--border);
    margin: 10px 0;
}

/* ── Modal ── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayIn 0.15s ease-out;
    padding: 12px;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    padding: 16px;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    animation: modalIn 0.15s ease-out;
}

.modal h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 12px;
    color: var(--muted-foreground);
    margin-bottom: 12px;
}

.modal-content {
    margin-bottom: 14px;
}

.modal-content .email-preview {
    background: var(--muted);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
    font-size: 12px;
    margin-bottom: 10px;
}

.modal-content .preview-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.modal-content .groups-preview {
    background: var(--muted);
    border-radius: var(--radius);
    max-height: 120px;
    overflow-y: auto;
    font-size: 12px;
}

.modal-content .groups-preview div {
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
}

.modal-content .groups-preview div:last-child {
    border-bottom: none;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted-foreground);
}

/* ── Animations ── */

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

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

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

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes dots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}
