:root {
  --bg: #0b0f17;
  --panel: #121a2b;
  --panel2: #0f1626;
  --line: #1f2b45;
  --line2: #2b3a5e;
  --txt: #cdd7ee;
  --muted: #67748f;
  --accent: #2f6bff;
  --accent2: #3b7bff;
  --ok: #17c072;
  --warn: #f5a623;
  --err: #f5544d;
  --new: #ffd54a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; color: #9fb1e0; font-size: 12px; }

/* ---- top ---- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10182a, #0b0f17);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo { font-size: 30px; line-height: 1; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.upstream-badge {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.work { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: blink 1s infinite; }
.dot.err { background: var(--err); box-shadow: 0 0 8px var(--err); }
@keyframes blink { 50% { opacity: .4; } }

/* ---- tabs ---- */
.tabs {
  display: flex; gap: 2px; padding: 0 22px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 63px; z-index: 4;
}
.tab {
  background: none; border: none; color: var(--muted);
  font-size: 14px; padding: 13px 16px; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color .15s;
}
.tab:hover { color: var(--txt); }
.tab.active { color: #fff; border-bottom-color: var(--accent); }

/* ---- layout ---- */
main { flex: 1; padding: 20px 22px 40px; width: 100%; max-width: 1380px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
.filter { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter label { font-size: 13px; color: var(--muted); display: flex; gap: 7px; align-items: center; cursor: pointer; }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.livedot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
.livedot.off { background: var(--muted); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--txt);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
  transition: all .15s;
}
.btn:hover { border-color: var(--line2); background: var(--panel2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }

/* ---- tables ---- */
.tablewrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; max-height: calc(100vh - 230px);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
thead th {
  position: sticky; top: 0; background: var(--panel2); color: var(--muted);
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 2;
}
tbody td { padding: 10px 13px; border-bottom: 1px solid rgba(31,43,69,.6); vertical-align: middle; }
tbody tr:hover { background: rgba(47,107,255,.05); }
tbody tr.new { background: rgba(255,213,74,.07); }
.empty { color: var(--muted); text-align: center; padding: 26px !important; }

.pill { padding: 2px 9px; border-radius: 999px; font-size: 11px; background: var(--panel2); color: var(--muted); }
.pill.new { background: rgba(255,213,74,.15); color: var(--new); }
.pill.ok { background: rgba(23,192,114,.15); color: var(--ok); }
.pill.err { background: rgba(245,84,77,.15); color: var(--err); }
.login { font-weight: 600; color: #fff; }
.pw {
  font-family: "SF Mono", "Consolas", monospace; font-size: 12px;
  background: var(--panel2); padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--line); cursor: pointer; user-select: none; word-break: break-all;
}
.pw.shown { user-select: all; }
.copybtn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.copybtn:hover { color: #fff; }

/* ---- form ---- */
.label { display: block; font-size: 13px; color: var(--muted); margin: 16px 0 6px; }
.label small { color: var(--muted); opacity: .7; font-weight: 400; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--txt); border-radius: 9px; padding: 9px 12px; font-size: 13px;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { font-family: "SF Mono", "Consolas", monospace; font-size: 12px; line-height: 1.5; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }
@media (max-width: 780px) { .grid2 { grid-template-columns: 1fr; } }

/* ---- kpis ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px;
}
.kpi .n { font-size: 26px; font-weight: 700; color: #fff; line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 5px; }

h3 { font-size: 14px; color: var(--muted); margin: 24px 0 10px; }

/* ---- foot ---- */
.foot {
  padding: 10px 22px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; background: var(--panel2);
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1a2740; color: #fff; border: 1px solid var(--line2);
  padding: 11px 20px; border-radius: 10px; font-size: 13px;
  transition: transform .25s; pointer-events: none; z-index: 20;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--err); }

/* ---- login screen ---- */
.login-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 34px 32px; width: 100%; max-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card .logo.big { font-size: 40px; text-align: center; }
.login-card h1 { text-align: center; margin: 6px 0 2px; font-size: 22px; }
.login-card .sub { text-align: center; }
.login-card input { margin-top: 14px; }
.login-card .btn { margin-top: 18px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }
.err-msg { color: var(--err); min-height: 16px; }

/* ---- top-right / user chip ---- */
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.role-pill {
  padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: rgba(245,166,35,.15); color: var(--warn);
}
.role-pill.admin { background: rgba(47,107,255,.15); color: var(--accent2); }

/* ---- editor (арендаторы/кампании) ---- */
.editor {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 4px;
}
.editor h3 { margin: 0 0 4px; color: var(--txt); font-size: 15px; }
.mlink { color: var(--accent2); text-decoration: none; font-family: "SF Mono","Consolas",monospace; font-size: 12px; }
.mlink:hover { text-decoration: underline; }
tr.mutedrow td { opacity: .55; }
.hidden { display: none !important; }
