/* Кабинет и админка: окно как ClickGUI. Рейл слева, панель контента, карточки-плитки внутри.
   Токены и кнопки берутся из site.css, здесь только раскладка приложения. */

.app-body { min-height: 100vh; min-height: 100dvh; }
.app-body .sky__shade { --dim: 0.62; }

.app {
  display: flex; gap: var(--s8);
  width: 100%; max-width: 1240px; margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  padding: var(--s21);
}
.app__rail, .app__main {
  background: rgba(14, 14, 16, 0.72);
  backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
  border-radius: var(--r-panel);
  box-shadow: 0 0 0 1px var(--hairline);
}
.app__rail {
  position: sticky; top: var(--s21);
  width: 220px; flex: none; height: calc(100dvh - 42px);
  display: flex; flex-direction: column; padding: var(--s13);
}
.app__brand { display: flex; align-items: center; gap: var(--s8); height: 55px; padding: 0 var(--s8); font-weight: 600; }
.app__brand img { width: 24px; height: 23px; }
.app__brand small { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12px; }
.app__group { color: var(--muted); font-size: 12px; padding: var(--s13) var(--s13) var(--s5); }
.app__nav { display: grid; gap: 2px; }
.app__item {
  display: flex; align-items: center; gap: var(--s13);
  height: 38px; padding: 0 var(--s13); border: 0; border-radius: var(--r-tile);
  background: none; color: var(--muted); font-size: 14px; text-align: left; cursor: pointer;
  transition: background-color 0.18s, color 0.18s;
}
.app__item:hover { color: var(--ink); background: var(--tile); }
.app__item[aria-current="true"] { color: var(--ink); background: var(--selected); font-weight: 500; }
.app__item .n { margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.app__user { margin-top: auto; display: flex; align-items: center; gap: var(--s8); padding: var(--s8) var(--s8) var(--s8) var(--s13); border-radius: var(--r-tile); background: var(--tile); }
.app__user .av { width: 30px; height: 30px; border-radius: 50%; background: var(--control); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.app__user .who { flex: 1; min-width: 0; }
.app__user b, .app__user small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app__user b { font-size: 13px; font-weight: 500; }
.app__user small { color: var(--muted); font-size: 11.5px; }
.icon-btn { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border: 0; border-radius: var(--r-control); background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--control); color: var(--ink); }

.app__main { flex: 1; min-width: 0; padding: var(--s21) var(--s21) var(--s34); }
.app__head { display: flex; align-items: center; gap: var(--s13); min-height: 42px; margin-bottom: var(--s21); flex-wrap: wrap; }
.app__head h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.app__head .crumbs { color: var(--muted); font-size: 14px; }
.app__head .tools { margin-left: auto; display: flex; gap: var(--s8); flex-wrap: wrap; }

.view-in { animation: view-in 0.36s var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(13px); } }

/* Сетка карточек */
.grid { display: grid; gap: var(--s13); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { .grid--stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat span { white-space: normal; } }
.span-2 { grid-column: span 2; }
.card2 { background: var(--tile); border-radius: var(--r-tile); padding: var(--s21); min-width: 0; animation: view-in 0.42s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }
.card2__head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s8) var(--s13); margin-bottom: var(--s13); }
.card2__head > div { flex: 1 1 200px; min-width: 0; }
.card2__head h2 { font-size: 15px; font-weight: 600; }
.card2__head p { color: var(--muted); font-size: 12.5px; }
.card2__head .end { margin-left: auto; }
.card2 > p.muted { font-size: 13.5px; }

.stat b { display: block; font-size: 28px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { display: block; margin-top: var(--s5); color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small { display: block; margin-top: var(--s5); color: var(--faint); font-size: 12px; }

/* Поля форм */
.form { display: grid; gap: var(--s13); }
.label { display: grid; gap: var(--s5); font-size: 13px; color: var(--muted); }
.input {
  height: 40px; width: 100%; padding: 0 var(--s13);
  border: 0; border-radius: var(--r-control); outline: none;
  background: var(--control); color: var(--ink); font-size: 14px;
  box-shadow: inset 0 0 0 1px transparent; transition: background-color 0.15s, box-shadow 0.15s;
}
.input:focus { background: var(--control-hover); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.input::placeholder { color: var(--faint); }
.input--mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: 0.04em; }
.input--sm { height: 34px; font-size: 13px; }
select.input { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.inline { display: flex; gap: var(--s8); align-items: center; flex-wrap: wrap; }
.inline .input { flex: 1; min-width: 140px; }
.btn--danger { background: rgba(255, 87, 87, 0.14); color: #ff8a8a; }
.btn--danger:hover { background: rgba(255, 87, 87, 0.24); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.hint { color: var(--faint); font-size: 12.5px; }
.error-text { color: #ff8a8a; font-size: 13px; min-height: 18px; }

/* Таблицы */
.table-wrap { overflow-x: auto; margin: 0 calc(var(--s21) * -1); padding: 0 var(--s21); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 var(--s13) var(--s8); white-space: nowrap; }
.table td { padding: var(--s13); border-top: 1px solid var(--hairline); vertical-align: middle; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--tile); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td .sub { display: block; color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.empty-state { padding: var(--s34) 0; text-align: center; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 var(--s8);
  border-radius: 11px; background: var(--control); color: var(--muted); font-size: 12px; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--ok { color: #7ee2a8; background: rgba(126, 226, 168, 0.12); }
.pill--warn { color: #ffcf6e; background: rgba(255, 207, 110, 0.12); }
.pill--bad { color: #ff8a8a; background: rgba(255, 87, 87, 0.13); }
.pill--plain::before { display: none; }

/* Кольцо подписки */
.sub { display: flex; align-items: center; gap: var(--s21); }
.sub__ring { position: relative; width: 120px; height: 120px; flex: none; }
.sub__ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.sub__ring circle { fill: none; stroke-width: 8; }
.sub__ring .track { stroke: var(--control); }
.sub__ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1.2s var(--ease-out); }
.sub__ring .val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.sub__ring .val b { font-size: 30px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.sub__ring .val span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.sub__text h3 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.sub__text p { color: var(--muted); font-size: 14px; margin-top: 3px; }
.sub__text .inline { margin-top: var(--s13); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--s8) var(--s21); font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.list { display: grid; }
.list__row { display: flex; align-items: center; gap: var(--s13); padding: var(--s13) 0; border-top: 1px solid var(--hairline); font-size: 14px; }
.list__row:first-child { border-top: 0; padding-top: 0; }
.list__row .grow { flex: 1; min-width: 0; }
.list__row small { display: block; color: var(--muted); font-size: 12.5px; }

/* Тарифы в кабинете */
.plan-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s8); }
.plan-pick button {
  display: grid; gap: 3px; text-align: left; padding: var(--s13) var(--s13) var(--s13);
  border: 0; border-radius: var(--r-tile); background: var(--control); color: var(--ink); cursor: pointer;
  box-shadow: inset 0 0 0 1px transparent; transition: background-color 0.15s, box-shadow 0.15s;
}
.plan-pick button:hover { background: var(--control-hover); }
.plan-pick button[aria-pressed="true"] { box-shadow: inset 0 0 0 1.5px var(--ink); }
.plan-pick b { font-size: 18px; font-weight: 600; }
.plan-pick span { color: var(--muted); font-size: 12.5px; }

/* Столбики графиков */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bars span { flex: 1; min-height: 2px; border-radius: 3px 3px 1px 1px; background: var(--selected); position: relative; transform-origin: bottom; animation: grow 0.7s var(--ease-out) both; animation-delay: calc(var(--i) * 25ms); }
.bars span:last-child { background: var(--accent); }
.bars span:hover::after { content: attr(data-v); position: absolute; bottom: calc(100% + 5px); left: 50%; transform: translateX(-50%); padding: 2px 6px; border-radius: 5px; background: #222226; font-size: 11px; white-space: nowrap; }
@keyframes grow { from { transform: scaleY(0); } }
.bars-axis { display: flex; justify-content: space-between; margin-top: var(--s8); color: var(--faint); font-size: 11.5px; }

/* Боковая панель пользователя в админке */
.drawer-back { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.45); animation: fade 0.2s; }
.drawer {
  position: fixed; z-index: 61; top: var(--s13); right: var(--s13); bottom: var(--s13);
  width: min(460px, calc(100vw - 26px)); overflow-y: auto;
  background: #141417; border-radius: var(--r-panel); box-shadow: 0 0 0 1px var(--hairline), 0 34px 89px rgba(0, 0, 0, 0.6);
  padding: var(--s21); animation: drawer-in 0.42s var(--ease-out);
}
@keyframes drawer-in { from { transform: translateX(34px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.drawer h2 { font-size: 20px; font-weight: 600; }
.drawer section { margin-top: var(--s21); }
.drawer section > h3 { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: var(--s8); }

/* Окно входа: пропорция формы аккаунта клиента 377×233, растёт по содержимому */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--s21); }
.auth__card {
  width: min(400px, 100%); padding: var(--s34) var(--s34) var(--s21);
  background: rgba(14, 14, 16, 0.78); backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
  border-radius: var(--r-panel); box-shadow: 0 0 0 1px var(--hairline), 0 34px 89px rgba(0, 0, 0, 0.45);
  animation: view-in 0.5s var(--ease-out);
}
.auth__logo { width: 40px; height: 38px; margin-bottom: var(--s21); }
.auth__card h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.auth__card > p { color: var(--muted); font-size: 14px; margin: var(--s5) 0 var(--s21); }
.auth__card .segmented { margin-bottom: var(--s21); }
.auth__card .segmented button { flex: 1; justify-content: center; }
.auth__foot { margin-top: var(--s21); text-align: center; font-size: 13px; color: var(--muted); }
.auth__foot a { color: var(--ink); }

/* Уведомления */
.toasts { position: fixed; z-index: 80; left: 50%; bottom: var(--s21); transform: translateX(-50%); display: grid; gap: var(--s8); justify-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: var(--s8);
  padding: var(--s8) var(--s13) var(--s8) var(--s13); border-radius: 12px;
  background: #1d1d21; box-shadow: 0 0 0 1px var(--hairline), 0 13px 34px rgba(0, 0, 0, 0.5);
  font-size: 14px; animation: toast-in 0.4s var(--spring);
}
.toast--bad { color: #ff9a9a; }
.toast.is-out { opacity: 0; transform: translateY(8px); transition: 0.3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(13px) scale(0.96); } }

.codes { display: grid; gap: 3px; max-height: 220px; overflow: auto; padding: var(--s13); border-radius: var(--r-control); background: rgba(0, 0, 0, 0.3); font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; user-select: all; }

.skeleton { height: 120px; border-radius: var(--r-tile); background: linear-gradient(90deg, var(--tile), var(--tile-hover), var(--tile)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 900px) {
  .app { flex-direction: column; padding: var(--s8); gap: var(--s8); }
  .app__rail { position: static; width: 100%; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: var(--s5); padding: var(--s8); }
  .app__brand { height: 38px; }
  .app__brand small { display: none; }
  .app__group { display: none; }
  .app__nav { display: flex; overflow-x: auto; scrollbar-width: none; order: 3; width: 100%; }
  .app__item { flex: none; height: 34px; }
  .app__item span.lbl { display: inline; }
  .app__user { margin: 0 0 0 auto; background: none; padding: 0; }
  .app__user .who { display: none; }
  .app__main { padding: var(--s13) var(--s13) var(--s21); }
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .plan-pick { grid-template-columns: 1fr; }
  .sub { flex-direction: column; align-items: flex-start; }
}

/* --- Дополнения: язык, подвал карточек --- */
.app__lang { padding: var(--s13) var(--s8) var(--s8); margin-top: auto; }
.app__lang + .app__user { margin-top: 0; }
.auth__top { display: flex; align-items: flex-start; justify-content: space-between; }
.sub__meta { margin-top: var(--s8); }
.card2__foot { margin-top: var(--s13); }
.hwid { display: flex; align-items: center; overflow: hidden; }
.link { text-decoration: underline; text-underline-offset: 3px; color: var(--ink); }
@media (max-width: 900px) { .app__lang { order: 2; margin: 0; padding: 0; } }

/* --- Коды из писем: шаги входа, подтверждение почты --- */
.auth__row { display: flex; justify-content: space-between; gap: var(--s13); margin-top: var(--s5); font-size: 13px; color: var(--muted); }
.auth__row:has(> :only-child) { justify-content: center; }
.auth__row .link { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: var(--muted); }
.auth__row .link:hover { color: var(--ink); }
.auth__card--step { animation: auth-step .32s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes auth-step { from { opacity: 0; transform: translateY(8px); } }
.input--code { letter-spacing: .45em; font-size: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.verify__form .input--code { flex: 0 0 168px; min-width: 0; }
.verify { display: flex; gap: var(--s13); align-items: flex-start; margin-bottom: var(--s13);
  border-color: color-mix(in srgb, #f5b84b 40%, transparent); transition: opacity .3s, transform .3s; }
.verify.is-done { opacity: 0; transform: scale(.98); }
.verify__icon { color: #f5b84b; flex: none; margin-top: 2px; }
.verify__body { flex: 1; min-width: 0; }
.verify__body h2 { font-size: 16px; }
.verify__body p { color: var(--muted); font-size: 14px; margin: var(--s5) 0 var(--s13); }
@media (prefers-reduced-motion: reduce) { .auth__card--step { animation: none; } }

/* --- Телефон: нижняя панель вкладок, таблицы карточками, шторка снизу --- */
.app__tabbar { display: none; }
@media (max-width: 900px) {
  .app { padding: var(--s8) var(--s8) calc(76px + env(safe-area-inset-bottom)); }
  .app__rail { flex-wrap: nowrap; padding: var(--s5) var(--s8); }
  .app__rail > .app__nav { display: none; }
  .app__brand { margin-right: auto; }
  .app__lang { order: 0; margin: 0; padding: 0; }
  .app__user { margin: 0 0 0 var(--s5); }
  .app__user .av { display: none; }
  .app__main { padding: var(--s13) var(--s13) var(--s21); }
  .app__head { min-height: 0; margin-bottom: var(--s13); }
  .app__head h1 { font-size: 22px; }
  .app__head .tools { margin-left: 0; width: 100%; min-width: 0; }
  .app__head .tools > * { max-width: 100%; }
  .card2 { padding: var(--s13) var(--s13) var(--s21); }
  .sub { align-items: center; text-align: center; }
  .sub__text .inline { justify-content: center; }
  .sub__text .inline .btn { flex: 1 1 auto; }
  .kv { gap: var(--s8) var(--s13); }

  .app__tabbar {
    position: fixed; z-index: 55; left: var(--s8); right: var(--s8); bottom: calc(var(--s8) + env(safe-area-inset-bottom));
    display: flex; gap: 2px; padding: var(--s5);
    background: rgba(16, 16, 19, 0.88); border-radius: 18px;
    backdrop-filter: blur(21px) saturate(1.4); -webkit-backdrop-filter: blur(21px) saturate(1.4);
    box-shadow: 0 0 0 1px var(--hairline), 0 13px 34px rgba(0, 0, 0, 0.5);
    overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
  }
  .app__tabbar::-webkit-scrollbar { display: none; }
  .tab {
    position: relative; flex: 1 0 64px; min-height: 52px; padding: var(--s5) var(--s3) 4px;
    display: grid; justify-items: center; align-content: center; gap: 3px;
    border: 0; border-radius: var(--r-tile); background: none; color: var(--muted);
    font-size: 11px; font-weight: 500; line-height: 1.1; text-align: center; cursor: pointer;
    transition: background-color 0.18s, color 0.18s;
    -webkit-tap-highlight-color: transparent;
  }
  .tab .ic, .tab svg { width: 20px; height: 20px; }
  .tab .lbl { white-space: nowrap; }
  .tab[aria-current="true"] { color: var(--ink); background: var(--selected); }
  .tab:active { background: var(--tile); }
  .tab .n {
    position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 600; line-height: 16px;
  }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); width: calc(100% - 32px); }
  .toast { max-width: 100%; }
}

@media (max-width: 640px) {
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  .table, .table tbody { display: block; }
  .table thead { display: none; }
  .table tr { display: grid; gap: var(--s5); padding: var(--s13) 0; border-top: 1px solid var(--hairline); }
  .table tbody tr:first-child { border-top: 0; padding-top: 0; }
  .table td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s13);
    padding: 0; border: 0; white-space: normal; text-align: right; min-width: 0; overflow-wrap: anywhere;
  }
  .table td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12px; text-align: left; }
  .table td[data-label=""]::before { display: none; }
  .table td[data-label=""] { justify-content: flex-end; }
  .table td:first-child { font-weight: 500; font-size: 15px; justify-content: flex-start; text-align: left; }
  .table td:first-child::before { display: none; }
  .table td .sub { display: inline; margin-left: var(--s5); }
  .table tr.clickable:hover td { background: none; }
  .table tr.clickable:active { background: var(--tile); }

  .drawer {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 92dvh;
    border-radius: var(--r-panel) var(--r-panel) 0 0;
    padding: var(--s21) var(--s13) calc(var(--s21) + env(safe-area-inset-bottom));
    animation: sheet-in 0.42s var(--ease-out);
  }
  .drawer .inline .input { min-width: 0; }
  .auth { padding: var(--s13); align-items: start; padding-top: max(var(--s21), env(safe-area-inset-top)); }
  .auth__card { padding: var(--s21) var(--s21) var(--s13); }
  .grid--stats { gap: var(--s8); }
  .stat b { font-size: 24px; }
}
@keyframes sheet-in { from { transform: translateY(55px); opacity: 0; } }

/* Поля 16px на телефоне: иначе iOS увеличивает страницу при фокусе. Зоны нажатия от 40px. */
@media (pointer: coarse), (max-width: 640px) {
  .input, .input--sm { font-size: 16px; }
  .input--sm { height: 40px; }
  .icon-btn { width: 40px; height: 40px; }
  .auth__row .link { min-height: 40px; }
  .link { display: inline-flex; align-items: center; min-height: 32px; }
}
.input.search { width: 220px; }
@media (max-width: 900px) { .input.search { width: 100%; } }
