:root {
  --bg: #f5f5f2; --card: #ffffff; --text: #1c1d1f; --muted: #6b6f76; --line: #e3e3de;
  --accent: #1f6f5c; --accent-text: #ffffff; --danger: #b3261e; --warn-bg: #fff4d6; --warn-text: #6b4e00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a; --card: #222427; --text: #ececec; --muted: #9a9fa6; --line: #33363a;
    --accent: #58b79f; --accent-text: #0d1f1a; --danger: #ff8a80; --warn-bg: #3b3115; --warn-text: #f1d88a;
  }
}
* { 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 -apple-system, BlinkMacSystemFont, "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left)); background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
#search { flex: 1 1 160px; min-width: 0; }

input, textarea, select {
  font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; border-radius: 8px; padding: 9px 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); display: inline-flex; align-items: center; gap: 6px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 14px; font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn b { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 13px; }

.banner { background: var(--warn-bg); color: var(--warn-text); padding: 10px 16px; font-size: 14px; }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 64px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }

.cat { margin: 22px 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.cat:first-child { margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
a.card:hover { border-color: var(--accent); }
.card .name { font-weight: 600; overflow-wrap: anywhere; }
.card .sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.card .count { font-size: 13px; color: var(--muted); margin-top: 6px; }

.back { display: inline-block; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.head h1 { font-size: 24px; overflow-wrap: anywhere; }
.head .actions { display: flex; gap: 6px; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 14px; }
.section h2 { font-size: 15px; margin-bottom: 8px; color: var(--muted); font-weight: 600; }

.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; gap: 8px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.files li:first-child { border-top: 0; }
.files .open { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.files .open .label { font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.files .open .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.addrow { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.addrow input[type=url] { flex: 1 1 220px; min-width: 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 15px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.qr { display: flex; gap: 14px; align-items: center; }
.qr img { width: 120px; height: 120px; border-radius: 6px; background: #fff; }
.qr .url { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.inboxItem { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.inboxItem:first-of-type { border-top: 0; }
.inboxItem .fields { display: flex; gap: 8px; flex-wrap: wrap; }
.inboxItem .fields > * { flex: 1 1 150px; min-width: 0; }
.inboxItem .fields .btn { flex: 0 0 auto; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(94vw, 480px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { font-size: 18px; margin-bottom: 4px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label input, dialog label textarea { font-size: 16px; color: var(--text); background: var(--bg); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlgBtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(92vw, 560px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20;
}
.toast.err { background: var(--danger); color: #fff; }
@media (max-width: 520px) {
  .head h1 { font-size: 21px; }
  .row2 { grid-template-columns: 1fr; }
}
