:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #d6d3d1;
  --accent: #0f766e;
  --accent-ink: #ecfdf5;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --mono: "IBM Plex Mono", "Consolas", monospace;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #e7e5e4 0, transparent 40%),
    linear-gradient(180deg, #fafaf9, var(--bg));
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  font-weight: 600;
}

.nav a.active,
.nav a:hover {
  color: var(--ink);
}

.lang-switch {
  margin-left: 8px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.lang-switch a.active {
  color: var(--ink);
  text-decoration: underline;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 18px 8px;
  margin-bottom: 18px;
}

.panel h1,
.panel h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.stack {
  display: grid;
  gap: 12px;
}

form.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

input[type="text"] {
  min-width: 240px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

button,
.button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
}

button.secondary,
.button.secondary {
  background: #e7e5e4;
  color: var(--ink);
}

button.danger,
.button.danger {
  background: #fecaca;
  color: #7f1d1d;
}

.category-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: end;
}

.category-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.category-form label.check {
  flex-direction: row;
  align-items: center;
  padding-bottom: 10px;
}

.category-form input[type="text"],
.category-form input[type="number"] {
  min-width: 120px;
}

.category-form .grow,
.category-form input.grow {
  flex: 1 1 220px;
  min-width: 180px;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-item {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.category-item.dragging {
  opacity: 0.55;
}

.category-item .row-form {
  flex: 1 1 420px;
  margin: 0;
  align-items: center;
}

.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: -2px;
  padding: 4px 6px;
}

.drag-handle:active {
  cursor: grabbing;
}

.inline-form {
  display: inline-block;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.flash {
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.flash.notice {
  background: #dcfce7;
  color: #14532d;
}

.flash.error {
  background: #fee2e2;
  color: #7f1d1d;
}

.job {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: #fff;
}

.job.running {
  border: 2px solid var(--accent);
  background: #ecfeff;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
  font-size: 1.02rem;
}

tr.is-job-active {
  background: #f0fdfa;
  box-shadow: inset 3px 0 0 var(--accent);
}

tr.is-job-queued {
  background: #f8fafc;
  box-shadow: inset 3px 0 0 #94a3b8;
}

.store-job-progress {
  margin-bottom: 6px;
}

.store-job-progress .job-inline-label {
  margin-bottom: 2px;
}

.store-job-progress .job-inline-msg {
  font-size: 0.85rem;
  line-height: 1.35;
  word-break: break-word;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #e7e5e4;
}

.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #ffedd5; color: var(--warn); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.info { background: #ccfbf1; color: #0f766e; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.95rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.mono {
  font-family: var(--mono);
  font-size: 0.88rem;
}

.pre {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.5;
  background: #1c1917;
  color: #f5f5f4;
  border-radius: 12px;
  padding: 16px;
  overflow: auto;
}

.variant-list {
  margin: 0;
  padding-left: 18px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.filters label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.filters select,
.filters input[type="search"],
.filters input[type="text"] {
  min-width: 160px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.filters label.grow {
  flex: 1 1 220px;
}

.filters .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: end;
  margin-top: 12px;
  width: 100%;
}

.store-pick {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  width: 100%;
}

.store-pick legend {
  padding: 0 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.store-pick-all {
  display: inline-flex;
  margin-bottom: 8px;
}

.store-pick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.store-pick-grid .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
}

.filters label.grow input {
  width: 100%;
  min-width: 200px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.collapsible {
  margin: 0;
}

.collapsible-summary {
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 700;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.collapsible-summary::-webkit-details-marker {
  display: none;
}

.collapsible-summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 0.95rem;
}

.collapsible[open] > .collapsible-summary::before {
  content: "▾";
}

.collapsible > .muted:first-of-type,
.collapsible > .recent-new {
  margin-top: 12px;
}

.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.panel-toolbar h2 {
  margin: 0;
}

.check-cell {
  width: 36px;
  text-align: center;
  vertical-align: middle;
}

.check-cell input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.recent-new {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recent-new-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.recent-new-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.recent-new-body {
  min-width: 0;
  flex: 1;
}

.recent-new-meta {
  margin-top: 4px;
  font-size: 0.9rem;
}

.thumb-cell {
  width: 72px;
}

.thumb-btn {
  display: inline-flex;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  border-radius: 8px;
}

.thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  display: block;
}

.thumb-btn:hover .thumb,
.thumb-btn:focus-visible .thumb {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: zoom-out;
  background: rgba(28, 25, 23, 0.72);
}

.lightbox-figure {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: min(920px, 96vw);
  max-height: 90vh;
}

.lightbox-image {
  display: block;
  max-width: 100%;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions {
  justify-content: flex-end;
}

.row-actions button {
  padding: 6px 10px;
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  input[type="text"] {
    min-width: 0;
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}

.ai-settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 560px;
  margin-top: 12px;
}

.ai-settings-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.ai-settings-form label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.ai-settings-form input[type="password"],
.ai-settings-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

.ai-settings-form textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}

a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  background: var(--accent);
  color: var(--accent-ink);
}

a.button:hover {
  text-decoration: none;
}

.assistant-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 70vh;
}

.assistant-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-start;
  justify-content: space-between;
}

.assistant-head h1 {
  margin: 0 0 6px;
}

.assistant-chat {
  flex: 1;
  min-height: 360px;
  max-height: min(62vh, 640px);
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.assistant-msg {
  display: flex;
}

.assistant-msg.user {
  justify-content: flex-end;
}

.assistant-msg.assistant {
  justify-content: flex-start;
}

.assistant-bubble {
  max-width: min(720px, 92%);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}

.assistant-msg.user .assistant-bubble {
  background: #ecfdf5;
  border-color: #99f6e4;
  white-space: pre-wrap;
}

.assistant-msg.thinking .assistant-bubble {
  color: var(--muted);
  font-style: italic;
}

.assistant-md {
  white-space: normal;
}

.assistant-md p {
  margin: 0 0 0.55em;
}

.assistant-md p:last-child {
  margin-bottom: 0;
}

.assistant-md ul {
  margin: 0.35em 0 0.55em 1.2em;
  padding: 0;
}

.assistant-md code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: #f5f5f4;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.assistant-inline-img {
  display: block;
  max-width: min(320px, 100%);
  max-height: 240px;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.assistant-md a {
  word-break: break-all;
}

.assistant-tools {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.assistant-tools pre {
  margin: 8px 0 0;
  padding: 8px;
  overflow-x: auto;
  background: #f5f5f4;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
}

.assistant-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.assistant-composer textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

.assistant-composer button {
  min-height: 44px;
}

.assistant-empty {
  margin: auto;
  text-align: center;
}

@media (max-width: 720px) {
  .assistant-composer {
    grid-template-columns: 1fr;
  }
}
