:root {
  --bg-top: #162240;
  --bg-bottom: #080b12;
  --panel: rgba(21, 27, 43, 0.9);
  --border: #34415f;
  --accent: #8cc8ff;
  --accent-strong: #a9d6ff;
  --text: #f2f5fb;
  --muted: #abb8d1;
  --error: #ffb4a8;
  --ok: #9be3b4;
  --warn: #ffd98c;
  --field: #0f1524;
  --dark: #0d1322;
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; background: var(--bg-bottom); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%) no-repeat;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

img { display: block; }

h1, h2, h3, p { margin: 0; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(140, 200, 255, 0.35);
}

.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;
}

/* ---------- Layout ---------- */
.shell { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 20px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand img { width: 44px; height: 44px; flex: none; }
.brand h1 { font-size: 1.2rem; font-weight: 650; letter-spacing: 0.01em; }
.brand small { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 400; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.stack { display: grid; gap: 16px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: background-color .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { border-color: var(--accent); background: rgba(140, 200, 255, 0.08); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--dark); }
.btn.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 0.9rem; }
.btn-link { border-color: transparent; color: var(--accent); padding: 0 10px; }

.btn.is-busy { position: relative; }
.btn.is-busy::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 0.92rem; color: var(--muted); }
.input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  font: inherit; color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.input::placeholder { color: #6f7d99; }
.input:focus-visible { border-color: var(--accent); }
.input[aria-invalid="true"] { border-color: var(--error); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 84px; }
.input-wrap .toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 36px; padding: 0 12px; font-size: 0.85rem;
}
.field-error { color: var(--error); font-size: 0.88rem; line-height: 1.3; min-height: 1.3em; }
.login-card .field-error { display: none; }

.form-error {
  color: var(--error);
  background: rgba(255, 180, 168, 0.08);
  border: 1px solid rgba(255, 180, 168, 0.4);
  border-radius: 12px; padding: 10px 14px; font-size: 0.92rem;
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login-card { width: 100%; max-width: 400px; display: grid; gap: 18px; padding: 28px 24px; }
.login-head { display: grid; justify-items: center; gap: 10px; text-align: center; }
.login-head img { width: 72px; height: 72px; }
.login-head h1 { font-size: 1.4rem; font-weight: 650; }
.login-head p { color: var(--muted); font-size: 0.92rem; }
.login-card form { display: grid; gap: 16px; }
.login-card .btn-primary { width: 100%; min-height: 48px; margin-top: 4px; }

/* ---------- Admin cards ---------- */
.card { display: grid; gap: 8px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head h2 { font-size: 1.1rem; font-weight: 650; }
.card-head p { color: var(--muted); font-size: 0.9rem; }
.badge-changed {
  flex: none; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.03em;
  color: var(--warn); border: 1px solid rgba(255, 217, 140, 0.5);
  background: rgba(255, 217, 140, 0.1);
  padding: 3px 10px; border-radius: 999px;
}
.card.is-changed { border-color: rgba(140, 200, 255, 0.6); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.savebar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; margin-top: 4px;
  background: rgba(13, 19, 34, 0.94);
  border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(8px);
}
.savebar p { color: var(--muted); font-size: 0.9rem; }
.savebar .btn-primary { min-width: 140px; }

/* ---------- Info panel ---------- */
.info h2 { font-size: 1.1rem; font-weight: 650; }
.info .sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 14px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.meta div { background: var(--field); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; }
.meta dt { color: var(--muted); font-size: 0.8rem; }
.meta dd { margin: 2px 0 0; font-weight: 600; }
.meta { margin-left: 0; }
details summary {
  cursor: pointer; color: var(--accent); font-weight: 600; padding: 8px 0; border-radius: 8px;
}
pre.json {
  margin: 8px 0 0; padding: 14px; overflow: auto; max-height: 280px;
  background: var(--field); border: 1px solid var(--border); border-radius: 12px;
  color: var(--muted); font-size: 0.85rem; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- States ---------- */
.state { text-align: center; display: grid; justify-items: center; gap: 14px; padding: 36px 20px; }
.state p { color: var(--muted); }
.state.error p { color: var(--error); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  z-index: 20; max-width: calc(100% - 32px);
  padding: 12px 20px; border-radius: 14px;
  background: #12301f; color: var(--ok); border: 1px solid rgba(155, 227, 180, 0.5);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); font-weight: 600;
}
.toast.is-error { background: #3a1a17; color: var(--error); border-color: rgba(255, 180, 168, 0.5); }

@media (max-width: 480px) {
  .shell { padding: 12px 12px 40px; }
  .panel { padding: 16px; }
  .brand h1 { font-size: 1.05rem; }
  .savebar { flex-direction: column; align-items: stretch; }
  .savebar .btn-primary { width: 100%; min-height: 48px; }
  .meta { grid-template-columns: 1fr; }
  .copy-row { flex-wrap: wrap; }
  .copy-row .input { flex: 1 1 100%; }
  .copy-row .btn { flex: 1; }
  .card-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 2s !important; transition: none !important; }
}

main > * + * { margin-top: 16px; }
