/* Kluchiki: тёмная и светлая темы по системной настройке.
   Палитра, размеры и отступы — docs/ui.md §1–4. */

:root {
  color-scheme: dark light;
  --bg: #101216;
  --surface: #191d24;
  --text: #e8eaed;
  --muted: #a9b0bb;
  --accent: #7fb0ff;
  --danger: #ff9a9a;
  --border: #616e85;
  --focus: #ffd166;
  --on-accent: var(--bg);
  --on-danger: var(--bg);
  --backdrop: rgba(0, 0, 0, 0.55);
  --font-text: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #14181f;
    --muted: #5b6472;
    --accent: #1b5bb5;
    --danger: #b3261e;
    --border: #8b95a5;
    --focus: #7a4b00;
    --on-accent: var(--surface);
    --on-danger: var(--surface);
    --backdrop: rgba(16, 24, 40, 0.45);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 var(--font-text);
}

button,
input,
textarea {
  font-family: inherit;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.page {
  width: 100%;
  max-width: 728px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

@media (min-width: 480px) {
  .page {
    max-width: 728px;
    padding: 24px 24px 48px;
  }
}

@media (min-width: 1280px) {
  .page {
    max-width: 744px;
    padding: 32px 32px 48px;
  }
}

body.has-toast .page {
  padding-bottom: 112px;
}

h1 {
  margin: 0;
  font: 700 22px/1.25 var(--font-text);
  overflow-wrap: anywhere;
}

h1:focus {
  outline-offset: 2px;
}

h2,
.h2 {
  margin: 0 0 12px;
  font: 600 18px/1.3 var(--font-text);
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  margin-bottom: 16px;
}

.screen-header h1 {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-spacer {
  width: 44px;
  min-width: 44px;
}

.subtitle {
  margin: 0 0 16px;
  font: 400 14px/1.45 var(--font-text);
  color: var(--muted);
}

.notice {
  margin: 0 0 12px;
  font: 400 14px/1.45 var(--font-text);
  color: var(--muted);
}

.text {
  margin: 0 0 16px;
  font: 400 16px/1.55 var(--font-text);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: 600 16px/1.2 var(--font-text);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: var(--on-danger);
}

.btn-danger-outline {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}

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

.btn-text {
  background: transparent;
  border-color: transparent;
  padding: 0 8px;
  color: var(--accent);
}

.btn:disabled,
.btn[aria-disabled="true"],
.btn-text:disabled {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
  cursor: default;
}

.btn-danger-text:disabled {
  background: transparent;
  border-color: transparent;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: 600 20px/1 var(--font-text);
  cursor: pointer;
}

summary.icon-btn {
  list-style: none;
}

summary.icon-btn::-webkit-details-marker {
  display: none;
}

.menu {
  position: relative;
}

.menu-list {
  position: absolute;
  right: 0;
  top: 52px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 240px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.menu-item {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 400 16px/1.2 var(--font-text);
  text-align: left;
  cursor: pointer;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin: 16px 0;
}

.actions.stacked {
  flex-direction: column;
}

@media (min-width: 480px) {
  .actions {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .actions .btn {
    min-width: 160px;
  }
}

.form {
  margin: 16px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.label {
  font: 600 13px/1.3 var(--font-text);
  color: var(--muted);
}

.input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: 400 16px/1.3 var(--font-text);
}

.input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.textarea {
  height: 150px;
  padding: 10px 12px;
  line-height: 1.45;
  resize: vertical;
}

.inline-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 480px) {
  .inline-field {
    flex-direction: row;
    align-items: center;
  }

  .inline-field .input {
    flex: 1;
  }
}

.counter {
  margin: 0;
  font: 600 14px/1.3 var(--font-text);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.counter.is-short {
  color: var(--danger);
}

.error {
  margin: 0;
  font: 400 14px/1.45 var(--font-text);
  color: var(--danger);
}

.hint {
  margin: 4px 0 0;
  font: 400 14px/1.45 var(--font-text);
  color: var(--muted);
}

.hint-sm {
  margin: 4px 0 24px;
  font-size: 13px;
}

.file-pick {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}

.file-pick:focus-within .btn {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.checkbox {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 8px 0;
  font: 400 16px/1.4 var(--font-text);
  cursor: pointer;
}

.checkbox-input {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  opacity: 0;
  cursor: pointer;
}

.checkbox-box {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  border: 2px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: transparent;
  font: 700 13px/1 var(--font-text);
}

.checkbox-input:checked + .checkbox-box {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.checkbox-input:focus + .checkbox-box {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.checkbox-input:disabled,
.checkbox-input:disabled + .checkbox-box {
  cursor: default;
  opacity: 0.6;
}

.checkbox-stack {
  display: flex;
  flex-direction: column;
}

.search-field {
  margin-bottom: 8px;
}

.search-input {
  width: 100%;
}

.list {
  border-top: 1px solid var(--border);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: 600 16px/1.3 var(--font-text);
  text-align: left;
  cursor: pointer;
}

.row-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  flex: none;
  color: var(--muted);
  font: 400 16px/1 var(--font-text);
}

.empty {
  padding: 32px 0;
}

.empty .text {
  margin-bottom: 16px;
}

.banner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
}

.banner-danger {
  border-color: var(--danger);
}

.banner-text {
  margin: 0;
  font: 400 16px/1.55 var(--font-text);
  overflow-wrap: anywhere;
}

.banner-slot:empty {
  display: none;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
}

.value-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.value-label {
  font: 600 13px/1.3 var(--font-text);
  color: var(--muted);
}

.value-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.value {
  flex: 1;
  min-width: 0;
  font: 400 16px/1.45 var(--font-text);
  overflow-wrap: anywhere;
}

.value.mono {
  font-family: var(--font-mono);
}

.value-notes {
  white-space: pre-wrap;
}

@media (min-width: 768px) {
  .value-row {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  .value-label {
    padding-top: 12px;
  }
}

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

.code-cell {
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font: 500 20px/1.4 var(--font-mono);
  letter-spacing: 0.02em;
  text-align: center;
  overflow-wrap: anywhere;
}

@media (max-width: 359px) {
  .code-cell {
    font-size: 18px;
  }
}

@media (min-width: 768px) {
  .code {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

.gen-result {
  min-height: 60px;
  padding: 16px;
  border-radius: 10px;
  background: var(--surface);
  font: 500 20px/1.4 var(--font-mono);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.gen-block .counter {
  margin-top: 4px;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
}

.length-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.length-input {
  width: 96px;
  text-align: center;
}

.section {
  margin-bottom: 48px;
}

.slot-list {
  border-top: 1px solid var(--border);
}

.slot-row,
.slot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.slot-row {
  cursor: pointer;
}

.slot-row:disabled {
  color: var(--muted);
  cursor: default;
}

.slot-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.slot-label {
  font: 600 16px/1.3 var(--font-text);
  overflow-wrap: anywhere;
}

.slot-sub,
.slot-id {
  font: 400 14px/1.45 var(--font-text);
  color: var(--muted);
}

.slot-id {
  font-size: 13px;
  font-family: var(--font-mono);
}

.slot-panel {
  padding: 0 0 16px;
}

.slot-panel[hidden] {
  display: none;
}

.inline-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

@media (min-width: 480px) {
  .inline-form {
    flex-direction: row;
    align-items: flex-end;
  }

  .inline-form .field {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
  }
}

.slot-item {
  flex-direction: column;
  align-items: stretch;
}

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

.slot-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.slot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (min-width: 480px) {
  .slot-item {
    flex-direction: row;
    align-items: center;
  }

  .slot-head {
    flex: 1;
  }
}

.status-pill {
  flex: none;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: 400 13px/22px var(--font-text);
  white-space: nowrap;
}

.status-pill.is-lost,
.status-pill.is-unavailable {
  color: var(--danger);
}

.danger-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--danger);
  border-radius: 14px;
}

.danger-panel .text:last-child {
  margin-bottom: 0;
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: var(--backdrop);
}

.dialog-title {
  margin: 0 0 8px;
  font: 600 18px/1.3 var(--font-text);
}

.dialog-text {
  margin: 0;
  font: 400 16px/1.55 var(--font-text);
}

.dialog-form {
  margin: 0;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

@media (min-width: 480px) {
  .dialog-actions {
    flex-direction: row;
    justify-content: flex-end;
  }
}

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 16px;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}

.toast {
  width: 100%;
  max-width: 420px;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: 400 14px/1.45 var(--font-text);
  overflow-wrap: anywhere;
  pointer-events: auto;
}

.noscript {
  max-width: 680px;
  margin: 48px auto;
  padding: 0 16px;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}
