:root,
[data-theme="light"] {
  --bg: #f3eee4;
  --bg-elevated: #faf7f1;
  --bg-soft: #ebe4d7;
  --panel: #fffdf8;
  --ink: #1a1612;
  --muted: #6a5f54;
  --line: rgb(26 22 18 / 0.12);
  --brand: #c24b28;
  --brand-soft: rgb(194 75 40 / 0.12);
  --accent: #d9eb4d;
  --ok: #1f7a45;
  --warn: #a36b12;
  --danger: #b42318;
  --shadow: 0 18px 40px rgb(26 22 18 / 0.08);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #12100e;
  --bg-elevated: #1a1714;
  --bg-soft: #221e1a;
  --panel: #1e1a16;
  --ink: #f4efe6;
  --muted: #b0a497;
  --line: rgb(244 239 230 / 0.12);
  --brand: #e06a45;
  --brand-soft: rgb(224 106 69 / 0.18);
  --accent: #e4f35a;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow: 0 18px 40px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(900px 500px at 100% 0%, rgb(194 75 40 / 0.12), transparent 55%),
    radial-gradient(700px 400px at 0% 100%, rgb(217 235 77 / 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

.eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--brand);
  margin: 0 0 0.4rem;
}
.muted { color: var(--muted); }
.hint { font-size: 0.82rem; color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; }
.error-text { color: var(--danger); font-size: 0.8rem; }
tr.row-dirty { background: color-mix(in srgb, var(--brand) 6%, transparent); }
.btn-expand {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--muted);
  width: 1.5rem;
  height: 1.5rem;
}
.btn-expand:hover { color: var(--brand); }
tr.nested-row td { padding: 0 0 0.75rem 2.25rem; border-bottom: none; }
table.nested-orders { width: 100%; background: var(--bg-soft); border-radius: 8px; }
table.nested-orders th, table.nested-orders td { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
code {
  background: var(--bg-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  font-size: 0.85em;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
[data-theme="dark"] .btn-primary { background: var(--brand); border-color: var(--brand); color: #1a1612; }
.btn-secondary { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn-ghost { background: transparent; }
.btn-danger { background: rgb(180 35 24 / 0.12); color: var(--danger); border-color: transparent; }
.btn.full { width: 100%; }
.btn.small { padding: 0.4rem 0.75rem; font-size: 0.78rem; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-family: var(--serif);
  font-size: 2rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.03em;
}

.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.sidebar {
  border-right: 1px solid var(--line);
  background: rgb(250 247 241 / 0.72);
  backdrop-filter: blur(12px);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
[data-theme="dark"] .sidebar { background: rgb(26 23 20 / 0.85); }
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand-mark {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 650;
}
.brand-mark em {
  font-style: italic;
  color: var(--brand);
  font-weight: 500;
}
.theme-toggle {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  display: grid;
  place-items: center;
}
[data-theme="light"] .theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: none; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; overflow-y: auto; }
.nav-btn {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.3;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--brand-soft);
  color: var(--brand);
}
.nav-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.6;
  padding: 0.6rem 0.75rem 0.2rem;
}
.nav-group-label:first-child { padding-top: 0.1rem; }
.nav-divider { border: 0; border-top: 1px solid var(--line); margin: 0.5rem 0.4rem; }
.sidebar-foot { display: grid; gap: 0.45rem; }

.main { padding: 1.5rem 1.75rem 3rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.topbar h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2rem;
  letter-spacing: -0.03em;
}
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}
.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card { padding: 1rem 1.1rem; }
.stat-card .label { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.stat-card .value {
  font-family: var(--serif);
  font-size: 2rem;
  margin-top: 0.35rem;
  letter-spacing: -0.03em;
}
.panel { padding: 1.1rem 1.2rem; }

.toolbar {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}
.toolbar input, .toolbar select, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}
.toolbar input { width: min(280px, 100%); }
.toolbar select { width: auto; min-width: 140px; }

.table-wrap { overflow: auto; }
table.catalog {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.catalog th, table.catalog td {
  text-align: left;
  padding: 0.85rem 0.7rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.catalog th {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
table.catalog tr { cursor: pointer; }
table.catalog tbody tr:hover { background: var(--bg-soft); }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge.filament { background: rgb(194 75 40 / 0.14); color: var(--brand); }
.badge.category { background: rgb(217 235 77 / 0.22); color: #5d6b10; }
[data-theme="dark"] .badge.category { color: var(--accent); }
.badge.published { background: rgb(31 122 69 / 0.14); color: var(--ok); }
.badge.draft { background: rgb(163 107 18 / 0.16); color: var(--warn); }

.editor-layout {
  display: grid;
  grid-template-columns: 1.5fr 0.9fr;
  gap: 1rem;
  align-items: start;
}
.stack { display: flex; flex-direction: column; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span, .field-label {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
}
.field textarea { min-height: 120px; resize: vertical; }
.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
}
.field.checkbox input { width: auto; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.section-head h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.row-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: var(--bg-elevated);
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}
.row-card-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}
.swatch-preview {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.editor-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  position: sticky;
  top: 1rem;
}
.meta-list {
  display: grid;
  gap: 0.55rem;
  font-size: 0.88rem;
}
.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 0.4rem;
}
.meta-list span:first-child { color: var(--muted); }

.recent-list { display: grid; gap: 0.45rem; }
.recent-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.2rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.recent-item:hover { color: var(--brand); }

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  background: var(--ink);
  color: var(--bg);
  padding: 0.85rem 1.1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-weight: 600;
  font-size: 0.9rem;
}
[data-theme="dark"] .toast { background: var(--accent); color: #1a1612; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .stats, .editor-layout, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
