/* SGV Parts — one stylesheet, phone first. */

:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --ink: #18181b;
  --ink-2: #52525b;
  --ink-3: #8a8a93;
  --line: #e4e4e7;
  --line-2: #d4d4d8;
  --accent: #15803d;
  --accent-ink: #ffffff;
  --accent-soft: #e8f5ec;
  --accent-text: #166534;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warn-soft: #fff6e0;
  --warn-text: #7a4b00;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); }
img { display: block; max-width: 100%; }
.mono { font-family: var(--mono); letter-spacing: -0.01em; }
.muted { color: var(--ink-2); margin: 0 0 12px; }
.small { font-size: 14px; }
.ic { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }
.js .nojs-only { display: none; }

/* ---- top bar ---------------------------------------------------- */

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar .iconbtn:first-child { margin-left: -8px; }
.bar-title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 18px; font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-action { display: flex; align-items: center; gap: 4px; }
.count { font-size: 14px; color: var(--ink-3); padding: 0 4px; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }

/* ---- buttons ------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
  font: 500 16px/1 var(--font); text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn-sm .ic { width: 16px; height: 16px; }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); border-color: #f1c4c4; margin-top: 16px; }
.btn[disabled] { opacity: 0.6; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink); cursor: pointer;
}
.iconbtn:active { background: var(--line); }
.iconbtn.danger { color: var(--danger); }
.linkbtn {
  align-self: flex-start; border: 0; background: none; padding: 8px 0 0; color: var(--accent-text);
  font: 500 15px var(--font); cursor: pointer;
}

/* ---- flash messages ---------------------------------------------- */

.flash { padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 14px; font-size: 15px; }
.flash-ok    { background: var(--accent-soft); color: var(--accent-text); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warn  { background: var(--warn-soft); color: var(--warn-text); }

/* ---- list page ---------------------------------------------------- */

.search {
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 6px 0 14px;
  background: var(--card); border: 1px solid var(--line-2); border-radius: var(--radius);
  color: var(--ink-3);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input[type=search] {
  flex: 1; min-width: 0; height: 100%; min-height: 0; padding: 0;
  border: 0; outline: 0; background: none; box-shadow: none;
  font: 16px var(--font); color: var(--ink);
}
.search input::-webkit-search-cancel-button { display: none; }
.search-clear { display: flex; padding: 8px; color: var(--ink-3); }

.chips {
  display: flex; gap: 8px; overflow-x: auto; margin: 12px -16px 4px; padding: 2px 16px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--card);
  color: var(--ink-2); font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.chip span { color: var(--ink-3); font-weight: 400; }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.is-on span { color: #c4c4c8; }
.chip.is-static { height: 30px; padding: 0 12px; }

.resultline { margin: 4px 0 8px; font-size: 14px; color: var(--ink-3); }

.list {
  list-style: none; margin: 4px 0 0; padding: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.list li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; min-height: 76px; color: inherit; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.row:active { background: #fafafa; }
.row > .ic { color: var(--line-2); }
.thumb {
  width: 56px; height: 56px; flex: none; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--ink-3);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more { margin-top: 12px; }

.empty { text-align: center; padding: 48px 16px; }
.empty-title { font-size: 18px; font-weight: 600; margin: 0 0 6px; }

.fab {
  position: fixed; z-index: 15; right: 16px; bottom: calc(16px + var(--safe-b));
  display: inline-flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 22px 0 18px; border-radius: 999px;
  background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 600; font-size: 16px;
  box-shadow: 0 6px 20px rgba(21, 128, 61, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
}
.fab .ic { width: 22px; height: 22px; }
@media (min-width: 700px) { .fab { right: calc(50% - 320px + 16px); } }

/* ---- cards and forms ---------------------------------------------- */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px; margin-bottom: 16px;
}
.card-title { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 22px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-size: 14px; font-weight: 500; color: var(--ink); padding: 0; }
.field legend { margin-bottom: 8px; }
.req { font-weight: 400; color: var(--ink-3); font-size: 13px; margin-left: 4px; }
.hint { margin: 2px 0 0; font-size: 13px; color: var(--ink-3); }
.field-error { margin: 2px 0 0; font-size: 14px; color: var(--danger); }

input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
  font: 16px/1.4 var(--font);   /* 16px stops iOS zooming on focus */
  -webkit-appearance: none; appearance: none;
}
input.mono { font-family: var(--mono); }
textarea { resize: vertical; min-height: 110px; }
select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2352525b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
[aria-invalid=true] { border-color: var(--danger) !important; }
::placeholder { color: #a1a1aa; }

/* category: list or a new name */
.catpick { display: flex; flex-direction: column; gap: 8px; }
.js .catpick #new_category { display: none; }
.js .catpick.is-new #new_category { display: block; }
.js .catpick.is-new select { display: none; }

/* photo tiles */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--bg); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.tile-x {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(24, 24, 27, 0.72); color: #fff; border: 0; padding: 0; cursor: pointer;
}
.tile-x .ic { width: 16px; height: 16px; }
.tile-gone {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: 8px; text-align: center; font-size: 12px; font-weight: 500; color: var(--danger);
  background: rgba(255, 255, 255, 0.82);
}
.tile input:checked ~ .tile-gone { display: flex; }
.tile input:checked ~ .tile-x { display: none; }
.tile-keep input:checked ~ .tile-gone { display: none; }
.tile-keep input:checked ~ .tile-x { display: flex; }
.tile-keep input:not(:checked) ~ .tile-gone { display: flex; }
.tile-keep input:not(:checked) ~ .tile-x { display: none; }
.tile-first::after {
  content: "Cover"; position: absolute; left: 6px; bottom: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500;
  background: rgba(24, 24, 27, 0.72); color: #fff;
}
.tile-busy::before {
  content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, 0.6);
}
.tile-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px dashed var(--line-2); background: var(--card); color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.tile-add .ic { width: 26px; height: 26px; }
.tile-add input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.field.has-error .tile-add { border-color: var(--danger); color: var(--danger); }

.savebar {
  position: sticky; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  margin: 0 -16px -20px; padding: 12px 16px calc(12px + var(--safe-b));
  background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
.has-savebar .wrap { padding-bottom: 16px; }

/* ---- part page ---------------------------------------------------- */

.gallery { margin: -16px -16px 16px; background: #0f0f10; }
.gallery-track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; outline: 0;
}
.gallery-track::-webkit-scrollbar { display: none; }
.gallery-slide {
  flex: 0 0 100%; scroll-snap-align: center; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center;
}
.gallery-slide img { width: 100%; height: 100%; object-fit: contain; }
.flash + .gallery { margin-top: 0; }
.dots { display: flex; justify-content: center; gap: 6px; padding: 10px 0 12px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: #55555c; transition: background 0.2s; }
.dots span.is-on { background: #fff; }
@media (min-width: 700px) { .gallery { margin: 0 0 16px; border-radius: var(--radius); overflow: hidden; } }

.detail-name { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.detail-pn { margin: 4px 0 12px; font-size: 16px; color: var(--ink-2); }
.label { margin: 20px 0 6px; font-size: 13px; font-weight: 500; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.notes { font-size: 16px; line-height: 1.6; white-space: normal; overflow-wrap: anywhere; }
.stamp { margin: 20px 0 0; font-size: 13px; color: var(--ink-3); }

.confirm { border-color: #f1c4c4; }
.confirm h3 { margin: 0 0 6px; font-size: 18px; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: #000; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.lb-stage {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
}
.lb-img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  transform-origin: center center; will-change: transform; -webkit-user-drag: none;
}
.lb-img.is-anim { transition: transform 0.2s ease-out; }
.lb-btn {
  position: absolute; z-index: 2; width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 0; background: rgba(40, 40, 44, 0.7); color: #fff; cursor: pointer;
}
.lb-btn .ic { width: 24px; height: 24px; }
.lb-close { top: max(12px, env(safe-area-inset-top)); right: 12px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-count {
  position: absolute; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); margin: 0;
  text-align: center; font-size: 14px; color: #c4c4c8;
}
@media (hover: none) { .lb-prev, .lb-next { display: none; } }
body.lb-open { overflow: hidden; }

/* ---- settings ------------------------------------------------------ */

.catlist { list-style: none; margin: 12px 0 16px; padding: 0; }
.catlist li {
  display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 0;
  border-top: 1px solid var(--line);
}
.catlist li:last-child { border-bottom: 1px solid var(--line); }
.catname { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.catcount { font-size: 14px; color: var(--ink-3); white-space: nowrap; }
.iconslot { width: 44px; flex: none; }
.catrename, .catadd { display: flex; gap: 8px; align-items: center; width: 100%; }
.catrename input, .catadd input { flex: 1; min-width: 0; }
.catadd .btn, .catrename .btn { min-height: 48px; }
form.inline { display: inline; margin: 0; }

/* ---- login ---------------------------------------------------------- */

.loginpage { min-height: 100vh; display: flex; align-items: center; background: var(--bg); }
.loginpage .wrap { width: 100%; padding-bottom: 32px; }
.loginbox {
  max-width: 380px; margin: 0 auto; padding: 28px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.loginlogo { width: 140px; height: auto; margin: 0 0 18px; mix-blend-mode: multiply; }
.login-title { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
