:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --brand: #2f6fed;
  --brand-dark: #2559c4;
  --ok: #17845a;
  --warn: #b26a00;
  --err: #c62b2b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--brand); }

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

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

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: #16181d;
  color: #cbd0d8;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h1 { font-size: 15px; color: #fff; margin: 0 0 2px; padding: 0 10px; }
.sidebar .tag { font-size: 11px; color: #7b828e; padding: 0 10px; margin-bottom: 18px; display: block; }
.sidebar nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: #cbd0d8;
  text-decoration: none;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: #22252c; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar .foot { margin-top: 22px; padding: 0 10px; font-size: 11px; color: #6d7480; }

.main { flex: 1; padding: 22px 26px 60px; max-width: 1180px; min-width: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------------------------- panels ---------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card h3 .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }

.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 600; letter-spacing: -0.5px; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }

/* ---------------------------- forms ----------------------------- */

label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 150px; margin-bottom: 0; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #cbdbfb; border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 13px; }
input[type=checkbox] { width: auto; margin-right: 6px; vertical-align: -2px; }
.check { font-size: 13px; color: var(--ink); font-weight: 400; }

button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: #f0f2f5; }
button.danger { background: #fff; color: var(--err); border-color: #f0c9c9; }
button.danger:hover { background: #fdf1f1; }
button.sm { padding: 4px 9px; font-size: 12px; }

/* ---------------------------- tables ---------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; background: #eef0f3; color: var(--muted);
}
.badge.ok { background: #e3f5ec; color: var(--ok); }
.badge.warn { background: #fdf1dd; color: var(--warn); }
.badge.err { background: #fdecec; color: var(--err); }
.badge.info { background: #e7effd; color: var(--brand-dark); }

.bar { height: 6px; background: #eef0f3; border-radius: 4px; overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.spacer { flex: 1; }

/* ---------------------------- misc ------------------------------ */

.banner {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px;
  background: #fdf1dd; color: #7a4a00; border: 1px solid #f2ddb4;
}
.banner.err { background: #fdecec; color: #8d1f1f; border-color: #f3c9c9; }
.banner.ok { background: #e3f5ec; color: #0f5c40; border-color: #b9e3cf; }

#toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
#toast div {
  background: #1c2024; color: #fff; padding: 10px 14px; border-radius: 8px;
  font-size: 13px; max-width: 380px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#toast div.err { background: var(--err); }
#toast div.ok { background: var(--ok); }

iframe.preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.bulk-upload { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 22px; }
.bulk-upload [hidden] { display: none; }
.bulk-upload input[type='file'] { padding: 12px; border-style: dashed; background: #f8faff; }
.bulk-upload input::file-selector-button { margin-right: 12px; border: 1px solid #ccd9ef; border-radius: 6px; padding: 8px 12px; background: #fff; color: var(--brand-dark); cursor: pointer; }
.bulk-counts { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 14px; background: #eef3fd; border: 1px solid #dce6fb; border-radius: 8px; margin: 16px 0 10px; }
.bulk-counts strong { width: 100%; font-size: 16px; color: var(--brand-dark); }
.bulk-counts span { font-size: 12px; color: var(--muted); }
.bulk-upload .table-wrap { max-height: 280px; overflow: auto; margin: 14px 0 8px; }
.bulk-upload details { margin: 12px 0; overflow-wrap: anywhere; }
.bulk-upload #bulkSendButton { margin-top: 14px; width: 100%; }
.bulk-upload #bulkSendResult { margin-top: 16px; }

.tagbtn {
  display: inline-block; margin: 0 5px 5px 0; padding: 2px 8px; border-radius: 6px;
  background: #eef0f3; border: 1px solid var(--line); font-size: 12px;
  font-family: ui-monospace, Consolas, monospace; cursor: pointer;
}
.tagbtn:hover { background: #e2e6ec; }

.step {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.step:last-child { border-bottom: 0; }

.logline { font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 3px 0; border-bottom: 1px solid #f0f2f4; }
.logline .ts { color: var(--muted); margin-right: 8px; }
.logline.error { color: var(--err); }
.logline.warn { color: var(--warn); }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .main { padding: 16px; }
}
