:root {
    --bg: #f3f4f8;
    --surface: #ffffff;
    --border: #e6e8ee;
    --border-strong: #d7dae3;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #97a1b3;
    --primary: #0f172a;
    --primary-hover: #1e293b;
    --accent: #4f46e5;
    --accent-soft: #eef0fd;
    --success-bg: #dcfaee;
    --success-text: #067a4d;
    --success-dot: #10b981;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --warning-dot: #f59e0b;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --danger-dot: #ef4444;
    --neutral-bg: #f1f3f7;
    --neutral-text: #6b7280;
    --neutral-dot: #b2b8c4;
    --radius-sm: 7px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.07), 0 2px 6px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.topnav {
    background: var(--primary);
    color: white;
    padding: 22px 40px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.topnav-inner {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.topnav-left { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 40px; width: auto; display: block; }
.brand { font-size: 16px; font-weight: 700; letter-spacing: 0.01em; }
.brand-sep { color: rgba(255,255,255,0.3); }
.brand-sub {
    font-size: 12.5px;
    color: #aab3c5;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}
.topnav-link {
    font-size: 12.5px;
    color: #aab3c5;
    text-decoration: none;
    font-weight: 500;
}
.topnav-link:hover { color: white; }

.container { max-width: 1080px; margin: 0 auto; padding: 32px 40px 64px; }

h1.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px 0; letter-spacing: -0.01em; }
.page-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 28px 0; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    margin-bottom: 18px;
    font-weight: 500;
}
.banner-success { background: var(--success-bg); color: var(--success-text); }
.banner-error { background: var(--danger-bg); color: var(--danger-text); }

.upload-card {
    margin-bottom: 28px;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}
.upload-card .icon-wrap {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.upload-info { display: flex; gap: 14px; align-items: center; }
.upload-card h2 { font-size: 14px; margin: 0; font-weight: 600; }
.upload-card p { font-size: 12.5px; color: var(--text-muted); margin: 3px 0 0 0; }
.upload-form { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.file-input-label {
    font-size: 12.5px;
    color: var(--text-muted);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    cursor: pointer;
    background: var(--bg);
    white-space: nowrap;
}
.file-input-label:hover { border-color: var(--accent); color: var(--accent); }
.upload-form input[type="file"] { display: none; }

.bulk-actions-card {
    padding: 14px 20px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
#selection-count { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.bulk-buttons { display: flex; gap: 10px; }
.bulk-buttons form { display: inline; }

table { width: 100%; border-collapse: collapse; }
.col-check { width: 36px; text-align: center !important; }
.col-check input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent); }
.table-card { overflow: hidden; }
th, td { padding: 13px 20px; text-align: left; font-size: 13.5px; }
thead th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    padding-top: 16px;
    padding-bottom: 12px;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
td.col-actions { text-align: right; white-space: nowrap; }

.client-cell { display: flex; align-items: center; gap: 11px; }
.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11.5px; font-weight: 700;
    flex-shrink: 0;
}
.client-name { font-weight: 600; font-size: 13.5px; }
.client-id { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.email-cell { color: var(--text-muted); font-size: 13px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-sent { background: var(--success-bg); color: var(--success-text); }
.badge-sent .badge-dot { background: var(--success-dot); }
.badge-generated { background: var(--warning-bg); color: var(--warning-text); }
.badge-generated .badge-dot { background: var(--warning-dot); }
.badge-failed { background: var(--danger-bg); color: var(--danger-text); }
.badge-failed .badge-dot { background: var(--danger-dot); }
.badge-none { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-none .badge-dot { background: var(--neutral-dot); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 7px 13px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--bg); border-color: var(--text-faint); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 7px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn[disabled], .btn-disabled {
    background: var(--neutral-bg) !important;
    color: var(--text-faint) !important;
    cursor: not-allowed;
    border-color: transparent !important;
}
.btn svg { width: 14px; height: 14px; }

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-muted);
}
.empty-state svg { width: 36px; height: 36px; color: var(--text-faint); margin-bottom: 12px; }
.empty-state p { font-size: 13.5px; margin: 0; }

/* preview page */
.preview-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 22px;
    gap: 16px;
}
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 10px;
}
.back-link:hover { color: var(--text); }
.back-link svg { width: 13px; height: 13px; }
.preview-actions { display: flex; gap: 10px; flex-shrink: 0; }

.meta-row { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.meta-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-muted);
    display: inline-flex;
    gap: 5px;
    align-items: center;
}
.meta-pill strong { color: var(--text); font-weight: 600; }
.meta-pill code {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 11.5px;
    color: var(--text);
    font-weight: 600;
}

.email-preview-card {
    padding: 16px 20px;
    margin-bottom: 18px;
    font-size: 13px;
}
.email-preview-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.email-preview-row:last-child { border-bottom: none; }
.email-preview-label { width: 60px; flex-shrink: 0; color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 2px; }
.email-preview-body pre { margin: 0; font-family: inherit; white-space: pre-wrap; color: var(--text); }

.section-heading {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 28px 0 10px 0;
}
.section-heading:first-of-type { margin-top: 0; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field-hint { font-weight: 400; color: var(--text-faint); text-transform: none; letter-spacing: 0; }
.field-input {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    margin-bottom: 16px;
    color: var(--text);
}
.field-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-textarea { resize: vertical; line-height: 1.5; }

.progress-card { padding: 16px 20px; margin-bottom: 18px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 10px; }
.progress-head #progress-count { color: var(--text-muted); font-weight: 500; }
.progress-track { height: 8px; border-radius: 999px; background: var(--neutral-bg); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0%; transition: width 0.3s ease; }

.device-code-card { padding: 20px; margin-bottom: 14px; }
.device-code-card p { font-size: 13.5px; margin: 0 0 10px 0; }
.device-code-card a { color: var(--accent); font-weight: 600; }
.device-code {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text);
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    display: inline-block;
}

.reset-card {
    padding: 18px 20px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.reset-card h2 { font-size: 14px; margin: 0; font-weight: 600; }
.reset-card p { font-size: 12.5px; color: var(--text-muted); margin: 3px 0 0 0; }
.reset-card.danger { border-color: #fecaca; background: #fffafa; }
.btn-danger { background: var(--danger-text); color: white; }
.btn-danger:hover { background: #7f1d1d; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 420px;
    padding: 24px;
}
.modal-message { font-size: 14px; color: var(--text); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.pdf-frame-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    background: var(--surface);
}
.pdf-frame-card iframe {
    width: 100%;
    height: 82vh;
    border: none;
    display: block;
}
