/* Nakamachi Admin — calm, readable, light and dark. */
:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1f2027;
  --muted: #676a75;
  --border: #e2dfd8;
  --accent: #6b5bd2;
  --accent-text: #ffffff;
  --accent-soft: #ece9fb;
  --danger: #c2413a;
  --danger-soft: #fbeceb;
  --success: #2f7d4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161b;
    --surface: #1d1f26;
    --surface-2: #252832;
    --text: #e9e8ee;
    --muted: #9c9fab;
    --border: #2f323d;
    --accent: #8f82ee;
    --accent-text: #15161b;
    --accent-soft: #2a2743;
    --danger: #ef7a72;
    --danger-soft: #3a2224;
    --success: #6cc792;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: 0.86em; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: 0.5rem 0.75rem; border-radius: var(--radius); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem 0.9rem; display: flex; flex-direction: column; gap: 0.75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); text-decoration: none; padding: 0 0.4rem; }
.brand-mark { font-size: 1.4rem; color: var(--accent); }
.brand-name { display: block; font-weight: 650; }
.brand-sub { display: block; font-size: 0.8rem; color: var(--muted); }
.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.nav-group { margin: 0.9rem 0 0.25rem; padding: 0 0.5rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.55rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.is-soon { color: var(--muted); cursor: default; }
.nav-item.is-soon:hover { background: none; }
.nav-icon { width: 1.1rem; text-align: center; }
.soon { margin-left: auto; font-size: 0.68rem; font-weight: 600; padding: 0.05rem 0.4rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.release { margin-top: auto; padding: 0 0.5rem; font: 0.72rem var(--mono); color: var(--muted); word-break: break-all; }

.env-badge { align-self: flex-start; margin-left: 0.4rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.env-production { background: var(--danger); color: #fff; }
.env-staging { background: #e7a93a; color: #231a05; }

.main-column { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.9rem 1.75rem; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.page-title { font-size: 1.15rem; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.actor { color: var(--muted); font-size: 0.9rem; }
main { padding: 1.75rem; max-width: 1200px; width: 100%; outline: none; }

/* Building blocks */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.75rem; }
.eyebrow { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.25rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 1rem 0; margin: 0; }
.link { text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.nowrap { white-space: nowrap; }
.pill { display: inline-block; font-size: 0.78rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--surface-2); }
.pill-muted { color: var(--muted); }
code.id { font-size: 0.78rem; color: var(--muted); margin-left: 0.35rem; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; font: inherit; font-size: 0.9rem; font-weight: 550; padding: 0.45rem 0.9rem; border-radius: 8px; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.button:disabled { opacity: 0.6; cursor: default; }
.button-primary { background: var(--accent); color: var(--accent-text); }
.button-quiet { background: var(--surface); color: var(--text); border-color: var(--border); }
.button-quiet:hover { background: var(--surface-2); }
.button-danger { background: var(--danger-soft); color: var(--danger); }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.6rem; }
label { display: grid; gap: 0.3rem; font-size: 0.85rem; font-weight: 550; }

/* Dashboard */
.intro { margin-bottom: 1.5rem; }
.intro h2 { font-size: 1.5rem; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.9rem; margin-bottom: 1.5rem; }
.module-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
a.module-card:hover { border-color: var(--accent); }
.module-card.is-soon { opacity: 0.7; }
.module-card h3 { display: flex; align-items: center; gap: 0.5rem; }
.module-card p { color: var(--muted); font-size: 0.88rem; margin: 0; }
.module-icon { display: block; font-size: 1.3rem; color: var(--accent); margin-bottom: 0.35rem; }

/* Tables and filters */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-bottom: 1rem; }
.filter-actions { display: flex; gap: 0.5rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: var(--surface-2); }
.more-row td { text-align: center; }

/* Audit detail */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.9rem 1.5rem; margin: 0; }
.facts dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.facts dd { margin: 0.15rem 0 0; }
.state-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.json { margin: 0; padding: 0.9rem; background: var(--surface-2); border-radius: 8px; overflow: auto; max-height: 520px; white-space: pre-wrap; word-break: break-word; }
.value { white-space: pre-wrap; word-break: break-word; }
.value.before { color: var(--danger); }
.value.after { color: var(--success); }

/* Standalone pages */
.standalone { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.standalone-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 2rem; width: min(480px, 100%); }
.standalone-brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.5rem; }
.standalone-brand .env-badge { margin-left: auto; }
.actions { display: flex; gap: 0.6rem; margin-top: 1.25rem; }
.problem { background: var(--danger-soft); border-radius: 8px; padding: 1rem; }

/* Feedback */
.busy-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); opacity: 0; transition: opacity 0.2s; z-index: 20; }
.busy-bar.htmx-request, .htmx-request .busy-bar { opacity: 1; }
.toasts { position: fixed; bottom: 1.25rem; right: 1.25rem; display: grid; gap: 0.5rem; z-index: 30; max-width: min(420px, calc(100vw - 2.5rem)); }
.toast { background: var(--text); color: var(--bg); padding: 0.75rem 1rem; border-radius: var(--radius); box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); font-size: 0.9rem; }
.toast-error { background: var(--danger); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .state-grid { grid-template-columns: 1fr; }
  main { padding: 1rem; }
}

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

/* Utilities */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.pill-success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); font-weight: 600; }
.notice { border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1.25rem; }
.notice-success { background: color-mix(in srgb, var(--success) 14%, var(--surface)); color: var(--success); font-weight: 550; }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.button-danger:hover { background: var(--danger); color: #fff; }

/* Nakamachi list */
.order-cell { white-space: nowrap; width: 1%; }
.icon-button { font: inherit; width: 1.9rem; height: 1.9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.icon-button:hover:not(:disabled) { background: var(--surface-2); }
.icon-button:disabled { opacity: 0.35; cursor: default; }
.entity-link { display: flex; align-items: center; gap: 0.7rem; color: var(--text); text-decoration: none; }
.entity-link:hover strong { color: var(--accent); }
.entity-link code.id { display: block; margin-left: 0; }
.thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; background: var(--surface-2); flex: none; }
.thumb-empty { display: grid; place-items: center; font-weight: 700; color: var(--muted); }

/* Editor */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.25rem; align-items: start; }
.editor-side { position: sticky; top: 5rem; }
.editor fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem 1.25rem; }
.field { display: grid; gap: 0.3rem; margin-bottom: 1rem; align-content: start; }
.field-grid .field { margin-bottom: 0; }
.field-label { display: block; font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; line-height: 1.5; }
.field textarea.prompt { font-family: var(--mono); font-size: 0.85rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.required { color: var(--danger); margin-left: 0.15rem; }
.hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.field-error { margin: 0; font-size: 0.82rem; color: var(--danger); font-weight: 550; }
.field-success { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--success); font-weight: 550; }
.counter { margin: 0; font-size: 0.75rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.counter.is-over { color: var(--danger); font-weight: 650; }
.readonly-value { display: block; padding: 0.45rem 0.6rem; border-radius: 8px; background: var(--surface-2); }
.traits { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
.trait-scale { display: grid; grid-template-columns: 5.5rem 1fr 5.5rem 2.5rem; align-items: center; gap: 0.6rem; }
.trait-scale span:nth-of-type(2) { text-align: right; }
.trait-scale input[type="range"] { width: 100%; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.trait-scale output { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; }
.editor .interest-group { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.9rem 0.8rem; margin: 0 0 0.8rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.interest-group legend { font-size: 0.78rem; font-weight: 650; color: var(--muted); padding: 0 0.3rem; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 450; font-size: 0.9rem; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.image-field { display: grid; gap: 0.5rem; align-content: start; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.swatch { height: 170px; display: grid; place-items: center; padding: 0.75rem; }
.swatch img { max-width: 100%; max-height: 100%; object-fit: contain; }
.swatch-light { background: #faf9f6; color: #676a75; }
.swatch-dark { background: #17181d; color: #9c9fab; }
.asset-key { font-size: 0.72rem; color: var(--muted); word-break: break-all; }
.image-actions { display: flex; gap: 0.5rem; }
.file-button { position: relative; }
.file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.save-bar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.25rem; margin: 0 -0.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 -4px 16px rgb(0 0 0 / 0.06); z-index: 1; }

@media (max-width: 1100px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-side { position: static; }
}
