:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #2b241b;
  --muted: #8a7f6d;
  --accent: #b5651d;
  --accent-soft: #f0dfc8;
  --empty: #e8e3d8;
  --border: #ddd4c2;
  --highlight: #ffe27a;
  --danger: #b3432b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1913;
    --surface: #2a251c;
    --ink: #ecE4d4;
    --muted: #a89a80;
    --accent: #e0975a;
    --accent-soft: #4a3a26;
    --empty: #332d22;
    --border: #453b2b;
    --highlight: #6b5a1f;
    --danger: #e0705a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 1.2rem;
  margin: 0;
  white-space: nowrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

#searchInput {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 0.95rem;
}

#searchInput:focus {
  outline: 2px solid var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}

.search-result {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--accent-soft); }
.search-result .item-name { font-weight: 600; }
.search-result .section-tag {
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.search-result .section-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.search-empty {
  padding: 0.75rem 0.9rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.topbar-actions button {
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.85rem;
}
.topbar-actions button:hover { background: var(--accent-soft); }

main#eaves {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.eave {
  background: var(--surface);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.eave-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.eave-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .eave-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 0.75rem; }
}

.section-box {
  position: relative;
  aspect-ratio: 1.1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--empty);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  text-align: center;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.section-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.section-box.has-items {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.section-box.match {
  outline: 3px solid var(--highlight);
  outline-offset: 2px;
}

.eave-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.section-row {
  border: 1px solid var(--border);
  background: var(--empty);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  cursor: pointer;
}

.section-row:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.section-row.has-items {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.section-row.match {
  outline: 3px solid var(--highlight);
  outline-offset: 2px;
}

.section-row-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.section-row-header .section-id {
  font-size: 1rem;
  font-weight: 700;
}

.section-row-header .section-custom-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.section-row-items {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
  color: var(--ink);
}

.section-row-items li {
  font-size: 0.9rem;
}

.section-row-empty {
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.tag-dots {
  display: flex;
  gap: 0.3rem;
}

.tag-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.section-box .tag-dots {
  position: absolute;
  bottom: 8px;
  left: 8px;
}

.tag-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-toggle {
  border: 2px solid var(--tag-bg);
  background: transparent;
  color: var(--tag-bg);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.tag-toggle.active {
  background: var(--tag-bg);
  color: var(--tag-text);
}

.section-id {
  font-size: 1.1rem;
  font-weight: 700;
}

.section-custom-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.item-count {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.7rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 30;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 92vw);
  background: var(--surface);
  z-index: 31;
  padding: 1.25rem;
  box-shadow: -8px 0 24px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h2 { margin: 0; }

#panelClose {
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
}

.section-label-input {
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.add-item-row {
  display: flex;
  gap: 0.5rem;
}

.add-item-row input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.add-item-row button {
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.item-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}

.item-list button {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.95rem;
}

.empty-state {
  color: var(--muted);
  font-style: italic;
}

.hidden { display: none !important; }
