/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
  --text:   #1a1a1a;
  --bg:     #f9f9f7;
  --border: #c8c8c0;
  --accent: #1a56cc;
  --muted:  #666;
  --danger: #c0392b;
  --ok:     #2e8b47;
  --radius: 3px;
  --max-w:  52rem;
  --gap:    1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text:   #e8e8e4;
    --bg:     #1a1a18;
    --border: #3a3a38;
    --accent: #6ea8fe;
    --muted:  #999;
    --danger: #e05c4b;
    --ok:     #4caf6f;
  }
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────────────────────────────────── */
body {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.6rem; margin: 0.75rem 0 0.5rem; }
h2 { font-size: 1.3rem; margin: 1rem 0 0.5rem; }
h3 { font-size: 1.1rem; margin: 1rem 0 0.4rem; }
p  { margin: 0.5rem 0; }
small { color: var(--muted); }
code { font-family: 'Courier New', Courier, monospace; font-size: 0.9em; }

/* ── Rendered markdown (item descriptions, .md attachments) ────────────────
   The reset above zeroes padding on every element, which strips the default
   left inset that list markers need — without this they render clipped
   against the edge of the page/iframe. */
.markdown-content ol,
.markdown-content ul { padding-left: 1.5rem; margin: 0.5rem 0; }
.markdown-content li { margin: 0.15rem 0; }
.markdown-content table { border-collapse: collapse; margin: 0.5rem 0; }
.markdown-content th,
.markdown-content td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; text-align: left; }
.markdown-content th { background: var(--border); }

/* ── Links ──────────────────────────────────────────────────────────────── */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius); }

/* ── Layout ─────────────────────────────────────────────────────────────── */
header {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  margin-bottom: 1.25rem;
}

footer {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0;
  margin-top: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }

.git-status-ok { color: var(--ok); }
.git-status-error { color: var(--danger); }
.git-status-link:hover { text-decoration: underline; }

main > section { margin-bottom: 1.5rem; }

/* ── Navigation / breadcrumb ────────────────────────────────────────────── */
nav > ul {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  gap: 0;
  font-size: 0.9rem;
}

nav > ul li:not(:last-child)::after {
  content: "›";
  margin: 0 0.4rem;
  color: var(--muted);
}

/* ── Header row with a right-aligned action link (e.g. page title + button) ── */
.header-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.header-row h1 { margin: 0.5rem 0; }
.header-row a[role="button"], .header-row button { margin: 0; }

/* ── Search form in header ──────────────────────────────────────────────── */
header form[role="search"] {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

header form[role="search"] input { width: auto; flex: 1; margin-top: 0; }
header form[role="search"] button { margin-top: 0; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
label { display: block; font-size: 0.9rem; font-weight: 600; margin-top: 0.75rem; }
input, textarea, select {
  display: block;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  margin-top: 0.2rem;
}

input[type="file"]   { border: none; padding: 0; }
input[type="radio"]  { display: inline; width: auto; margin: 0 0.25rem 0 0; }
input[type="hidden"] { display: none; }
input[type="submit"] { display: inline-block; width: auto; }

textarea { resize: vertical; min-height: 8rem; }

input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

fieldset { border: none; padding: 0; margin-top: 0.75rem; }
fieldset legend { font-weight: 600; font-size: 0.9rem; }
fieldset label { display: inline; font-weight: normal; margin-right: 1rem; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
button, input[type="submit"], a[role="button"] {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  margin-top: 0.75rem;
  margin-right: 0.4rem;
  text-decoration: none;
}

button:hover, input[type="submit"]:hover, a[role="button"]:hover { background: var(--border); text-decoration: none; }
button:focus-visible, input[type="submit"]:focus-visible, a[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: var(--bg); }

/* ── Item chips (inside / siblings lists) ───────────────────────────────── */
.item-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 1rem;
  list-style: none;
}

.item-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  padding: 0.4rem 0.9rem;
  font-size: 1rem;
  min-height: 2.5rem;
}

.item-chip img {
  height: 2rem;
  width: auto;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: -0.4rem;
}

.item-chip a { color: var(--text); }
.item-chip a:hover { color: var(--accent); text-decoration: none; }

/* ── Field chips (custom metadata on item page) ─────────────────────────── */
.field-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0;
  list-style: none;
}

.field-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  padding: 0.2rem 0.65rem;
  font-size: 0.85rem;
}

.field-chip .field-key { opacity: 0.6; }
.field-chip a { color: var(--text); }
.field-chip a:hover { color: var(--accent); text-decoration: none; }

/* ── Custom field editor rows (edit form) ───────────────────────────────── */
.field-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.field-row input { flex: 1; width: auto; margin: 0; }
.field-row button { flex-shrink: 0; margin: 0; }

/* ── Filter/sort form (filter page) ──────────────────────────────────────
   Mixes <select> (wide intrinsic content) with <input>: flex-basis:8rem plus
   wrap lets narrow rows stack instead of squeezing the select down to where
   its selected option text is clipped. */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.filter-row input,
.filter-row select {
  flex: 1 1 8rem;
  min-width: 0;
  margin: 0;
}

.filter-row button { flex-shrink: 0; margin: 0; }

.autocomplete-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 12rem;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.autocomplete-list li {
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.autocomplete-list li:hover { background: var(--accent); color: var(--bg); }

/* ── Item header (photo + name) ─────────────────────────────────────────── */
.item-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.item-header h1 { margin: 0; line-height: 1; }
.item-header > img { max-height: 200px; max-width: 100%; border-radius: var(--radius); }

/* ── Item action buttons ────────────────────────────────────────────────── */
.item-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.75rem 0; align-items: center; }
.item-actions button, .item-actions a { margin: 0; }

/* ── Attachments ────────────────────────────────────────────────────────── */
.attachments-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; margin: 0.5rem 0; }

.attachments-list > li { border: 1px solid var(--border); border-radius: var(--radius); }

.attachments-list > li > details,
.attachments-list > li > div { width: 100%; }

.attachments-list > li > details > summary,
.attachments-list > li > div {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  cursor: default;
  list-style: none;
  min-width: 0;
}

.attachments-list > li > details > summary { cursor: pointer; }
.attachments-list > li > details > summary::marker,
.attachments-list > li > details > summary::-webkit-details-marker { display: none; }

.attachment-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-icon {
  border: none;
  background: none;
  padding: 0.15rem 0.3rem;
  margin: 0;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: var(--radius);
  line-height: 1;
}

.btn-icon:hover { background: var(--border); }
.btn-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.attachments-list > li > details > :not(summary) { padding: 0 0.5rem 0.5rem; }
.attachments-list > li > details img { max-width: 100%; display: block; }
.attachments-list > li > details iframe,
.attachments-list > li > details embed { display: block; width: 100%; }

/* ── Dialog ─────────────────────────────────────────────────────────────── */
dialog {
  margin: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  padding: 1.5rem;
  max-width: 28rem;
  width: 90%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

dialog form { display: inline; }
dialog div { display: flex; align-items: center; gap: 0.25rem; }
dialog div input { margin-top: 0; }
dialog div > span { white-space: nowrap; color: var(--muted); }
dialog::backdrop { background: rgba(0,0,0,0.4); }

/* ── All-items collapsible tree ─────────────────────────────────────────── */
.all-items-tree ul { list-style: none; padding-left: 1.25rem; }
.all-items-tree > ul { padding-left: 0; }

.collapsible { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 0.3rem; }
.collapsible img { height: 2.5rem; width: 2.5rem; object-fit: cover; border-radius: var(--radius); flex-shrink: 0; }

.content { display: none; }
.expanded > .content { display: block; }
.collapsed > .content { display: none; }
.expanded > .collapsible::before,
.collapsed > .collapsible::before {
  content: "▶";
  display: inline-block;
  width: 0.9em;
  font-size: 0.7em;
  color: var(--muted);
}
.expanded > .collapsible::before { transform: rotate(90deg); }
