@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/fonts/inter-cyrillic-ext-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/fonts/inter-cyrillic-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/fonts/inter-latin-ext-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/fonts/inter-latin-wght-normal.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eef3ff;
  --primary-ink: #1d4ed8;
  --ring: rgba(37, 99, 235, 0.22);
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e4e9f0;
  --border-strong: #d3dae5;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --good: #15803d;
  --good-soft: #e8f7ee;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --neutral-soft: #eef1f6;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.2);
  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 18px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: #1a2a4a;
  --primary-ink: #93c5fd;
  --ring: rgba(96, 165, 250, 0.3);
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2639;
  --border: #243149;
  --border-strong: #33435f;
  --text: #e8edf5;
  --text-2: #b4c0d3;
  --muted: #8f9db3;
  --good: #4ade80;
  --good-soft: #12301f;
  --warn: #fbbf24;
  --warn-soft: #3a2a0c;
  --bad: #f87171;
  --bad-soft: #3b1619;
  --neutral-soft: #1f2a3e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a {
  color: inherit;
  text-decoration: none;
}

.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.i-s {
  width: 15px;
  height: 15px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13.5px;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.num {
  font-variant-numeric: tabular-nums;
}

/* Каркас */
.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100dvh;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}

.brand img {
  width: 34px;
  height: 34px;
}

.brand b {
  display: block;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand span {
  color: var(--muted);
  font-size: 12.5px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-s);
  color: var(--text-2);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary-ink);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  padding: 6px 12px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.mobile-bar {
  display: none;
}

.main {
  min-width: 0;
  padding: 28px 32px 48px;
}

.content {
  max-width: 1180px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 22px;
}

.page-head p {
  margin-top: 2px;
  color: var(--muted);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.back-link:hover {
  color: var(--text);
}

/* Карточки */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: 20px;
}

.card-pad > h2 {
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.tile {
  padding: 16px 18px;
}

.tile-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
}

.tile-value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.tile-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.tiles-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

:root[data-theme='dark'] .btn.primary:hover:not(:disabled) {
  color: #0b1220;
}

.btn.danger {
  border-color: var(--bad);
  background: transparent;
  color: var(--bad);
}

.btn.danger:hover:not(:disabled) {
  background: var(--bad-soft);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.block {
  width: 100%;
}

.btn.icon-only {
  width: 40px;
  padding: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Поля */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field-label {
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
}

.field small {
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-2 {
  grid-column: 1 / -1;
}

.inline-form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.inline-form .field {
  flex: 0 1 220px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.search {
  position: relative;
  flex: 1 1 260px;
}

.search .i {
  position: absolute;
  top: 12px;
  left: 12px;
  color: var(--muted);
}

.search input {
  padding-left: 38px;
}

.toolbar select {
  flex: 0 1 200px;
  width: auto;
}

/* Выбор срока и тарифа */
.choice-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
}

.choice {
  position: relative;
  display: block;
  cursor: pointer;
}

.choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
}

.choice span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  font-weight: 550;
  text-align: center;
  white-space: nowrap;
}

.choice small {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
}

.choice input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-ink);
}

.choice input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Метки */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}

.pill.good {
  background: var(--good-soft);
  color: var(--good);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.pill.neutral {
  background: var(--neutral-soft);
  color: var(--text-2);
}

.pill.plan {
  padding: 3px 10px;
  background: var(--primary-soft);
  color: var(--primary-ink);
}

/* Список клиентов */
.table-head,
.client-row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) 130px 178px 176px 92px 18px;
  gap: 12px;
  align-items: center;
  padding: 12px 18px;
}

.table-head {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.client-row {
  min-height: 60px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.client-row:last-child {
  border-bottom: 0;
}

.client-row:hover {
  background: var(--surface-2);
}

.client-row:first-child {
  border-radius: var(--radius-m) var(--radius-m) 0 0;
}

.client-row:last-child {
  border-radius: 0 0 var(--radius-m) var(--radius-m);
}

.client-name {
  min-width: 0;
}

.client-name b {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-name span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-note {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.row-chevron {
  color: var(--muted);
}

.device-label {
  display: none;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
}

.empty b {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}

/* Карточка клиента */
.defs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.def span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.def b {
  display: block;
  margin-top: 2px;
  font-size: 17px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.kv {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kv-row span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kv-row div {
  overflow-wrap: anywhere;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list-row:first-child {
  padding-top: 0;
}

.list-row > .small {
  flex: none;
  white-space: nowrap;
}

.list-main {
  min-width: 0;
}

.list-main b {
  display: block;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.list-main span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  background: var(--neutral-soft);
  color: var(--text-2);
  font-size: 14px;
}

.notice.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.notice.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.notice .i {
  margin-top: 2px;
}

.copy-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-line code {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font: 500 14px/1.45 ui-monospace, 'Cascadia Mono', Consolas, Menlo, monospace;
  overflow-wrap: anywhere;
}

/* Тарифы */
.plans-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.plan-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.plan-head h2 {
  font-size: 18px;
}

.perm {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
}

.perm input {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 2px 0 0;
  padding: 0;
  flex: none;
  accent-color: var(--primary);
}

.perm b {
  display: block;
  font-weight: 500;
  line-height: 1.35;
}

.perm small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.divider {
  height: 1px;
  margin: 14px 0;
  background: var(--border);
}

/* Журнал */
.log-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 14px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
}

.log-row:last-child {
  border-bottom: 0;
}

.log-time {
  color: var(--muted);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.log-text span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

/* Вход */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 20px 16px;
  background: radial-gradient(900px 500px at 50% -10%, var(--primary-soft), transparent 70%), var(--bg);
}

.login-card {
  width: min(400px, 100%);
  padding: 28px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  text-align: center;
}

.login-brand img {
  width: 52px;
  height: 52px;
}

.login-brand p {
  color: var(--muted);
}

/* Диалоги и уведомления */
dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}

.dialog-head h2 {
  font-size: 18px;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 20px 20px;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

.form-error {
  color: var(--bad);
  font-size: 14px;
}

#toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
}

.toast.error {
  color: var(--bad);
}

.toast .i {
  margin-top: 3px;
}

.loading {
  padding: 40px;
  color: var(--muted);
  text-align: center;
}

/* Планшет */
@media (max-width: 1100px) {
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tiles-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .two-col,
  .plans-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .table-head {
    display: none;
  }

  .client-row {
    grid-template-columns: minmax(0, 1fr) auto 18px;
    grid-template-areas:
      'name name chevron'
      'plan status chevron'
      'until devices chevron';
    row-gap: 8px;
  }

  .cell-name { grid-area: name; }
  .cell-plan { grid-area: plan; }
  .cell-status { grid-area: status; justify-self: end; }
  .cell-until { grid-area: until; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
  .cell-devices { grid-area: devices; justify-self: end; color: var(--muted); font-size: 13.5px; text-align: right; }
  .cell-devices .cell-note { color: var(--warn); }
  .cell-chevron { grid-area: chevron; }
  .device-label { display: inline; }
}

/* Телефон */
@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .mobile-bar .brand {
    padding: 0;
  }

  .mobile-bar .brand img {
    width: 30px;
    height: 30px;
  }

  .mobile-bar .actions {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .bottom-nav .nav-link {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 50px;
    padding: 4px 2px;
    font-size: 12px;
  }

  .main {
    padding: 18px 16px calc(92px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 21px;
  }

  .tiles,
  .tiles-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile {
    padding: 13px 14px;
  }

  .tile-value {
    font-size: 24px;
  }

  .defs,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head .btn,
  .page-head .actions {
    width: 100%;
  }

  .page-head .actions .btn {
    flex: 1 1 140px;
    width: auto;
  }

  .toolbar select {
    flex: 1 1 140px;
  }

  .log-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    padding: 11px 14px;
  }

  #toasts {
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 16px;
    max-width: none;
  }

  .dialog-foot .btn {
    flex: 1 1 120px;
  }
}

@media (min-width: 761px) {
  .bottom-nav {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
