:root {
  /* Design tokens (interface plan §15). The admin UI is deliberately
     restrained — Inter/system UI, neutral surfaces, blue primary action —
     while JMA brand colors stay on the signage output, where contrast is
     controlled and the brand should be loud. */
  --page-bg: #f7f8fa;
  --bg: #f7f8fa;
  --surface: #fff;
  --surface-alt: #fafbfc;
  --text: #1b1f24;
  --muted: #6a737d;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #fff;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;
  --danger-bg: #fdecec; --danger: #b42318;
  --warn-bg: #fff4e5;  --warn: #9a3412;
  --ok-bg: #e7f6ec;    --ok: #1e7e34;
  --accent: #f2a900;            /* JMA yellow — accents only, never a button face */

  --radius-input: 6px;
  --radius: 8px;
  --control-h: 38px;

  --fs-body: 14px;
  --fs-label: 12px;
  --fs-title: 26px;

  --sidebar-w: 250px;
  --content-max: 1440px;

  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--fs-body);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page-bg); color: var(--text); font-size: var(--fs-body); line-height: 1.5; }
body.login { display: grid; place-items: center; min-height: 100vh; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 2rem; width: min(400px, 92vw); box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.muted { color: var(--muted); }

/* ---- form controls (plan §3) ------------------------------------------------
   One height, one radius, one focus treatment for every control type, so
   selects stop looking like raw browser widgets next to styled inputs. */
label { display: block; margin: 0 0 .25rem; font-weight: 600; font-size: var(--fs-label);
        text-transform: none; letter-spacing: .01em; }
label.collapsed { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .65rem; font: inherit;
  font-size: var(--fs-body); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-input);
  min-height: var(--control-h); transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: auto; line-height: 1.45; }
select {
  appearance: none; padding-right: 2rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236a737d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .6rem center;
}
input:hover, select:hover, textarea:hover { border-color: #b9c0cc; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin: 0; display: inline-block; accent-color: var(--primary); }
input::placeholder, textarea::placeholder { color: #9aa3af; }
small { display: block; margin-top: .3rem; font-weight: 400; }

button {
  margin: 0; width: auto; padding: 0 1rem; height: var(--control-h); font: inherit; font-weight: 600;
  font-size: var(--fs-body); background: var(--primary); color: var(--primary-text); border: 1px solid var(--primary);
  border-radius: var(--radius-input); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .4rem; transition: background .12s, border-color .12s;
}
button:hover { background: var(--primary-hover); border-color: var(--primary-hover); filter: none; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .3); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover { background: var(--surface-alt); border-color: #b9c0cc; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: #99200f; border-color: #99200f; }
.card button { margin-top: 1.25rem; width: 100%; }
button.link { width: auto; height: auto; margin: 0; padding: 0; background: none; border: 0;
              color: var(--primary); font-weight: 500; display: inline; }
button.link:hover { background: none; text-decoration: underline; }
.danger-link { color: var(--danger); }

.alert { background: var(--danger-bg); color: var(--danger); padding: .7rem .9rem; border-radius: var(--radius-input);
         border: 1px solid #f3cfcb; margin: .75rem 0 1rem; }

/* ---- status chips (plan §5) -------------------------------------------------
   A chip carries a dot plus a word, so status is scannable down a column
   instead of read word by word. */
.badge, .chip {
  display: inline-flex; align-items: center; gap: .35rem; font-size: 12px; font-weight: 600;
  padding: .15rem .55rem; border-radius: 999px; background: #eef0f3; color: #495057;
  border: 1px solid transparent; white-space: nowrap;
}
.chip::before, .badge.ok::before, .badge.warn::before, .badge.danger::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto;
}
.badge.ok,   .chip.ok   { background: var(--ok-bg);   color: var(--ok); }
.badge.warn, .chip.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger, .chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.neutral::before { background: #98a2b3; }

/* ---- app shell (plan §1, §2) ------------------------------------------------
   Full-width: topbar across the top, a permanent flush sidebar, and content
   that uses the height of the window. No floating cards for chrome. */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 0 1.5rem; height: 56px;
          background: var(--surface); border-bottom: 1px solid var(--border);
          position: sticky; top: 0; z-index: 40; }
.topbar strong { font-size: 15px; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
form.inline { display: inline; }

.page { max-width: var(--content-max); margin: 0; padding: 1.5rem 2rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.5rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---- permanent sidebar (plan §1) --------------------------------------------
   The sidebar is chrome, not content: flush to the window edge, full height,
   its own scroll. Content sits beside it and is left-aligned rather than
   centred in a narrow wrapper. */
.page.withsidebar {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 0; align-items: stretch; max-width: none; padding: 0;
  min-height: calc(100vh - 56px);
}
.page.withsidebar > div { min-width: 0; max-width: var(--content-max); padding: 1.5rem 2rem 3rem; }
.sidebar {
  display: flex; flex-direction: column; gap: 1px; position: sticky; top: 56px; align-self: start;
  height: calc(100vh - 56px); overflow-y: auto;
  background: var(--surface); border: 0; border-right: 1px solid var(--border);
  border-radius: 0; padding: .85rem .6rem;
}
.sidebar a {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .6rem; border-radius: var(--radius-input);
  color: #3d444d; text-decoration: none; font-size: var(--fs-body); font-weight: 500; border-left: 0;
}
.sidebar a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar a.active { background: #eaf0fe; color: var(--primary); font-weight: 600; }
.nav-icon { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center;
            color: #8b949e; flex: 0 0 auto; }
.nav-icon svg { width: 16px; height: 16px; }
.sidebar a.active .nav-icon { color: var(--primary); }
.nav-count { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--muted);
             background: var(--surface-alt); border: 1px solid var(--border); border-radius: 999px; padding: 0 .4rem; }
.sidebar a.active .nav-count { background: #fff; }
.nav-count.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.sidebar .sidebar-section:first-child { margin-top: 0; }
.sidebar-section { margin: 1rem 0 .3rem; padding: 0 .6rem; font-size: 11px; font-weight: 700;
                   letter-spacing: .07em; text-transform: uppercase; color: #8b949e; }

/* ---- page header (plan §2) --------------------------------------------------
   Title, one-line description, primary action on the right — the same shape
   on every page. */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem;
             padding-bottom: 1rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.page-head h1 { margin: 0; font-size: var(--fs-title); line-height: 1.2; letter-spacing: -.01em; }
.page-head .page-desc { margin: .25rem 0 0; color: var(--muted); max-width: 70ch; }
.page-head .page-actions { display: flex; gap: .6rem; flex: 0 0 auto; }

@media (max-width: 900px) {
  .page.withsidebar { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap;
             border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-section { display: none; }
  .page.withsidebar > div { padding: 1.25rem; }
}
/* ---- tables (plan §4) -------------------------------------------------------
   Taller rows, a quiet header, hover feedback, and overflow left visible so
   the row-action popover isn't clipped. */
table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: .75rem;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        overflow: visible; font-size: var(--fs-body); }
thead th { background: var(--surface-alt); font-size: 11px; font-weight: 700; letter-spacing: .06em;
           text-transform: uppercase; color: var(--muted); text-align: left;
           padding: .6rem .9rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: .75rem .9rem; border-bottom: 1px solid #f0f2f5; vertical-align: middle; min-height: 50px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child { border-top-right-radius: var(--radius); }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
code { background: #eceff2; padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }

/* ---- locations / screens forms & status badges (step 4) ------------------ */
.badge.ok { background: #e6f4ea; color: #1e7e34; }
h2 { font-size: 1.05rem; margin: 2rem 0 .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 1.5rem;
             background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
             padding: 1.25rem 1.5rem 1.5rem; max-width: 640px; }
.form-grid label { margin: .75rem 0 0; }
.form-grid label.span2 { grid-column: 1 / -1; }
.form-grid button { grid-column: 1 / -1; width: auto; padding: .6rem 1.4rem; justify-self: start; }

/* ---- layout editor (step 5) ---------------------------------------------- */
fieldset.region { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
                   padding: 1rem 1.5rem 1.25rem; margin: 0 0 1.25rem; max-width: 640px; }
fieldset.region legend { font-weight: 600; padding: 0 .4rem; }
fieldset.region > label:first-of-type { margin-top: 0; }
.widget-fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 1.5rem; margin-top: .25rem; }
.widget-fields label { margin-top: .75rem; }
.widget-fields label.span2 { grid-column: 1 / -1; }
button.danger { background: var(--danger); }
.inline-select { display: inline; }
.inline-select select { display: inline-block; width: auto; margin: 0; padding: .3rem .5rem; font-size: .9em; }

/* ---- small inline-style replacements (CSP has no 'unsafe-inline' for style) */
.checkbox-inline { width: auto; display: inline-block; margin-right: .4em; }
.uppercase { text-transform: uppercase; }

/* ---- media library (step 6) ----------------------------------------------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.media-card img, .media-card video { width: 100%; height: 120px; object-fit: cover; display: block; background: #000; }
.media-card-info { padding: .6rem .75rem .2rem; }
.media-card-name { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card form { padding: .2rem .75rem .6rem; }
.danger-link { color: var(--danger); }
.area-input { display: inline-block; width: 12em; }
.rect-input { display: inline-block; width: 4.5em; }

/* ---- layout freeform canvas editor ----------------------------------------
   Positioning mirrors the display client exactly: every region is
   position:absolute with left/top/width/height as percentages of this
   canvas, and the canvas itself holds the layout's real aspect ratio —
   what you see while placing something here is what actually renders on
   the screen. */
.canvas-controls { display: flex; gap: 2rem; margin: .5rem 0 .75rem; font-size: .92rem; }
.canvas-controls .link { font-weight: 700; padding: 0 .3em; }
.layout-canvas {
  position: relative;
  width: 100%;
  max-width: 700px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
  margin-bottom: 1rem;
}
.canvas-region {
  position: absolute;
  box-sizing: border-box;
  pointer-events: auto;
  cursor: grab;
  background: rgba(37, 99, 235, 0.12);
  border: 2px solid var(--primary);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 600; color: var(--primary);
  text-align: center; padding: .25rem; overflow: hidden;
}
.canvas-region:active { cursor: grabbing; }
.canvas-region-lifted { opacity: .55; }
.canvas-region.canvas-region-container {
  background: rgba(154, 52, 18, 0.12);
  border-style: dashed;
  border-color: var(--warn);
  color: var(--warn);
}
.resize-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: var(--primary); border: 2px solid var(--surface);
  border-radius: 3px;
  pointer-events: auto;
}
.resize-handle-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.resize-handle-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.resize-handle-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.resize-handle-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.canvas-region-container .resize-handle { background: var(--warn); }
.selection-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1.25rem; max-width: 640px;
}
.selection-panel form { margin-top: .6rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.selection-panel form:first-of-type { margin-top: .3rem; }

/* ---- nested-grid navigation (breadcrumb) ---------------------------------- */
.breadcrumb { margin: .5rem 0 1rem; font-size: .95rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---- backgrounds / decorations --------------------------------------------- */
.color-swatch { display: inline-block; width: 1em; height: 1em; border-radius: 3px;
                border: 1px solid var(--border); vertical-align: -0.15em; margin-right: .3em; }

/* ---- layout edit page: tabs ------------------------------------------------ */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--border); margin: 1rem 0 1.5rem; }
.tab-btn {
  background: none; border: none; font: inherit; font-weight: 600; font-size: .95rem;
  color: var(--muted); cursor: pointer; padding: .6rem 1rem; margin-bottom: -2px;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- widget palette --------------------------------------------------------- */
.widget-palette { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; }
.palette-tile {
  cursor: grab; user-select: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .6rem 1rem; font-size: .85rem; font-weight: 600; color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.palette-tile:active { cursor: grabbing; }

/* ---- regions tab: canvas + properties panel ------------------------------- */
.editor-split { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1.5rem; }
.editor-canvas-col { flex: 1 1 420px; min-width: 0; }
.editor-canvas-col .layout-canvas { max-width: none; }
.properties-panel {
  flex: 0 0 320px; min-width: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; position: sticky; top: 1rem;
}
.properties-panel h3 { margin: 0 0 .75rem; font-size: 1.05rem; }
.properties-panel h3 .muted { font-weight: 500; font-size: .85rem; margin-left: .4rem; }
.properties-panel form { margin-bottom: .75rem; }
.properties-panel .inline-select { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.rect-form { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .75rem; align-items: center; }
.rect-form label { display: flex; align-items: center; gap: .4rem; font-size: .85rem; margin: 0; }
.rect-form button { grid-column: 1 / -1; justify-self: start; }
.widget-fields-panel { border: 1px solid var(--border); border-radius: 6px; padding: .75rem 1rem; margin: .75rem 0; }
.widget-fields-panel legend { font-weight: 600; font-size: .85rem; padding: 0 .3rem; }
.widget-fields-panel label { display: block; margin-bottom: .5rem; font-size: .85rem; }
.widget-fields-panel .draft-save { margin-top: .5rem; width: auto; }
.canvas-region.selected { border-width: 3px; box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.canvas-region.canvas-region-container.selected { box-shadow: 0 0 0 3px rgba(154, 52, 18, .25); }
.add-region-manual { margin-top: .5rem; }
.add-region-manual summary { cursor: pointer; font-size: .9rem; }
.add-region-manual form { margin-top: .75rem; }

/* ---- region style editor ----------------------------------------------- */
.style-details { margin: .75rem 0; }
.style-details summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.style-form { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .75rem; margin-top: .6rem; }
.style-form label { display: block; font-size: .85rem; margin: 0; }
.style-form label.span2, .style-form button { grid-column: 1 / -1; }
.style-form button { justify-self: start; width: auto; }
.widget-fields-panel p.muted { font-size: .8rem; margin: .25rem 0 .5rem; }

.layer-form { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; font-size: .85rem; }
.layer-form label { display: flex; align-items: center; gap: .4rem; margin: 0; }

.css-input { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.style-form p.muted { font-size: .78rem; margin: 0; }

.row-actions { white-space: nowrap; }
.row-actions .inline { display: inline; margin-left: .5rem; }
.row-edit { display: inline-block; }
.row-edit summary { cursor: pointer; color: var(--primary); list-style: none; display: inline; }
.row-edit summary::-webkit-details-marker { display: none; }
.row-edit[open] { display: block; margin-top: .5rem; }
.row-edit[open] .form-grid { white-space: normal; min-width: 420px; margin-top: .5rem; }

/* ---- users page ------------------------------------------------------- */
.alert.notice { background: #eaf7ee; border-color: #b7e0c3; color: #1e6b36; }
.alert.notice code { font-size: .9rem; word-break: break-all; }
.user-manage { min-width: 480px; white-space: normal; }
.user-manage .form-grid { margin-bottom: .75rem; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.checkbox-grid label { display: flex; align-items: center; gap: .35rem; font-size: .85rem; margin: 0; }
.user-actions { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .9rem; }

/* ---- alerts page ------------------------------------------------------ */
.badge.danger { background: var(--danger-bg); color: var(--danger); }
tr.row-active td { background: #fff8e6; }
.button-row { display: flex; gap: .75rem; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); width: auto; }
.small { font-size: .8rem; }
.row-actions .inline label { margin-right: .3rem; }

/* ---- layout editor workspace (3-panel) --------------------------------------
   The editor is a workspace, not a settings page: palette left, canvas
   taking the width, a sticky inspector right. It escapes the normal
   .page max-width so a 1920px desktop gives the canvas ~1200px. */
.editor { padding: 0 1.25rem 1.5rem; }
.editor-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; padding: 1rem 0 .75rem; }
.editor-head h1 { margin: .15rem 0 0; font-size: 1.5rem; }
.crumbs { font-size: .85rem; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.editor-actions.tabs { border-bottom: none; margin: 0; align-items: center; gap: .5rem; }
.editor-actions .canvas-dims { margin-right: .75rem; font-size: .85rem; }
.editor-actions .tab-btn { border: 1px solid var(--border); border-radius: 6px; padding: .45rem .9rem; margin: 0; }
.editor-actions .tab-btn.active { border-color: var(--primary); }
.editor-actions .tab-btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.editor-actions .tab-btn-primary.active { background: var(--primary); color: #fff; }
.editor-alert { margin-bottom: .75rem; }

.workspace { display: grid; grid-template-columns: 220px minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .workspace { grid-template-columns: 1fr; } .palette, .inspector { position: static; max-height: none; } }

.panel-title { font-weight: 700; font-size: .95rem; margin-bottom: .6rem; }
.panel-title .muted { font-weight: 500; font-size: .8rem; margin-left: .35rem; }

.palette { position: sticky; top: .75rem; max-height: calc(100vh - 2rem); overflow: auto;
           background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
.palette-group { margin-bottom: .9rem; }
.palette-group-label { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 .35rem .2rem; }
.palette .palette-tile { display: flex; align-items: center; gap: .55rem; padding: .45rem .55rem; margin-bottom: .25rem;
                          border: 1px solid transparent; border-radius: 6px; box-shadow: none; font-weight: 500; font-size: .88rem; }
.palette .palette-tile:hover { background: var(--bg); border-color: var(--border); }
.palette-icon { display: inline-flex; width: 1.5rem; height: 1.5rem; align-items: center; justify-content: center;
                background: var(--bg); border-radius: 5px; font-size: .85rem; font-weight: 700; flex: 0 0 auto; }
.palette-hint { margin-top: .5rem; line-height: 1.35; }

.stage { min-width: 0; }
.stage-toolbar { display: flex; gap: 1.25rem; align-items: center; font-size: .85rem; margin-bottom: .5rem; }
.stage-toolbar label { display: flex; align-items: center; gap: .35rem; margin: 0; }
.stage-scroll { background: #2a2f36; border-radius: var(--radius); padding: 1rem; }
.stage .layout-canvas { max-width: none; margin: 0 auto; background: #0b0d10; border-color: #444; }
.layout-canvas.show-grid {
  background-image:
    linear-gradient(to right, rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 2.5% 2.5%;
}
.stage .canvas-region { color: #dfe7f5; background: rgba(37, 99, 235, 0.28); }
.stage .canvas-region.canvas-region-container { color: #ffd6b8; }
.stage .add-region-manual { margin-top: .6rem; }

.inspector { position: sticky; top: .75rem; max-height: calc(100vh - 2rem); overflow: auto;
             background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.prop-group { border-top: 1px solid var(--border); padding: .5rem 0 .6rem; }
.prop-group:first-of-type { border-top: none; }
.prop-group > summary { cursor: pointer; font-weight: 600; font-size: .9rem; padding: .3rem 0; list-style: none; display: flex; align-items: center; gap: .4rem; }
.prop-group > summary::-webkit-details-marker { display: none; }
.prop-group > summary::before { content: "▸"; font-size: .75rem; color: var(--muted); }
.prop-group[open] > summary::before { content: "▾"; }
.inspector form { margin: .45rem 0 .6rem; }
.inspector .form-grid { grid-template-columns: 1fr 1fr; gap: .45rem .6rem; }
.inspector .form-grid label, .inspector .style-form label, .inspector .widget-fields-panel label { font-size: .82rem; }
.inspector .form-grid button, .inspector .widget-fields-panel .draft-save, .inspector .style-form button { width: auto; }
.inspector h3 { font-size: .9rem; margin: .8rem 0 .25rem; }
.inspector p.muted { font-size: .8rem; margin: .2rem 0 .4rem; }
.inspector table { font-size: .82rem; }
.rect-title { grid-column: 1 / -1; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: .25rem; }
.rect-form label { font-size: .82rem; }
.publish-panel { max-width: 720px; }

.publish-panel { max-width: 720px; margin: 0 auto; }

/* ---- interface polish pass ------------------------------------------------
   Compact table actions, floating edit popovers (so an inline edit never
   stretches its table row), consistent headings and form buttons. */
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h1 .badge { vertical-align: middle; margin-left: .35rem; }
.page > div > p.muted:first-of-type, .page > div > h1 + p.muted { max-width: 70ch; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
td { vertical-align: middle; }
.row-actions { white-space: nowrap; text-align: right; position: relative; }
.row-actions form.inline, .row-actions .row-edit { display: inline-block; margin-left: .75rem; vertical-align: middle; }
.row-actions button { font-size: .85rem; }
.row-actions button.link, .row-edit summary { font-size: .85rem; font-weight: 600; }
.row-edit { position: relative; }
.row-edit summary { padding: .2rem 0; }
.row-edit[open] { display: inline-block; margin-top: 0; }
/* the expanded editor floats over the table instead of inflating the row */
.row-edit[open] > *:not(summary) {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 1rem 1.25rem; text-align: left; white-space: normal;
  min-width: 460px;
}
.row-edit[open] > .form-grid { display: grid; margin: 0; max-width: none; }
.row-edit[open] > .user-manage { min-width: 520px; }
.form-grid { gap: 0 1.25rem; }
.form-grid label { margin: .6rem 0 0; font-size: .88rem; }
.form-grid button { margin-top: 1rem; }
.form-grid .button-row button { margin-top: 0; }
.inline-select button, .inline-select select { margin: 0; }
.alert { margin: .75rem 0 1rem; }
.alert.notice { margin: .75rem 0 1rem; }

/* alerts table: one tidy actions row per alert */
.alert-actions { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; flex-wrap: nowrap; }
.alert-actions form.inline { margin: 0; display: inline-flex; align-items: center; gap: .4rem; }
.alert-actions .rect-input { width: 3.6em; margin: 0; padding: .35rem .45rem; }
.alert-actions label { margin: 0; font-weight: 400; display: inline-flex; align-items: center; gap: .3rem; }
tr.row-active td:first-child { border-left: 3px solid var(--warn); }

.row-edit summary:focus { outline: none; }
.row-edit summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }
.row-edit[open] > summary { color: var(--text); }
.big-num { font-size: 1.15rem; }
.date-input { display: inline-block; width: auto; margin: 0; padding: .35rem .45rem; }

/* ---- dashboard / topbar ------------------------------------------------- */
.topbar-warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; font-size: .85rem;
               padding: .3rem .7rem; border-radius: 999px; text-decoration: none; }
.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.4rem; min-width: 130px; }
.stat-num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: .2rem; }
.stat.ok .stat-num { color: #1e7e34; }
.stat.bad .stat-num { color: var(--danger); }

/* ---- schedule fields ------------------------------------------------------ */
.sched-form { min-width: 420px; }
.sched-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .75rem; }
.sched-grid label { font-size: .82rem; margin: .3rem 0 0; }
.sched-days { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; margin: .6rem 0 .2rem; }
.sched-days label { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; margin: 0; font-weight: 500; }
.sched-days input { width: auto; margin: 0; }
.sched-visible { display: flex; align-items: center; gap: .4rem; font-size: .85rem; margin: .2rem 0 .4rem; }
.sched-form button { margin-top: .6rem; }
.prop-group summary .badge { font-size: .68rem; vertical-align: middle; }

/* ---- editor tranche 2: undo/redo, layers, context menu, zoom ------------- */
.icon-btn { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
            padding: .3rem .55rem; font-size: .9rem; line-height: 1; }
.icon-btn:hover { background: var(--bg); filter: none; }
.icon-btn:disabled { opacity: .4; cursor: default; background: var(--surface); }
.editor-actions form.inline { display: inline-block; margin: 0 .15rem 0 0; }
.saved-indicator { font-size: .8rem; margin-right: .5rem; }
.kbd-hint { cursor: help; margin-left: auto; }
.kbd { float: right; margin-left: 1.5rem; font-size: .72rem; color: var(--muted); }
.layers-title { margin-top: 1rem; display: flex; justify-content: space-between; align-items: baseline; }
.layers { list-style: none; margin: 0; padding: 0; }
.layer-row { display: flex; align-items: center; justify-content: space-between; gap: .3rem; padding: .25rem .3rem;
             border-radius: 6px; border: 1px solid transparent; }
.layer-row:hover { background: var(--bg); }
.layer-row.selected { background: #e8effd; border-color: var(--primary); }
.layer-row.is-hidden .layer-name { opacity: .5; text-decoration: line-through; }
.layer-row.is-locked .layer-name::after { content: " 🔒"; font-size: .7rem; }
.layer-select { flex: 1 1 auto; min-width: 0; text-align: left; background: none; border: 0; padding: .15rem .2rem;
                color: var(--text); font-weight: 500; font-size: .85rem; display: flex; flex-direction: column; gap: 0; }
.layer-select .muted { font-size: .7rem; font-weight: 400; }
.layer-tools { display: flex; gap: .15rem; flex: 0 0 auto; }
.layer-tools form.inline { display: inline-flex; gap: .15rem; margin: 0; }
.layer-tools .icon-btn { padding: .15rem .35rem; font-size: .75rem; }
.canvas-region.is-locked { cursor: default; border-style: dotted; }
.canvas-region.is-locked .resize-handle { display: none; }
.canvas-region.is-hidden { opacity: .35; }
.ctx-menu { position: fixed; z-index: 3000; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
            box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: .3rem; min-width: 210px; }
.ctx-menu button { display: block; width: 100%; text-align: left; background: none; color: var(--text); border: 0;
                   padding: .45rem .7rem; border-radius: 5px; font-weight: 500; font-size: .88rem; }
.ctx-menu button:hover { background: var(--bg); filter: none; }
.ctx-menu button.danger-link { color: var(--danger); }
#zoom-select { margin: 0; padding: .25rem .4rem; width: auto; }

/* ---- editor tranche 2 additions ---------------------------------------------- */
.layer-row[draggable="true"] { cursor: grab; }
.layer-row.dragging { opacity: .45; background: var(--bg); }
.layout-canvas.show-safe::after {
  content: ""; position: absolute; inset: 5%; border: 2px dashed rgba(255, 200, 60, .75);
  pointer-events: none; z-index: 900; border-radius: 4px;
}

/* ---- display-bug fixes ---------------------------------------------------- */
/* inspector: never let a wide <select> (long media names) push past the panel */
.inspector select, .inspector input[type="text"], .inspector input[type="password"], .inspector textarea,
.inspector input[type="number"]:not(.rect-input), .inspector input[type="date"], .inspector input[type="time"] {
  max-width: 100%; box-sizing: border-box;
}
.inspector select { width: 100%; }
/* forms: a row of buttons must not stretch to the grid row's height, and
   checkbox groups take their own full row instead of floating beside a field */
.form-grid .button-row { grid-column: 1 / -1; align-items: center; margin-top: 1rem; }
.form-grid .button-row button { margin-top: 0; height: auto; align-self: center; }
.form-grid .checkbox-grid { grid-column: 1 / -1; margin-top: .6rem; }
.form-grid .checkbox-inline + label, .form-grid label:has(> .checkbox-inline) { align-self: end; }
.field-title { font-weight: 700; font-size: .8rem; margin-top: .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- multi-select alignment ------------------------------------------------- */
.align-bar { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem;
             background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .35rem .6rem; }
.align-bar button { padding: .25rem .55rem; font-size: 1rem; line-height: 1; background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.align-bar button:hover { background: var(--surface); border-color: var(--primary); }
.align-count { font-size: .8rem; font-weight: 600; margin-right: .3rem; }
.canvas-region.multi { outline: 2px solid #f59e0b; outline-offset: -2px; }

/* ---- shell & readability pass ------------------------------------------------
   Problems this fixes, all visible on a wide monitor:
   - content hugged the left with a dead right half
   - explanatory paragraphs ran 150+ characters wide (unreadable measure)
   - sections had no visual separation from each other
   - forms sprawled to the full column width instead of a sane form measure  */

/* The grid's content column gets a readable ceiling of its own, so a 2560px
   monitor doesn't stretch a settings form across two feet of glass. */
.page.withsidebar > div { max-width: 1040px; }

/* Every block of explanatory prose, wherever it appears, is capped at a
   comfortable reading measure rather than only the first paragraph. */
.page p, .page .muted, .page li { max-width: 78ch; }
.page p.muted { line-height: 1.5; }

/* Section rhythm: each h2 starts a visually distinct band with a rule above
   it, so "Media storage" and "Branding" read as separate things. */
.page h2 {
  margin: 2.25rem 0 .35rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 1.15rem;
}
.page h1 + h2, .page h1 + p + h2, .page h1 + .alert + h2 { border-top: none; padding-top: 0; margin-top: 1.25rem; }
.page h3 { margin: 1.25rem 0 .3rem; font-size: .98rem; }

/* Forms read as cards, at a form-appropriate width rather than the full
   column — long single-line inputs are harder to scan, not easier. */
.page > div > form.form-grid {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; max-width: 720px; margin: .75rem 0 .5rem;
}
.page > div > form.form-grid + p.muted { margin-top: .6rem; }

/* Tables sit flush with the section heading and stretch to the column. */
.page table { margin-top: .75rem; }

/* Sidebar aligns with the top of the content instead of floating. */
.page.withsidebar { padding-top: .25rem; }
.sidebar { top: 1rem; }

/* Field help under an input, for the places where a placeholder isn't enough. */
.field-help { display: block; font-size: .78rem; color: var(--muted); margin-top: .2rem; max-width: 60ch; }
.help-note { max-width: 720px; margin: .25rem 0 .5rem; }
.help-note summary { cursor: pointer; font-size: .85rem; }
.help-note p { margin: .5rem 0; font-size: .85rem; }

/* header primary action, styled as a button but semantically a link to the
   page's create form (which stays in place — no modal machinery yet) */
.btn-primary-link {
  display: inline-flex; align-items: center; height: var(--control-h); padding: 0 1rem;
  background: var(--primary); color: var(--primary-text); border-radius: var(--radius-input);
  font-weight: 600; font-size: var(--fs-body); text-decoration: none; white-space: nowrap;
}
.btn-primary-link:hover { background: var(--primary-hover); }
h2[id="add"], h3[id="add"] { scroll-margin-top: 5rem; }
/* headings inside the content column: the page-head rule already provides the
   top separator, so the first h2 after it shouldn't double up */
.page-head + h2, .page-head + .alert + h2 { border-top: none; padding-top: 0; margin-top: .5rem; }
.media-font-tile { display: flex; align-items: center; justify-content: center; height: 120px;
                   background: var(--surface-alt); border: 1px dashed var(--border-strong);
                   border-radius: var(--radius-input); font-size: 2rem; font-weight: 700; color: var(--muted); }

/* ---- media drop zone --------------------------------------------------- */
.dropzone { position: relative; display: block; border: 2px dashed var(--border-strong); border-radius: var(--radius);
            background: var(--surface-alt); padding: 2rem 1rem; text-align: center; cursor: pointer;
            transition: border-color .12s, background .12s; margin-top: .5rem; }
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #f3f7ff; }
.dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; min-height: 0; }
.dropzone-text { display: block; font-weight: 400; font-size: var(--fs-body); }
.dropzone-files { display: block; margin-top: .6rem; }
/* brief highlight on the field the + Add button lands you in */
.focus-flash { animation: focus-flash 1.2s ease-out; }
@keyframes focus-flash {
  0%   { box-shadow: 0 0 0 4px rgba(37, 99, 235, .35); }
  100% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0); }
}

/* Account page: two-factor setup and recovery codes */
.mfa-setup { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; margin: .5rem 0 1rem; }
.mfa-qr { background: #fff; padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius); line-height: 0; min-width: 236px; min-height: 236px; }
.mfa-qr svg { display: block; }
.mfa-secret { font-size: 1.05rem; letter-spacing: .08em; word-break: break-all; }
.recovery-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: .5rem; margin: .5rem 0 1.5rem; max-width: 44rem; }
.recovery-codes code { font-size: 1.05rem; padding: .45rem .6rem; text-align: center; letter-spacing: .06em; }
.topbar nav a.muted { text-decoration: none; }
.topbar nav a.muted:hover { text-decoration: underline; }
