:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --paper: #f1f5f9;
  --card: #ffffff;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #ffedd5;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --header: #0f172a;
  --header-text: #f8fafc;
  --nav-link: #fdba74;
  --focus: #fb923c;
  --touch: 44px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Nirmala UI", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-hover);
}

/* Header */
.top {
  background: var(--header);
  color: var(--header-text);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}

.top-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.nav-toggle {
  display: none;
  font: inherit;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-text);
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 0 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle[aria-expanded="true"] {
  background: rgba(251, 146, 60, 0.25);
  border-color: rgba(251, 146, 60, 0.45);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
}

.top nav a {
  color: var(--nav-link);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
}

.top nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fed7aa;
}

.top form {
  margin: 0;
}

.top button.ghost {
  background: rgba(255, 255, 255, 0.12);
  color: var(--header-text);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.top button.ghost:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Main */
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.75fr);
  gap: 20px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.sticky {
  position: sticky;
  top: 72px;
}

h1 {
  font-size: clamp(1.35rem, 4vw, 1.55rem);
  margin: 0 0 8px;
  line-height: 1.25;
}

h2 {
  font-size: 1.08rem;
  margin: 0 0 12px;
}

p.lead {
  color: var(--muted);
  margin-top: 0;
  font-size: 0.95rem;
}

label {
  display: block;
  font-weight: 650;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 8px;
}

.field {
  margin-bottom: 18px;
}

input:not([type]),
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="email"],
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.25);
}

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

textarea.code {
  min-height: min(420px, 55vh);
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

button,
.button {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: 0;
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.1s;
}

button:hover,
.button:hover {
  background: var(--accent-hover);
}

button:active,
.button:active {
  transform: scale(0.98);
}

button.ghost,
.button.ghost {
  background: #e2e8f0;
  color: var(--ink);
}

button.ghost:hover,
.button.ghost:hover {
  background: #cbd5e1;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #991b1b;
}

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

.row-actions form {
  display: inline-flex;
  margin: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar .button {
  flex-shrink: 0;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f8fafc;
}

.errors {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid #fecaca;
}

.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
}

details {
  margin-top: 6px;
}

summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 0;
}

details pre,
.preview pre,
#json-preview {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.45;
  max-height: min(70vh, 520px);
}

.pair,
.triple {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
  align-items: start;
}

.pair {
  grid-template-columns: 1fr 1fr auto;
}

.triple {
  grid-template-columns: 1fr 140px 1fr auto;
}

.pair button,
.triple button {
  min-height: 42px;
}

.login {
  max-width: 420px;
  margin: 6vh auto 0;
}

.presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.presets button {
  background: var(--accent-soft);
  color: #9a3412;
  min-height: 40px;
  font-size: 0.88rem;
  padding: 0 12px;
}

/* Mobile */
@media (max-width: 768px) {
  .top-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .top-bar {
    width: 100%;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .top-actions {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 0;
    padding: 10px 0 2px;
    border-top: 0;
  }

  .top-actions.is-open {
    display: flex;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .top nav {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 4px;
  }

  .top nav a {
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    text-align: center;
  }

  .top form {
    width: 100%;
  }

  .top form button {
    width: 100%;
    min-height: var(--touch);
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .sticky {
    position: static;
  }

  .pair,
  .triple {
    grid-template-columns: 1fr;
  }

  .pair button[data-remove],
  .triple button[data-remove] {
    width: 100%;
  }

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

  .toolbar .button {
    width: 100%;
    text-align: center;
  }

  table.data-table {
    min-width: 0;
  }

  table.data-table thead {
    display: none;
  }

  table.data-table tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    padding: 4px 0;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }

  table.data-table tbody tr:hover {
    background: #fff;
  }

  table.data-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    border-bottom: 1px solid #f1f5f9;
    padding: 10px 14px;
  }

  table.data-table td:last-child {
    border-bottom: 0;
  }

  table.data-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    flex: 0 0 38%;
    max-width: 42%;
  }

  table.data-table td.row-actions-cell {
    display: block;
    padding-top: 12px;
  }

  table.data-table td.row-actions-cell::before {
    display: block;
    margin-bottom: 10px;
    max-width: none;
  }

  table.data-table td.row-actions-cell .row-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  table.data-table td.row-actions-cell .row-actions > a.button {
    width: 100%;
    grid-column: 1 / -1;
  }

  table.data-table td.row-actions-cell .row-actions > form {
    width: 100%;
    min-width: 0;
    margin: 0;
  }

  table.data-table td.row-actions-cell .row-actions > form:has(button.danger) {
    grid-column: 1 / -1;
  }

  table.data-table td.row-actions-cell .row-actions form button {
    width: 100%;
    min-height: 42px;
    padding: 0 10px;
    font-size: 0.9rem;
  }
}

@media (min-width: 769px) {
  .nav-toggle {
    display: none !important;
  }

  .top-actions {
    display: flex !important;
  }
}

@media (max-width: 900px) and (min-width: 769px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .sticky {
    position: static;
  }
}
