/* Admin-specific styles. Inherits primitives from /styling/style.css. */

@import url('/core/_tokens.css');

:root {
  /* Admin tokens are aliases over the unified scale in /core/_tokens.css. */
  --admin-sidebar-bg: var(--brand-blue);
  --admin-bg:         var(--bg);
  --admin-surface-1:  var(--white);
  --admin-surface-2:  var(--acc-1);
  --admin-surface-3:  var(--border);
  --admin-surface-4:  var(--border-2);
  --admin-border:     var(--border);
  --admin-border-2:   var(--border-2);
  --admin-muted:      var(--muted);
  --admin-muted-2:    #A1A1AA;
  --admin-text:       var(--brand-blue);
  --admin-accent:     var(--brand-blue);
  --admin-radius:        12px;
  --admin-radius-inner:  8px;
}

.admin-body {
  margin: 0;
  min-height: 100vh;
  background: var(--admin-bg);
  color: var(--admin-text);
  /* Override global `body { overflow: hidden }` so the page scrolls. The sidebar
     is position:fixed (out of flow, always full-height); .admin-main is offset by
     its width. No grid — that let the sticky sidebar scroll away once the page
     grew taller than the viewport. */
  overflow: auto;
}

/* Admin uses ONE scroll container: body.admin-body (overflow:auto above). The
   Views tab borrows the view-editor markup but NOT the client shell's
   height-capped flex/internal-scroll layout. These admin-owned rules override
   the unscoped `.vwe-*` rules in /styling/style.css (which serve the client
   shell + in-app drawer) so the Views body is a plain grid that grows with its
   content and scrolls at the page level — letting the sticky rail (.vwe-rail)
   stick against the single body scroll. No `overflow` ancestor may sit between
   body.admin-body and the rail, or sticky breaks. */
.admin-view-builder {
  /* plain block — no flex/overflow constraints */
}
.admin-view-builder-header {
  /* normal non-sticky header, consistent with the Clients tab */
  margin-bottom: 16px;
}
.admin-view-builder-header .vwe-modal-title {
  font-family: Outfit, system-ui, sans-serif;
  color: var(--admin-text);
}
.admin-view-builder-header .vwe-modal-sub {
  color: var(--admin-muted);
  font-size: .9rem;
}
.admin-view-builder .vwe-page-body {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 20px;
  /* Reset the client-shell base rule (style.css `.vwe-page-body`) which sets
     flex:1/overflow:hidden/min-height:0 for the height-capped shell. We win on
     specificity for the props we set, but must explicitly clear the rest so no
     overflow-clipping ancestor sits above the sticky rail. */
  flex: none;
  overflow: visible;
  min-height: auto;
}
.admin-view-builder .vwe-left,
.admin-view-builder .vwe-right {
  /* let the page scroll; do NOT reintroduce overflow-y:auto here */
  overflow: visible;
}
/* The view-list is short; keep it pinned so its column doesn't leave a blank
   white band as the (much taller) document scrolls beside it. */
.admin-view-builder .vwe-left {
  position: sticky;
  top: 92px; /* clear the sticky page header */
  align-self: start;
}
/* Keep the overview rail below the sticky header too (only sticky at wide widths;
   it goes static ≤1024px via the media query below). */
.admin-view-builder .vwe-rail { top: 92px; }

/* Keep the document canvas from being starved by the side columns (admin nav 220
   + view-list 200 + overview rail). The doc has `min-width:0`, so a hard-width
   rail would otherwise collapse it to near-zero on normal windows (labels
   char-wrap, controls become slivers).

   The real constraint is the *editor* width — i.e. the space left after the
   admin nav and the view-list, NOT the viewport. A viewport media query can't
   see that the nav+list have already eaten 420px, so it mis-fires. We make
   `.vwe-editor` a query container and drive the rail split + the field tiling
   off its own inline-size with @container queries. This is robust to the
   view-list collapsing (≤900px), to the admin sidebar, and to any future
   chrome, because every breakpoint keys on the actual editor width. */
.admin-view-builder .vwe-editor {
  container-type: inline-size;
  container-name: vwe-editor;
  grid-template-columns: minmax(0, 1fr) 220px;
}

/* The grid TRACKS of .vwe-editor cannot be restyled from inside its own
   @container (a container can't query itself for its own track sizing without
   risking a layout loop), so the rail-drop breakpoint stays a viewport media
   query. It is intentionally generous: by ~1024px the rail is better below the
   doc regardless of list state. The field tiling below is what does the heavy
   responsive lifting, and that IS container-driven. */
@media (max-width: 1024px) {
  .admin-view-builder .vwe-editor { grid-template-columns: minmax(0, 1fr); }
  .admin-view-builder .vwe-rail {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 16px;
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--admin-border);
  }
  .admin-view-builder .vwe-rail-nav { flex-direction: row; flex-wrap: wrap; }
}

/* Narrow: collapse the view-list above the editor. */
@media (max-width: 900px) {
  .admin-view-builder .vwe-page-body { grid-template-columns: minmax(0, 1fr); }
  .admin-view-builder .vwe-left {
    border-right: 0;
    border-bottom: 1px solid var(--admin-border);
    padding-bottom: 12px;
  }
}

/* ── Responsive multi-column field tiling (container-driven) ──
   The old single-column list wasted all the horizontal whitespace: short labels
   over full-width mock bars made the document a mile-long ladder of near-empty
   rows. Tile the fields into 1/2/3 columns keyed off the *document* width via
   @container, so a mock control stays readably wide (~250px+) at each step.
   `minmax(0, 1fr)` on every track keeps long labels from forcing overflow.
   DnD is id/target based (not geometry), so tiling is safe. */
.admin-view-builder .vwe-field-list {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 10px 16px;
}
/* The canvas itself is the meaningful width for tiling fields. Make .vwe-doc a
   query container so columns key on the document, not the editor (which still
   includes the rail at wide sizes). */
.admin-view-builder .vwe-doc {
  container-type: inline-size;
  container-name: vwe-doc;
}
@container vwe-doc (min-width: 560px) {
  .admin-view-builder .vwe-field-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@container vwe-doc (min-width: 860px) {
  .admin-view-builder .vwe-field-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
/* Textarea-type fields get a roomier mock bar; let them span the full row so
   they don't sit awkwardly half-width next to short single-line fields. */
.admin-view-builder .vwe-field:has(.vwe-mock-ctrl.tall) {
  grid-column: 1 / -1;
}

.admin-sidebar {
  background: var(--admin-sidebar-bg);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* Fixed full-height rail — always visible, never scrolls away. */
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 220px;
  box-sizing: border-box;
  z-index: 50;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.18) transparent;
}

.admin-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.admin-brand-title { font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; }
.admin-brand-sub   { font-size: .8rem; opacity: .55; font-weight: 400; }

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}
.admin-nav-item {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,.85);
  text-align: left;
  padding: 10px 12px;
  min-height: 40px;
  border-radius: var(--admin-radius-inner);
  cursor: pointer;
  font: inherit;
  transition-property: background, color, transform;
  transition-duration: .15s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.admin-nav-item:hover  { background: rgba(255,255,255,.08); color: #fff; }
.admin-nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.admin-nav-item:active { transform: scale(0.96); }
.admin-nav-item:focus-visible {
  outline: 2px solid rgba(255,255,255,.85);
  outline-offset: 2px;
}

.admin-main {
  /* Offset by the fixed sidebar; content fills the remaining width. */
  margin-left: 220px;
  padding: 24px 32px;
  max-width: 1560px;
  width: auto;
  box-sizing: border-box;
}

/* Sticky page header — pins to the top while the (long) page scrolls. Bleeds
   into .admin-main's padding so its opaque background covers edge-to-edge and
   content tucks cleanly underneath. */
.admin-page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--admin-bg);
  margin: -24px -32px 16px;
  padding: 18px 32px 10px;
  border-bottom: 1px solid var(--admin-border);
}
.admin-page-header h1 { margin: 0 0 4px; font-family: Outfit, system-ui, sans-serif; color: var(--admin-text); }
.admin-page .page-header { background: transparent; }
.admin-page-sub       { margin: 0; color: var(--admin-muted); }

.admin-card {
  background: var(--admin-surface-1);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  padding: 16px;
}

.admin-hint { color: var(--admin-muted); font-size: .85rem; margin-top: 12px; }

/* ── Clients: responsive card grid ── */
.admin-client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  align-items: start;
}

.admin-client-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius);
  background: var(--admin-surface-1);
  transition: border-color .15s, box-shadow .15s;
}
.admin-client-card:hover { border-color: var(--admin-border-2); box-shadow: 0 2px 10px rgba(0,0,0,.05); }
/* An open card spans the full grid width so the roomy panel has room. */
.admin-client-card.is-open {
  grid-column: 1 / -1;
  border-color: var(--admin-accent);
  box-shadow: 0 6px 24px rgba(0,0,0,.08);
}

.admin-client-cardhead {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.admin-client-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--admin-radius-inner);
  border: 1px solid var(--admin-border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: Outfit, system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.admin-client-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.admin-client-ident { min-width: 0; }
.admin-client-name {
  font-weight: 600;
  color: var(--admin-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-client-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  color: var(--admin-muted);
  font-variant-numeric: tabular-nums;
}
.admin-client-open {
  color: var(--admin-accent);
  text-decoration: none;
  font-weight: 600;
  font-size: .85rem;
  white-space: nowrap;
}
.admin-client-open:hover { text-decoration: underline; }

/* Live branding preview strip on each card. */
.admin-swatch-strip {
  display: flex;
  height: 18px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--admin-border-2);
}
.admin-swatch-strip-cell { flex: 1; }

.admin-client-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-client-viewline { min-width: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-client-metalabel {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--admin-muted-2);
  margin-right: 4px;
}
.admin-client-viewname { color: var(--admin-muted); }

.admin-client-edit {
  appearance: none;
  border: 1px solid var(--admin-border-2);
  background: var(--admin-surface-1);
  color: var(--admin-text);
  font: inherit;
  font-weight: 600;
  font-size: .85rem;
  padding: 6px 14px;
  border-radius: var(--admin-radius-inner);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, border-color .15s, transform .1s;
}
.admin-client-edit:hover  { background: var(--admin-surface-2); border-color: var(--admin-accent); }
.admin-client-edit:active { transform: scale(0.96); }
.admin-client-edit[aria-expanded="true"] { background: var(--admin-accent); color: #fff; border-color: var(--admin-accent); }
.admin-client-edit:focus-visible { outline: 2px solid var(--admin-accent); outline-offset: 2px; }

/* ── Inline settings panel (expand-in-place) ── */
.admin-client-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  margin-top: 4px;
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius-inner);
  background: var(--admin-surface-2);
}

.admin-panel-section { display: flex; flex-direction: column; gap: 10px; }
.admin-panel-section-title {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--admin-muted-2);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--admin-border);
}
.admin-panel-section-body { display: flex; flex-direction: column; gap: 12px; }

.admin-field { display: flex; flex-direction: column; gap: 6px; }
.admin-field-label { font-size: .85rem; font-weight: 600; color: var(--admin-text); }
.admin-input {
  padding: 6px 8px;
  border: 1px solid var(--admin-border-2);
  border-radius: var(--admin-radius-inner);
  background: var(--admin-surface-1);
  font: inherit;
  color: var(--admin-text);
}
.admin-input:focus { outline: 2px solid var(--admin-accent); outline-offset: -1px; }
.admin-subnote { font-size: .78rem; color: var(--admin-muted); }

.admin-color-rows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
}
.admin-color-row {
  display: grid;
  grid-template-columns: 80px 32px 1fr;
  align-items: center;
  gap: 8px;
}
.admin-color-label { font-size: .82rem; color: var(--admin-muted); }
.admin-color-picker {
  width: 32px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--admin-border-2);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.admin-hex-input {
  padding: 4px 6px;
  border: 1px solid var(--admin-border-2);
  border-radius: var(--admin-radius-inner);
  background: var(--admin-surface-1);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .85rem;
  color: var(--admin-text);
  min-width: 0;
}
.admin-hex-input.invalid { border-color: #c0392b; background: #fdecea; }

.admin-color-preview {
  display: flex;
  gap: 0;
  height: 24px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--admin-border-2);
}
.admin-preview-swatch { flex: 1; }

.admin-panel-note { font-size: .8rem; color: var(--admin-muted); margin: 0; }
.admin-panel-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Views layout */
.admin-views-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  min-height: 70vh;
}

.admin-views-left  { border-right: 1px solid var(--admin-border); padding-right: 12px; }
.admin-views-right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.admin-views-actions { margin-bottom: 8px; }
.admin-views-list    { list-style: none; padding: 0; margin: 0; }
.admin-views-list li {
  padding: 8px 10px;
  border-radius: var(--admin-radius-inner);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-views-list li:hover    { background: var(--admin-surface-3); }
.admin-views-list li.selected { background: var(--admin-surface-4); font-weight: 600; }
.admin-views-list li .ro      { font-size: .7rem; color: var(--admin-muted-2); margin-left: 6px; }

.admin-views-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-views-toolbar .spacer { flex: 1; }

.admin-input {
  padding: 6px 10px;
  border: 1px solid var(--admin-border-2);
  border-radius: var(--admin-radius-inner);
  font: inherit;
  min-width: 240px;
  background: var(--admin-surface-1);
  color: var(--admin-text);
}

.admin-json {
  width: 100%;
  flex: 1;
  min-height: 380px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  padding: 10px;
  border: 1px solid var(--admin-border-2);
  border-radius: var(--admin-radius-inner);
  resize: vertical;
  background: var(--admin-surface-2);
  color: var(--admin-text);
}

.admin-status         { min-height: 1.5em; font-size: .9rem; }
.admin-status .ok     { color: var(--admin-text); font-weight: 600; }
.admin-status .err    { color: var(--admin-text); white-space: pre-wrap; font-weight: 600; }
.admin-status .warn   { color: var(--admin-muted); }

/* Logout button (sidebar) */
.admin-sidebar-footer { margin-top: auto; padding-top: 12px; }
.admin-logout {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,.22);
  color: rgba(255,255,255,.9);
  padding: 9px 12px;
  min-height: 40px;
  border-radius: var(--admin-radius-inner);
  cursor: pointer;
  font: inherit;
  transition-property: background, color, border-color, transform;
  transition-duration: .15s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.admin-logout:hover  { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.35); }
.admin-logout:active { transform: scale(0.96); }
.admin-logout:focus-visible {
  outline: 2px solid rgba(255,255,255,.85);
  outline-offset: 2px;
}

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--brand-blue, #1a2540);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-overlay.hidden { display: none; }

.login-card {
  background: #fff;
  border-radius: var(--admin-radius);
  padding: 32px 36px;
  width: min(420px, 92vw);
  box-shadow: 0 24px 60px rgba(0,0,0,.32);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}
.login-title {
  margin: 0;
  font-family: Outfit, system-ui, sans-serif;
  color: var(--admin-text);
  font-size: 1.6rem;
}
.login-sub {
  margin: 0;
  color: var(--admin-muted);
  font-size: .95rem;
}

.pin-inputs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 4px 0;
}
.pin-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  text-align: center;
  font-size: 1.6rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--admin-border-2);
  border-radius: var(--admin-radius-inner);
  background: var(--admin-surface-2);
  color: var(--admin-text);
  box-sizing: border-box;
  padding: 0;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.pin-box:focus {
  border-color: var(--admin-accent);
  box-shadow: 0 0 0 2px rgba(26, 37, 64, .12);
}

.login-error {
  background: rgba(192, 57, 43, .08);
  color: #b3261e;
  border: 1px solid rgba(192, 57, 43, .25);
  border-radius: var(--admin-radius-inner);
  padding: 8px 10px;
  font-size: .9rem;
}
.login-error.hidden { display: none; }

.login-submit {
  background: var(--admin-accent);
  color: #fff;
  border: 0;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: var(--admin-radius-inner);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition-property: filter, transform, box-shadow;
  transition-duration: .15s;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.login-submit:hover  { filter: brightness(1.08); }
.login-submit:active { transform: scale(0.96); }
.login-submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(24,24,27,.22);
}
