/* ---------- tokens ---------- */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --sheet: #ffffff;
  --raised: #ffffff;
  --text: #111114;
  --muted: #6e6e76;
  --border: rgba(60, 60, 67, 0.16);
  --border-strong: rgba(60, 60, 67, 0.3);
  --field: rgba(118, 118, 128, 0.12);
  --press: rgba(118, 118, 128, 0.12);
  --bar: rgba(249, 249, 251, 0.86);
  --accent: #e5484d;
  --accent-soft: rgba(229, 72, 77, 0.12);
  --on-accent: #ffffff;
  --ok: #1f9d55;
  --ok-soft: rgba(31, 157, 85, 0.14);
  --danger: #d92d20;
  --img-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
  --av-bg-l: 90%;
  --av-fg-l: 32%;
  --av-bg-s: 75%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --sheet: #1c1c1e;
    --raised: #636366;
    --text: #f2f2f7;
    --muted: #98989f;
    --border: rgba(84, 84, 88, 0.55);
    --border-strong: rgba(120, 120, 128, 0.6);
    --field: rgba(118, 118, 128, 0.24);
    --press: rgba(118, 118, 128, 0.24);
    --bar: rgba(22, 22, 24, 0.84);
    --accent: #ff6369;
    --accent-soft: rgba(255, 99, 105, 0.16);
    --ok: #30d158;
    --ok-soft: rgba(48, 209, 88, 0.16);
    --danger: #ff6961;
    --img-bg: #f4f4f6;
    --shadow: none;
    --av-bg-l: 26%;
    --av-fg-l: 84%;
    --av-bg-s: 30%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --sheet: #1c1c1e;
  --raised: #636366;
  --text: #f2f2f7;
  --muted: #98989f;
  --border: rgba(84, 84, 88, 0.55);
  --border-strong: rgba(120, 120, 128, 0.6);
  --field: rgba(118, 118, 128, 0.24);
  --press: rgba(118, 118, 128, 0.24);
  --bar: rgba(22, 22, 24, 0.84);
  --accent: #ff6369;
  --accent-soft: rgba(255, 99, 105, 0.16);
  --ok: #30d158;
  --ok-soft: rgba(48, 209, 88, 0.16);
  --danger: #ff6961;
  --img-bg: #f4f4f6;
  --shadow: none;
  --av-bg-l: 26%;
  --av-fg-l: 84%;
  --av-bg-s: 30%;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.sheet-open, html.sheet-open body { overflow: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
button, a, input, textarea { touch-action: manipulation; }
button, .tab, .row, .card { -webkit-user-select: none; user-select: none; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.i { width: 24px; height: 24px; flex: none; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left));
}
.page.with-tabs { padding-bottom: calc(env(safe-area-inset-bottom) + 100px); }

.head { margin: 4px 0 16px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.head h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; overflow-wrap: anywhere; }
.back {
  display: inline-flex; align-items: center; gap: 2px; height: 36px; margin-left: -8px;
  color: var(--accent); font-size: 17px; text-decoration: none;
}
.back .i { width: 26px; height: 26px; }
.round-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 2px 10px rgba(229, 72, 77, 0.35);
  transition: transform 0.12s;
}
.round-btn:active { transform: scale(0.92); }
.round-btn .i { width: 22px; height: 22px; stroke-width: 2.6; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px max(8px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--border);
}
.tab {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 2px 0 4px;
  color: var(--muted); text-decoration: none; font-size: 10.5px; font-weight: 500;
}
.tab .i { width: 27px; height: 27px; }
.tab.active { color: var(--accent); }
.tab.active .i-heart { fill: currentColor; }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card {
  position: relative; display: block; width: 100%; text-align: left;
  background: var(--surface); border-radius: 16px; overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.card:active { transform: scale(0.97); }
.card.full .ph { opacity: 0.45; }
.card-body { padding: 10px 12px 12px; }
.card-name {
  font-size: 15px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-note { margin-top: 2px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ph { position: relative; aspect-ratio: 1 / 1; background: var(--img-bg); overflow: hidden; }
.ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 8%; }
.ph.cover img { object-fit: cover; padding: 0; }
.ph.empty-ph { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.ph .ph-icon { width: 36%; height: 36%; opacity: 0.8; stroke-width: 1.6; }

.badge {
  position: absolute; top: 8px; left: 8px; max-width: calc(100% - 16px);
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px 4px 7px; border-radius: 999px;
  background: var(--ok); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 1.2;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.badge .i { width: 14px; height: 14px; stroke-width: 3; }
.badge.mine { background: var(--accent); }
.badge.neutral { background: rgba(0, 0, 0, 0.55); padding: 4px 9px; }

/* ---------- lists ---------- */
.list { background: var(--surface); border-radius: 14px; overflow: hidden; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 60px; padding: 10px 16px;
  text-align: left; text-decoration: none; color: inherit;
}
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 68px; border-top: 0.5px solid var(--border); }
a.row:active, button.row:active { background: var(--press); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 17px; overflow-wrap: anywhere; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); }
.row-icon { width: 20px; height: 20px; color: var(--muted); }
.row-lead { width: 22px; height: 22px; color: var(--accent); margin: 0 9px; }

.avatar {
  --h: 0;
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  background: hsl(var(--h) var(--av-bg-s) var(--av-bg-l));
  color: hsl(var(--h) 55% var(--av-fg-l));
}
.avatar.lg { width: 68px; height: 68px; font-size: 26px; }

.section { margin-top: 28px; }
.section-title { margin: 0 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.section-desc { margin: -2px 4px 10px; font-size: 13px; color: var(--muted); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; padding: 0 18px; border-radius: 14px;
  background: var(--field); color: var(--text);
  font-size: 17px; font-weight: 600; text-decoration: none; text-align: center;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn:disabled { opacity: 0.5; transform: none; cursor: default; }
.btn .i { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.plain { background: none; color: var(--accent); min-height: 44px; }
.btn.danger { color: var(--danger); }
.btn.small { width: auto; flex: none; min-height: 44px; padding: 0 14px; border-radius: 12px; font-size: 15px; }
.btn .host { font-weight: 400; color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }

.link { color: var(--accent); text-decoration: none; font-size: 15px; font-weight: 500; }
.link.center { display: block; text-align: center; margin-top: 24px; padding: 8px; }
.link-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px; color: var(--accent); font-size: 15px; font-weight: 500; }
.link-btn .i { width: 18px; height: 18px; }

.input {
  width: 100%; min-height: 48px; padding: 12px 14px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--field); border: 1px solid transparent; border-radius: 12px;
  outline: none; -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: var(--muted); opacity: 0.8; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: none; min-height: 72px; line-height: 1.4; }
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row .input { flex: 1; min-width: 0; }

.seg { display: flex; padding: 2px; border-radius: 10px; background: var(--field); }
.seg button { flex: 1; min-height: 36px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.seg button.on { background: var(--raised); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }

.qty { display: flex; align-items: center; gap: 10px; }
.step { width: 44px; height: 44px; border-radius: 12px; background: var(--field); font-size: 24px; font-weight: 500; line-height: 1; }
.step:disabled { opacity: 0.35; }
.qty-val { min-width: 30px; text-align: center; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip { margin-left: auto; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.pill { flex: none; padding: 3px 10px; border-radius: 999px; background: var(--field); color: var(--muted); font-size: 13px; font-weight: 600; }
.pill.on { background: var(--ok-soft); color: var(--ok); }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.form { display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { padding-left: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field-msg { margin: 0 4px; font-size: 13px; color: var(--muted); }
.field-msg:empty { display: none; }
.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.form-msg { color: var(--danger); font-size: 14px; text-align: center; }
.form-msg:empty { display: none; }
.fine { font-size: 13px; color: var(--muted); text-align: center; }
.fine.left { text-align: left; margin: 0 4px; }
.card-form { padding: 20px 16px; border-radius: 16px; background: var(--surface); }
.card-form h2 { font-size: 20px; }

.photo-field { display: flex; align-items: center; gap: 14px; }
.photo-box { position: relative; width: 104px; flex: none; border-radius: 14px; overflow: hidden; }
.photo-box.loading { opacity: 0.5; animation: pulse 1s ease-in-out infinite alternate; }
.photo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.photo-btns .btn.plain { min-height: 36px; padding: 0 4px; }

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.38);
  opacity: 0; transition: opacity 0.3s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: 640px; margin: 0 auto;
  max-height: 92vh;
  max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 6px max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.14);
  transform: translateY(100%);
  transition: transform 0.34s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.show { transform: none; }
.grabber { width: 36px; height: 5px; margin: 2px auto 10px; border-radius: 3px; background: var(--border-strong); }
.sheet-head {
  position: sticky; top: -6px; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  margin: 0 0 14px; padding: 4px 0;
  background: var(--sheet);
}
.sheet-head h2 { font-size: 17px; font-weight: 600; text-align: center; }
.sheet-head > :last-child { justify-self: end; }
.head-btn { justify-self: start; padding: 8px 2px; color: var(--accent); font-size: 17px; }
.head-btn.strong { font-weight: 600; }
.head-btn:disabled { opacity: 0.4; }
.sheet-title-center { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 6px 0 8px; }
.sheet-title-center h2 { font-size: 21px; }

.ph-lg { border-radius: 16px; margin: 2px 0 16px; aspect-ratio: auto; height: min(calc(100vw - 32px), 42vh, 420px); }
.detail { display: flex; flex-direction: column; gap: 12px; }
.detail-name { font-size: 22px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.detail-note { color: var(--muted); font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-status { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; color: var(--ok); }
.detail-status .i { width: 18px; height: 18px; stroke-width: 2.6; }

/* ---------- misc ---------- */
.login .brand { padding: 36px 0 28px; text-align: center; }
.brand-icon { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 6px 20px rgba(229, 72, 77, 0.3); }
.brand h1 { margin: 16px 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.login-foot { display: flex; flex-direction: column; align-items: center; gap: 18px; margin-top: 32px; }
.login-foot .seg { width: 220px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 48px 20px; text-align: center; color: var(--muted); }
.empty p { max-width: 300px; }
.empty .btn { width: auto; }
.empty-icon { width: 64px; height: 64px; padding: 16px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }

.tip { margin-top: 20px; padding: 12px 14px; border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 14px; line-height: 1.45; }

.loading-block { display: grid; place-items: center; padding: 64px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--field); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

#toast {
  position: fixed; left: 50%; z-index: 100;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 500; text-align: center;
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { opacity: 0.25; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
