:root {
  --bg: #eef1f5;
  --panel: #fff;
  --ink: #1c2430;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #2f6fed;
  --danger: #c0392b;
  --ok: #1e7a46;
  --side: #152033;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --field-min: 220px;
  --control-h: 42px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; }

/* —— Login —— */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(160deg, #d9e4f5, #eef1f5 55%);
}
.login-card {
  width: min(100%, 360px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.login-card label:not(.field) {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.login-card input {
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  font-weight: 400;
}
.muted { color: var(--muted); margin: 0; }

/* —— Shell / nav —— */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.side {
  background: var(--side);
  color: #d7deea;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
}
.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}
.brand { color: #fff; font-weight: 700; letter-spacing: 0.02em; }
.nav-toggle {
  display: none;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
.side nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.side nav button {
  text-align: left;
  background: transparent;
  border: none;
  color: #c5cedd;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  min-height: 40px;
}
.side nav button:hover,
.side nav button.is-active {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.side .logout {
  color: #9aa8bd;
  background: none;
  border: none;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  min-height: 40px;
}
.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top h1 { margin: 0; font-size: 20px; line-height: 1.25; }
.top--gallery {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.gal-page-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: #e8edf4;
  border: 1px solid #d0d8e4;
  border-radius: 999px;
}
.gal-page-switch__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.gal-page-switch__btn:hover {
  color: var(--ink);
}
.gal-page-switch__btn.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 36, 48, 0.08);
}
.gal-plus {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: transparent;
  font-size: 0;
  line-height: 0;
  flex-shrink: 0;
}
.gal-plus::before,
.gal-plus::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: #fff;
  border-radius: 1px;
  transform: translate(-50%, -50%);
}
.gal-plus::before {
  width: 10px;
  height: 2px;
}
.gal-plus::after {
  width: 2px;
  height: 10px;
}
.gal-page-switch__btn.is-active .gal-plus {
  background: #1c2430;
}
.content { padding: 16px 20px 40px; max-width: 1100px; width: 100%; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card strong { display: block; font-size: 22px; }
.card span { color: var(--muted); font-size: 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.3;
  word-break: break-word;
}
.panel h2 code { font-weight: 500; }

/* —— Forms: single column + language steps —— */
.form-grid,
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
  align-items: stretch;
}
.form-stack > .row-actions,
.form-grid > .row-actions {
  margin-top: 4px;
}

.lang-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  background: #e8edf4;
  border-radius: 10px;
  border: 1px solid #d0d8e4;
}
.lang-tab {
  flex: 1 1 auto;
  min-width: 96px;
  min-height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 8px 12px;
}
.lang-tab:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
}
.lang-tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 36, 48, 0.08);
}

.i18n-field[data-i18n-lang]:not(.is-active) {
  display: none !important;
}

.field,
label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field-title {
  display: block;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  min-height: 1.3em;
}
.field input:not([type="file"]):not([type="hidden"]),
.field textarea,
.field select,
.form-stack > label:not(.field) input,
.form-stack > label:not(.field) textarea,
.form-stack > label:not(.field) select,
.form-grid > label:not(.field) input,
.form-grid > label:not(.field) textarea,
.form-grid > label:not(.field) select {
  width: 100%;
  min-height: var(--control-h);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
}
.field textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.4;
}
.field select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 11px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
.field-hint {
  display: block;
  order: 3;
  font-weight: 400;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
  margin: 0;
}
.field input,
.field textarea,
.field select,
.file-path {
  order: 2;
}
.field-title { order: 1; }
.field--narrow { max-width: 420px; margin-bottom: 16px; }

.btn-ghost {
  background: #e8eef8 !important;
  color: #1c2430 !important;
}

.file-field input[type="file"] {
  width: 100%;
  min-height: var(--control-h);
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-size: 13px;
}
.file-path {
  font-size: 12px;
  font-weight: 400;
  word-break: break-all;
}
.file-preview {
  order: 4;
  max-width: min(180px, 100%);
  margin-top: 4px;
  border-radius: 8px;
  display: block;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 4px;
}
button.btn, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
}
button.danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 36px;
  cursor: pointer;
  font: inherit;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: var(--panel);
}
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
}
.table th { background: #f7f9fc; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }

.table--docs {
  min-width: 720px;
  table-layout: fixed;
}
.table--docs .th-wide,
.table--docs .td-wide {
  width: 46%;
}
.table--docs .th-actions,
.table--docs td.row-actions {
  width: 108px;
  white-space: nowrap;
}
.titles-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.titles-stack__row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}
.titles-stack__lang {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1.45;
  padding-top: 1px;
}
.titles-stack__text {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.btn-sm,
button.btn-sm,
button.danger.btn-sm {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
}
.row-actions--compact {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-top: 0;
}
.row-actions--compact .btn,
.row-actions--compact button {
  width: 100%;
}
.msg { margin: 0 0 12px; font-weight: 600; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }
code { font-size: 12px; background: #f0f3f8; padding: 1px 5px; border-radius: 4px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 14px; line-height: 1.4; }

.vid-grid {
  display: flex;
  gap: 14px;
  overflow: hidden;
  width: 100%;
}
.vid-carousel {
  position: relative;
}
.vid-carousel__viewport {
  overflow: hidden;
  width: 100%;
}
.vid-carousel__track {
  display: flex;
  gap: 14px;
  will-change: transform;
  transition: transform 0.35s ease;
}
.vid-card {
  flex: 0 0 calc((100% - 28px) / 3);
  width: calc((100% - 28px) / 3);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
}
.vid-carousel__nav {
  position: absolute;
  top: 28%;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.vid-carousel__nav--prev { left: -6px; }
.vid-carousel__nav--next { right: -6px; }
.vid-carousel.is-static .vid-carousel__nav { display: none; }
@media (max-width: 900px) {
  .vid-card {
    flex-basis: 100%;
    width: 100%;
  }
}
.vid-card__thumb {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: #1c2430;
}
.vid-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.vid-card__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.vid-card__meta strong {
  font-size: 13px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.vid-card__meta code {
  font-size: 11px;
  word-break: break-all;
}

.gal-add-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.gal-add-hero h2 { margin: 0 0 4px; }
.gal-plus-circle {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: transparent;
  font-size: 0;
  line-height: 0;
}
.gal-plus-circle::before,
.gal-plus-circle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: #fff;
  border-radius: 1px;
  transform: translate(-50%, -50%);
}
.gal-plus-circle::before {
  width: 22px;
  height: 3px;
}
.gal-plus-circle::after {
  width: 3px;
  height: 22px;
}

.gal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.gal-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
}
.gal-card--bare {
  position: relative;
  padding: 0;
  gap: 0;
  background: #e4e9f0;
  overflow: hidden;
  aspect-ratio: 1;
  cursor: grab;
  touch-action: none;
}
.gal-card--bare:active {
  cursor: grabbing;
}
.gal-card--bare.is-dragging {
  opacity: 0.45;
}
.gal-card--bare.is-drop-target {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.gal-card--bare img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gal-card--bare .gal-card__cap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: #fff;
  background: rgba(20, 28, 36, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  pointer-events: none;
  transition: background 0.28s ease, backdrop-filter 0.28s ease;
}
.gal-card--bare:hover .gal-card__cap,
.gal-card--bare:focus-within .gal-card__cap {
  background: rgba(20, 28, 36, 0.94);
}
.gal-card__img {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 8px;
  background: #e4e9f0;
}
.gal-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gal-card__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.gal-card__meta strong {
  font-size: 13px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.gal-card__cap {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.gal-card__del {
  width: 100%;
}
.gal-card--bare .gal-card__del {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(28, 36, 48, 0.72);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.gal-card--bare:hover .gal-card__del,
.gal-card--bare:focus-within .gal-card__del {
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal.hidden { display: none !important; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 51, 0.45);
}
.modal__box {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: 0 16px 40px rgba(28, 36, 48, 0.2);
}
.modal__box h3 {
  margin: 0 0 8px;
  font-size: 18px;
}
.modal__box .row-actions {
  margin-top: 16px;
  justify-content: flex-end;
}

.toast-wrap {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  left: auto;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(28, 36, 48, 0.18);
  animation: toast-in 0.2s ease;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

/* Tablet */
@media (max-width: 960px) {
  .form-stack,
  .form-grid {
    max-width: none;
  }
}

/* Mobile */
@media (max-width: 800px) {
  .shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }
  .side {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    max-height: none;
    padding: 12px;
    gap: 8px;
  }
  .nav-toggle { display: inline-flex; align-items: center; }
  .side nav,
  .side .logout {
    display: none;
  }
  .side.is-open nav {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 2px;
    padding-top: 4px;
  }
  .side.is-open .logout {
    display: block;
    width: 100%;
  }
  .side nav button,
  .side .logout {
    width: 100%;
  }
  .top {
    padding: 12px 14px;
  }
  .top h1 { font-size: 18px; }
  .content {
    padding: 12px 14px 32px;
  }
  .form-stack,
  .form-grid {
    max-width: none;
    gap: 12px;
  }
  .field--narrow {
    max-width: none;
  }
  .panel { padding: 14px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toast-wrap {
    left: 12px;
    right: 12px;
    width: auto;
  }
  .btn, button.btn {
    width: 100%;
  }
  .row-actions {
    width: 100%;
  }
  .row-actions .btn,
  .row-actions button {
    flex: 1 1 auto;
  }
  .table-wrap { margin: 0 -2px; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
  .login-card { padding: 18px; }
}
