:root {
  --bg: #e7ecf2;
  --panel: #fbfcfd;
  --panel-2: #f2f5f9;
  --ink: #0e1f38;
  --ink-soft: #56687f;
  --ink-faint: #8d9cb0;
  --rule: #c8d3e0;
  --rule-soft: #dee5ee;
  --accent: #1e38c8;
  --accent-2: #101c68;
  --accent-soft: #e6eaff;
  --ok: #0b7a5c;
  --ok-soft: #dff2ec;
  --warn: #9a5b00;
  --warn-soft: #fbeed8;
  --bad: #a31d1d;
  --bad-soft: #fae4e4;
  --idle: #7e8fa6;
  --idle-soft: #e9edf3;
  --shadow: 0 1px 2px rgba(14, 31, 56, .06), 0 8px 24px rgba(14, 31, 56, .07);
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ------------------------------------------------------------ вход */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card .login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
}
.login-card h1.wordmark {
  margin: 0;
  font: 700 19px/1 var(--sans);
  letter-spacing: -.01em;
  color: var(--ink);
}
.login-card h1.wordmark span { color: var(--accent); }
.login-card .section-tag {
  display: inline-block;
  margin: 0 0 26px;
  padding: 3px 8px;
  background: var(--accent-soft);
  border-radius: 3px;
  font: 600 10px/1.4 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ------------------------------------------------------------ каркас */

.shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.logo {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 5px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 1px 2px rgba(14, 31, 56, .3), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.logo i { border-radius: 2px; background: rgba(255, 255, 255, .92); }
.logo i:nth-child(3) { background: rgba(255, 255, 255, .5); }

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.wordmark {
  font: 700 15px/1 var(--sans);
  letter-spacing: -.01em;
  color: var(--ink);
}
.wordmark span { color: var(--accent); }

.tabs { display: flex; gap: 4px; padding-left: 8px; border-left: 1px solid var(--rule); }
.tab {
  background: none;
  border: 0;
  font: 600 11px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 7px 10px;
  border-radius: 3px;
  color: var(--ink-soft);
}
.tab:hover { color: var(--ink); background: var(--panel-2); }
.tab.active { background: var(--accent-soft); color: var(--accent); }

.topbar-actions {
  order: 2;
  flex: 1 1 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
#btn-logout { order: 1; margin-left: auto; }

.search {
  flex: 1 1 220px;
  min-width: 160px;
  position: relative;
}
.search input {
  width: 100%;
  padding: 8px 10px 8px 30px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 13px;
}
.search::before {
  content: "⌕";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-52%);
  color: var(--ink-faint);
  font-size: 15px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  padding: 8px 13px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: #e8edf4; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #172ea9; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { color: var(--ink); background: var(--panel-2); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.sm { padding: 5px 9px; font-size: 12px; }

/* ------------------------------------------------------------ главная */

.page-home {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px 24px 40px;
}
.home-hero { text-align: center; margin-bottom: 40px; }
.home-hero .logo.lg {
  width: 48px;
  height: 48px;
  padding: 9px;
  gap: 5px;
  border-radius: 12px;
  margin: 0 auto 16px;
}
.home-hero .wordmark.lg { font-size: 26px; }
.home-hero p { margin: 12px 0 0; color: var(--ink-soft); font-size: 14px; }

.home-sections {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.home-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  transition: border-color .12s, transform .12s;
}
.home-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.home-card-tag {
  display: inline-block;
  padding: 3px 8px;
  margin-bottom: 8px;
  background: var(--accent-soft);
  border-radius: 3px;
  font: 600 10px/1.4 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}
.home-card-desc { font-size: 13px; color: var(--ink-soft); }

/* ------------------------------------------------------------ рабочая область */

.body {
  display: grid;
  grid-template-columns: 232px 1fr;
  align-items: start;
}

.sidebar {
  padding: 18px 14px 40px;
  border-right: 1px solid var(--rule);
  position: sticky;
  top: 51px;
  max-height: calc(100vh - 51px);
  overflow-y: auto;
}
.side-title {
  font: 500 10px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 22px 0 8px 6px;
}
.side-title:first-child { margin-top: 0; }

.pool-btn {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px;
  background: none;
  border: 0;
  border-radius: 3px;
  text-align: left;
  color: var(--ink-soft);
}
.pool-btn:hover { background: var(--panel-2); color: var(--ink); }
.pool-btn.on { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule); font-weight: 500; }
.pool-btn .rail {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--idle);
  margin-right: 2px;
}
.pool-btn[data-pool="working"] .rail { background: var(--ok); }
.pool-btn[data-pool="free"] .rail { background: var(--accent); }
.pool-btn[data-pool="blocked"] .rail { background: var(--bad); }
.pool-btn[data-pool="all"] .rail { background: var(--ink-faint); }
.pool-btn .n { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }
.pool-btn.on .n { color: var(--ink); }

/* сводка по каналам */
.gauge {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 10px 11px;
  margin-bottom: 8px;
}
.gauge-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 600 11px/1 var(--mono);
  letter-spacing: .12em;
  margin-bottom: 9px;
}
.gauge-head b { font-family: var(--mono); font-size: 13px; }
.bar { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: var(--idle-soft); }
.bar i { display: block; }
.bar i.s-active { background: var(--ok); }
.bar i.s-temp_ban { background: var(--warn); }
.bar i.s-ban { background: var(--bad); }
.gauge-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-soft);
}
.gauge-legend span { font-family: var(--mono); }

.city-btn {
  width: 100%;
  display: flex;
  gap: 8px;
  padding: 5px 8px;
  background: none;
  border: 0;
  border-radius: 3px;
  text-align: left;
  font-size: 13px;
  color: var(--ink-soft);
}
.city-btn:hover { background: var(--panel-2); color: var(--ink); }
.city-btn.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.city-btn .n { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }

/* ------------------------------------------------------------ таблица */

.main { padding: 18px 20px 60px; min-width: 0; }

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters select {
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 13px;
}
.filters .count {
  margin-left: auto;
  font: 400 12px/1 var(--mono);
  color: var(--ink-soft);
}

.board {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.thead, .row {
  display: grid;
  grid-template-columns: 4px 168px minmax(120px, 1fr) minmax(200px, 260px) minmax(200px, 260px) minmax(90px, 1fr) 34px;
  align-items: center;
}
.thead {
  background: var(--panel-2);
  border-bottom: 1px solid var(--rule);
  font: 500 10px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.thead > div { padding: 9px 10px; }
.thead > div:first-child { padding: 0; }

.thead.users-row, .row.users-row {
  grid-template-columns: minmax(120px, 1fr) 100px 110px minmax(160px, auto);
}
.thead.users-row > div:first-child { padding: 9px 10px; }
.row.users-row > div { grid-column: auto; }
.row.users-row > div:last-child { display: flex; gap: 4px; flex-wrap: wrap; }

.whoami { order: 1; color: var(--ink-soft); font-size: 12px; white-space: nowrap; }
.whoami b { color: var(--ink); font-weight: 500; }

.role-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  font: 600 10px/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.role-badge.admin { background: var(--accent-soft); color: var(--accent); }
.role-badge.guest { background: var(--idle-soft); color: var(--ink-soft); }

.row { border-bottom: 1px solid var(--rule-soft); }
.row:last-child { border-bottom: 0; }
.row:hover { background: #f5f8fc; }
.row > div { padding: 9px 10px; min-width: 0; }
.row .rail { padding: 0; align-self: stretch; background: var(--idle); }
.row[data-pool="working"] .rail { background: var(--ok); }
.row[data-pool="free"] .rail { background: var(--accent); }
.row[data-pool="blocked"] .rail { background: var(--bad); }

.cell-phone {
  font-family: var(--mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.cell-phone small {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0;
}
.cell-city { font-weight: 500; }
.cell-city em {
  font-style: normal;
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 13px;
}
.cell-note { font-size: 12px; color: var(--ink-soft); }

/* подпись — парные чипы каналов */
.chip {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  background: var(--idle-soft);
  border: 1px solid transparent;
  border-radius: 3px;
  text-align: left;
  color: var(--ink-soft);
  transition: border-color .12s;
}
.chip:hover { border-color: var(--rule); }
.chip .led {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--idle);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .8);
}
.chip .tag {
  font: 600 10px/1 var(--mono);
  letter-spacing: .1em;
  flex: none;
  width: 34px;
}
.chip .meta {
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip[data-status="active"] { background: var(--ok-soft); color: var(--ok); }
.chip[data-status="active"] .led { background: var(--ok); }
.chip[data-status="temp_ban"] { background: var(--warn-soft); color: var(--warn); }
.chip[data-status="temp_ban"] .led { background: var(--warn); }
.chip[data-status="ban"] { background: var(--bad-soft); color: var(--bad); }
.chip[data-status="ban"] .led { background: var(--bad); }

.row-menu {
  padding: 0 6px !important;
  background: none;
  border: 0;
  color: var(--ink-faint);
  font-size: 16px;
  line-height: 1;
}
.row-menu:hover { color: var(--ink); }

.empty { padding: 56px 20px; text-align: center; color: var(--ink-soft); }
.empty b { display: block; color: var(--ink); margin-bottom: 6px; font-size: 15px; }

/* ------------------------------------------------------------ панель номера */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(14, 31, 56, .28);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--rule);
  z-index: 41;
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 40px rgba(14, 31, 56, .16);
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--rule);
}
.drawer-head h2 {
  margin: 0;
  font: 500 19px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
}
.drawer-head p { margin: 3px 0 0; font-size: 12px; color: var(--ink-soft); }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer-foot {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--rule);
  background: var(--panel-2);
}

fieldset {
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 12px 14px 14px;
  margin: 0 0 14px;
}
legend {
  padding: 0 6px;
  font: 600 10px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
fieldset.chan legend { display: flex; align-items: center; gap: 7px; }
fieldset.chan legend .led { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); }
fieldset.chan[data-status="active"] legend { color: var(--ok); }
fieldset.chan[data-status="active"] legend .led { background: var(--ok); }
fieldset.chan[data-status="temp_ban"] legend { color: var(--warn); }
fieldset.chan[data-status="temp_ban"] legend .led { background: var(--warn); }
fieldset.chan[data-status="ban"] legend { color: var(--bad); }
fieldset.chan[data-status="ban"] legend .led { background: var(--bad); }

.field { margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 9px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 13px;
}
.field input.mono, .field.mono input { font-family: var(--mono); }
.field textarea { resize: vertical; min-height: 54px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: #fff;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; gap: 0; }
.seg button {
  flex: 1;
  padding: 6px 4px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-left-width: 0;
  font-size: 12px;
  color: var(--ink-soft);
}
.seg button:first-child { border-left-width: 1px; border-radius: 3px 0 0 3px; }
.seg button:last-child { border-radius: 0 3px 3px 0; }
.seg button.on { color: #fff; background: var(--ink); border-color: var(--ink); font-weight: 500; }
.seg button.on[data-status="active"] { background: var(--ok); border-color: var(--ok); }
.seg button.on[data-status="temp_ban"] { background: var(--warn); border-color: var(--warn); }
.seg button.on[data-status="ban"] { background: var(--bad); border-color: var(--bad); }

.log { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.log li {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--rule-soft);
  color: var(--ink-soft);
}
.log li:last-child { border-bottom: 0; }
.log time { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); flex: none; }

/* ------------------------------------------------------------ модальные окна */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 31, 56, .28);
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 20px 22px 18px;
}
.modal-card h2 {
  margin: 0 0 4px;
  font: 500 16px/1.2 var(--sans);
}
.modal-card > p { margin: 0 0 16px; font-size: 12.5px; color: var(--ink-soft); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.note {
  padding: 9px 11px;
  background: var(--accent-soft);
  border-radius: 3px;
  font-size: 12px;
  color: var(--ink);
  margin-bottom: 12px;
}
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.ok { background: var(--ok-soft); color: var(--ok); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 3px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------ адаптив */

@media (max-width: 1080px) {
  .thead, .row { grid-template-columns: 4px 150px 1fr 190px 190px 34px; }
  .thead > div:nth-child(6), .row > div:nth-child(6) { display: none; }
}

@media (max-width: 700px) {
  .whoami { display: none; }
}

@media (max-width: 860px) {
  .body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0 18px;
    align-items: start;
  }
  .thead { display: none; }
  .row {
    grid-template-columns: 4px 1fr;
    padding: 0 0 10px;
    align-items: stretch;
  }
  .row > div { grid-column: 2; }
  .row .rail { grid-row: 1 / -1; grid-column: 1; }
  .row > div:nth-child(6) { display: block; }
  .row-menu { justify-self: start; }
  .main { padding: 14px 12px 48px; }
}
