/* Минимальная аккуратная стилизация без зависимостей */

:root {
  --bg: #0b0d12;
  --card: #121624;
  --text: #e7eaf3;
  --muted: #aab2c8;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #6ea8fe;
  --danger: #ff6b6b;
  --ok: #41d17b;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  background: radial-gradient(1200px 500px at 20% -10%, rgba(110, 168, 254, 0.18), transparent 60%),
    radial-gradient(900px 420px at 80% 0%, rgba(255, 107, 107, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}

.topbar {
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  background: rgba(11, 13, 18, 0.7);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
}

.brand__link {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.nav { display: flex; gap: 14px; row-gap: 8px; align-items: center; flex-wrap: wrap; }
.nav__link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 10px;
}
.nav__link:hover {
  background: rgba(110, 168, 254, 0.10);
}
/* Делай выделение активного пункта максимально заметным */
.nav__link.nav__link--active {
  color: var(--text);
  background: rgba(110, 168, 254, 0.16);
  border: 1px solid rgba(110, 168, 254, 0.45);
}
.nav__user { color: var(--muted); font-size: 14px; }

.page-main {
  flex: 1 0 auto;
  width: 100%;
}

.footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  color: var(--muted);
  background: rgba(11, 13, 18, 0.62);
}

.footer .container {
  padding-top: 14px;
  padding-bottom: 14px;
}

.footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.footer__nav {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

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

.footer__link--button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.footer__link--button:hover {
  color: var(--text);
}

@media (max-width: 720px) {
  .footer__inner {
    flex-direction: column;
    align-items: flex-start;
  }
}

.card {
  background: rgba(18, 22, 36, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.card--compact { padding: 14px; }
.tesla-card { margin-bottom: 16px; }
.tesla-card { min-height: 170px; }
.tesla-card__body { min-height: 120px; }

.howto-card { margin-bottom: 16px; }
.howto {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.howto__item {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  padding: 12px;
}
@media (min-width: 980px) {
  .howto { grid-template-columns: 1fr 1fr; }
  .howto__item--full { grid-column: 1 / -1; }
}

.auth-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

@media (min-width: 980px) {
  .auth-layout {
    grid-template-columns: 1fr auto;
    gap: 18px;
  }
  .auth-card { justify-self: end; }
}

.auth-card { width: min(360px, 100%); }

.list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
}
.list li { margin: 6px 0; }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: stretch;
  grid-auto-rows: 1fr;
}
@media (min-width: 980px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

/* Чтобы "плашки" в колонках были одной высоты */
.grid > section,
.grid > .card {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.grid > section.card,
.grid > .card {
  min-height: 260px;
}

.h1 { margin: 0 0 10px; font-size: 22px; }
.h2 { margin: 0 0 10px; font-size: 18px; color: var(--text); }
.h3 { margin: 0 0 8px; font-size: 16px; color: var(--text); }
.muted { color: var(--muted); margin: 0 0 12px; }
.hint { color: var(--muted); margin: 8px 0 0; font-size: 13px; line-height: 1.35; }

.label { display: block; margin: 10px 0 6px; color: var(--muted); font-size: 14px; }
.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
}
.input:focus { border-color: rgba(110, 168, 254, 0.6); }
.input--invalid { border-color: rgba(255, 107, 107, 0.65); }
.input--textarea {
  min-height: 132px;
  resize: vertical;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 0;
}

.check__box {
  margin-top: 2px;
}

.check__text {
  color: var(--muted);
  line-height: 1.35;
}

/* Native select dropdown keeps light popup in some browsers, so force readable option colors. */
select.input option {
  color: #0b1220;
  background: #f3f6ff;
}

select.input option:checked {
  color: #0b1220;
  background: #cfe0ff;
}

.row { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.btn {
  border: 1px solid rgba(110, 168, 254, 0.6);
  background: rgba(110, 168, 254, 0.14);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn--sm { padding: 8px 12px; border-radius: 10px; }
.btn:hover { background: rgba(110, 168, 254, 0.20); }
.btn--danger {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.55);
  background: rgba(255, 107, 107, 0.06);
}
.btn--danger:hover {
  background: rgba(255, 107, 107, 0.10);
}

.card--compact .label { margin: 8px 0 6px; font-size: 13px; }
.card--compact .input { padding: 9px 11px; border-radius: 10px; }
.card--compact .row { margin-top: 12px; }

.alert {
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  margin: 10px 0 14px;
}
.alert--info { border-color: rgba(110, 168, 254, 0.55); background: rgba(110, 168, 254, 0.12); }
.alert--error { border-color: rgba(255, 107, 107, 0.55); background: rgba(255, 107, 107, 0.10); }

.metrics-loading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metrics-loading__spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.dl { margin: 0; }
.dl__row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
}
.dl__row dt { color: var(--muted); }
.dl__row dd { margin: 0; }

.table {
  display: grid;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  /* резервируем место под scrollbar, чтобы высота не "плавала" */
  scrollbar-gutter: stable;
}
.table__row {
  display: grid;
  grid-template-columns: 220px 90px 1fr 1fr;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  align-items: center;
  min-width: 760px;
}
.table__row--head {
  font-weight: 800;
  background: rgba(255,255,255,0.06);
}
.table__row--audit {
  grid-template-columns: 220px 240px 170px 120px 1fr;
  min-width: 980px;
}

code {
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 2px 6px;
  border-radius: 8px;
  color: #dbe5ff;
}

.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 9999;
  max-width: min(420px, calc(100vw - 32px));
}

.toasts--dialog {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: min(420px, calc(100% - 24px));
}

.toast {
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: rgba(18, 22, 36, 0.92);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast--show {
  opacity: 1;
  transform: translateY(0);
}

.toast--hide {
  opacity: 0;
  transform: translateY(8px);
}

.toast--success { border-color: rgba(110, 168, 254, 0.45); }
.toast--error { border-color: rgba(255, 107, 107, 0.55); }

.tesla-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.tesla-card__actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tesla-card__body { margin-top: 12px; }

.tesla-split {
  display: grid;
  grid-template-columns: minmax(0, 860px) 240px;
  gap: 16px;
  align-items: start;
  justify-content: start;
}
.tesla-split__main { min-width: 0; }

.actions-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  justify-self: start;
  align-self: stretch;
  width: 240px;
  position: sticky;
  top: 88px;
}
.actions-card__title {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.actions-card form { margin: 0; }
.actions-card .btn {
  width: 100%;
  text-align: center;
  justify-content: center;
}

/* Поведение 1-в-1 как у блока "Устройства" */
@media (max-width: 720px) {
  .tesla-split { grid-template-columns: 1fr; }
  .actions-card {
    width: 100%;
    justify-self: stretch;
    align-self: stretch;
    position: static;
  }
}

.tesla-cars-scroll {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  scrollbar-gutter: stable;
  scroll-snap-type: x mandatory;
}

.tesla-car-card {
  flex: 0 0 auto;
  /* Карточки ещё компактнее и ближе к "по контенту" */
  width: fit-content;
  min-width: min(360px, 78vw);
  max-width: 420px;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  padding: 12px;
}

@media (min-width: 980px) {
  .tesla-car-card { min-width: 340px; max-width: 400px; }
}

/* VIN длинный — даём перенос, чтобы карточка могла быть уже */
.tesla-car__line code {
  word-break: break-all;
}

.tesla-car-card .tesla-car__img {
  background: rgba(0,0,0,0.12);
}

.tesla-car {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
}
.tesla-car__img {
  width: 120px;
  height: 70px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  display: grid;
  place-items: center;
}
.tesla-car__silhouette {
  width: 92px;
  height: 34px;
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(110,168,254,0.25), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,255,255,0.08);
}
.tesla-car__name { font-weight: 800; margin-bottom: 6px; }
.tesla-car__line { color: var(--muted); margin: 4px 0; }

.tesla-card__buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.devices-scroll {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  scrollbar-gutter: stable;
  scroll-snap-type: x mandatory;
}

.device-card {
  flex: 0 0 auto;
  /* На узких экранах карточка должна влезать во viewport */
  width: min(460px, 92vw);
  max-width: 92vw;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 12px;
  align-items: center;
}

.device-card__meta { min-width: 0; }
.device-card__line { overflow-wrap: anywhere; }
.device-card__line code { word-break: break-all; }

.device-card__title {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.device-card__line { color: var(--muted); margin: 4px 0; }

.device-card__media {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.12);
  overflow: hidden;
  text-decoration: none;
}
.device-card__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.device-card__bind {
  margin-top: 2px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.metrics-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  padding: 10px 12px;
}

.metrics-card__label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metrics-card__value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}

.metrics-card__meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

.metrics-disclosure {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  padding: 10px 12px;
}

.metrics-disclosure__summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  user-select: none;
}

.metrics-disclosure__content {
  margin-top: 8px;
}

.commands-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 260px));
  gap: 10px;
  justify-content: start;
}

.commands-groups {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.commands-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.commands-group__title {
  margin: 0 0 10px;
}

.commands-grid form {
  margin: 0;
}

.commands-grid .btn {
  width: 100%;
}

@media (max-width: 620px) {
  .commands-grid {
    grid-template-columns: 1fr;
  }
}

/* Dialog */
.portal-dialog {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(18, 22, 36, 0.96);
  color: var(--text);
  padding: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.portal-dialog::backdrop {
  background: rgba(0,0,0,0.55);
}
.portal-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.portal-dialog__title { font-weight: 800; }
.portal-dialog__body { margin-top: 4px; }

/* 2FA */
.sep {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 16px 0;
}

.twofa-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.twofa-setup {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
  margin-top: 12px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.twofa-qr__img {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.codebox {
  display: inline-block;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  user-select: all;
}

.codes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.codes li code {
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

@media (max-width: 720px) {
  .twofa-setup {
    grid-template-columns: 1fr;
  }
  .grid2 {
    grid-template-columns: 1fr;
  }
  .twofa-qr__img {
    width: min(220px, 70vw);
    height: auto;
  }
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.badge--ok { border-color: rgba(110,168,254,0.45); color: var(--text); }

/* маленькая зелёная плашка с иконкой */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  min-width: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  font-weight: 800;
  vertical-align: middle;
}
.pill--ok {
  border-color: rgba(65, 209, 123, 0.45);
  background: rgba(65, 209, 123, 0.14);
  color: var(--ok);
}
.pill--danger {
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}
.device-card__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
}
.device-card__actions form { margin: 0; }
.device-card__actions .btn { flex: 1 1 160px; }

.devices-split {
  display: grid;
  grid-template-columns: minmax(0, 860px) 240px;
  gap: 16px;
  align-items: start;
  justify-content: start;
  margin-top: 12px;
}
.devices-split__main { min-width: 0; }

@media (max-width: 720px) {
  .devices-split { grid-template-columns: 1fr; }
}
.pill__icon {
  width: 12px;
  height: 12px;
  display: block;
}

@media (max-width: 560px) {
  .dl__row { grid-template-columns: 1fr; gap: 6px; }
  .tesla-car { grid-template-columns: 1fr; }
  .tesla-car__img { width: 100%; height: 80px; }
}
