@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,500;0,600;1,500&display=swap');

:root {
  --bg: #f4f1e8;
  --paper: #fffdf7;
  --ink: #2b2419;
  --muted: #7d7462;
  --line: #e2dccb;
  --side: #2b2419;
  --side-ink: #efe6d2;
  --side-muted: #a99d84;
  --side-hover: #3d3324;
  --accent: #9c3f2e;
  --accent-ink: #fffdf7;
  --gold: #b8862f;
  --gold-soft: #e3c98f;
  --good: #3d6b4f;
  --row-hover: #f6efdc;
  --mono: 'DM Mono', monospace;
  --serif: 'Playfair Display', Georgia, serif;
  font-family: 'DM Sans', sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --bg: #17140f;
  --paper: #221d16;
  --ink: #ece4d3;
  --muted: #a39782;
  --line: #3a3226;
  --side: #110f0b;
  --side-hover: #2a2319;
  --accent: #c8644f;
  --accent-ink: #17140f;
  --gold-soft: #6e5a33;
  --row-hover: #2c251b;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
[hidden] { display: none !important; }

button, .toolbar input, .toolbar select, .field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  padding: 8px 12px;
}
button:hover { border-color: var(--gold); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------------------------------------------------------------- login */

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 34px 30px; display: grid; gap: 10px; }
.login-card .brand { color: var(--ink); margin-bottom: 8px; }
.login-card .brand small { color: var(--muted); }
.login-intro { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.login-card input { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; background: var(--bg); }
.login-message { color: var(--accent); font-size: 13px; min-height: 1em; margin: 4px 0 0; }

/* ---------------------------------------------------------------- layout */

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; font-size: 18px; font-weight: 700; }
.brand small { display: block; color: var(--side-muted); font-size: 11px; font-weight: 400; margin-top: 2px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--gold-soft); color: #2b2419; font: 600 21px var(--serif); }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; background: var(--side); color: var(--side-ink); padding: 28px 20px 20px; display: flex; flex-direction: column; overflow-y: auto; }
.play-link { display: block; margin-top: 30px; padding: 11px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 600; text-align: center; }
.play-link:hover { filter: brightness(1.08); }
.main-nav { display: grid; gap: 4px; margin-top: 18px; }
.nav-link { padding: 10px 11px; border: 0; border-radius: 6px; background: none; text-align: left; color: var(--side-muted); font-size: 14px; }
.nav-link span { font: 11px var(--mono); margin-right: 12px; opacity: .7; }
.nav-link:hover, .nav-link.active { background: var(--side-hover); color: var(--side-ink); }
.nav-link.active span { color: var(--gold-soft); opacity: 1; }
.sidebar-bottom { margin-top: auto; padding-top: 24px; display: grid; gap: 2px; }
.side-action { border: 0; background: none; padding: 6px 0; text-align: left; color: var(--side-muted); font-size: 12px; }
.side-action:hover { color: var(--side-ink); }

.page-shell { margin-left: 250px; padding: 0 4vw 60px; max-width: 1700px; }
.topbar { padding: 34px 0 20px; }
.kicker { font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); margin: 0 0 6px; }
.topbar h1 { font: 600 34px var(--serif); margin: 0; }
.view-description { color: var(--muted); margin: 6px 0 0; }

/* ---------------------------------------------------------------- collection */

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type="search"] { min-width: 240px; flex: 0 1 320px; }
.spacer { flex: 1; }
.count-line { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }

.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { position: sticky; top: 0; background: var(--paper); text-align: left; border-bottom: 1px solid var(--line); padding: 0; white-space: nowrap; }
.data-table th button { border: 0; background: none; padding: 11px 12px; font: 500 12px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; width: 100%; text-align: inherit; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr[data-id] { cursor: pointer; }
.data-table tbody tr[data-id]:hover, .data-table tbody tr[data-id]:focus { background: var(--row-hover); outline: none; }
.data-table td.wide { min-width: 260px; max-width: 460px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.number { text-align: right; font-family: var(--mono); }
.data-table th.number button { text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 26px; }

/* ---------------------------------------------------------------- editor */

.editor { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(860px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); }
.editor.small { width: min(460px, calc(100vw - 32px)); }
.editor::backdrop { background: rgba(20, 16, 10, .45); }
.editor-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px 6px; }
.editor-head h2 { font: 600 22px var(--serif); margin: 0; }
.icon-button { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px; color: var(--muted); }
.editor-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 16px; padding: 14px 24px; max-height: 66vh; overflow-y: auto; }
.editor-fields.single { grid-template-columns: 1fr; }
.field, .editor-fields.single label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.field.wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea { font-weight: 400; width: 100%; }
.editor-fields.single input { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: var(--bg); font-weight: 400; }
.field textarea { resize: vertical; min-height: 70px; }
.field small, .check small { font-weight: 400; color: var(--muted); font-size: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; align-self: end; padding-bottom: 8px; }
.check small { display: block; }
.editor-meta { color: var(--muted); font-size: 12px; padding: 0 24px; margin: 0; }
.editor-actions { display: flex; gap: 8px; padding: 16px 24px 22px; align-items: center; }

/* ---------------------------------------------------------------- summary and history */

.summary-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; align-items: start; }
.summary-column { display: grid; gap: 18px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.panel-head h2 { font: 600 19px var(--serif); margin: 0; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini-table th { text-align: left; font: 500 11px var(--mono); text-transform: uppercase; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line); }
.mini-table th.number { text-align: right; }
.mini-table td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.mini-table tr.total td { font-weight: 700; border-bottom: 0; }

.history { list-style: none; margin: 0; padding: 0; }
.history-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
.history-line { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline; }
.muted { color: var(--muted); font-size: 13px; }
.badge { font: 500 11px var(--mono); text-transform: uppercase; padding: 2px 8px; border-radius: 99px; background: var(--row-hover); }
.badge-creation { color: var(--good); }
.badge-suppression { color: var(--accent); }
.badge-restauration { color: var(--gold); }
.diff { list-style: none; margin: 8px 0 0; padding: 0 0 0 4px; font-size: 13px; display: grid; gap: 4px; }
.diff span { color: var(--muted); }
.diff del { color: var(--accent); }
.diff ins { color: var(--good); text-decoration: none; }

.notice { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 12px 16px; border-radius: 8px; background: var(--side); color: var(--side-ink); font-size: 14px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.notice.visible { opacity: 1; transform: none; }
.notice.error { background: var(--accent); color: var(--accent-ink); }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 900px) {
  .sidebar { position: static; width: auto; padding: 18px 16px; }
  .main-nav { margin-top: 16px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .sidebar-bottom { display: flex; flex-wrap: wrap; gap: 4px 16px; }
  .page-shell { margin-left: 0; padding: 0 16px 40px; }
  .summary-grid { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { min-width: 0; flex: 1 1 100%; }
  .data-table td.wide { min-width: 200px; }
}
