/* =========================================================================
   abacus-arcsystem — components.css
   Buttons, forms, cards, alerts, tables, and the admin/public shells.

   RULE: consume the design tokens from colors_and_type.css + themes.css.
   No hardcoded colors / type / spacing / radii / shadows. The handful of
   layout dimensions that the token system doesn't define are declared here
   as local CSS variables so every value is still a var().
   ========================================================================= */

:root {
  --sidebar-width: 248px;
  --topbar-height: 60px;
  --content-max: 1100px;
  /* Pre-launch fix D: prose/lead readability ceiling. Public body text fills
     the content container on normal desktops (no dead right third) but caps at
     ~100ch so lines don't run unreadably long on ultrawide monitors. Used as
     `max-width: min(100%, var(--prose-max))` so mobile/tablet are unaffected
     (100% wins below the cap). */
  --prose-max: 100ch;
  /* White text sits on the orange accent in both light and dark themes,
     so this is an intentional theme-independent constant. */
  --on-accent: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--accent-deep); }

/* ---------- Buttons --------------------------------------------------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1.2;
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-4);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  text-decoration: none;
  transition: background-color var(--dur-base) var(--ease-out),
              border-color var(--dur-base) var(--ease-out),
              color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-deep); }
.btn.primary:active { transform: translateY(1px); box-shadow: var(--shadow-xs); }
.btn.secondary { background: var(--bg-elev); color: var(--fg); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--bg-sunken); border-color: var(--fg-subtle); }
.btn.ghost { background: transparent; color: var(--fg); }
.btn.ghost:hover { background: var(--bg-sunken); }
.btn.danger { background: var(--danger); color: var(--on-accent); }
.btn.danger:hover { filter: brightness(0.92); }
.btn.lg { padding: var(--s-3) var(--s-5); font-size: var(--fs-body); border-radius: var(--r-lg); }
.btn.sm { padding: var(--s-1) var(--s-3); font-size: var(--fs-eyebrow); border-radius: var(--r-sm); }
.btn[disabled], .btn.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ---------- Forms ----------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field > label {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-sm);
  color: var(--fg);
}
.field > label .req { color: var(--danger); }
.field .hint { font-size: var(--fs-xs); color: var(--fg-subtle); }
.field .err { font-size: var(--fs-xs); color: var(--danger); }

.input, .select, .textarea {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-elev);
  color: var(--fg);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.input::placeholder { color: var(--fg-subtle); }
.input.error, .select.error { border-color: var(--danger); }
.textarea { min-height: var(--s-24); resize: vertical; }

.checkbox, .radio {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--fg);
}
.checkbox input, .radio input { accent-color: var(--accent); }

/* ---------- Cards ----------------------------------------------------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s-4); }
.card h2, .card h3 { margin-top: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-4);
}

/* ---------- Alerts / flash -------------------------------------------- */
.alert {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-3);
}
.alert.success { background: color-mix(in srgb, var(--success) 10%, var(--bg-elev)); border-color: var(--success); color: var(--success); }
.alert.info    { background: color-mix(in srgb, var(--info) 10%, var(--bg-elev)); border-color: var(--info); color: var(--info); }
.alert.warning { background: color-mix(in srgb, var(--warning) 12%, var(--bg-elev)); border-color: var(--warning); color: var(--warning); }
.alert.danger  { background: color-mix(in srgb, var(--danger) 10%, var(--bg-elev)); border-color: var(--danger); color: var(--danger); }

/* ---------- Tags / status pills --------------------------------------- */
.tag {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg-muted);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-xs);
}
.tag.accent { background: var(--accent-soft); color: var(--accent-deep); border-color: var(--accent-deep); }

.status {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-xs);
  border: 1px solid;
}
.status .dot { width: var(--s-2); height: var(--s-2); border-radius: var(--r-pill); }
.status.ok   { background: color-mix(in srgb, var(--success) 14%, var(--bg-elev)); color: var(--success); border-color: var(--success); }
.status.ok .dot { background: var(--success); }
.status.down { background: color-mix(in srgb, var(--danger) 14%, var(--bg-elev)); color: var(--danger); border-color: var(--danger); }
.status.down .dot { background: var(--danger); }
.status.unknown { background: var(--bg-sunken); color: var(--fg-muted); border-color: var(--border-strong); }
.status.unknown .dot { background: var(--fg-subtle); }

/* ---------- Tables ---------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td {
  text-align: left;
  padding: var(--s-3) var(--s-3);
  border-bottom: 1px solid var(--divider);
}
.table th {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.table tbody tr:hover { background: var(--ink-100); }
.table td.actions { white-space: nowrap; display: flex; gap: var(--s-2); }

/* =========================================================================
   ADMIN SHELL  (templates/base.html)
   ========================================================================= */
.admin-shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: var(--s-5) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-5);
}
.sidebar .brand .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h5);
  color: var(--fg);
  line-height: var(--lh-tight);
}
.sidebar .brand .sub {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-xs);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.nav-group { margin-bottom: var(--s-4); }
.nav-group > .nav-group-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--fg-subtle);
  padding: var(--s-1) var(--s-2);
  display: block;
}
.nav-link {
  display: block;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.nav-link:hover { background: var(--bg-sunken); color: var(--fg); text-decoration: none; }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}

.admin-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.admin-topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-6);
  background: var(--bg-elev);
}
.admin-topbar .who { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-sm); color: var(--fg-muted); }
.admin-content { padding: var(--s-8) var(--s-6); max-width: var(--content-max); width: 100%; }
.page-head { margin-bottom: var(--s-6); }
.page-head h1 { margin: 0 0 var(--s-1); }
.page-head .lead { margin: 0; }

.toolbar { display: flex; gap: var(--s-3); align-items: center; margin-bottom: var(--s-5); }
.toolbar .spacer { flex: 1 1 auto; }

/* =========================================================================
   PUBLIC SHELL  (templates/base_public.html)
   ========================================================================= */
.site-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  position: sticky; top: 0; z-index: 50;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.site-header-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-4) var(--s-6);
  display: flex; align-items: center; gap: var(--s-6);
}
.site-header .brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h5);
  color: var(--fg);
  display: flex; align-items: center; gap: var(--s-2);
}
.site-nav { display: flex; gap: var(--s-5); flex: 1 1 auto; }
.site-nav a {
  font-family: var(--font-body); font-weight: 500; font-size: var(--fs-sm);
  color: var(--fg-muted); padding: var(--s-1) 0; position: relative;
}
.site-nav a:hover { color: var(--fg); text-decoration: none; }

.site-main { max-width: var(--content-max); margin: 0 auto; padding: var(--s-12) var(--s-6); }

.under-construction { text-align: center; padding: var(--s-20) var(--s-4); }
.under-construction .eyebrow { display: block; margin-bottom: var(--s-4); }
.under-construction h1 { margin: 0 auto var(--s-4); max-width: 18ch; }
.under-construction .accent-word { position: relative; display: inline-block; }
.under-construction .accent-word::after {
  content: ""; position: absolute; left: 2px; right: 2px; bottom: -2px;
  height: var(--s-1); background: var(--accent); border-radius: var(--r-xs);
}

/* The public site footer (.site-footer / .site-footer-inner and friends)
   lives in public.css, which loads after this file and fully owns its
   layout. The old flexbox version that used to sit here was dead — only
   base_public.html renders a .site-footer, and it never used .col/.socials. */

/* =========================================================================
   LOGIN  (templates/login.html)
   ========================================================================= */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s-6);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: var(--s-8);
}
.login-card .brand {
  text-align: center; margin-bottom: var(--s-6);
}
.login-card .brand .name {
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-h3); color: var(--fg);
}
.login-card .brand .sub {
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-eyebrow);
  letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--accent-deep);
}
.login-card .btn { width: 100%; justify-content: center; }

/* ---------- Misc utilities -------------------------------------------- */
.stack > * + * { margin-top: var(--s-4); }
.muted { color: var(--fg-muted); }
.text-right { text-align: right; }
.empty-state { padding: var(--s-12); text-align: center; color: var(--fg-subtle); }

@media (max-width: 760px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-basis: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =========================================================================
   ADB — asset library, picker, detail
   ========================================================================= */
.adb-toolbar {
  display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center;
  margin-bottom: var(--s-4);
}
.adb-toolbar .input, .adb-toolbar .select { width: auto; }
.adb-toolbar form { display: contents; }
.adb-toolbar .spacer { flex: 1 1 auto; }

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--s-4);
}
.asset-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex; flex-direction: column;
  text-decoration: none;
  color: var(--fg);
  transition: border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.asset-tile:hover {
  text-decoration: none;
  border-color: var(--accent);
  transform: translateY(-1px);
}
.asset-tile .thumb {
  aspect-ratio: 4 / 3;
  width: 100%;
  background: var(--bg-sunken);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.asset-tile .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.asset-tile .icon {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h3);
  color: var(--fg-subtle);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
}
.asset-tile .meta {
  padding: var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-1);
}
.asset-tile .meta .title {
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: var(--lh-tight);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.asset-tile .meta .sub {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  display: flex; gap: var(--s-2); flex-wrap: wrap;
}

.asset-detail {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--s-5);
}
@media (max-width: 900px) {
  .asset-detail { grid-template-columns: 1fr; }
}
.asset-preview {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex; align-items: center; justify-content: center;
  min-height: 320px;
  overflow: hidden;
}
.asset-preview img, .asset-preview video, .asset-preview audio, .asset-preview iframe {
  max-width: 100%; max-height: 480px; border-radius: var(--r-md);
}
.asset-preview audio { width: 100%; }
.asset-preview iframe { width: 100%; height: 480px; background: white; border: 0; }
.asset-preview .placeholder {
  color: var(--fg-subtle);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-h4);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
}

.meta-list { display: flex; flex-direction: column; gap: var(--s-1); }
.meta-list .row {
  display: grid; grid-template-columns: 7em 1fr;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  padding: var(--s-1) 0;
  border-bottom: 1px solid var(--divider);
}
.meta-list .row:last-child { border-bottom: 0; }
.meta-list .label {
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.meta-list .value { word-break: break-word; }

.uploader-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--s-8);
  text-align: center;
  background: var(--bg-sunken);
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.uploader-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* =========================================================================
   Embeds admin
   ========================================================================= */
.embeds-tabs {
  display: flex; flex-wrap: wrap; gap: var(--s-1);
  padding: var(--s-1);
  background: var(--bg-sunken);
  border-radius: var(--r-md);
  margin-bottom: var(--s-3);
}
.embeds-tab {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-sm);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  text-decoration: none;
}
.embeds-tab:hover { background: var(--bg-elev); color: var(--fg); text-decoration: none; }
.embeds-tab.is-active {
  background: var(--bg-elev);
  color: var(--accent-deep);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* ----- Asset picker modal (used by CMS asset_ref / asset_refs fields) ----- */
.adb-picker-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: var(--s-4);
}
.adb-picker-modal.open { display: flex; }
.adb-picker-card {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.adb-picker-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.adb-picker-head .input, .adb-picker-head .select { width: auto; }
.adb-picker-head .spacer { flex: 1 1 auto; }
.adb-picker-body { padding: var(--s-4); overflow-y: auto; flex: 1 1 auto; }
.adb-picker-foot {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}
.adb-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s-3);
}
.adb-picker-tile {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg-elev);
  display: flex; flex-direction: column;
}
.adb-picker-tile.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.adb-picker-tile .thumb {
  aspect-ratio: 4 / 3;
  background: var(--bg-sunken);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.adb-picker-tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.adb-picker-tile .label {
  padding: var(--s-2);
  font-size: var(--fs-xs);
  line-height: var(--lh-tight);
}

.asset-ref-field, .asset-refs-field {
  display: flex; flex-direction: column; gap: var(--s-2);
}
.asset-ref-field .preview-row {
  display: flex; gap: var(--s-3); align-items: center;
}
.asset-ref-field .preview-row .thumb {
  width: 64px; height: 64px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.asset-ref-field .preview-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-ref-field input[type="text"] { font-family: var(--font-mono); font-size: var(--fs-xs); }

.asset-refs-list {
  display: flex; flex-direction: column; gap: var(--s-2);
}
.asset-refs-list .item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
}
.asset-refs-list .item .thumb {
  width: 48px; height: 48px;
  background: var(--bg-sunken);
  border-radius: var(--r-xs);
  overflow: hidden;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.asset-refs-list .item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-refs-list .item .uuid {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  flex: 1 1 auto;
  word-break: break-all;
}
.asset-refs-list .item .actions { display: flex; gap: var(--s-1); }

/* ----- Component picker — JSON validation feedback in the block editor --- */
.component-key-field textarea.valid { border-color: var(--success, var(--accent)); }
.component-key-field textarea.invalid { border-color: var(--danger); }
.json-feedback {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
}
.json-feedback.ok {
  background: var(--bg-sunken);
  color: var(--fg-muted);
}
.json-feedback.danger {
  background: var(--bg-sunken);
  color: var(--danger);
  font-weight: 600;
}

