/* ==========================================================================
   SITE EDITOR — the portfolio's own tones, a working tool's layout
   ========================================================================== */

:root {
  --bg: #1c1d1f;
  --bg-raised: #242528;
  --bg-field: #16171a;
  --fg: #ebe9e4;
  --fg-muted: #a3a29e;
  --fg-dim: #858481;
  --line: rgba(235, 233, 228, 0.1);
  --line-strong: rgba(235, 233, 228, 0.24);
  --accent: #d9a04b;
  --ok: #7fb58a;
  --bad: #e27d6a;
  --radius: 6px;
  --font: "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
h1, h2 { font-weight: 400; letter-spacing: -0.01em; margin: 0; }
p { margin: 0; }
.muted { color: var(--fg-muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: transparent; color: var(--fg); font: 500 14px/1.2 var(--font); cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}
.btn:hover { background: rgba(235, 233, 228, 0.06); }
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn--primary:hover { background: #fff; }
.btn--quiet { border-color: transparent; color: var(--fg-muted); }
.btn--quiet:hover { color: var(--fg); }
.btn--small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn--big { min-height: 52px; padding: 12px 24px; font-size: 16px; }
.btn svg { width: 20px; height: 20px; }
.btn.is-busy { opacity: 0.7; pointer-events: none; }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 60px; padding: 0 20px; border-bottom: 1px solid var(--line);
  background: rgba(28, 29, 31, 0.92); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.top__brand { font-weight: 500; letter-spacing: 0.18em; text-transform: uppercase; font-size: 12px; text-decoration: none; }
.top__brand span { color: var(--fg-dim); margin-left: 10px; }
.top__user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.top__avatar { width: 28px; height: 28px; border-radius: 50%; }

/* ---------- Screens ---------- */
.screen--center { max-width: 520px; margin: 14vh auto 0; padding: 0 24px; display: grid; gap: 18px; justify-items: start; }
.screen--center h1 { font-size: 34px; font-weight: 300; }

/* ---------- The editor: parts of the site beside their fields ---------- */
.editor { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.side {
  position: sticky; top: 60px; align-self: start; height: calc(100vh - 60px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; padding: 20px 14px 24px 20px; border-right: 1px solid var(--line);
}
.side__search {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg-field); color: var(--fg); font: inherit;
}
.side__filters { display: flex; gap: 6px; }
.side__filters button {
  flex: 1; min-height: 34px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent;
  color: var(--fg-muted); font: 500 13px var(--font); cursor: pointer;
}
.side__filters button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.side__groups { display: grid; gap: 2px; }
.side__head { margin: 14px 0 4px 10px; font-size: 11px; font-weight: 500; letter-spacing: 0.22em; text-transform: uppercase; color: var(--fg-dim); }
.side__group {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 38px;
  padding: 6px 10px; border: 0; border-radius: var(--radius); background: transparent; color: var(--fg-muted);
  font: 400 14px var(--font); text-align: left; cursor: pointer;
}
.side__group:hover { background: rgba(235, 233, 228, 0.05); color: var(--fg); }
.side__group[aria-current="true"] { background: rgba(235, 233, 228, 0.09); color: var(--fg); }
.side__counts { display: flex; gap: 4px; }
.dot { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 11px; font-weight: 600; line-height: 20px; text-align: center; }
.dot--edited { background: rgba(127, 181, 138, 0.18); color: var(--ok); }
.dot--todo { background: rgba(217, 160, 75, 0.18); color: var(--accent); }
.dot--unsaved { background: var(--fg); color: var(--bg); }
.side__history { margin-top: auto; justify-content: flex-start; }

.fields { padding: 28px clamp(20px, 4vw, 56px) 140px; max-width: 980px; }
.fields__head { display: grid; gap: 4px; margin-bottom: 24px; }
.fields__head h1 { font-size: 30px; font-weight: 300; }
.fields__section {
  margin: 34px 0 12px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 12px; font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; color: var(--fg-dim);
}

/* ---------- A field ---------- */
.field {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 14px; padding: 16px 18px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-raised);
}
.field__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.field__label { font-weight: 500; }
.field__badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.badge--edited { background: rgba(127, 181, 138, 0.16); color: var(--ok); }
.badge--unsaved { background: var(--fg); color: var(--bg); }
.badge--todo { background: rgba(217, 160, 75, 0.16); color: var(--accent); }
.field input:not([type="file"]), .field textarea {
  width: 100%; min-height: 42px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg-field); color: var(--fg); font: inherit; line-height: 1.5; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--fg-muted); outline: none; }
.field__foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.field__default { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field__default-value { color: var(--fg-dim); }
.field__key { color: var(--fg-dim); opacity: 0.6; font-size: 11px; overflow-wrap: anywhere; }

.field__media { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 14px; align-items: center; }
.field__media-actions { display: grid; gap: 6px; justify-items: start; }
.preview {
  display: grid; place-items: center; width: 180px; aspect-ratio: 16 / 10; overflow: hidden;
  border-radius: var(--radius); background: #2e2f33;
}
.preview img, .preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview--empty, .preview__missing { color: var(--fg-dim); font-size: 12px; }

/* ---------- Save bar, toast, history ---------- */
.savebar {
  position: fixed; left: 50%; bottom: 20px; z-index: 30; translate: -50% 0;
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 20px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: #2a2b2e; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.8);
}
.savebar__count { margin-right: 8px; font-weight: 500; }
.toast {
  position: fixed; right: 20px; top: 76px; z-index: 40; max-width: min(460px, calc(100vw - 40px));
  padding: 12px 16px; border-radius: 10px; background: var(--fg); color: var(--bg); font-weight: 500;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.8);
}
.toast.is-bad { background: var(--bad); color: #1a0f0c; }

.history {
  width: min(760px, calc(100vw - 32px)); max-height: 82vh; padding: 0; overflow: hidden;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--bg-raised); color: var(--fg);
}
.history::backdrop { background: rgba(0, 0, 0, 0.6); }
.history__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.history__head h2 { font-size: 20px; }
.history__list { list-style: none; margin: 0; padding: 8px 20px 20px; max-height: calc(82vh - 70px); overflow-y: auto; }
.history__item { display: grid; gap: 6px; justify-items: start; padding: 14px 0; border-bottom: 1px solid var(--line); }
.history__item p { overflow-wrap: anywhere; }
.history__meta { display: grid; gap: 2px; }

/* ---------- Phones ---------- */
@media (max-width: 760px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .side__groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side__group span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side__head { grid-column: 1 / -1; }
  .fields { padding: 20px 16px 140px; }
  .field__media { grid-template-columns: 1fr; }
  .preview { width: 100%; }
  .savebar { left: 12px; right: 12px; translate: none; bottom: 12px; }
  .savebar__count { margin-right: auto; }
  .top { padding: 0 16px; }
  .top__brand span { display: none; }
}
