:root {
  color-scheme: light;
  --primary: #0066cc;
  --primary-focus: #0071e3;
  --primary-dark: #2997ff;
  --ink: #1d1d1f;
  --muted: #7a7a7a;
  --muted-strong: #333333;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-soft: #fafafc;
  --line: #e0e0e0;
  --line-soft: #f0f0f0;
  --black: #000000;
  --dark: #272729;
  --danger: #b42318;
  --danger-bg: #fff2f1;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.47 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  min-height: 44px;
  padding: 0 28px;
  background: var(--black);
  color: #fff;
}
.brand {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 600;
  line-height: 44px;
  white-space: nowrap;
}
nav {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
nav a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 0;
  color: rgba(255,255,255,.78);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
nav a:hover {
  color: #fff;
  text-decoration: none;
}
nav a[aria-current="page"] {
  color: #fff;
  background: rgba(255,255,255,.12);
}

.content {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 32px 28px 56px;
  min-width: 0;
}
h1 {
  margin: 0 0 24px;
  color: var(--ink);
  font-size: clamp(30px, 4vw, 40px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0;
}
h2 {
  margin: 32px 0 14px;
  color: var(--ink);
  font-size: clamp(21px, 2.6vw, 28px);
  font-weight: 600;
  line-height: 1.19;
  letter-spacing: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin-bottom: 0; min-width: 0; }
.title-line {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  flex-wrap: wrap;
}
.title-line h1 { margin-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 12px;
  border: 1px solid rgba(0,102,204,.16);
  border-radius: 9999px;
  background: #fff;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
}
.danger-badge {
  border-color: rgba(180,35,24,.16);
  background: var(--danger-bg);
  color: var(--danger);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metrics div,
.login-panel,
.panel,
.tariff-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
}
.metrics span {
  display: block;
  color: var(--ink);
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 600;
  line-height: 1.1;
}
.metrics small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.43;
}
.panel { margin-bottom: 24px; }
.panel h2:first-child { margin-top: 0; }
details.panel summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
  list-style-position: inside;
}
details.panel[open] summary { margin-bottom: 18px; }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.toolbar form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar > input,
.toolbar > select,
.toolbar form > input,
.toolbar form > select {
  flex: 1 1 220px;
  max-width: 420px;
}

button,
.button {
  appearance: none;
  border: 1px solid var(--primary);
  border-radius: 9999px;
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  line-height: 1.2;
  white-space: nowrap;
  font: inherit;
  font-size: 15px;
  transition: transform .12s ease, background-color .15s ease, border-color .15s ease;
}
button:hover,
.button:hover {
  background: var(--primary-focus);
  border-color: var(--primary-focus);
  text-decoration: none;
}
button:active,
.button:active { transform: scale(.95); }
button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--primary-focus);
  outline-offset: 2px;
}
.secondary,
.button.secondary {
  background: var(--panel);
  color: var(--primary);
  border-color: var(--primary);
}
.secondary:hover,
.button.secondary:hover {
  background: #f2f8ff;
  color: var(--primary);
}
.danger,
.button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.danger:hover,
.button.danger:hover {
  background: #d92d20;
  border-color: #d92d20;
}
button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 9999px;
  background: var(--panel);
  color: var(--ink);
  padding: 11px 18px;
  font: inherit;
  font-size: 15px;
  line-height: 1.3;
}
textarea {
  border-radius: 18px;
  resize: vertical;
}
input::placeholder,
textarea::placeholder { color: var(--muted); }
input[readonly],
input:disabled,
select:disabled,
textarea:disabled {
  background: var(--panel-soft);
  color: var(--muted);
}
label {
  display: grid;
  gap: 7px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.3;
}
.wide { grid-column: 1 / -1; }
.check {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 0;
  color: var(--muted-strong);
}
.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

table {
  width: 100%;
  min-width: 0;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  -webkit-overflow-scrolling: touch;
}
table > tbody {
  display: table;
  width: 100%;
  min-width: 780px;
}
th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  font-size: 14px;
}
th {
  color: var(--muted);
  font-weight: 600;
  background: var(--panel-soft);
}
tr:last-child td { border-bottom: 0; }
tr.click-row { cursor: pointer; }
tr.click-row:hover td { background: #f8fbff; }
td input,
td select,
td textarea {
  min-width: 140px;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
}
td code,
pre code,
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .92em;
}
td code { white-space: nowrap; }
.actions {
  display: grid;
  gap: 8px;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 16px;
}
.muted {
  color: var(--muted);
  max-width: 360px;
  word-break: break-word;
  white-space: normal;
}
pre {
  max-width: 100%;
  overflow: auto;
  border-radius: 18px;
  background: var(--dark);
  color: #fff;
  padding: 18px;
}

.server-load {
  display: grid;
  gap: 18px;
}
.gauge-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 28px;
  align-items: center;
  min-width: 0;
  padding: 28px 32px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.gauge-item {
  display: grid;
  justify-items: center;
  min-width: 0;
}
.gauge {
  width: min(184px, 100%);
  height: 126px;
  overflow: visible;
}
.gauge path {
  fill: none;
  stroke-width: 13;
  stroke-linecap: round;
}
.gauge-track { stroke: var(--line-soft); }
.gauge-value {
  stroke: var(--primary);
  transition: stroke-dashoffset .35s ease, stroke .2s ease;
}
.gauge.is-danger .gauge-value { stroke: #c8443f; }
.gauge text {
  fill: var(--ink);
  font-size: 23px;
  font-weight: 600;
}
.gauge-caption {
  margin-top: -6px;
  max-width: 100%;
  color: var(--muted-strong);
  font-size: 15px;
  font-weight: 400;
  text-align: center;
  white-space: nowrap;
  overflow-wrap: anywhere;
}
.gauge-caption b { font-weight: 600; }

.tariff-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 16px;
}
.archive-filter { margin: 0; }
.archive-filter .check { min-height: 42px; }
.tariff-card {
  display: grid;
  gap: 16px;
  min-width: 0;
}
.tariff-card.is-deleted { background: var(--panel-soft); }
.tariff-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.tariff-card h2 { margin: 0; }
.tariff-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.tariff-id {
  color: var(--muted);
  font-weight: 600;
}
.tariff-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tariff-stats span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 9999px;
  background: var(--panel-soft);
  color: var(--muted-strong);
  padding: 5px 11px;
  font-size: 14px;
  font-weight: 600;
}
.tariff-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.tariff-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.tariff-actions form { margin: 0; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-panel {
  width: min(390px, 100%);
  display: grid;
  gap: 14px;
}
.login-panel h1 { margin-bottom: 0; }
.error {
  margin: 0;
  color: var(--danger);
}

@media (max-width: 1200px) {
  .content { padding: 28px 22px 48px; }
  .gauge-panel {
    gap: 20px;
    padding: 24px;
  }
  .gauge-caption { font-size: 14px; }
}

@media (max-width: 900px) {
  .sidebar {
    align-items: stretch;
    gap: 10px;
    padding: 0 14px;
  }
  .brand { line-height: 44px; }
  nav a { padding: 0 9px; }
  .content {
    padding: 22px 18px 44px;
    max-width: none;
  }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .gauge-panel {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
    gap: 18px;
    padding: 20px;
  }
  .gauge-caption {
    white-space: normal;
    font-size: 14px;
  }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 30px; }
  h2 { font-size: 21px; }
  .sidebar {
    display: block;
    padding: 0 12px 8px;
  }
  .brand {
    height: 40px;
    line-height: 40px;
  }
  nav { min-height: 36px; }
  nav a {
    min-height: 36px;
    padding: 0 8px;
  }
  .content { padding: 18px 14px 36px; }
  .metrics,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }
  .metrics div,
  .login-panel,
  .panel,
  .tariff-card {
    border-radius: 18px;
    padding: 18px;
  }
  .toolbar,
  .toolbar form {
    align-items: stretch;
  }
  .toolbar > input,
  .toolbar > select,
  .toolbar form > input,
  .toolbar form > select,
  .toolbar > .button,
  .toolbar button,
  .toolbar form {
    width: 100%;
    max-width: none;
  }
  button,
  .button {
    width: 100%;
  }
  .page-head button,
  .page-head .button,
  .tariff-actions button,
  .tariff-actions form {
    width: 100%;
  }
  .tariff-fields { grid-template-columns: 1fr; }
  table { border-radius: 18px; }
  table > tbody { min-width: 720px; }
  th,
  td { padding: 11px 12px; }
  .gauge-panel {
    grid-template-columns: 1fr;
    padding: 18px;
  }
}

@media (max-width: 420px) {
  .content { padding-left: 10px; padding-right: 10px; }
  .metrics div,
  .login-panel,
  .panel,
  .tariff-card,
  .gauge-panel {
    padding: 16px;
  }
}
