* { box-sizing: border-box; }

:root {
    --primary: #7C6FE8;
    --primary-dark: #5F52D6;
    --primary-light: #EFEDFD;
    --pink: #E85DA0;
    --pink-light: #FCEAF3;
    --amber: #F0A63B;
    --amber-light: #FDF1DE;
    --green: #22B573;
    --green-light: #E4F8EE;
    --red: #EF5350;
    --red-light: #FDEAEA;
    --gray-light: #F1F1F5;

    --bg: #F5F6FB;
    --surface: #FFFFFF;
    --border: #ECEDF3;
    --text-primary: #201C3C;
    --text-secondary: #8B899E;
    --text-muted: #B4B2C3;
    --shadow: 0 2px 10px rgba(32, 28, 60, 0.05);
    --shadow-md: 0 6px 24px rgba(32, 28, 60, 0.08);
    --radius: 14px;
}

body {
    margin: 0;
    font-family: -apple-system, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
}

a { color: inherit; }

/* ---------- Shell layout ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 24px;
    font-size: 17px;
    font-weight: 700;
}
.logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--pink));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
}

.sidebar nav { display: flex; flex-direction: column; gap: 3px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .12s, color .12s;
}
.nav-item svg { flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: var(--gray-light); color: var(--text-primary); }
.nav-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 12px 8px 0;
    font-size: 11.5px;
    color: var(--text-muted);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .page-title { font-size: 17px; font-weight: 700; }
.topbar .crumb { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.user-menu { position: relative; }
.user-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 10px 6px 6px;
    border-radius: 30px;
    border: 1px solid transparent;
}
.user-trigger:hover { background: var(--gray-light); }
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--pink));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}
.user-trigger .name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-trigger .role { font-size: 11.5px; color: var(--text-muted); line-height: 1.2; }
.chev { color: var(--text-muted); transition: transform .15s; }
.user-menu.open .chev { transform: rotate(180deg); }

.user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    min-width: 190px;
    padding: 6px;
    z-index: 20;
}
.user-menu.open .user-dropdown { display: block; }
.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13px;
    text-decoration: none;
    color: var(--text-primary);
}
.user-dropdown a:hover { background: var(--gray-light); }
.user-dropdown a.danger { color: var(--red); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 5px 2px; }

.content { padding: 24px 28px 40px; flex: 1; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; }
.subtle { color: var(--text-secondary); font-size: 13px; }

/* ---------- Stat tiles ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.stat-tile {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.stat-tile .stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat-tile .stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.stat-tile .stat-icon {
    width: 38px; height: 38px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
}
.stat-tile .stat-num { font-size: 26px; font-weight: 700; }

.icon-pending { background: var(--gray-light); color: #6B6980; }
.icon-sending { background: var(--amber-light); color: var(--amber); }
.icon-sent { background: var(--green-light); color: var(--green); }
.icon-failed { background: var(--red-light); color: var(--red); }

/* ---------- Donut ---------- */

.donut-wrap { display: flex; align-items: center; gap: 28px; }
.donut {
    width: 150px; height: 150px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.donut-hole {
    width: 100px; height: 100px; border-radius: 50%;
    background: var(--surface);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-hole .num { font-size: 22px; font-weight: 700; }
.donut-hole .lbl { font-size: 11px; color: var(--text-muted); }
.legend { display: flex; flex-direction: column; gap: 10px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-item .val { margin-left: auto; font-weight: 700; padding-left: 18px; }

/* ---------- Table ---------- */

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

.badge { display: inline-block; padding: 3px 12px; border-radius: 30px; font-size: 12px; font-weight: 600; }
.badge-pending { background: var(--gray-light); color: #6B6980; }
.badge-sending { background: var(--amber-light); color: var(--amber); }
.badge-sent { background: var(--green-light); color: var(--green); }
.badge-failed { background: var(--red-light); color: var(--red); }

.error-text { color: var(--red); font-size: 12.5px; }

form.inline { display: inline; }

/* ---------- Forms & buttons ---------- */

input[type=text], input[type=password], input[type=file], textarea, select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 9px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-primary);
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}
textarea { resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 9px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-light); color: var(--text-primary); }
.btn-secondary:hover { background: #E5E5EC; }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: #FADBDA; }
.btn-small { padding: 5px 12px; font-size: 12px; }

.btn-add {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 30px;
    padding: 9px 20px 9px 16px;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn-add:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(124, 111, 232, .3);
}
.btn-add svg { transition: transform .12s ease; }
.btn-add:hover svg { transform: rotate(90deg); }

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(32, 28, 60, .38);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 16px;
    width: 440px;
    max-width: 100%;
    padding: 22px 24px 24px;
    box-shadow: var(--shadow-md);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.modal-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; }
.modal-close {
    cursor: pointer;
    background: var(--gray-light);
    border: none;
    width: 28px; height: 28px;
    border-radius: 50%;
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: #E5E5EC; color: var(--text-primary); }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; margin-bottom: 6px; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, #EFEDFD 0%, #F5F6FB 45%, #FCEAF3 100%); }
.login-card { width: 360px; box-shadow: var(--shadow-md); }
.login-card .logo-mark { width: 44px; height: 44px; border-radius: 13px; font-size: 19px; margin: 0 auto 14px; }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtle { text-align: center; display: block; margin-bottom: 22px; }
.alert { padding: 10px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--red-light); color: var(--red); }
.alert-success { background: var(--green-light); color: var(--green); }

.key-value { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; background: var(--gray-light); padding: 4px 8px; border-radius: 6px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 6px; }

.empty-row td { color: var(--text-muted); text-align: center; padding: 28px 0; }
