:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #6b7885;
  --line: #dfe4ea;
  --brand: #1f6feb;
  --brand-dark: #1858c4;
  --ok: #1a7f4b;
  --warn: #b26a00;
  --danger: #c02b2b;
  --danger-bg: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .12), 0 6px 18px rgba(20, 30, 45, .06);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.topbar nav a:hover { background: #eef2f6; color: var(--ink); }
.topbar nav a.active { background: var(--brand); color: #fff; }
.spacer { flex: 1; }
.badge {
  background: #eef2f6; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em;
}
.badge.cloud { background: #e6f4ec; color: var(--ok); }

/* ---- layout ---- */
main {
  max-width: 1180px; margin: 22px auto; padding: 0 20px;
}
h1 { font-size: 1.5rem; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.grow { flex: 1; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card h2 { font-size: 1.05rem; margin: 0 0 12px; }

/* ---- stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .n { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .9rem; }
.stat.warn .n { color: var(--warn); }
.stat.brand .n { color: var(--brand); }

/* ---- buttons ---- */
button, .btn {
  font: inherit; font-weight: 650;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
button:hover, .btn:hover { border-color: #c3ccd6; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: #e6b8b8; background: var(--danger-bg); }
button.sm { padding: 5px 10px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: .88rem; margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4fb; border-color: var(--brand); }
textarea { min-height: 72px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.checkline { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.checkline input { width: auto; }

/* ---- tables / lists ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fb; }
th.clickable { cursor: pointer; user-select: none; }
th.clickable:hover { color: var(--ink); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.pill.gray { background: #eef2f6; color: var(--muted); }
.pill.warn { background: #fdf0dc; color: var(--warn); }
.pill.ok { background: #e6f4ec; color: var(--ok); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.brand { background: #e7f0fe; color: var(--brand); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.searchbar { display: flex; gap: 10px; margin-bottom: 14px; }
.searchbar input { max-width: 420px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(18, 26, 38, .45);
  display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
  width: 100%; max-width: 720px; padding: 20px;
}
.modal.lg { max-width: 920px; }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-head h2 { margin: 0; flex: 1; font-size: 1.2rem; }
.modal-close { border: none; background: transparent; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* ---- toast ---- */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow);
  font-weight: 600; max-width: 360px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.section-title { display: flex; align-items: center; gap: 10px; margin: 20px 0 8px; }
.section-title h3 { margin: 0; font-size: 1rem; }
.section-title .line { flex: 1; height: 1px; background: var(--line); }

.msg-preview {
  background: #f3f7f2; border: 1px solid #d7e6d4; border-radius: 8px;
  padding: 12px; white-space: pre-wrap; font-size: .95rem;
}
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: .92rem; }
.kv div:nth-child(odd) { color: var(--muted); }

@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
