:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: #1c1c1e;
  background: #f2f2f7;
  font-synthesis: none;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #d1d1d6;
  --accent: #0a84ff;
  --danger: #ff3b30;
  --shadow: 0 8px 28px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 2px 18px;
}
.topbar h1, .login-card h1 { margin: 0; font-size: clamp(28px, 7vw, 38px); line-height: 1.05; letter-spacing: -.03em; }
.sync-state { margin-top: 5px; color: var(--muted); font-size: 13px; }
.text-button, .close-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 8px 2px;
  font-weight: 600;
}
.close-button { font-size: 30px; line-height: 1; color: var(--muted); }

.drawer-list { display: grid; gap: 12px; }
.drawer {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 17px 18px;
  text-align: left;
}
.drawer-title { font-weight: 700; font-size: 18px; }
.drawer-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.chevron { color: var(--muted); transition: transform .18s ease; font-size: 20px; }
.drawer.open .chevron { transform: rotate(90deg); }
.drawer-body { border-top: 1px solid var(--line); }
.product-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.product-row:last-of-type { border-bottom: 0; }
.product-name { font-weight: 600; overflow-wrap: anywhere; }
.product-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.add-product {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--accent);
  padding: 14px 18px;
  text-align: left;
  font-weight: 700;
}
.drawer-empty { padding: 14px 18px; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); padding: 70px 20px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,.34);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(560px, 100%);
  max-height: min(82dvh, 760px);
  overflow: auto;
  background: var(--card);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 22px 60px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 16px; font-size: 24px; }
.modal-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-heading-row h2 { margin-bottom: 0; }
input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
form { display: grid; gap: 12px; }
label { display: grid; gap: 7px; font-weight: 600; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.primary, .secondary, .danger, .move-button {
  border: 0;
  border-radius: 13px;
  padding: 12px 14px;
  font-weight: 700;
}
.primary { background: var(--accent); color: white; }
.secondary { background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--text); }
.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.full { width: 100%; }

.manage-list { display: grid; gap: 10px; margin-top: 16px; }
.manage-row {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}
.manage-name { font-weight: 700; margin-bottom: 10px; }
.manage-actions { display: grid; grid-template-columns: 42px 42px 1fr 1fr; gap: 7px; }
.move-button { padding: 10px 0; background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--text); }
.move-button:disabled { opacity: .35; cursor: default; }
.manage-actions .secondary, .manage-actions .danger { padding-inline: 8px; }
.manage-footer { display: grid; gap: 10px; margin-top: 16px; }

.login-view { min-height: calc(100vh - 46px); min-height: calc(100dvh - 46px); display: grid; place-items: center; }
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
}
.login-icon { width: 82px; height: 82px; border-radius: 20px; margin-bottom: 18px; }
.login-card .muted { margin: 8px 0 20px; }
.muted { color: var(--muted); }
.error-text { min-height: 1.2em; color: var(--danger); margin: 8px 0 0; font-size: 14px; }

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  transform: translateX(-50%);
  width: min(440px, calc(100% - 28px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(28,28,30,.94);
  color: white;
  border-radius: 15px;
  padding: 13px 15px;
  box-shadow: 0 12px 35px rgba(0,0,0,.25);
  backdrop-filter: blur(14px);
}
.toast button { border: 0; background: transparent; color: #64d2ff; font-weight: 800; }
.message-toast { justify-content: center; text-align: center; }

@media (min-width: 700px) {
  .modal-backdrop { place-items: center; }
  .app-shell { padding-inline: 22px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #98989d;
    --line: #38383a;
    --accent: #0a84ff;
    --shadow: 0 8px 30px rgba(0,0,0,.38);
  }
  .toast { background: rgba(44,44,46,.96); }
}
