/* ==========================================================================
   Cold Email Platform — UI
   ========================================================================== */
:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #111827;
    --text-2: #4b5563;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-600: #4338ca;
    --primary-50: #eef2ff;
    --success: #059669;
    --success-50: #ecfdf5;
    --warning: #d97706;
    --warning-50: #fffbeb;
    --danger: #dc2626;
    --danger-50: #fef2f2;
    --info: #0284c7;
    --info-50: #f0f9ff;
    --sidebar: #111827;
    --sidebar-text: #9ca3af;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .25);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 13px; letter-spacing: .5px; }
.brand-name { color: #fff; font-weight: 600; font-size: 14.5px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; font-size: 14px; }
.nav-link svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(99,102,241,.18); color: #fff; }
.nav-link.as-button { background: none; border: 0; width: 100%; cursor: pointer; font-family: inherit; text-align: left; }
.nav-logout { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; margin: 0; }
.nav-user { padding: 0 12px 8px; font-size: 12.5px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.page-title { font-size: 18px; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.menu-toggle { display: none; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-title { font-size: 15px; }
.card-subtitle { color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent, var(--primary)); }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat.s-success { --accent: var(--success); } .stat.s-danger { --accent: var(--danger); }
.stat.s-warning { --accent: var(--warning); } .stat.s-info { --accent: var(--info); } .stat.s-muted { --accent: #9ca3af; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 4px 0 12px; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent; font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s; text-decoration: none !important; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-600); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: #f3f4f6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.6); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-secondary.loading::after, .btn-ghost.loading::after { border-color: var(--muted); border-top-color: transparent; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--text-2); display: inline-grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-weight: 500; font-size: 13px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input[type=url], select, textarea {
    width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font: 14px var(--font); color: var(--text); background: #fff; transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.55; }
textarea.code { font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
.check-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.check-list .checkbox { justify-content: space-between; width: 100%; }
.check-list .meta { color: var(--muted); font-size: 12px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { border: 1px solid var(--border-strong); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 13px; user-select: none; }
.days input { display: none; }
.days label:has(input:checked) { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #d1d5db; border-radius: 20px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; flex-wrap: wrap; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; min-width: 140px; }
.toolbar .spacer { flex: 1; }
.bulk-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--primary-50); border-bottom: 1px solid var(--border); font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .check { width: 36px; }
.table .truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { color: var(--muted); font-size: 12px; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; gap: 10px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: #f3f4f6; color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.b-success { background: var(--success-50); color: var(--success); }
.badge.b-danger { background: var(--danger-50); color: var(--danger); }
.badge.b-warning { background: var(--warning-50); color: var(--warning); }
.badge.b-info { background: var(--info-50); color: var(--info); }
.badge.b-primary { background: var(--primary-50); color: var(--primary); }
.badge.b-plain::before { display: none; }

/* ---------- Progress ---------- */
.progress { height: 8px; background: #eef0f4; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.progress.p-warning > span { background: var(--warning); }
.progress.p-danger > span { background: var(--danger); }
.util-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 70px; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.util-row:last-child { border-bottom: 0; }
.util-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Alerts / empty / loading ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; border: 1px solid; }
.alert-danger { background: var(--danger-50); color: #991b1b; border-color: #fecaca; }
.alert-success { background: var(--success-50); color: #065f46; border-color: #a7f3d0; }
.alert-warning { background: var(--warning-50); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--info-50); color: #075985; border-color: #bae6fd; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; fill: #d1d5db; margin-bottom: 8px; }
.empty h4 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty p { margin: 0 0 14px; }
.loading-row { padding: 40px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 8px; }
.skeleton { background: linear-gradient(90deg, #eef0f4 25%, #f6f7f9 50%, #eef0f4 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 4px; color: transparent !important; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; max-width: 380px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; animation: toast-in .2s ease-out; border-left: 4px solid var(--info); }
.toast.t-success { border-left-color: #10b981; } .toast.t-error { border-left-color: #ef4444; } .toast.t-warning { border-left-color: #f59e0b; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Modal ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 12px; box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.modal.wide { width: min(860px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(17, 24, 39, .5); }
.modal-box { padding: 22px 24px; margin: 0; }
.modal-title { font-size: 17px; margin-bottom: 8px; }
.modal-text { color: var(--text-2); margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

/* ---------- Misc components ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.var-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border-strong); background: var(--surface-2); border-radius: 6px; padding: 3px 8px; font: 12px var(--mono); cursor: pointer; color: var(--text-2); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.preview-frame { width: 100%; min-height: 360px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.preview-subject { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 10px; font-size: 13.5px; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist .ck-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; background: #f3f4f6; color: var(--muted); }
.checklist .ok .ck-icon { background: var(--success-50); color: var(--success); }
.checklist .bad .ck-icon { background: var(--danger-50); color: var(--danger); }
.checklist .warn .ck-icon { background: var(--warning-50); color: var(--warning); }
.checklist .ck-title { font-weight: 600; }
.checklist .ck-desc { color: var(--muted); font-size: 12.5px; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; background: var(--surface-2); }
.dropzone.drag, .dropzone:hover { border-color: var(--primary); background: var(--primary-50); color: var(--primary); }
.dropzone strong { color: var(--text); }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.text-muted { color: var(--muted); } .text-danger { color: var(--danger); } .text-success { color: var(--success); }
.small { font-size: 12.5px; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mt-2 { margin-top: 12px; } .mb-2 { margin-bottom: 12px; }
.flex { display: flex; gap: 10px; align-items: center; } .flex-wrap { flex-wrap: wrap; } .between { justify-content: space-between; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; align-items: center; }
.feed li:last-child { border-bottom: 0; }
.feed .when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- Login ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #eef2ff 0%, #f5f6fa 60%); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); padding: 32px; }
.auth-card .brand { padding: 0 0 18px; }
.auth-card .brand-name { color: var(--text); }
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; height: 40px; margin-top: 6px; }
.public-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.public-card { max-width: 460px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--border); padding: 36px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .grid-main-side, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .menu-toggle { display: inline-grid; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .grid-2, .form-grid { grid-template-columns: 1fr; }
    .util-row { grid-template-columns: 1fr 70px; }
    .util-row .progress { grid-column: 1 / -1; grid-row: 2; }
    .kv { grid-template-columns: 1fr; }
}
