:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #99a1b3;
  --primary: #4f8cff;
  --primary-600: #3b7bff;
  --green: #35c98a;
  --red: #ff5f66;
  --amber: #ffb454;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand b { font-size: 16px; letter-spacing: .3px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 12px var(--primary); }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { color: var(--muted); font-size: 12px; padding: 8px; }
.language-switch { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 9px; }
.language-switch button { flex: 1; padding: 5px 9px; font-size: 12px; background: transparent; }
.language-switch button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

.content { padding: 26px 32px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }

/* ---------- cards / grid ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value.small { font-size: 20px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
.project-row:hover { background: transparent; }
.project-row th {
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}
.project-row th, .project-label { font-weight: 700; }
.project-row th { display: table-cell; }
.project-row th > span:first-child { margin-right: 8px; }
.project-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(79,140,255,.16);
  color: var(--primary);
  font-size: 12px;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
button:hover, .btn:hover { border-color: var(--primary); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-600); }
button.danger { color: var(--red); border-color: transparent; background: transparent; }
button.danger:hover { border-color: var(--red); }
button.ghost { background: transparent; }
button.sm { padding: 5px 10px; font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
input:user-invalid { border-color: var(--red); }
.field-error { display: none; color: var(--red); font-size: 12px; margin-top: 4px; }
input:user-invalid + .field-error { display: block; }
.required-mark { color: var(--red); }
textarea { min-height: 64px; resize: vertical; font-family: var(--mono); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline label { margin: 0; }
.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.checkbox input { width: auto; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.active { background: rgba(53,201,138,.15); color: var(--green); }
.badge.paused { background: rgba(255,180,84,.15); color: var(--amber); }
.badge.off { background: rgba(153,161,179,.15); color: var(--muted); }
.badge.bot { background: rgba(255,95,102,.15); color: var(--red); }

/* ---------- misc ---------- */
.mono { font-family: var(--mono); font-size: 13px; }
.copy { cursor: pointer; color: var(--muted); }
.copy:hover { color: var(--primary); }
.muted { color: var(--muted); }
.project-label { margin-right: 8px; color: var(--text); }
.domain-label { margin-right: 8px; color: var(--muted); font-family: var(--mono); }
.right { text-align: right; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
.list-controls { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.list-controls label { margin: 0; }
.list-controls select { width: auto; min-width: 170px; }
.visually-hidden {
  position: absolute !important; clip-path: inset(50%) !important; overflow: hidden !important;
  width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important;
  border: 0 !important; white-space: nowrap !important;
}
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* bar chart */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 10px; }
.bars .bar { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; opacity: .85; }
.bars .bar:hover { opacity: 1; }
.bars .bar span { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart-wrap { padding-bottom: 24px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 720px; padding: 22px 24px; }
.modal h2 { margin: 0 0 4px; }
.modal .modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 34px; width: 340px;
}
.login .brand { justify-content: center; padding-bottom: 20px; }
.login h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.login .err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; text-align: center; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--green); padding: 12px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--red); }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .list-controls { align-items: stretch; }
  .list-controls label { width: 100%; }
  .list-controls select { width: 100%; }
}
