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

:root {
  --blue:       #2563eb;
  --blue-dark:  #1d4ed8;
  --blue-light: #eff6ff;
  --blue-mid:   #dbeafe;
  --ink:        #111827;
  --ink-2:      #374151;
  --muted:      #6b7280;
  --subtle:     #9ca3af;
  --line:       #e5e7eb;
  --line-2:     #f3f4f6;
  --white:      #ffffff;
  --green:      #16a34a;
  --green-bg:   #f0fdf4;
  --red:        #dc2626;
  --red-bg:     #fef2f2;
  --radius:     8px;
  --radius-lg:  14px;
  --nav-h:      56px;
  --tab-h:      48px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

html, body {
  height: 100%;
}

body {
  background: var(--white);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; }

button { cursor: pointer; font: inherit; border: none; background: none; }
input, textarea { font: inherit; }

/* ─── Top nav bar ────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--blue);
}

.topbar-user {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

.quick-add {
  position: relative;
}

.quick-add-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--blue);
  color: var(--white);
  transition: background 120ms;
}

.quick-add-toggle:hover,
.quick-add-toggle[aria-expanded="true"] {
  background: var(--blue-dark);
}

.quick-add-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 250;
  width: min(360px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: 0 18px 50px rgba(0,0,0,0.16);
}

.quick-add-section + .quick-add-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.quick-add-options {
  display: grid;
  gap: 8px;
}

.quick-add-option {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  text-align: left;
  transition: background 120ms, border-color 120ms;
}

.quick-add-option:hover {
  border-color: var(--blue);
  background: var(--blue-light);
}

.quick-add-option strong,
.quick-add-option span {
  display: block;
}

.quick-add-option strong {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

.quick-add-option span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.quick-add-back {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.quick-add-back:hover {
  color: var(--blue);
}

.quick-add-section h2 {
  margin-bottom: 9px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
}

.user-name {
  font-size: 0.875rem;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu {
  position: relative;
}

.avatar-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--blue-light);
  color: var(--blue);
  overflow: hidden;
}

.avatar-button:hover,
.avatar-button[aria-expanded="true"] {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  font-size: 0.88rem;
  font-weight: 700;
}

.account-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 260;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--white);
  box-shadow: 0 18px 50px rgba(0,0,0,0.16);
}

.account-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
}

.account-menu-item:hover {
  background: var(--line-2);
  color: var(--ink);
}

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 42px;
  padding: 0 18px;
  border-radius: var(--radius);
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 120ms;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--blue-dark); }

.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 120ms;
  white-space: nowrap;
}
.btn-primary-sm:hover { background: var(--blue-dark); }

.btn-outline-sm {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius);
  border: 1px solid var(--blue);
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
  font-size: 0.85rem;
  transition: border-color 120ms, background 120ms;
  white-space: nowrap;
}
.btn-outline-sm:hover { border-color: var(--blue-dark); background: var(--blue-dark); color: var(--white); }

.btn-default-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, color 120ms;
}

.btn-default-sm:hover,
.btn-default-sm.active {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
}

.order-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  flex: 0 0 auto;
}

.btn-order-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  width: 34px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 120ms, border-color 120ms, color 120ms, opacity 120ms;
}

.btn-order-sm:hover:not(:disabled) {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
}

.btn-order-sm:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn-danger-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--red);
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 120ms;
}
.btn-danger-sm:hover { background: #b91c1c; }

.btn-ghost-sm {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 120ms, color 120ms;
}
.btn-ghost-sm:hover { background: var(--line-2); color: var(--ink); }

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 48px;
  padding: 0 24px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 120ms, border-color 120ms, box-shadow 120ms;
  width: 100%;
}
.btn-google:hover {
  background: var(--line-2);
  border-color: var(--subtle);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ─── Sign-in screen ─────────────────────────────────────────────────── */
.signin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--nav-h));
  padding: 24px 16px;
  background: var(--line-2);
}

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: calc(100vh - var(--nav-h));
  color: var(--muted);
  background: var(--line-2);
  font-size: 0.95rem;
  font-weight: 500;
}

.loading-mark {
  width: 30px;
  height: 30px;
  border: 3px solid var(--blue-mid);
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.signin-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
  text-align: center;
}

.signin-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--blue-light);
  margin-bottom: 20px;
}

.signin-logo svg {
  width: 28px;
  height: 28px;
  color: var(--blue);
}

.signin-card h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  color: var(--ink);
}

.signin-card p {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 28px;
}

/* ─── Main app ───────────────────────────────────────────────────────── */
.app {
  min-height: calc(100vh - var(--nav-h));
  display: flex;
  flex-direction: column;
}

/* ─── Tab bar ────────────────────────────────────────────────────────── */
.tab-bar-wrap {
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.tab-bar-inner {
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  overflow: hidden;
}

.tab-list {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-list::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--tab-h);
  padding: 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 120ms;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  font-weight: 600;
}

.new-list-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.new-list-form input {
  width: 100%;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--white);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.new-list-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ─── Workspace ──────────────────────────────────────────────────────── */
.workspace {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* ─── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  gap: 16px;
  text-align: center;
  color: var(--subtle);
}
.empty-state svg { color: var(--subtle); opacity: 0.6; }
.empty-state h2 { font-size: 1.3rem; font-weight: 600; color: var(--muted); }
.empty-state p { font-size: 0.95rem; color: var(--subtle); max-width: 360px; }

/* ─── List toolbar (share + filters) ────────────────────────────────── */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.share-section {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.shared-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--blue-mid);
  color: var(--blue-dark);
  font-size: 0.8rem;
  font-weight: 600;
}

.share-form {
  display: flex;
  gap: 7px;
}

.share-form.collapsed input {
  display: none;
}

.share-form input {
  width: 210px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--ink);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.share-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-group {
  display: flex;
  gap: 0;
  background: var(--line-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
}

.filter {
  height: 32px;
  padding: 0 14px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 120ms, color 120ms;
}
.filter.active {
  background: var(--white);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ─── Add item form ──────────────────────────────────────────────────── */
.add-item-wrap {
  margin-top: 20px;
  padding: 18px;
  background: var(--line-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.add-item-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.add-item-form input,
.add-item-form textarea {
  display: block;
  width: 100%;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}

.add-item-form input { height: 42px; }

.add-item-form textarea {
  padding: 10px 13px;
  resize: none;
  grid-column: 1;
}

.add-item-form input:focus,
.add-item-form textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.add-item-form .btn-primary {
  grid-column: 1;
  justify-self: stretch;
}

/* ─── Item list ──────────────────────────────────────────────────────── */
.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.item-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: start;
  padding: 14px 10px 14px 0;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  transition: background 120ms;
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--line-2); }

.item-row.bought { background: var(--green-bg); }
.item-row.bought:hover { background: #dcfce7; }

/* Custom checkbox */
.item-check-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 2px;
  cursor: pointer;
}

.item-check-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.item-check-box {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-radius: 5px;
  background: var(--white);
  transition: background 120ms, border-color 120ms;
  flex-shrink: 0;
}
.item-check-label:hover .item-check-box { border-color: var(--blue); }

.item-check:checked + .item-check-box {
  background: var(--green);
  border-color: var(--green);
}
.item-check:checked + .item-check-box::after {
  content: "";
  width: 11px;
  height: 6px;
  border: 2px solid white;
  border-top: none;
  border-right: none;
  transform: rotate(-45deg) translate(0, -1px);
}

.item-content {
  min-width: 0;
  padding-top: 1px;
}

.item-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.item-name {
  font-size: 0.975rem;
  font-weight: 500;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.item-row.bought .item-name {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.item-link-pill {
  display: none;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--blue-mid);
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.77rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms;
}
.item-link-pill:hover { background: var(--blue-mid); }

.item-desc {
  margin-top: 4px;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.item-meta {
  margin-top: 5px;
  font-size: 0.8rem;
  color: var(--subtle);
}

.item-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--subtle);
  opacity: 0;
  transition: opacity 120ms, background 120ms, color 120ms;
  margin: 0 4px;
}
.item-row:hover .item-delete { opacity: 1; }
.item-delete:hover { background: var(--red-bg); color: var(--red); }

/* ─── Items empty message ────────────────────────────────────────────── */
.items-empty {
  padding: 32px 0;
  text-align: center;
  color: var(--subtle);
  font-size: 0.925rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 200;
  padding: 11px 20px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--white);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 28px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── iOS install hint ───────────────────────────────────────────────── */
.ios-install,
.android-install {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  box-shadow: 0 12px 34px rgba(0,0,0,0.16);
}

.ios-install strong,
.ios-install span,
.android-install strong,
.android-install span {
  display: block;
}

.ios-install strong,
.android-install strong {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

.ios-install span,
.android-install span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.85rem;
}

.ios-install button,
.install-primary {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius);
  background: var(--blue);
  color: var(--white);
  font-size: 0.84rem;
  font-weight: 600;
}

.install-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.install-dismiss {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.install-dismiss:hover {
  background: var(--line-2);
  color: var(--ink);
}

/* ─── Utility ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { font-size: 14px; }

  .topbar-inner { padding: 0 14px; }
  .user-name { display: none; }

  .tab-bar-inner { padding: 0 10px; }

  .tab { padding: 0 13px; font-size: 0.88rem; }

  .order-actions {
    margin-left: 8px;
    padding-left: 8px;
  }

  .quick-add-menu {
    position: fixed;
    top: calc(var(--nav-h) + 8px);
    left: 12px;
    right: 12px;
    width: auto;
  }

  .workspace { padding: 16px 14px 36px; }

  .list-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .share-form { width: 100%; }
  .share-form input { flex: 1; width: auto; }
  .share-form.collapsed { width: auto; }

  .add-item-form {
    grid-template-columns: 1fr;
  }
  .add-item-form textarea { grid-column: 1; }
  .add-item-form .btn-primary { grid-column: 1; width: 100%; }

  .item-row {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    padding-right: 0;
  }

  .item-delete { opacity: 1; }
}

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