:root {
  --ui-gap-1: 0.25rem;
  --ui-gap-2: 0.5rem;
  --ui-gap-3: 0.75rem;
  --ui-gap-4: 1rem;
  --ui-radius-1: 8px;
  --ui-radius-2: 12px;
  --ui-muted: #94a3b8;
}

.ui-section { display:flex; align-items:flex-end; justify-content:space-between; gap: var(--ui-gap-3); margin: 0 0 .5rem 0; }
.ui-section .eyebrow { color: var(--ui-muted); font-size: .85rem; margin: 0; }
.ui-section h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.ui-section .actions { display:flex; gap: var(--ui-gap-2); }

.ui-card { background: #fff; border:1px solid #e2e8f0; border-radius: var(--ui-radius-1); box-shadow: 0 4px 12px rgba(15,23,42,0.06); }
.ui-card .ui-card__header { padding: .65rem .85rem; border-bottom:1px solid #e2e8f0; font-weight:700; }
.ui-card .ui-card__body { padding: .75rem .85rem; }
.ui-card .ui-card__footer { padding: .6rem .85rem; border-top:1px solid #e2e8f0; }

.ui-filter { display:grid; gap: var(--ui-gap-2); grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); align-items:end; }
.ui-filter .actions { grid-column: 1 / -1; display:flex; justify-content:flex-end; gap: var(--ui-gap-2); }

.ui-btn,
.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger,
.btn-warn {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:.45rem;
  border-radius: var(--ui-radius-2);
  padding:.55rem .95rem;
  font-weight:600;
  font-size:.95rem;
  line-height:1.2;
  border:1px solid transparent;
  background:#f8fafc;
  color:#0f172a;
  cursor:pointer;
  text-decoration:none;
  transition: background .18s ease, color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .12s ease;
}
.ui-btn.lg,
.btn.btn-lg { padding:.8rem 1.1rem; }
.ui-btn.sm,
.btn.btn-sm { padding:.4rem .7rem; font-size:.85rem; }
.ui-btn:focus-visible,
.btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-ghost:focus-visible,
.btn-danger:focus-visible,
.btn-warn:focus-visible {
  outline:none;
  box-shadow:0 0 0 2px color-mix(in srgb, var(--brand-accent,#22c55e) 30%, transparent);
}
.ui-btn:active,
.btn:active,
.btn-primary:active,
.btn-secondary:active,
.btn-ghost:active,
.btn-danger:active,
.btn-warn:active { transform: translateY(1px); }
.ui-btn.disabled,
.btn.disabled,
.btn-primary.disabled,
.btn-secondary.disabled,
.btn-ghost.disabled,
.btn-danger.disabled,
.btn-warn.disabled,
.ui-btn:disabled,
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled,
.btn-warn:disabled {
  opacity:0.55;
  cursor:not-allowed;
  box-shadow:none;
}
.ui-btn.primary,
.btn.btn-primary,
.btn-primary {
  background: var(--brand-accent, #22c55e);
  color:#fff;
  border-color: color-mix(in srgb, var(--brand-accent,#22c55e) 82%, #0f172a);
  box-shadow:0 12px 24px color-mix(in srgb, var(--brand-accent,#22c55e) 32%, transparent);
}
.ui-btn.primary:hover,
.btn.btn-primary:hover,
.btn-primary:hover {
  background: color-mix(in srgb, var(--brand-accent,#22c55e) 92%, #0f172a 8%);
}
.ui-btn.secondary,
.btn.btn-secondary,
.btn-secondary,
.ui-btn,
.btn {
  background:#e2e8f0;
  color:#0f172a;
  border-color:#cbd5f5;
  box-shadow:0 6px 14px rgba(15,23,42,0.08);
}
.ui-btn.secondary:hover,
.btn.btn-secondary:hover,
.btn-secondary:hover,
.ui-btn:hover:not(.primary):not(.ghost):not(.danger):not(.warn),
.btn:hover:not(.btn-primary):not(.btn-ghost):not(.btn-danger):not(.btn-warn) {
  background:color-mix(in srgb, #e2e8f0 85%, #ffffff 15%);
}
.ui-btn.ghost,
.btn.btn-ghost,
.btn-ghost {
  background:transparent;
  color: var(--brand-accent,#0f766e);
  border-color: rgba(148,163,184,0.5);
  box-shadow:none;
}
.ui-btn.ghost:hover,
.btn.btn-ghost:hover,
.btn-ghost:hover {
  background:color-mix(in srgb, var(--brand-accent,#22c55e) 12%, transparent);
}
.ui-btn.danger,
.btn.btn-danger,
.btn-danger {
  background:#ef4444;
  color:#fff;
  border-color:color-mix(in srgb, #ef4444 85%, #be123c);
  box-shadow:0 10px 22px rgba(239,68,68,0.35);
}
.ui-btn.danger:hover,
.btn.btn-danger:hover,
.btn-danger:hover { background:color-mix(in srgb, #ef4444 90%, #7f1d1d 10%); }
.ui-btn.warn,
.btn.btn-warn,
.btn-warn {
  background:#f97316;
  color:#111827;
  border-color:color-mix(in srgb, #f97316 78%, #9a3412);
  box-shadow:0 10px 22px rgba(249,115,22,0.35);
}
.ui-btn.warn:hover,
.btn.btn-warn:hover,
.btn-warn:hover { background:color-mix(in srgb, #f97316 90%, #9a3412 10%); }
.ui-btn i,
.btn i,
.ui-btn svg,
.btn svg { font-size:0.95em; }

.ui-badge { display:inline-flex; padding:.18rem .5rem; border-radius:999px; font-size:.8rem; }
.ui-badge.success { background: rgba(34,197,94,.15); color:#065f46; }
.ui-badge.info { background: rgba(14,165,233,.15); color:#075985; }
.ui-badge.warn { background: rgba(245,158,11,.15); color:#92400e; }
.ui-badge.danger { background: rgba(239,68,68,.15); color:#991b1b; }
.ui-badge.neutral { background: #f1f5f9; color:#334155; }

.ui-kv { display:grid; grid-template-columns: 140px 1fr; gap: var(--ui-gap-2); }
.ui-kv .label { color: var(--ui-muted); }

.pill-grid { display:flex; flex-wrap:wrap; gap:var(--ui-gap-2); }
.pill { display:inline-flex; flex-direction:column; padding:.45rem .85rem; border-radius:999px; background:#f1f5f9; border:1px solid #e2e8f0; min-width:120px; }
.pill__label { font-size:.8rem; text-transform:uppercase; letter-spacing:.06em; color:#64748b; }
.pill__value { font-size:1.1rem; font-weight:700; color:#0f172a; }
.pill__hint { font-size:.8rem; color:#475569; }

.crud-workspace { display:flex; flex-direction:column; gap:1.25rem; margin-bottom:2rem; }
.crud-hero { display:flex; justify-content:space-between; gap:1rem; flex-wrap:wrap; align-items:flex-end; }
.crud-hero__actions { display:flex; gap:.5rem; flex-wrap:wrap; justify-content:flex-end; }
.crud-grid { display:grid; grid-template-columns:minmax(260px,320px) minmax(0,1fr); gap:1.25rem; align-items:flex-start; }
.crud-list { background:#fff; border:1px solid #e2e8f0; border-radius:var(--ui-radius-1); padding:1rem; box-shadow:0 6px 18px rgba(15,23,42,0.06); display:flex; flex-direction:column; gap:1rem; position:sticky; top:5.5rem; max-height:calc(100vh - 6rem); overflow:auto; }
.crud-list__search { display:flex; gap:.5rem; align-items:center; }
.crud-list__search input { flex:1; border-radius:var(--ui-radius-1); border:1px solid #cbd5f5; padding:.5rem .9rem; }
.crud-list__items { display:flex; flex-direction:column; gap:.4rem; }
.crud-list__item { width:100%; text-align:left; border:1px solid transparent; background:#f8fafc; border-radius:var(--ui-radius-1); padding:.6rem .75rem; display:flex; flex-direction:column; gap:.15rem; cursor:pointer; transition:border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.crud-list__item:hover { border-color:#cbd5f5; }
.crud-list__item.is-active { border-color:var(--brand-accent, #22c55e); background:color-mix(in srgb, var(--brand-accent, #22c55e) 5%, #f0fdf4); box-shadow:0 0 0 2px color-mix(in srgb, var(--brand-accent, #22c55e) 25%, transparent); }
.crud-list__title { font-weight:600; color:#0f172a; display:flex; justify-content:space-between; align-items:center; gap:.5rem; }
.crud-list__meta { font-size:.85rem; color:#64748b; }
.crud-list__tag { font-size:.75rem; text-transform:uppercase; letter-spacing:.05em; color:#475569; }
.crud-list__section { border-top:1px solid #e2e8f0; padding-top:.75rem; }
.crud-list__section-title { font-size:.85rem; font-weight:600; margin:0 0 .35rem; color:#475569; }
.crud-detail { display:flex; flex-direction:column; gap:1rem; }
.crud-detail .settings-card,
.crud-detail .ui-card { width:100%; }
.crud-detail__actions { display:flex; justify-content:flex-end; gap:.5rem; flex-wrap:wrap; margin-top:1rem; }
.crud-detail__actions--sticky { position:sticky; top:4.5rem; z-index:20; padding:.75rem 1rem; margin:-.5rem -1rem .5rem; background:linear-gradient(180deg, rgba(248,250,252,0.95) 0%, rgba(255,255,255,0.85) 100%); border:1px solid rgba(148,163,184,0.35); border-radius:var(--ui-radius-2); box-shadow:0 12px 24px rgba(15,23,42,0.12); }
.crud-detail__actions .action-group { display:flex; align-items:center; gap:.45rem; flex-wrap:wrap; }
.crud-detail__actions .action-group:last-child .ui-btn.primary,
.crud-detail__actions .action-group:last-child .btn-primary { min-width:170px; }
.crud-detail .is-highlight { box-shadow:0 0 0 2px color-mix(in srgb, var(--brand-accent, #22c55e) 30%, transparent); border-radius:var(--ui-radius-1); }
.crud-mini-list { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:.35rem; font-size:.85rem; color:#475569; }
.crud-mini-list strong { color:#0f172a; }
.crud-helper { font-size:.8rem; color:#64748b; margin-top:.2rem; }
.dup-hint { margin-top:.6rem; display:flex; gap:.65rem; border:1px solid #fcd34d; background:#fefce8; border-radius:var(--ui-radius-1); padding:.6rem .75rem; color:#92400e; font-size:.85rem; align-items:flex-start; }
.dup-hint__icon { width:1.65rem; height:1.65rem; border-radius:50%; background:#fbbf24; color:#fff; font-weight:700; display:flex; align-items:center; justify-content:center; font-size:.85rem; }
.dup-hint__body strong { display:block; font-size:.9rem; }
.dup-hint__actions { margin-top:.35rem; }
.autocomplete-panel { position:absolute; z-index:2000; background:#fff; border:1px solid #cbd5f5; border-radius:var(--ui-radius-1); box-shadow:0 10px 30px rgba(15,23,42,0.15); padding:.25rem; max-height:260px; overflow:auto; }
.autocomplete-list { display:flex; flex-direction:column; gap:.15rem; }
.autocomplete-item { width:100%; border:none; background:transparent; text-align:left; padding:.35rem .45rem; border-radius:var(--ui-radius-1); display:flex; flex-direction:column; gap:.1rem; cursor:pointer; font-size:.9rem; color:#0f172a; }
.autocomplete-item .label { font-weight:600; }
.autocomplete-item .meta { font-size:.75rem; color:#475569; text-transform:uppercase; letter-spacing:.05em; }
.autocomplete-item:hover,
.autocomplete-item.is-active { background:color-mix(in srgb, var(--brand-accent,#22c55e) 10%, #f0fdf4); }
.crud-input { border:1px solid #cbd5f5; border-radius:var(--ui-radius-1); padding:.55rem .75rem; background:#fff; color:#0f172a; transition:border-color .15s ease, box-shadow .15s ease; }
.crud-input:focus { border-color:color-mix(in srgb, var(--brand-accent,#22c55e) 50%, #cbd5f5); box-shadow:0 0 0 2px color-mix(in srgb, var(--brand-accent,#22c55e) 20%, transparent); outline:none; }
.crud-az { display:flex; flex-wrap:wrap; gap:.25rem; margin:.4rem 0 .2rem; }
.crud-az button { border:1px solid transparent; background:#f1f5f9; color:#475569; border-radius:var(--ui-radius-1); padding:.25rem .45rem; font-size:.75rem; cursor:pointer; transition:background .15s ease, color .15s ease, border-color .15s ease; }
.crud-az button.is-active { border-color:var(--brand-accent,#22c55e); background:color-mix(in srgb, var(--brand-accent,#22c55e) 18%, #f0fdf4); color:#065f46; }

@media (max-width: 960px) {
  .crud-grid { grid-template-columns:1fr; }
  .crud-list { position:static; max-height:none; }
  .crud-hero { flex-direction:column; align-items:flex-start; }
  .crud-hero__actions { width:100%; justify-content:flex-start; }
}

html[data-theme='dark'] .ui-card { background:#0f172a; border-color:#1e293b; box-shadow:none; }
html[data-theme='dark'] .ui-card .ui-card__header, html[data-theme='dark'] .ui-card .ui-card__footer { border-color:#1e293b; }
html[data-theme='dark'] .ui-btn.ghost { color:#e2e8f0; border-color:#1e293b; }
html[data-theme='dark'] .ui-section .eyebrow { color:#94a3b8; }
html[data-theme='dark'] .pill { background:#0f172a; border-color:#1e293b; }
html[data-theme='dark'] .pill__label { color:#94a3b8; }
html[data-theme='dark'] .pill__value { color:#e2e8f0; }
html[data-theme='dark'] .crud-list { background:#0f172a; border-color:#1e293b; box-shadow:none; }
html[data-theme='dark'] .crud-list__item { background:#0b172b; border-color:#1e293b; color:#e2e8f0; }
html[data-theme='dark'] .crud-list__item.is-active { background:color-mix(in srgb, var(--brand-accent, #22c55e) 18%, #0f172a); }
html[data-theme='dark'] .crud-list__meta { color:#94a3b8; }
html[data-theme='dark'] .crud-list__section { border-color:#1e293b; }
html[data-theme='dark'] .crud-mini-list strong { color:#e2e8f0; }
html[data-theme='dark'] .crud-mini-list { color:#94a3b8; }
html[data-theme='dark'] .crud-input { background:#0f172a; border-color:#1e293b; color:#e2e8f0; }
html[data-theme='dark'] .crud-input:focus { border-color:color-mix(in srgb, var(--brand-accent,#22c55e) 40%, #1e293b); box-shadow:0 0 0 2px color-mix(in srgb, var(--brand-accent,#22c55e) 20%, transparent); }
html[data-theme='dark'] .crud-az button { background:#182437; color:#94a3b8; border-color:transparent; }
html[data-theme='dark'] .crud-az button.is-active { background:color-mix(in srgb, var(--brand-accent,#22c55e) 25%, #0f172a); color:#f0fdf4; border-color:color-mix(in srgb, var(--brand-accent,#22c55e) 55%, #1e293b); }
html[data-theme='dark'] .dup-hint { background:rgba(146,64,14,0.18); border-color:rgba(234,179,8,0.6); color:#fde68a; }
html[data-theme='dark'] .dup-hint__icon { background:#d97706; }
html[data-theme='dark'] .autocomplete-panel { background:#0f172a; border-color:#1e293b; box-shadow:0 12px 28px rgba(2,6,23,0.65); }
html[data-theme='dark'] .autocomplete-item { color:#e2e8f0; }
html[data-theme='dark'] .autocomplete-item .meta { color:#94a3b8; }
html[data-theme='dark'] .crud-detail__actions--sticky { background:linear-gradient(180deg, rgba(15,23,42,0.96) 0%, rgba(15,23,42,0.85) 100%); border-color:#1e293b; box-shadow:0 18px 32px rgba(2,6,23,0.55); }


/* Template: Document A */
body.ui-template-document-a .sidebar {
  background: radial-gradient(circle at top, color-mix(in srgb, var(--brand-primary) 28%, #0f172a) 0%, #0f172a 52%, #0b1120 100%);
  border-right: none;
  color: #e2e8f0;
}

body.ui-template-document-a .nav-link {
  border-left: 3px solid transparent;
  color: rgba(255,255,255,0.78);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

body.ui-template-document-a .nav-link:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #f8fafc;
}

body.ui-template-document-a .nav-link.is-active {
  background: rgba(15, 23, 42, 0.45);
  color: #f8fafc;
  border-left-color: var(--brand-accent);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.35);
}

body.ui-template-document-a .top-bar {
  background: linear-gradient(120deg, rgba(15,23,42,0.96) 0%, rgba(15,23,42,0.82) 38%, rgba(15,23,42,0.72) 100%);
  color: #f1f5f9;
  border-bottom: none;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

body.ui-template-document-a .top-bar .btn.btn-ghost,
body.ui-template-document-a .top-bar .btn-ghost,
body.ui-template-document-a .top-bar .btn.btn-primary,
body.ui-template-document-a .top-bar .btn-primary,
body.ui-template-document-a .top-bar .ui-btn.ghost,
body.ui-template-document-a .top-bar .ui-btn.primary {
  border-color: rgba(148, 163, 184, 0.28);
  color: #f1f5f9;
}

body.ui-template-document-a .main-content {
  background: linear-gradient(180deg, rgba(241,245,249,0.85) 0%, rgba(248,250,252,1) 16%);
}

body.ui-template-document-a .ui-card {
  border-color: color-mix(in srgb, var(--brand-accent) 16%, #e2e8f0);
  box-shadow: 0 18px 34px rgba(15,23,42,0.08);
}

body.ui-template-document-a .ui-section h2 {
  letter-spacing: -0.01em;
}


/* Template: Document B */
body.ui-template-document-b .sidebar {
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
}

body.ui-template-document-b .nav-link {
  background: transparent;
  border-radius: 12px;
  border: 1px solid transparent;
}

body.ui-template-document-b .nav-link:hover {
  border-color: rgba(148, 163, 184, 0.36);
  background: rgba(226, 232, 240, 0.35);
}

body.ui-template-document-b .nav-link.is-active {
  border-color: color-mix(in srgb, var(--brand-accent) 60%, #cbd5f5);
  background: rgba(34, 197, 94, 0.1);
  color: #0f172a;
  box-shadow: inset 0 0 0 2px rgba(34,197,94,0.18);
}

body.ui-template-document-b .top-bar {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.06);
}

body.ui-template-document-b .main-content {
  background: #f8fafc;
}

body.ui-template-document-b .ui-card {
  border-color: #e2e8f0;
  box-shadow: 0 20px 36px rgba(15,23,42,0.07);
}

body.ui-template-document-b .ui-section .eyebrow {
  color: color-mix(in srgb, var(--brand-accent) 50%, #475569);
}


/* Template previews (settings page) */
.style-preview-document-a {
  background-image: linear-gradient(135deg, rgba(15,23,42,0.92), rgba(15,23,42,0.75));
  position: relative;
}

.style-preview-document-a::after {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 10px;
  background:
    linear-gradient(90deg, rgba(34,197,94,0.65), rgba(14,165,233,0.28)) padding-box,
    linear-gradient(180deg, rgba(15,23,42,0.3), rgba(15,23,42,0)) border-box;
  border: 1px solid rgba(226,232,240,0.55);
}

.style-preview-document-b {
  background-image: linear-gradient(135deg, rgba(148,163,184,0.32), rgba(241,245,249,0.9));
  position: relative;
}

.style-preview-document-b::after {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(34,197,94,0.08), rgba(14,165,233,0.12)) padding-box,
    linear-gradient(135deg, rgba(148,163,184,0.36), rgba(203,213,225,0.08)) border-box;
  border: 1px solid rgba(148,163,184,0.4);
}

.style-preview-legacy {
  background-image: linear-gradient(135deg, rgba(203,213,225,0.65), rgba(148,163,184,0.75));
  position: relative;
}

.style-preview-legacy::after {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.8), rgba(226,232,240,0.95));
  border: 1px dashed rgba(100,116,139,0.5);
}
