/* ============ Design tokens: colors and fonts in one place ============ */
:root {
  --herb: #1D5C45;        /* main green: buttons, logo */
  --herb-dark: #144533;   /* button hover */
  --mint: #EAF2EC;        /* page background */
  --paper: #FFFFFF;       /* cards and inputs */
  --ink: #17231D;         /* main text */
  --muted: #55625A;       /* secondary text */
  --line: #CAD6CE;        /* borders */
  --turmeric: #E5A43C;    /* item count badge */
  --error: #B3261E;

  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  background: var(--mint);
  color: var(--ink);
}

/* Make sure hidden screens stay hidden, even though screens use display: grid/flex */
[hidden] { display: none !important; }

h1, h2 { font-family: var(--display); margin: 0; }
.muted { color: var(--muted); margin: 0; }

/* ============ Brand (logo + app name) ============ */
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--herb);
  color: var(--paper);
}
.wordmark { font-family: var(--display); font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }

/* ============ Login screen layout ============ */
.screen { max-width: 960px; margin: 0 auto; padding: 28px 20px 48px; }

.login {
  display: grid;
  gap: 28px;
  grid-template-areas: "brand" "hero" "form";
}
.login .brand { grid-area: brand; }
.hero { grid-area: hero; display: flex; flex-direction: column; gap: 28px; }
.login form { grid-area: form; }

.hero h1 {
  font-size: clamp(34px, 8vw, 54px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.03em;
  max-width: 13ch;
}

/* Laptop and wider: headline on the left, form on the right */
@media (min-width: 860px) {
  .screen { padding-top: 40px; }
  .login {
    grid-template-columns: 1.15fr 1fr;
    grid-template-areas: "brand brand" "hero form";
    column-gap: 64px;
    align-items: center;
  }
}

/* Round tick circle, used on each item in a list */
.box {
  width: 20px; height: 20px; flex-shrink: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
}

/* ============ Form card ============ */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
}
.card h2 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }

.stack { display: flex; flex-direction: column; gap: 8px; }
label { font-weight: 600; font-size: 14px; margin-top: 8px; }

input {
  height: 50px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
input:focus { outline: none; border-color: var(--herb); box-shadow: 0 0 0 4px rgba(29, 92, 69, 0.18); }

button { font: inherit; font-weight: 600; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--herb); outline-offset: 3px; }

.primary {
  height: 52px;
  margin-top: 10px;
  border: 0;
  border-radius: 12px;
  background: var(--herb);
  color: var(--paper);
  font-size: 17px;
}
.primary:hover { background: var(--herb-dark); }
.primary:active { transform: translateY(1px); }

.quiet {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--herb);
}
.quiet:hover { background: rgba(29, 92, 69, 0.08); }

.error { color: var(--error); min-height: 1.2em; margin: 4px 0 0; font-size: 14px; }

/* ============ Home screen ============ */
.home { max-width: 560px; display: flex; flex-direction: column; gap: 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.home-title h1 { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; }
.empty {
  padding: 32px 24px;
  border: 2px dashed var(--line);
  border-radius: 20px;
  text-align: center;
}
.empty-title { font-family: var(--display); font-weight: 800; font-size: 22px; margin: 0 0 4px; }

/* ============ Lists screen ============ */

/* Hidden on screen, but read out by screen readers */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.add-row { display: flex; gap: 10px; }
.add-row input { flex: 1; min-width: 0; }
.add-row .primary { margin-top: 0; height: 50px; padding: 0 18px; }
.home .error { margin-top: -18px; }

/* The lists sit on one "notepad" panel, rows split by dashed lines */
.lists-panel {
  list-style: none;
  margin: 0;
  padding: 4px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.list-row:last-child { border-bottom: 0; }

.list-summary { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list-name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.list-actions { display: flex; gap: 2px; flex-shrink: 0; }

.small { min-height: 44px; padding: 0 10px; font-size: 15px; }
.primary.small { height: 44px; margin-top: 0; padding: 0 16px; font-size: 15px; }
.danger { color: var(--error); }
.danger:hover { background: rgba(179, 38, 30, 0.08); }

.rename-form { display: flex; align-items: center; gap: 8px; width: 100%; }
.rename-form input { flex: 1; min-width: 0; height: 44px; }

/* ============ "Are you sure?" box ============ */
dialog {
  width: min(92vw, 400px);
  padding: 24px;
  border: 0;
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgba(23, 35, 29, 0.45); }
dialog h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.danger-button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--error);
  color: var(--paper);
}
.danger-button:hover { background: #8F1E18; }

/* ============ Moving between views ============ */
.view { display: flex; flex-direction: column; gap: 28px; }
.view .error { margin-top: -18px; }

/* A list's name + count is a link that opens the list */
.list-summary {
  flex: 1;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  border-radius: 10px;
}
.list-summary:hover .list-name { text-decoration: underline; text-underline-offset: 4px; }
a:focus-visible { outline: 3px solid var(--herb); outline-offset: 3px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  margin: -10px 0 4px -6px;
  padding: 0 6px;
  color: var(--herb);
  font-weight: 600;
  text-decoration: none;
  border-radius: 10px;
}
.back-link:hover { background: rgba(29, 92, 69, 0.08); }

/* ============ Items ============ */
.item-row { border-bottom: 1px dashed var(--line); }
.item-row:last-child { border-bottom: 0; }

/* Each item is one big button: easy to tap with a cart in the other hand */
.item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 10px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}
.item .box { width: 24px; height: 24px; }
.item-words { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-text { font-size: 17px; overflow-wrap: anywhere; }
.item-by { font-size: 13px; color: var(--muted); }

/* Ticked-off items: filled circle, crossed out */
.item[aria-pressed="true"] .box {
  background: var(--herb);
  border-color: var(--herb);
  box-shadow: inset 0 0 0 4px var(--paper);
}
.item[aria-pressed="true"] .item-text { color: var(--muted); text-decoration: line-through; }

.completed { display: flex; flex-direction: column; gap: 12px; }
.section-title { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.done-panel { background: rgba(255, 255, 255, 0.6); }

/* "Clear completed" sits at the very bottom, under the completed items */
.clear-button {
  min-height: 48px;
  border: 1.5px solid rgba(179, 38, 30, 0.35);
  border-radius: 12px;
  background: var(--paper);
  color: var(--error);
}
.clear-button:hover { background: rgba(179, 38, 30, 0.06); }

/* "Bought by …" line on ticked-off items */
.item-bought { color: var(--herb); }

/* =====================================================================
   Phone-friendly touches
   ===================================================================== */

/* Taps feel instant: no grey flash, no double-tap-to-zoom delay */
html { -webkit-text-size-adjust: 100%; }
button, a, input { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* Pressed feedback (phones have no hover) */
.item:active, .list-summary:active, .icon-button:active { opacity: 0.6; }
.primary:active, .clear-button:active, .danger-button:active { transform: scale(0.98); }

/* Pencil and bin buttons on each list */
.icon-button {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent;
  color: var(--muted);
}
.icon-button:hover { background: rgba(29, 92, 69, 0.08); color: var(--herb); }
.icon-button.danger { color: var(--error); }
.icon-button.danger:hover { background: rgba(179, 38, 30, 0.08); color: var(--error); }

/* ---------- Phone-sized screens ---------- */
@media (max-width: 640px) {
  .screen { padding-left: 16px; padding-right: 16px; }

  /* Login: keep clear of the notch */
  .login { padding-top: calc(20px + env(safe-area-inset-top)); gap: 24px; }

  /* Main app: room at the bottom for the fixed "add" bar and the home indicator */
  .home {
    padding-top: 0;
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
    gap: 18px;
  }

  /* App bar stays at the top while you scroll, like a native app */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    margin: 0 -16px;
    padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
    background: rgba(234, 242, 236, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }

  .view { gap: 18px; }
  .home-title h1 { font-size: 32px; }
  .home .error, .view .error { margin-top: 0; min-height: 0; }
  .home .error:empty { display: none; }

  /* The "add" box stays at the top, under the title, so when the keyboard
     opens you can still see the lists or items that are already there. */

  .lists-panel { padding: 0 16px; border-radius: 16px; }
  .list-row { min-height: 60px; gap: 8px; }
  .list-name { font-size: 19px; }
  .empty { padding: 24px 16px; }

  /* "Are you sure?" slides up from the bottom, like an iPhone action sheet */
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  }
  dialog[open] { animation: sheet-up 0.22s ease-out; }
  .dialog-actions { flex-direction: column-reverse; gap: 8px; }
  .dialog-actions button { width: 100%; min-height: 50px; font-size: 17px; }
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { dialog[open] { animation: none; } }

/* =====================================================================
   Option A: "Polished market" look
   ===================================================================== */

/* Top bar: your initial next to Log out */
.topbar-right { display: flex; align-items: center; gap: 6px; }

/* People's initials in circles */
.avatar {
  width: 30px; height: 30px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  font-weight: 700; font-size: 13px;
}
.avatar.mini { width: 18px; height: 18px; font-size: 10px; }
.avatar.siva  { background: var(--herb); color: var(--paper); }
.avatar.ramya { background: var(--turmeric); color: var(--ink); }
.avatar.other { background: var(--line); color: var(--ink); }

/* Title with an Edit button on the right */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.home-title h1 { font-size: 38px; }
.home-title .muted { margin-top: 4px; }

/* Grouped white cards, like iPhone Settings */
.lists-panel {
  border: 0;
  box-shadow: 0 1px 0 #D4DED7, 0 10px 30px -24px rgba(23, 35, 29, 0.35);
}
.list-row, .item-row { border-bottom: 1px solid #E6ECE8; }
.list-row:last-child, .item-row:last-child { border-bottom: 0; }
.done-panel { box-shadow: none; }

/* A list row: ring, name, "2 of 5 bought", arrow */
.list-summary { display: flex; align-items: center; gap: 14px; padding: 6px 0; }
.list-words { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.list-sub { color: var(--muted); font-size: 13px; }
.ring { display: grid; flex-shrink: 0; font-family: var(--body); }
.chevron { color: #9AA59E; display: grid; }

/* Items: who added it as a small circle, plus the time */
.item .box { border-color: #7A867E; }
.item-text { font-weight: 500; }
.item-by { display: flex; align-items: center; gap: 6px; margin-top: 2px; }

/* Progress under the list name: one segment per item */
.progress { display: flex; gap: 4px; margin-top: 12px; }
.progress:empty { display: none; }
.progress > span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress > span.on { background: var(--herb); }
.progress > .bar { position: relative; overflow: hidden; }
.progress > .bar > .on { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--herb); }

/* "Bought" heading with Clear on the right */
.section-head { display: flex; align-items: center; justify-content: space-between; }

/* Rounded add box with a round + button */
.add-row input { border-radius: 25px; padding: 0 18px; }
.add-button {
  width: 50px; height: 50px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--herb);
  color: var(--paper);
}
.add-button:hover { background: var(--herb-dark); }
.add-button:active { transform: scale(0.94); }
.add-button:disabled { opacity: 0.6; }

@media (max-width: 640px) {
  .home-title h1 { font-size: 34px; }
}

/* Bought items: solid green circle with a white tick */
.item[aria-pressed="true"] .box {
  border-color: var(--herb);
  box-shadow: none;
  background: var(--herb) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E") center / 16px no-repeat;
}

/* ============ Edit and delete on each item ============ */
.item-row { display: flex; align-items: center; gap: 4px; }
.item-row .item { flex: 1; min-width: 0; }
.item-row .rename-form { padding: 10px 0; }

/* Friendly note, e.g. "That list no longer exists" */
.notice {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(29, 92, 69, 0.08);
  color: var(--ink);
  font-size: 14px;
}

/* Items that are still saving, or failed to save */
.item-row.pending .item-text { color: var(--muted); }
.item-failed { color: var(--error); }

/* Messages that belong to one row (rename or edit) sit right under it */
.list-row.editing, .item-row.editing { flex-wrap: wrap; }
.row-error { width: 100%; margin: -4px 0 10px; }

/* "Milk is already on this list." + Add anyway */
.duplicate { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* "You're offline" banner */
.offline-banner {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--turmeric);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

/* ============ Progress ring colours ============ */
.ring-track { fill: none; stroke: #E6ECE8; stroke-width: 4; }
.ring-arc { fill: none; stroke: var(--herb); stroke-width: 4; stroke-linecap: round; }
.ring-fill { fill: transparent; }
.ring-number { font-family: var(--body); font-size: 14px; font-weight: 800; fill: var(--ink); }
.ring-check { fill: none; stroke: var(--paper); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* Something to buy: turmeric circle, so it stands out */
.ring.ring-to-buy .ring-fill { fill: var(--turmeric); }
/* Nothing on the list yet: quiet grey number */
.ring.ring-empty .ring-number { fill: var(--muted); font-weight: 600; }
/* Everything bought: green circle with a white tick */
.ring.ring-done .ring-fill { fill: var(--herb); }

/* ============ Create account (invite) and Invite sheet ============ */
.hint { margin: -2px 0 4px; font-size: 13px; color: var(--muted); }
.hero .muted { font-size: 17px; line-height: 1.45; max-width: 32ch; }
.switch-link { margin: 0; font-weight: 600; }
.switch-link a { color: var(--herb); text-decoration: none; }
.switch-link a:hover { text-decoration: underline; }

#invite-link { width: 100%; font-size: 14px; color: var(--muted); }
.invite-actions { display: flex; gap: 10px; }
.invite-actions button { flex: 1; min-height: 48px; margin-top: 0; }
#invite-dialog .primary { margin-top: 4px; }

/* ============ Demo login (under the login form) ============ */
.demo-login {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.demo-login p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.demo-login strong { color: var(--ink); }
.demo-login code {
  font: 600 15px var(--body);
  color: var(--ink);
  background: var(--mint);
  border-radius: 6px;
  padding: 1px 6px;
}
.demo-button {
  height: 48px;
  border: 1.5px solid var(--herb);
  border-radius: 12px;
  background: var(--paper);
  color: var(--herb);
  font-size: 16px;
}
.demo-button:hover { background: var(--mint); }
