/* ==========================================================================
   Dispatch — bulk mail control panel
   Design tokens
   ========================================================================== */
:root {
    --ink:        #10152B;
    --ink-2:      #1B2140;
    --panel:      #FFFFFF;
    --paper:      #F5F4F0;
    --line:       #E4E1D8;
    --amber:      #E1963A;
    --amber-dark: #B9741E;
    --green:      #2E8B63;
    --green-bg:   #E7F3EC;
    --red:        #C2543F;
    --red-bg:     #FBEAE6;
    --slate:      #6B7080;
    --slate-dark: #383D52;

    --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 21, 43, 0.06), 0 6px 20px rgba(16, 21, 43, 0.05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

::selection { background: var(--amber); color: var(--ink); }

/* ---------- Layout shell ---------- */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--ink);
    color: #EDEBE3;
    padding: 28px 18px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: 0.02em;
    padding: 0 8px 26px 8px;
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 0 3px rgba(225, 150, 58, 0.25);
    flex-shrink: 0;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 8px;
    font-size: 14.5px;
    font-weight: 500;
    color: #B9B7AE;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }

.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-item.active {
    background: rgba(225, 150, 58, 0.14);
    color: #fff;
}
.nav-item.active svg { opacity: 1; color: var(--amber); }

.sidebar-foot {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 14px;
    margin-top: 14px;
    font-size: 12.5px;
    color: #8B8A82;
}

.sidebar-foot a { display:block; margin-top: 8px; color: #D9AE72; text-decoration: none; font-weight: 600; }
.sidebar-foot a:hover { text-decoration: underline; }

/* ---------- Main content ---------- */
.main {
    padding: 34px 42px 60px;
    max-width: 1180px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 26px;
    flex-wrap: wrap;
    gap: 14px;
}

.page-head h1 {
    font-family: var(--font-display);
    font-size: 26px;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

.page-head p { margin: 0; color: var(--slate); font-size: 14.5px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Cards & grid ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.card + .card { margin-top: 18px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stat-card .stat-label {
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--slate);
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-family: var(--font-mono);
    font-size: 30px;
    font-weight: 600;
    color: var(--ink);
}

.stat-card .stat-value.amber { color: var(--amber-dark); }
.stat-card .stat-value.green { color: var(--green); }
.stat-card .stat-value.red { color: var(--red); }

.section-title {
    font-family: var(--font-display);
    font-size: 15.5px;
    font-weight: 600;
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ---------- Forms ---------- */
label { font-size: 13.5px; font-weight: 600; color: var(--slate-dark); display: block; margin-bottom: 6px; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=datetime-local], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 14px;
    background: #fff;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(225, 150, 58, 0.18);
}

textarea { resize: vertical; min-height: 90px; font-family: var(--font-body); }
textarea.mono { font-family: var(--font-mono); font-size: 13px; }

.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { font-size: 12.5px; color: var(--slate); margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.05s ease, background 0.15s ease, border-color .15s ease;
    font-family: var(--font-body);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--ink-2); }

.btn-amber { background: var(--amber); color: #2A1B04; }
.btn-amber:hover:not(:disabled) { background: var(--amber-dark); color: #fff; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--slate); }

.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--slate);
    font-weight: 700;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}
td { padding: 11px 12px; border-bottom: 1px solid #EFEDE6; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); font-size: 13px; }
.empty-row td { text-align: center; color: var(--slate); padding: 36px 12px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.sent, .badge.completed { background: var(--green-bg); color: var(--green); }
.badge.failed, .badge.bounced { background: var(--red-bg); color: var(--red); }
.badge.pending, .badge.draft { background: #F0EEE7; color: var(--slate-dark); }
.badge.sending { background: #FCEFDC; color: var(--amber-dark); }
.badge.unsubscribed { background: #F0EEE7; color: var(--slate); }
.badge.scheduled { background: #EAF1FB; color: #2D5FA6; }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.toolbar .search-box { flex: 1; min-width: 220px; max-width: 320px; }

/* ---------- Postage / progress signature element ----------
   A perforated "stamp meter" progress bar used while a campaign sends.
   The dashed edges evoke a postage stamp / mail-manifest strip. */
.postage-meter {
    position: relative;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px 20px 20px;
    margin-top: 4px;
}
.postage-meter::before, .postage-meter::after {
    content: '';
    position: absolute;
    left: 14px; right: 14px;
    height: 0;
    border-top: 2px dashed #D8D4C8;
}
.postage-meter::before { top: 0; }
.postage-meter::after { bottom: 0; }

.postage-track {
    height: 10px;
    border-radius: 100px;
    background: #EDEAE1;
    overflow: hidden;
    margin: 10px 0 12px;
}
.postage-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--amber), var(--amber-dark));
    width: 0%;
    transition: width 0.35s ease;
}
.postage-stats {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--slate-dark);
}
.postage-label {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(16,21,43,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    max-width: 560px;
    width: 100%;
    max-height: 86vh;
    overflow-y: auto;
    padding: 26px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 18px; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--slate); line-height: 1; }

/* ---------- Toasts ---------- */
#toast-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: var(--ink);
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13.5px;
    box-shadow: var(--shadow);
    min-width: 220px;
    max-width: 360px;
    border-left: 3px solid var(--amber);
    animation: toast-in 0.2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Misc ---------- */
.checkbox-cell { width: 34px; }
.subtle { color: var(--slate); }
.divider { height: 1px; background: var(--line); margin: 20px 0; }
.tag-chip {
    display: inline-block;
    padding: 2px 9px;
    background: #EFEDE6;
    border-radius: 100px;
    font-size: 11.5px;
    color: var(--slate-dark);
    font-weight: 600;
}
.recipient-preview {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--slate);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 8px;
}

/* ---------- Automation: cron / webhook code boxes ---------- */
.code-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}
.code-box code {
    flex: 1;
    font-size: 12.5px;
    color: var(--slate-dark);
    word-break: break-all;
    white-space: normal;
}
.code-box .btn { flex-shrink: 0; }

/* ---------- Login page ---------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    background-image: radial-gradient(circle at 20% 20%, rgba(225,150,58,0.10), transparent 45%);
}
.login-card {
    background: #fff;
    padding: 38px 34px;
    border-radius: 14px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.login-mark { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.login-mark-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); }
.login-sub { color: var(--slate); font-size: 13.5px; margin: 6px 0 22px; }
.login-error { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.login-form label { margin-top: 14px; }
.login-form label:first-child { margin-top: 0; }
.login-form button { margin-top: 22px; }
.login-hint { font-size: 12px; color: var(--slate); margin: 18px 0 0; text-align: center; }
.login-hint code { background: var(--paper); padding: 1px 5px; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: relative; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
    .brand { padding-bottom: 0; margin-right: 12px; }
    .nav { flex-direction: row; }
    .sidebar-foot { display: none; }
    .main { padding: 22px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .field-row { grid-template-columns: 1fr; }
}
