/* Mailforge design system: deep navy sidebar, blue-violet accent, soft-gray canvas. */
:root {
    --navy-950: #070b1f;
    --navy-900: #0c1330;
    --navy-800: #151d43;
    --navy-700: #222c5a;
    --accent: #6366f1;
    --accent-2: #8b5cf6;
    --accent-soft: #eef0ff;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --canvas: #f5f7fb;
    --card: #ffffff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--canvas); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
code, pre.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre.code { background: var(--navy-900); color: #c7d2fe; padding: 14px; border-radius: 10px; overflow:auto; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(180deg, var(--navy-900), var(--navy-950));
    color: #cbd5e1; padding: 22px 16px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 0 8px 22px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 18px -6px rgba(99,102,241,.7);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: #cbd5e1;
    transition: background .15s ease, color .15s ease;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: linear-gradient(90deg, rgba(99,102,241,.28), rgba(139,92,246,.12)); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav .nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 12px 6px; }
.nav svg { width: 17px; height: 17px; flex: 0 0 17px; }
.sidebar-foot { margin-top: auto; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.04); font-size: 12px; }

.main { min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; padding: 18px 32px;
    background: rgba(255,255,255,.7); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.content { padding: 28px 32px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }

/* ---------- Cards & metrics ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.metric { position: relative; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
.metric:hover { transform: translateY(-2px); box-shadow: 0 18px 40px -18px rgba(99,102,241,.35); }
.metric .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.metric .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.metric .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric .icon {
    position: absolute; right: 16px; top: 16px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent);
}
.metric .icon svg { width: 18px; height: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.chart-box { position: relative; height: 260px; }

/* ---------- Buttons & forms ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
    background: #fff; color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer; transition: all .15s ease;
}
.btn:hover { border-color: #cbd5e1; text-decoration: none; transform: translateY(-1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; box-shadow: 0 8px 18px -8px rgba(99,102,241,.8); }
.btn-primary:hover { color: #fff; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--ink-2); font-size: 12.5px; }
input, select, textarea {
    font: inherit; font-weight: 400; color: var(--ink); padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease; width: 100%;
}
textarea { min-height: 140px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,102,241,.15); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; grid-column: 1 / -1; }
legend { font-weight: 700; padding: 0 6px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; grid-column: 1 / -1; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.checkbox input { width: auto; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: #fafbfd; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f8faff; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 280px; }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; align-items: center; color: var(--muted); }

/* ---------- Badges, alerts, toasts ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: var(--ink-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: #ecfdf5; color: #047857; }
.badge-warning { background: #fffbeb; color: #b45309; }
.badge-danger  { background: #fef2f2; color: #b91c1c; }
.badge-info    { background: var(--accent-soft); color: #4338ca; }
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.alert-error { background: #fef2f2; color: #991b1b; }
.alert-success { background: #ecfdf5; color: #065f46; }
.alert-info { background: var(--accent-soft); color: #3730a3; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast {
    background: var(--navy-900); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 16px 40px -12px rgba(0,0,0,.4);
    animation: toast-in .3s ease, toast-out .4s ease 4.2s forwards; max-width: 360px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); } }

/* ---------- Progress, skeleton, empty states ---------- */
.progress { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .6s ease; }
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 8px; height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.empty { text-align: center; padding: 42px 16px; color: var(--muted); }
.empty .orb { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 20px; background: linear-gradient(135deg, var(--accent-soft), #f5f3ff); display: grid; place-items: center; color: var(--accent); }
.empty .orb svg { width: 28px; height: 28px; }

/* ---------- Auth & install ---------- */
.auth-body, .install-body { min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background: radial-gradient(900px 500px at 10% -10%, rgba(99,102,241,.35), transparent 60%), radial-gradient(700px 500px at 110% 110%, rgba(139,92,246,.3), transparent 60%), var(--navy-950); }
.auth-card, .install-card { width: min(440px, 100%); background: #fff; border-radius: 20px; padding: 32px; box-shadow: 0 30px 80px -30px rgba(0,0,0,.6); }
.install-card { width: min(760px, 100%); }
.install-card .brand-mark, .auth-card .brand-mark { margin-bottom: 14px; }
.stack-form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

/* ---------- Layout helpers (replace inline grid styles so they can respond) ---------- */
.split-main-side { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.split-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.fields-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px 18px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.toolbar > * { min-width: 0; }
.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }
.metric .value { overflow-wrap: anywhere; }
img, iframe, canvas { max-width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
    .split-main-side { grid-template-columns: minmax(0, 1fr) 240px; }
}
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .fields-5 { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .split-main-side { grid-template-columns: 1fr; }
}

/* Tablet and phone: off-canvas sidebar opened from the top bar. */
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 84vw); height: 100vh; z-index: 40;
        transform: translateX(-100%); visibility: hidden; transition: transform .25s ease, visibility .25s; overflow-y: auto;
    }
    body.nav-open .sidebar { transform: translateX(0); visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.4); }
    body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(7,11,31,.5); z-index: 30; }
    .menu-toggle { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; margin-right: 12px; flex: 0 0 40px; }
    .menu-toggle svg { width: 20px; height: 20px; }
    .topbar { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
    .topbar .muted { font-size: 12px !important; }
    .topbar-left { display: flex; align-items: center; min-width: 0; }
    .grid-3, .grid-2, .split-2, .form-grid, .fields-5 { grid-template-columns: 1fr !important; }
    .split-main-side { grid-template-columns: 1fr; }
    .content { padding: 20px 16px 40px; }
    .page-head { align-items: stretch; }
    .page-head > .stack, .page-head > div:last-child { flex-wrap: wrap; }
    .card { padding: 16px; }
    .chart-box { height: 220px; }
    .btn { min-height: 40px; }
    .toolbar input, .toolbar select { max-width: none !important; width: 100%; flex: 1 1 100%; }
    .toolbar .btn { flex: 1 1 auto; justify-content: center; }
    .form-actions { flex-wrap: wrap; }
    .form-actions .btn { flex: 1 1 auto; justify-content: center; }
    .toasts { left: 12px; right: 12px; bottom: 12px; }
    .toast { max-width: none; }
    .auth-card, .install-card { padding: 22px; border-radius: 16px; }
    .auth-body, .install-body { padding: 14px; }
}

/* Phone: stacked "cards" tables. JS copies each header label into data-label. */
@media (max-width: 640px) {
    .grid-4 { grid-template-columns: 1fr; }
    .metric .value { font-size: 24px; }
    .table-wrap { overflow: visible; }
    .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
    .table-wrap thead { display: none; }
    .table-wrap tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; padding: 6px 0; background: #fff; }
    .table-wrap tbody tr:hover { background: #fff; }
    .table-wrap td { border: 0; padding: 8px 14px; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; text-align: right; }
    .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; text-align: left; flex: 0 0 auto; padding-top: 2px; }
    .table-wrap td:empty { display: none; }
    .table-wrap td[data-label=""]::before { content: none; }
    .table-wrap td .actions, .table-wrap td form.actions { justify-content: flex-end; }
    .table-wrap td input[type="email"] { max-width: none !important; width: 100%; }
    .table-wrap td .actions form { display: inline-flex; }
    .table-wrap td[data-label="Actions"], .table-wrap td:last-child:not([data-label]) { justify-content: flex-end; }
    .pager { justify-content: space-between; flex-wrap: wrap; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar input, .toolbar select, .toolbar .btn { width: 100%; }
    .sidebar-foot { font-size: 12px; }
    .picker-grid { grid-template-columns: 1fr; }
    .topbar-date { display: none; }
}
@media (max-width: 380px) {
    .content { padding: 16px 12px 32px; }
    .brand { font-size: 15px; }
    h1 { font-size: 19px; }
}

/* =====================================================================
   Sign-in page
   ===================================================================== */
.auth-page { margin: 0; min-height: 100vh; background: var(--navy-950); font-family: var(--font); color: var(--ink); }
.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }

.auth-hero {
    position: relative; overflow: hidden; color: #e2e8f0; display: flex; align-items: center; padding: 56px;
    background: radial-gradient(900px 600px at 0% 0%, rgba(99,102,241,.45), transparent 60%),
                radial-gradient(700px 500px at 100% 100%, rgba(139,92,246,.35), transparent 60%),
                linear-gradient(160deg, var(--navy-900), var(--navy-950));
}
.auth-hero-inner { position: relative; z-index: 1; max-width: 520px; }
.auth-hero h2 { font-size: 40px; letter-spacing: -.02em; color: #fff; margin: 18px 0 10px; }
.auth-hero p { font-size: 16px; color: #a5b4fc; line-height: 1.65; margin: 0 0 28px; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: center; color: #cbd5e1; font-size: 15px; }
.auth-points i { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; flex: 0 0 36px;
    background: rgba(99,102,241,.18); color: #c7d2fe; border: 1px solid rgba(165,180,252,.2); }
.auth-points svg { width: 18px; height: 18px; }
.auth-orb { position: absolute; border-radius: 50%; filter: blur(40px); opacity: .55; pointer-events: none; animation: float 14s ease-in-out infinite; }
.auth-orb-1 { width: 320px; height: 320px; background: #6366f1; top: -80px; right: -80px; }
.auth-orb-2 { width: 260px; height: 260px; background: #8b5cf6; bottom: -60px; left: -40px; animation-delay: -6s; }
@keyframes float { 0%,100% { transform: translate(0,0); } 50% { transform: translate(18px,-22px); } }

.auth-panel { display: grid; place-items: center; padding: 40px 24px; background: #f5f7fb; }
.auth-card {
    width: min(420px, 100%); background: #fff; border-radius: 22px; padding: 36px 34px;
    box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 30px 60px -28px rgba(15,23,42,.35); border: 1px solid #eef2f7;
    animation: rise .5s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.99); } to { opacity: 1; transform: none; } }
.auth-head { text-align: center; margin-bottom: 26px; }
.auth-head h1 { font-size: 26px; margin: 14px 0 4px; }
.auth-head p { margin: 0; font-size: 14px; }
.brand-mark-lg { width: 52px; height: 52px; border-radius: 16px; font-size: 22px; margin: 0 auto; }
.auth-head .brand-mark { margin: 0 auto; width: 48px; height: 48px; font-size: 20px; border-radius: 14px; }

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon > i:first-child, .input-icon > svg:first-child { position: absolute; left: 14px; width: 18px; height: 18px; color: #94a3b8; pointer-events: none; }
.input-icon input { padding-left: 42px; padding-right: 44px; height: 48px; border-radius: 12px; background: #f8fafc; }
.input-icon input:focus { background: #fff; }
.icon-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 10px; border: 0;
    background: transparent; color: #64748b; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: #eef2ff; color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

.btn-block { width: 100%; justify-content: center; height: 48px; font-size: 15px; border-radius: 12px; margin-top: 6px; position: relative; }
.btn-block .spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-block.is-loading .btn-label { opacity: .0; }
.btn-block.is-loading .spinner { display: block; position: absolute; left: 50%; top: 50%; margin: -9px 0 0 -9px; }
.btn-block.is-loading { pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-alert { display: flex; gap: 10px; align-items: flex-start; border: 1px solid #fecaca; }
.auth-alert svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.auth-foot { text-align: center; margin: 20px 0 0; font-size: 13px; }

@media (max-width: 900px) {
    .auth-layout { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .auth-panel { min-height: 100vh; background: linear-gradient(160deg, var(--navy-900), var(--navy-950)); padding: 20px 14px; }
    .auth-card { padding: 28px 22px; border-radius: 18px; }
}
@media (max-width: 380px) {
    .auth-card { padding: 22px 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .auth-orb, .auth-card, .btn-block .spinner { animation: none !important; }
}
