:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1f1c19;
  --muted: #6b6359;
  --border: #e2dbd1;
  --accent: #b4542d;
  --accent-text: #ffffff;
  --accent-soft: #f6e3d9;
  --error: #b42318;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513;
    --surface: #221f1c;
    --text: #f2ede6;
    --muted: #a99f93;
    --border: #3a342e;
    --accent: #e07a4f;
    --accent-text: #1a0f0a;
    --accent-soft: #3b261c;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1100px; margin: 0 auto; padding: 24px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 40px; height: 40px; fill: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 1.6rem; line-height: 1.1; }
.brand p { margin: 2px 0 0; color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 48px; }
.status { color: var(--muted); min-height: 1.5em; }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--error); min-height: 1.2em; margin: 4px 0; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.card-head { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.card-title { margin: 0; font-size: 1.15rem; line-height: 1.3; }
.badge {
  flex: none; font-weight: 700; font-size: 0.9rem;
  padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge:empty { display: none; }
.card-body { display: grid; gap: 4px; }
.card-body .file { font-weight: 600; overflow-wrap: anywhere; }
.card-body .meta { color: var(--muted); font-size: 0.95rem; }
.card-body .note {
  margin: 6px 0 0; padding: 8px 10px; border-left: 3px solid var(--accent);
  background: var(--bg); border-radius: 6px; white-space: pre-wrap; font-size: 0.95rem;
}
.card-body .empty { color: var(--muted); margin: 0; }

.card-actions { display: grid; gap: 8px; margin-top: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn[aria-disabled="true"], .btn:disabled { opacity: 0.45; pointer-events: none; }

.history summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
.history ol { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.history li {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px;
  padding-top: 8px; border-top: 1px solid var(--border); font-size: 0.95rem;
}
.history li a { color: var(--accent); font-weight: 600; }

.footer { max-width: 1100px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 0.95rem; }
.footer a { color: var(--accent); }
.login { display: grid; place-items: center; padding-top: 24px; }
.login .panel { width: min(100%, 400px); }
.login h2 { margin: 0; }

label { font-weight: 600; margin-top: 4px; display: block; }
input[type="text"], input[type="password"], textarea, input[type="file"] {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-top: 4px;
}
progress { width: 100%; height: 10px; accent-color: var(--accent); }

.dialog {
  width: min(100% - 32px, 520px); max-height: calc(100% - 32px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 18px;
}
.dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.dialog form { display: flex; flex-direction: column; gap: 8px; }
.dialog.wide { width: min(100% - 16px, 1100px); height: calc(100% - 32px); padding: 12px; }
.dialog.wide[open] { display: flex; flex-direction: column; gap: 10px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.dialog-head h2 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.dialog-actions { display: flex; gap: 8px; }
#preview-frame { flex: 1; width: 100%; border: 0; border-radius: 8px; background: var(--bg); }
