:root {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --line: #e6dfd3;
  --text: #2b2722;
  --muted: #7b7267;
  --accent: #7d5d46;
  --accent-2: #c8a98f;
  --success: #e8f6ed;
  --error: #fbe9e9;
  --ui-font-size: 16px;
  --button-scale: 1;
  --field-scale: 1;
}

:root[data-theme="default"] {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --line: #e6dfd3;
  --text: #2b2722;
  --muted: #7b7267;
  --accent: #7d5d46;
  --accent-2: #c8a98f;
  --success: #e8f6ed;
  --error: #fbe9e9;
  --sidebar: #f0ebe3;
  --panel-white: #ffffff;
}

:root[data-theme="rose"] {
  --bg: #fbf3f3;
  --panel: #fffafb;
  --line: #ead7d9;
  --text: #34282b;
  --muted: #8a6d73;
  --accent: #a66c79;
  --accent-2: #d6a6af;
  --success: #edf9f1;
  --error: #fdecee;
  --sidebar: #f5e8ea;
  --panel-white: #ffffff;
}

:root[data-theme="forest"] {
  --bg: #f2f5f0;
  --panel: #fcfefa;
  --line: #d8e1d3;
  --text: #243126;
  --muted: #667664;
  --accent: #597654;
  --accent-2: #9bb391;
  --success: #e7f5ea;
  --error: #f9e8e8;
  --sidebar: #e8eee3;
  --panel-white: #ffffff;
}

:root[data-theme="dark"] {
  --bg: #1d1c1b;
  --panel: #262422;
  --line: #3b3734;
  --text: #f3eee7;
  --muted: #b8aea3;
  --accent: #b88962;
  --accent-2: #8f6a4f;
  --success: #24352b;
  --error: #412b2b;
  --sidebar: #211f1d;
  --panel-white: #2c2926;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  font-size: var(--ui-font-size);
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.logo { font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
.sidebar nav { display: grid; gap: 10px; }
.sidebar nav a {
  padding: calc(10px * var(--button-scale)) calc(12px * var(--button-scale));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; font-size: 0.875rem; color: var(--muted); }
.content { padding: 28px; }
h1, h2, h3 { margin-top: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 20px;
}
.stats-grid, .grid-2 { display: grid; gap: 16px; margin-bottom: 20px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  display: grid;
  gap: 8px;
}
.stat-card span { color: var(--muted); font-size: 0.875rem; }
.stat-card strong { font-size: 1.75rem; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 0.875rem; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  padding: calc(11px * var(--field-scale)) calc(12px * var(--field-scale));
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-white);
  color: var(--text);
}
button {
  padding: calc(11px * var(--button-scale)) calc(14px * var(--button-scale));
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
button:hover { opacity: 0.94; }
button.secondary { background: transparent; color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.checkbox { display: flex; align-items: center; gap: 10px; }
.checkbox input { width: auto; }
.checkbox-inline { display: inline-flex; }
.filters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; align-items: end; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 0.875rem; }
.muted, .hint { color: var(--muted); font-size: 0.8125rem; }
.flash { border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--line); }
.flash.success { background: var(--success); }
.flash.error { background: var(--error); }
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line); padding: 28px; border-radius: 20px; }
.cabinet-card, .subpanel { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--panel-white); margin-bottom: 12px; }
.row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.details { display: grid; grid-template-columns: 180px 1fr; gap: 10px; margin: 0 0 16px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.review-text { padding: 16px; background: var(--panel-white); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; white-space: pre-wrap; }
.mt16 { margin-top: 16px; }
.settings-hero { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.settings-badges { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 10%, var(--panel)); border: 1px solid var(--line); font-size: 0.8125rem; }
.badge-success { background: color-mix(in srgb, #8fd0a0 18%, var(--panel)); border-color: color-mix(in srgb, #8fd0a0 32%, var(--line)); }
.badge-muted { background: color-mix(in srgb, var(--bg) 60%, var(--panel)); color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-tile { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; min-height: 150px; }
.settings-tile h3 { margin-bottom: 8px; }
.settings-tile button { white-space: nowrap; }
.modal-lock { overflow: hidden; }
.modal { position: fixed; inset: 0; display: none; z-index: 50; }
.modal.is-open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(32, 27, 22, 0.45); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  margin: 16px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(43, 39, 34, 0.18);
}
.modal-wide { width: min(900px, calc(100vw - 32px)); }
.modal-xl { width: min(1180px, calc(100vw - 32px)); }
.modal-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.icon-button { width: 42px; min-width: 42px; height: 42px; padding: 0; display: inline-grid; place-items: center; border-radius: 12px; }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-white); }
.table-scroll table { min-width: 720px; }
.recommendation-add-panel { margin-bottom: 16px; }
.recommendation-panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.recommendation-dedupe-form { margin: 0; }
.recommendation-form-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 1.8fr 0.9fr auto auto;
  gap: 12px;
  align-items: end;
}
.recommendation-create-actions { display: flex; align-items: end; }
.recommendation-editor-scroll { overflow-x: auto; }
.recommendation-editor-table { min-width: 1040px; }
.recommendation-editor-table td,
.recommendation-editor-table th { white-space: nowrap; }
.recommendation-editor-table td:nth-child(4),
.recommendation-editor-table th:nth-child(4) { min-width: 220px; }
.recommendation-editor-table td:nth-child(6),
.recommendation-editor-table th:nth-child(6) { min-width: 130px; }
.recommendation-editor-table td:nth-child(7),
.recommendation-editor-table th:nth-child(7) { min-width: 190px; }
.recommendation-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.recommendation-row-actions form { margin: 0; }
.recommendation-row-actions button {
  padding: calc(8px * var(--button-scale)) calc(12px * var(--button-scale));
  border-radius: 10px;
  line-height: 1.1;
}
.appearance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.appearance-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: var(--panel-white);
}
.appearance-controls { display: grid; gap: 14px; }
.range-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.range-row output {
  min-width: 64px;
  text-align: right;
  color: var(--muted);
  font-size: 0.875rem;
}
.appearance-preview-shell {
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 18px;
}
.appearance-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  display: grid;
  gap: 14px;
}
.appearance-preview-toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.appearance-preview-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.appearance-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.appearance-note { margin-top: 10px; }
input[type="range"] { padding: 0; accent-color: var(--accent); }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .grid-2, .stats-grid, .filters, .settings-grid, .appearance-grid { grid-template-columns: 1fr; }
  .settings-hero, .settings-tile, .recommendation-panel-head { flex-direction: column; }
  .recommendation-form-grid { grid-template-columns: 1fr; }
  .appearance-preview-fields { grid-template-columns: 1fr; }
}
.badge-warn { background: color-mix(in srgb, #f5d38d 22%, var(--panel)); border-color: color-mix(in srgb, #f0c36b 34%, var(--line)); }
.mt12 { margin-top: 12px; }
.cell-checkbox { width: 44px; min-width: 44px; }
.cell-checkbox input { width: 18px; height: 18px; }
.review-row { cursor: pointer; }
.review-row.is-selected { background: color-mix(in srgb, var(--accent) 9%, var(--panel-white)); }
.reviews-bulk-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.reviews-bulk-info { display: grid; gap: 8px; }
.reviews-bulk-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.reviews-counter { font-size: 0.875rem; color: var(--muted); }
.infinite-loader { padding: 14px 6px 4px; color: var(--muted); font-size: 0.875rem; }
.infinite-loader.is-error { color: #b04c4c; }
.reviews-sentinel { height: 1px; }
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: calc(11px * var(--button-scale)) calc(14px * var(--button-scale));
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.template-tools-panel,
.template-scenarios-panel,
.template-variants-panel { display: grid; gap: 14px; margin-bottom: 16px; }
.template-tools-grid,
.template-prompt-head,
.template-section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.template-tools-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.template-import-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.template-prompt-textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.45;
}
.template-scenario-create-form {
  display: grid;
  grid-template-columns: 0.7fr 1.4fr 1.8fr auto;
  gap: 12px;
  align-items: end;
}
.template-create-form {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr auto 2.4fr auto;
  gap: 12px;
  align-items: end;
}
.template-create-form .template-create-text { grid-column: span 1; }
.template-create-actions { display: flex; align-items: end; }
.template-editor-scroll { overflow-x: auto; }
.template-scenarios-table,
.template-editor-table { min-width: 980px; }
.template-editor-table td,
.template-editor-table th,
.template-scenarios-table td,
.template-scenarios-table th { vertical-align: top; }
.template-editor-table td:nth-child(5),
.template-editor-table th:nth-child(5) { min-width: 420px; }
.template-row-actions {
  display: inline-flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.readonly-input {
  background: color-mix(in srgb, var(--bg) 70%, var(--panel-white));
  color: var(--muted);
}
code {
  background: color-mix(in srgb, var(--bg) 60%, var(--panel-white));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 6px;
}
@media (max-width: 1100px) {
  .reviews-bulk-toolbar,
  .template-tools-grid,
  .template-prompt-head,
  .template-section-head { flex-direction: column; }
  .template-scenario-create-form,
  .template-create-form { grid-template-columns: 1fr; }
}
