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

:root {
    --bg:       #f4f6f9;
    --surface:  #ffffff;
    --border:   #e2e8f0;
    --primary:  #3b82f6;
    --primary-dark: #2563eb;
    --text:     #1e293b;
    --muted:    #64748b;
    --success:  #16a34a;
    --warning:  #d97706;
    --danger:   #dc2626;
    --radius:   8px;
    --sidebar-w: 220px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--text);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
}

.sidebar-logo {
    padding: 20px 16px 16px;
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid #334155;
    color: #fff;
}

.sidebar-logo span { color: var(--primary); }

.sidebar nav { flex: 1; padding: 12px 0; }

.sidebar nav a {
    display: block;
    padding: 10px 20px;
    color: #94a3b8;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: color .15s, background .15s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    color: #fff;
    background: #334155;
    border-left-color: var(--primary);
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid #334155;
    font-size: 12px;
    color: #64748b;
}

.sidebar-footer a { color: #94a3b8; text-decoration: none; }

.main { margin-left: var(--sidebar-w); flex: 1; padding: 28px 32px; }

/* ---- Card ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* ---- Stats ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }

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

.stat-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--text); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}
tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-sent     { background: #dcfce7; color: #166534; }
.badge-error    { background: #fee2e2; color: #991b1b; }
.badge-skipped  { background: #f1f5f9; color: #475569; }
.badge-ok       { background: #dcfce7; color: #166534; }
.badge-fail     { background: #fee2e2; color: #991b1b; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}
.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-group textarea { resize: vertical; min-height: 200px; font-family: monospace; font-size: 13px; }

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background .15s, opacity .15s;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-sm       { padding: 5px 12px; font-size: 12px; }
.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ---- Search/filter bar ---- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--primary); }

/* ---- Modal ---- */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    width: 90%;
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.draft-body { white-space: pre-wrap; font-size: 13px; line-height: 1.6; background: #f8fafc; padding: 14px; border-radius: 6px; border: 1px solid var(--border); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px; width: 100%; max-width: 380px; }
.login-box h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-box p  { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* ---- Health status ---- */
.health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.health-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.health-card .service-name { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.health-card .status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot-ok   { background: var(--success); }
.dot-fail { background: var(--danger); }
.health-card .detail { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---- Misc ---- */
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 22px; }
.text-muted { color: var(--muted); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
