/* Тема: светлая или тёмная по data-theme на <html>. Его ставит theme.js до отрисовки:
   выбор пользователя, а пока выбора нет — тёмная. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --surface-hover: #eceff3;
  --border: #e4e7ec;
  --border-strong: #d4d9e1;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #eef0fe;
  --danger: #dc2626;
  --danger-soft: #fdeeee;
  --toast-bg: #111827;
  --toast-text: #f9fafb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-raised: 0 8px 28px rgba(16, 24, 40, 0.14);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d0f13;
  --surface: #15181e;
  --surface-muted: #1c2028;
  --surface-hover: #222731;
  --border: #262b35;
  --border-strong: #343a46;
  --text: #e8eaee;
  --muted: #8d95a3;
  --accent: #8b87ff;
  --accent-hover: #a29fff;
  --accent-text: #0d0f13;
  --accent-soft: #23234a;
  --danger: #f87171;
  --danger-soft: #3a1c1f;
  --toast-bg: #e8eaee;
  --toast-text: #0d0f13;
  --shadow: none;
  --shadow-raised: 0 8px 28px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

:root {
  --radius: 14px;
  --radius-small: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s, color 0.2s;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

p {
  margin: 0;
}

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

.small-text {
  font-size: 13px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Иконки */

.icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-fill {
  fill: currentColor;
  stroke: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-mark.large {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.brand-mark.large svg {
  width: 26px;
  height: 26px;
}

/* Кнопки */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled) {
  transform: scale(0.97);
}

.button:disabled,
.icon-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.button.primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
}

.button.ghost:hover {
  background: var(--surface-hover);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.button.block {
  width: 100%;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.05s;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button.small {
  width: 32px;
  height: 32px;
}

/* В шапке кнопки одной высоты с обычными кнопками и с теми же 20px иконками, что у боковых. */
.topbar .icon-button {
  width: 38px;
  height: 38px;
  color: var(--text);
}

.topbar .button.small {
  min-height: 38px;
  font-size: 14px;
}

.topbar .icon {
  width: 20px;
  height: 20px;
}

.icon-button.spinning .icon {
  animation: spin 0.8s linear infinite;
}

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

.theme-button .icon {
  display: none;
}

.theme-button[data-choice="light"] .icon-light,
.theme-button[data-choice="dark"] .icon-dark {
  display: block;
}

button:focus-visible,
input:focus-visible,
.field-value:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Вход */

.login {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 16px;
}

.login-card {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-heading {
  display: grid;
  gap: 4px;
}

.input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--accent);
}

/* Каркас */


/* Уведомления */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--radius-small);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 14px;
  box-shadow: var(--shadow-raised);
  transform: translateX(-50%);
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.copy-buffer {
  position: fixed;
  top: -1000px;
  left: -1000px;
  opacity: 0;
}


/* Каркас: одна колонка шириной до 760px */

.app {
  display: grid;
  grid-template-columns: minmax(16px, 1fr) minmax(0, 728px) minmax(16px, 1fr);
  align-content: start;
  row-gap: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px 0 24px;
}

.app > * {
  grid-column: 2;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
}

.topbar .icon-button {
  width: 38px;
  height: 38px;
  color: var(--text);
}

.topbar .icon {
  width: 20px;
  height: 20px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  /* На телефоне вкладки уходят во вторую строку, а кнопки остаются справа. */
  margin-left: auto;
}

.user-name {
  min-width: 0;
  margin-right: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Вкладки протоколов: подложка плавно переезжает под выбранную, как у вкладок почты. */
.proto-tabs {
  position: relative;
  display: inline-grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  margin-left: 6px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.proto-tabs-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 2);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 0 0 1px var(--border);
  transition: transform 0.24s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.proto-tabs[data-count="1"] .proto-tabs-indicator {
  width: calc(100% - 6px);
}

.proto-tabs[data-active="amnezia"]:not([data-count="1"]) .proto-tabs-indicator {
  transform: translateX(100%);
}

:root[data-theme="dark"] .proto-tabs-indicator,
:root[data-theme="dark"] .segment[aria-pressed="true"] {
  background: var(--surface-hover);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.proto-tab {
  position: relative;
  min-width: 92px;
  height: 32px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.18s, transform 0.05s;
}

.proto-tab:hover {
  color: var(--text);
}

.proto-tab:active {
  transform: scale(0.97);
}

.proto-tab[aria-selected="true"] {
  color: var(--accent);
  cursor: default;
}

.panel-enter {
  animation: panel-enter 0.22s ease-out;
}

@keyframes panel-enter {
  from {
    opacity: 0.35;
    transform: translateY(6px);
  }
}

/* Карточки протоколов */

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 44px 20px;
  text-align: center;
}

.empty-state p {
  max-width: 440px;
}

.section {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.section-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.label {
  /* Отступ равен внутреннему отступу значения: подпись начинается над первым символом. */
  padding-left: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.field-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 7px 10px;
  line-height: 24px;
  border-radius: var(--radius-small);
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.field-value.changed {
  animation: field-changed 1.4s ease-out;
}

@keyframes field-changed {
  from {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
    color: var(--accent);
  }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

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

.meta {
  padding-left: 10px;
  font-size: 13px;
}

/* Выбор сервера и устройства */

.pickers {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.segment {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.05s;
}

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

.segment:active {
  transform: scale(0.97);
}

.segment[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 0 0 1px var(--border);
  color: var(--accent);
}

/* Точка: на этом сервере или устройстве ключ уже выдан. */
.segment.has-key::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.key-box {
  display: grid;
  gap: 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.section-body {
  display: grid;
  gap: 14px;
}

.key-empty {
  display: grid;
  justify-items: start;
  gap: 12px;
}

.qr-box {
  justify-self: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.qr-box img {
  display: block;
  width: 220px;
  height: 220px;
  image-rendering: pixelated;
}

.hint {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 14px 16px 14px 34px;
  border-radius: var(--radius-small);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 14px;
}

.hint strong {
  color: var(--text);
  font-weight: 600;
}

.loading {
  display: grid;
  place-items: center;
  min-height: 120px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.inline-error {
  display: grid;
  justify-items: start;
  gap: 10px;
}

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

/* На телефоне вкладки уходят во вторую строку шапки и занимают её целиком. */
@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  .brand {
    order: 3;
    flex-basis: 100%;
  }

  .brand .brand-mark {
    display: none;
  }

  .proto-tabs {
    width: 100%;
    margin-left: 0;
  }

  .section {
    padding: 16px;
  }

  .pickers,
  .picker,
  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
    justify-content: center;
    padding: 0 8px;
  }
}

@media (max-width: 480px) {
  .app {
    grid-template-columns: minmax(12px, 1fr) minmax(0, 728px) minmax(12px, 1fr);
    padding: 8px 0 16px;
  }

  .actions .button {
    flex: 1 1 auto;
  }
}
