:root {
  --ink: #081326;
  --panel: #10213a;
  --paper: #f3f7fc;
  --surface: #ffffff;
  --surface-soft: #faf9f5;
  --muted: #596360;
  --accent: #2468f2;
  --accent-dark: #174fbf;
  --line: rgba(8, 19, 38, 0.15);
  --line-strong: rgba(8, 19, 38, 0.28);
  --shadow: 0 18px 50px rgba(8, 19, 38, 0.08);
  font-family: Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  line-height: 1.45;
}

button,
input,
textarea,
select { font: inherit; }

button,
label.upload-button { -webkit-tap-highlight-color: transparent; }

a { color: inherit; }

[hidden] { display: none !important; }

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 18px;
  background: var(--ink);
  color: #fff;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 34px;
  font-size: 17px;
  font-weight: 700;
}

.mark {
  width: 42px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  font-size: 11px;
}

.side nav { display: grid; gap: 4px; }

.side nav a {
  padding: 11px 12px;
  border-radius: 7px;
  text-decoration: none;
  font-size: 14px;
}

.side nav a:hover,
.side nav a.active { background: rgba(255, 255, 255, 0.12); }

.side .exit {
  display: block;
  margin-top: 30px;
  color: #ffaaa5;
  font-size: 13px;
}

.main {
  width: min(100%, 1260px);
  padding: 48px clamp(24px, 5vw, 72px) 72px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

h1 {
  margin: 0 0 9px;
  font-size: clamp(30px, 4vw, 38px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  color: var(--muted);
}

.card {
  margin: 0 0 28px;
  padding: clamp(24px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.notice {
  padding: 14px 17px;
  margin: 0 0 24px;
  border-radius: 8px;
  background: #dcefe6;
  color: #173d2e;
}

.notice.error {
  background: #ffe3df;
  color: #741e17;
}

.grid,
.item-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 22px;
  row-gap: 24px;
}

.field {
  display: grid;
  align-content: start;
  gap: 9px;
  min-width: 0;
}

.card > .field { margin-top: 20px; }
.card > p:last-child { margin: 24px 0 0; }

.field.full,
.item-grid .field.full { grid-column: 1 / -1; }

.field label:not(.button) {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  text-transform: uppercase;
  letter-spacing: 0.065em;
}

.field input:not([type="file"]),
.field textarea,
.field select {
  width: 100%;
  min-height: 46px;
  padding: 12px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 104, 242, 0.16);
}

.field textarea {
  min-height: 116px;
  resize: vertical;
}

.field[data-field-type="checkbox"] {
  align-self: end;
}

.field .check-field {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1.35;
  text-transform: none;
}

.field .check-field:hover {
  border-color: #8995a9;
}

.field .check-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 104, 242, 0.16);
}

.field .check-field input[type="checkbox"] {
  appearance: auto;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  accent-color: var(--accent);
  box-shadow: none;
}

.collection-section {
  margin-top: 38px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.collection { display: grid; gap: 18px; }

.item {
  position: relative;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 21px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 700;
}

.item-actions,
.image-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 17px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
}

.button:hover,
.icon-button:hover { transform: translateY(-1px); }

.button:focus-visible,
.icon-button:focus-visible,
.media-option:focus-visible {
  outline: 3px solid rgba(36, 104, 242, 0.35);
  outline-offset: 2px;
}

.button.secondary { background: var(--ink); }

.button.light {
  border: 1px solid var(--line);
  background: #edf3fc;
  color: var(--ink);
}

.button.danger {
  min-height: 38px;
  padding: 9px 13px;
  background: transparent;
  color: #8f251d;
  border: 1px solid rgba(143, 37, 29, 0.28);
}

.button.text-button {
  min-height: 38px;
  padding: 8px 4px;
  background: transparent;
  color: var(--muted);
}

.primary-action { min-width: 180px; }

.icon-button {
  width: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 18px;
}

.toolbar {
  margin-top: 36px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.save-hint,
.meta,
.field-help {
  color: var(--muted);
  font-size: 13px;
}

.field-help {
  margin: 0;
  line-height: 1.45;
}

.field-help.is-error { color: #8f251d; }

.image-guidance { max-width: 700px; }

.upload-status:empty { display: none; }

.image-control {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.image-preview-wrap {
  width: 150px;
  min-height: 96px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.image-preview {
  display: block;
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.86);
}

.image-control-body {
  display: grid;
  align-content: center;
  gap: 12px;
  min-width: 0;
}

.upload-button { position: relative; flex: 0 0 auto; }

.preview {
  width: 110px;
  height: 70px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
}

.media-dialog {
  width: min(960px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.3);
}

.media-dialog::backdrop { background: rgba(3, 12, 28, 0.76); }

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.dialog-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  max-height: 620px;
  padding: 24px;
  overflow: auto;
}

.media-option {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.media-option:hover { border-color: var(--accent); }

.media-option img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 9px;
  object-fit: contain;
  border-radius: 6px;
  background: #edf3fc;
}

.media-option span {
  display: block;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 25px;
  background: var(--ink);
}

.login .card { width: min(440px, 100%); }

.code {
  display: block;
  padding: 13px;
  background: #f0eee5;
  border: 1px dashed #aaa;
  font: 700 18px monospace;
  letter-spacing: 0.1em;
  word-break: break-all;
}

.small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.backup {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
  .media-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .image-control { grid-template-columns: 140px minmax(0, 1fr); }
  .image-preview-wrap { width: 140px; }
}

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static;
    width: 100%;
    height: auto;
    padding: 18px;
  }
  .brand { margin-bottom: 18px; }
  .side nav {
    display: flex;
    gap: 6px;
    padding-bottom: 8px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }
  .side nav a { flex: 0 0 auto; }
  .side .exit { margin-top: 16px; }
  .main { padding: 32px 20px 52px; }
  .grid,
  .item-grid { grid-template-columns: 1fr; }
  .field.full,
  .item-grid .field.full { grid-column: auto; }
  .page-head { align-items: center; }
}

@media (max-width: 600px) {
  .page-head,
  .section-heading,
  .item-head { align-items: stretch; flex-direction: column; }
  .card { padding: 20px; }
  .item { padding: 18px; }
  .item-actions { justify-content: flex-start; }
  .image-actions .button { flex: 1 1 auto; }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 16px; }
  .dialog-head { padding: 18px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar .button { width: 100%; }
}

@media (max-width: 480px) {
  .image-control { grid-template-columns: 1fr; }
  .image-preview-wrap { width: 150px; }
  .image-preview { height: 96px; }
  .image-actions { align-items: stretch; flex-direction: column; }
  .image-actions .button { width: 100%; }
}

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