/* SandraCMS Studio — implements design/TOKENS.md.
   Its OWN copy, deliberately. The console has another. A shared stylesheet is
   how two products quietly become one, and this one has to stay liftable to its
   own domain (D23). The duplication is the cheap half of that trade. */

:root {
  --brand: #246974; --brand-d: #1C535C;
  --lime: #C6F24E; --lime-on: #16240F;
  --ink: #1F2A2C; --muted: #6E7679;
  --paper: #f3f3f3; --surface: #ffffff; --surface-2: #F7F8F8;
  --line: #E4E5E6; --line-strong: #D4D6D7;
  --ok: #3B6D11; --ok-bg: #EAF3DE;
  --warn: #854F0B; --warn-bg: #FAEEDA;
  --danger: #A32D2D;
  --font: "Puritan", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--paper); line-height: 1.55; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; font-weight: 700; margin: 0 0 .2em; letter-spacing: -.01em; }
h2 { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .5rem; }
h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 .3rem; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- shell ---------- */

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex: none; background: var(--brand); color: #B7D2D6;
  display: flex; flex-direction: column; padding: 18px 14px;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px; color: #fff;
  font-weight: 700; font-size: 1.05rem; margin: 4px 6px 22px;
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--lime); color: var(--lime-on);
  display: flex; align-items: center; justify-content: center; font-size: 1rem; flex: none;
}
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar__nav a { display: flex; align-items: center; gap: 10px; color: #B7D2D6; padding: 9px 11px; border-radius: 9px; font-size: .92rem; }
.sidebar__nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar__nav a.is-active { background: rgba(255,255,255,.13); color: #fff; }
.sidebar__foot { margin-top: auto; padding: 14px 6px 2px; border-top: 1px solid rgba(255,255,255,.12); font-size: .78rem; color: #8DB0B5; }
.sidebar__tagline { margin: 0 6px; font-size: .88rem; color: #8DB0B5; line-height: 1.5; }

.app__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: .7rem 1.5rem;
}
.appbar__title { font-weight: 700; }
.appbar__right { display: flex; align-items: center; gap: .9rem; font-size: .88rem; }
.appbar__avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: .74rem; font-weight: 700;
}
.appbar__email { color: var(--muted); }
main { padding: 1.6rem 1.5rem 4rem; max-width: 1080px; width: 100%; }
/* The editor is a workspace, not a document — it takes the window. */
main.main--wide { max-width: none; padding: 0; }

@media (max-width: 860px) {
  .sidebar { width: 100%; flex-direction: row; align-items: center; gap: 14px; padding: 10px 14px; overflow-x: auto; }
  .app { flex-direction: column; }
  .sidebar__brand { margin: 0; }
  .sidebar__nav { flex-direction: row; }
  .sidebar__foot { display: none; }
}

/* ---------- surfaces: flat boxes ---------- */

.panel { background: var(--surface); border: 1px solid var(--line); padding: 1.15rem 1.3rem; margin: 0 0 1.2rem; }
.panel > :last-child { margin-bottom: 0; }
.narrow { max-width: 430px; margin: 12vh auto 0; }
.lede { color: var(--muted); font-size: .92rem; margin: 0 0 1rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: .9rem; margin-top: 1rem; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--line); padding: 1.05rem 1.1rem;
  color: var(--ink); transition: border-color .12s;
}
.card:hover { border-color: var(--brand); text-decoration: none; }
.card p { margin: .25rem 0; }

/* ---------- controls ---------- */

button, .btn-secondary, .btn-accent {
  font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: 9px;
  padding: .55em .95em; font-weight: 500; display: inline-flex; align-items: center; gap: .4em;
  background: var(--brand); color: #fff; text-decoration: none;
}
button:hover { background: var(--brand-d); }
.btn-accent { background: var(--lime); color: var(--lime-on); border-color: var(--lime); }
.btn-accent:hover { filter: brightness(.96); }
button.link {
  background: none; border: 0; padding: 0; color: var(--danger);
  font-weight: 400; text-decoration: underline; border-radius: 0;
}
button.link:hover { background: none; filter: none; }
form.inline { display: inline; }
form.row { display: flex; gap: .6rem; align-items: center; margin: .7rem 0 1rem; }
form.row input[type=text] { flex: 1; margin: 0; }

label { display: block; margin: 0 0 .85rem; font-size: .9rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; margin-top: .3rem; padding: .55em .7em; font: inherit;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 0; color: var(--ink);
}
fieldset { border: 1px solid var(--line); border-radius: 0; padding: .9rem 1rem; margin: 0 0 1rem; }
legend { color: var(--muted); font-size: .82rem; padding: 0 .4rem; }
label.check { display: flex; align-items: baseline; gap: .5rem; margin: 0 0 .45rem; font-weight: 400; }

/* ---------- data ---------- */

table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: .5rem; }
th {
  text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: .45rem .7rem .45rem 0; border-bottom: 1px solid var(--line-strong);
}
td { padding: .6rem .7rem .6rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.dim { opacity: .5; }
.page { margin-bottom: 1.4rem; }

.badge, .pill {
  display: inline-block; padding: .12em .6em; border-radius: 99px; font-size: .74rem;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); margin-right: .25rem;
}
.pill.ok, .badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }

.notice { padding: .8rem 1.1rem; border: 1px solid var(--line); background: var(--surface); margin: 0 0 1.2rem; }
.notice.ok { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.notice.error { border-color: var(--danger); color: var(--danger); background: #FBF1F0; }
.key { word-break: break-all; background: var(--surface); border: 1px solid var(--line); padding: .6rem .7rem; margin: .5rem 0 0; }

.mono, code { font-family: var(--mono); font-size: .84rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

pre.config {
  background: var(--surface-2); border: 1px solid var(--line); padding: .9rem 1rem;
  overflow-x: auto; font-family: var(--mono); font-size: .8rem; line-height: 1.55; margin: 0;
}

.caps { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.caps li { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.dot { width: 8px; height: 8px; border-radius: 99px; background: var(--line-strong); flex: none; }
.dot.on { background: var(--ok); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .7rem; margin-top: .6rem; }
.media { margin: 0; background: var(--surface-2); border: 1px solid var(--line); }
.media img { display: block; width: 100%; height: 92px; object-fit: cover; background: var(--line); }
.media figcaption { padding: .45rem .5rem; display: grid; gap: .1rem; }

.preview-link { font-size: .78rem; font-weight: 400; margin-left: .5rem; }

.rules { margin: 0 0 .8rem; padding-left: 1.1rem; }
.rules li { margin-bottom: .35rem; font-size: .92rem; }
.rules.small li { font-size: .84rem; margin-bottom: .3rem; }
ol.rules { padding-left: 1.3rem; }

/* ================= editor shell ================= */

.editor { display: flex; flex-direction: column; height: calc(100vh - 49px); }
.editor__bar {
  display: flex; align-items: center; gap: .7rem; flex: none;
  background: var(--brand); color: #fff; padding: .5rem .9rem;
}
.studio__brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 700; }
.studio__brand:hover { text-decoration: none; }
.studio__select {
  font: inherit; font-size: .88rem; padding: .35em .6em; border-radius: 0;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; max-width: 190px;
}
.studio__select option { color: var(--ink); }
.studio__spacer { flex: 1; }
.editor__status { font-size: .85rem; color: rgba(255,255,255,.85); }
.editor__status.error { color: #FFD9D5; }
.studio__user { font-size: .8rem; color: rgba(255,255,255,.6); }
.studio__signout { color: rgba(255,255,255,.85); font-size: .8rem; }

.editor__body { flex: 1; display: flex; min-height: 0; }
/* The canvas sits centred on the desk, as Site Builder's does — a page you are
   looking at rather than a panel wedged into the window. */
.editor__canvas { flex: 1; min-width: 0; background: var(--paper); overflow-y: auto; padding: 1.4rem; }
.editor__canvas iframe {
  display: block; width: 100%; max-width: 1100px; height: 100%; min-height: 100%;
  margin: 0 auto; border: 0; background: #fff; box-shadow: 0 1px 10px rgba(20,32,26,.12);
}

.blocks { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .35rem; }
.block {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem;
  background: var(--surface-2); border: 1px solid var(--line); cursor: grab; font-size: .88rem;
}
.block.is-dragging { opacity: .4; }
.block__region {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border: 1px solid var(--line); padding: 0 .35em; background: #fff;
}
.block__name { flex: 1; font-weight: 500; }
.block__actions .link { color: var(--brand); }

/* ================= modal ================= */

.modal { position: fixed; inset: 0; background: rgba(20,32,26,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 2rem 1rem; }
.modal__box { background: var(--surface); border: 1px solid var(--line); width: 100%; max-width: 620px; max-height: 100%; display: flex; flex-direction: column; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal__head h3 { margin: 0; }
.modal__close { background: none; border: 0; color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 0 .2rem; border-radius: 0; }
.modal__close:hover { background: none; color: var(--ink); }
.modal__body { padding: 1.1rem; overflow-y: auto; }
.modal__foot { display: flex; align-items: center; gap: .6rem; padding: .8rem 1.1rem; border-top: 1px solid var(--line); background: var(--surface-2); }

.formgroup { margin: 0 0 1.1rem; }
.field { display: block; margin: 0 0 .85rem; }
.field__label { display: block; font-size: .84rem; font-weight: 500; margin-bottom: .25rem; }
.field__help { display: block; font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.modal textarea, .modal select {
  width: 100%; font: inherit; font-size: .9rem; padding: .5em .65em;
  border: 1px solid var(--line-strong); border-radius: 0; background: #fff; color: var(--ink);
}
.modal textarea { resize: vertical; }
.switch { display: flex; align-items: center; gap: .45rem; font-weight: 400; margin: 0; }

.rep { border: 1px solid var(--line); padding: .7rem; background: var(--surface-2); }
.rep__row { border-bottom: 1px solid var(--line); padding-bottom: .6rem; margin-bottom: .6rem; }
.rep__field { display: block; margin-bottom: .5rem; }
.rep__field span { display: block; font-size: .78rem; color: var(--muted); }

.mediafield { display: flex; align-items: center; gap: .6rem; }
.mediafield__preview img { width: 68px; height: 48px; object-fit: cover; border: 1px solid var(--line); display: block; }
.mediafield__none { font-size: .8rem; color: var(--muted); }

.palette__cat { margin: .8rem 0 .4rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.palette__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; }
.palette__item { display: block; text-align: left; background: var(--surface); border: 1px solid var(--line); color: var(--ink); padding: .6rem .7rem; border-radius: 0; font-weight: 400; }
.palette__item:hover { background: var(--surface-2); border-color: var(--brand); }
.palette__item strong { display: block; font-size: .88rem; }

.picker { position: fixed; inset: 0; background: rgba(20,32,26,.6); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 2rem; }
.picker__box { background: var(--surface); border: 1px solid var(--line); padding: 1.1rem; max-width: 640px; width: 100%; max-height: 80vh; overflow-y: auto; }
.picker__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; margin: .8rem 0; }
.picker__item { display: block; background: var(--surface-2); border: 1px solid var(--line); padding: 0; border-radius: 0; color: var(--ink); font-weight: 400; }
.picker__item img { width: 100%; height: 76px; object-fit: cover; display: block; }
.picker__item span { display: block; font-size: .72rem; padding: .3rem; color: var(--muted); word-break: break-all; }

/* `hidden` must win over the modal's display:flex, or it shows empty on load. */
[hidden] { display: none !important; }

.studio__icon {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.25);
  color: #fff; font-size: .84rem; padding: .35em .7em; border-radius: 0;
}
.studio__icon:hover { background: rgba(255,255,255,.2); }
.editor__railhead { margin-top: 1.4rem; }
.block--slot { background: #fff; }
.block--off { opacity: .5; }
.block__meta { font-size: .72rem; color: var(--muted); }
.pagerow { display: flex; align-items: center; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.pagerow__name { flex: 1; }
.pagerow__name strong { display: block; font-size: .9rem; }
.pagerow__name span { font-size: .76rem; color: var(--muted); font-family: var(--mono); }
.uploader { border: 1px dashed var(--line-strong); padding: .8rem; text-align: center; margin-bottom: .8rem; background: var(--surface-2); }
.uploader input { display: none; }

/* ================= screens ================= */

.subbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 1.5rem; }
.subbar__nav { display: flex; gap: 1.2rem; overflow-x: auto; }
.subbar__nav a {
  padding: .7rem 0; font-size: .88rem; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.subbar__nav a:hover { color: var(--ink); text-decoration: none; }
.subbar__nav a.is-active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head .back { font-size: .86rem; }
.page-head p { margin: .2rem 0 0; font-size: .8rem; }

.inline-create { display: flex; gap: .6rem; align-items: center; margin: 0 0 1.1rem; }
.inline-create input[type=text] { flex: 1; margin: 0; max-width: 380px; }
.inline-create input[type=file] { font-size: .86rem; }

.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.card-list .card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card__title { font-weight: 700; font-size: 1.02rem; }
.card__meta { display: flex; align-items: center; gap: .5rem; margin-top: .2rem; font-size: .8rem; }
.card__actions { display: flex; align-items: center; gap: .5rem; flex: none; }
.card__actions form { display: inline; }
.badge--published { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge--draft { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.btn-danger { background: var(--surface); border: 1px solid #E3C7C7; color: var(--danger); }
.btn-danger:hover { background: #FBF1F0; }
.empty { color: var(--muted); padding: 1.4rem 0; }
.panel-sub { margin: 1.3rem 0 .5rem; font-size: .76rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); border-top: 1px solid var(--line); padding-top: .9rem; }

.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; }
.swatch { display: grid; gap: .25rem; margin: 0; }
.swatch__name { font-size: .78rem; color: var(--muted); text-transform: capitalize; }
.swatch input[type=color] { width: 100%; height: 42px; padding: 0; border: 1px solid var(--line-strong); background: none; }
.swatch__hex { font-size: .72rem; color: var(--muted); }
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; }
.sizes input { width: 100%; margin-top: .3rem; padding: .5em .6em; border: 1px solid var(--line-strong); font: inherit; }

.slotrow { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 0; border-bottom: 1px solid var(--line); }
.slotrow:last-child { border-bottom: 0; }
.slotrow select { font: inherit; font-size: .86rem; padding: .4em .6em; border: 1px solid var(--line-strong); border-radius: 0; }

.editor__bar { background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--line); }
.editor__back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none; color: var(--muted);
  border: 1px solid var(--line); font-size: 1rem; line-height: 1;
}
.editor__back:hover { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.editor__path { color: var(--muted); font-size: .78rem; }
.editor__title { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.editor__status { font-size: .85rem; color: var(--muted); }
.editor__status.error { color: var(--danger); }

.modal input[type=date], .modal input[type=number] {
  font: inherit; font-size: .9rem; padding: .5em .65em;
  border: 1px solid var(--line-strong); border-radius: 0; background: #fff; color: var(--ink);
}
.modal input[type=number] { width: 12rem; }

/* ---------- The entry editor (P16) ----------
   An entry is a form, not a canvas: it has no arrangement to see, so there is
   nothing for a preview pane to show that the fields do not. Centred at a
   reading width, like the page canvas. */
.entry-editor { display: flex; flex-direction: column; min-height: 100%; }
.entry-editor__body { flex: 1; overflow: auto; padding: 1.5rem 1rem 4rem; }
.entry-editor__form { max-width: 720px; margin: 0 auto; }
.entry-editor__form .formgroup + .formgroup { margin-top: 1.6rem; }
.entry-editor__form textarea { min-height: 8rem; }
.entry-editor__form textarea[name="body"] { min-height: 18rem; }

.field--check { display: flex; align-items: center; gap: .5rem; }
.field--check input { width: auto; }
