/* ==========================================================================
   Lista de Compras — folha de estilo unica, sem framework.
   Mobile-first: alvos de toque grandes, areas seguras do iPhone respeitadas.
   ========================================================================== */

:root {
  --green-600: #0f7a4f;
  --green-500: #14915e;
  --green-400: #1fb277;
  --green-100: #e3f5ec;

  --bg: #f4f6f5;
  --bg-elevated: #ffffff;
  --bg-sunken: #eceeed;
  --surface-hover: #f2f4f3;
  --border: #dfe4e2;
  --border-strong: #c7cfcb;

  --text: #16211d;
  --text-muted: #5d6b65;
  --text-faint: #8b9691;

  --accent: var(--green-600);
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --danger-bg: #fdeceb;
  --warning: #b7791f;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(16, 32, 26, 0.06);
  --shadow: 0 6px 18px rgba(16, 32, 26, 0.1);
  --shadow-lg: 0 18px 48px rgba(16, 32, 26, 0.22);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1412;
    --bg-elevated: #151f1b;
    --bg-sunken: #0a110f;
    --surface-hover: #1c2824;
    --border: #243330;
    --border-strong: #354742;

    --text: #e8efeb;
    --text-muted: #9fb0aa;
    --text-faint: #72847e;

    --accent: var(--green-400);
    --accent-contrast: #05100b;
    --danger: #ff7a6b;
    --danger-bg: #351f1d;
    --warning: #e0b050;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------- layout --- */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.boot {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 16px;
  justify-items: center;
  color: var(--text-muted);
}

.boot__spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

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

/* ------------------------------------------------------------ topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__title {
  flex: 1;
  min-width: 0;
}

.topbar__title h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.iconbtn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text);
  flex: none;
}

.iconbtn:hover {
  background: var(--surface-hover);
}

.iconbtn:active {
  transform: scale(0.94);
}

.iconbtn svg {
  width: 22px;
  height: 22px;
}

.progress {
  height: 4px;
  margin-top: 10px;
  border-radius: 99px;
  background: var(--bg-sunken);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.badge--current {
  background: var(--green-100);
  color: var(--green-600);
}

.badge--finished {
  background: var(--bg-sunken);
  color: var(--text-muted);
}

@media (prefers-color-scheme: dark) {
  .badge--current {
    background: #10352a;
    color: var(--green-400);
  }
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}

.dot--live {
  background: var(--green-400);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--green-400) 60%, transparent);
  animation: pulse 2.4s ease-out infinite;
}

.dot--off {
  background: var(--warning);
  animation: none;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 7px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* -------------------------------------------------------------- main --- */

.main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 160px;
}

.section-title {
  margin: 22px 4px 8px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty svg {
  width: 56px;
  height: 56px;
  opacity: 0.4;
  margin-bottom: 12px;
}

.empty p {
  margin: 4px 0;
}

/* ------------------------------------------------------------- itens --- */

.items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 2px 8px 2px 4px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  transition: background 0.15s ease, opacity 0.2s ease;
}

.item:last-child {
  border-bottom: none;
}

.item--checked .item__name {
  text-decoration: line-through;
  color: var(--text-faint);
}

.item--checked {
  background: color-mix(in srgb, var(--bg-sunken) 55%, transparent);
}

.item--pending-sync {
  opacity: 0.65;
}

.item__check {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.item__check:active {
  transform: scale(0.9);
}

/* Lista finalizada: a caixa vira só um registro, sem parecer clicável. */
.item__check--static {
  opacity: 0.55;
}

.item__check--static:active {
  transform: none;
}

.check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.check svg {
  width: 16px;
  height: 16px;
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.15s ease;
  color: var(--accent-contrast);
}

.item--checked .check {
  background: var(--accent);
  border-color: var(--accent);
}

.item--checked .check svg {
  opacity: 1;
  transform: scale(1);
}

.item__body {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item__line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.item__name {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
}

.item__qty {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 1px 7px;
  border-radius: 99px;
  white-space: nowrap;
}

.item__sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item__link {
  flex: none;
  width: 44px;
  height: 44px;
  margin-top: 4px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--accent);
}

.item__link:hover {
  background: var(--surface-hover);
}

.item__link svg {
  width: 19px;
  height: 19px;
}

.items__divider {
  padding: 10px 16px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}

/* ------------------------------------------------------ barra de add --- */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}

.composer__inner {
  max-width: 720px;
  margin: 0 auto;
}

.composer__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer__field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 6px 0 16px;
}

.composer__field:focus-within {
  border-color: var(--accent);
}

.composer__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  padding: 13px 0;
  font-size: 16px; /* evita o zoom automatico do iOS */
  outline: none;
}

.composer__toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.composer__toggle svg {
  width: 18px;
  height: 18px;
  transition: transform 0.2s ease;
}

.composer__toggle[aria-expanded='true'] svg {
  transform: rotate(180deg);
  color: var(--accent);
}

.composer__send {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.composer__send:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.composer__send:active:not(:disabled) {
  transform: scale(0.92);
}

.composer__send svg {
  width: 24px;
  height: 24px;
}

.composer__extra {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.composer__extra[hidden] {
  display: none;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}

.input:focus,
.textarea:focus {
  border-color: var(--accent);
}

.textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.45;
}

.hint {
  font-size: 0.76rem;
  color: var(--text-faint);
}

/* ------------------------------------------------------- sugestoes ----- */

.suggestions {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 8px;
  scrollbar-width: none;
}

.suggestions::-webkit-scrollbar {
  display: none;
}

.suggestions[hidden] {
  display: none;
}

.chip {
  flex: none;
  padding: 7px 13px;
  border-radius: 99px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  white-space: nowrap;
}

.chip:active {
  transform: scale(0.95);
}

.chip--accent {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
  font-weight: 600;
}

/* -------------------------------------------------------------- menu --- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 16, 13, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.scrim--open {
  opacity: 1;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  width: min(86vw, 340px);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform 0.24s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.drawer--open {
  transform: translateX(0);
}

.drawer__head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.drawer__brand img {
  width: 30px;
  height: 30px;
}

.drawer__user {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 20px;
  -webkit-overflow-scrolling: touch;
}

.drawer__foot {
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.navlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.navitem {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 12px;
  text-align: left;
  color: var(--text);
}

.navitem:hover {
  background: var(--surface-hover);
}

.navitem--active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.navitem svg {
  width: 20px;
  height: 20px;
  flex: none;
  opacity: 0.8;
}

.navitem__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.navitem__count {
  font-size: 0.74rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------- listagens --- */

.listcard {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  background: var(--bg-elevated);
}

.listcard:last-child {
  border-bottom: none;
}

.listcard:hover {
  background: var(--surface-hover);
}

.listcard__main {
  flex: 1;
  min-width: 0;
}

.listcard__name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.listcard__meta {
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.listcard__chev {
  color: var(--text-faint);
  flex: none;
}

.listcard__chev svg {
  width: 18px;
  height: 18px;
}

/* ------------------------------------------------------------ botoes --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text);
  min-height: 48px;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
}

.btn svg {
  width: 19px;
  height: 19px;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn--danger {
  background: var(--danger-bg);
  border-color: transparent;
  color: var(--danger);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--block {
  width: 100%;
}

.btnrow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btnrow .btn {
  flex: 1;
  min-width: 140px;
}

/* -------------------------------------------------------------- sheet -- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 8px 16px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 88dvh;
  overflow-y: auto;
  max-width: 720px;
  margin: 0 auto;
}

.sheet--open {
  transform: translateY(0);
}

.sheet__grab {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-strong);
  margin: 6px auto 14px;
}

.sheet__title {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 650;
}

.sheet__desc {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.sheet__form {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  font-size: 0.9rem;
}

.checkline input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: none;
}

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

.login {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login__box {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login__logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: block;
}

.login h1 {
  margin: 0 0 4px;
  text-align: center;
  font-size: 1.25rem;
}

.login p.sub {
  margin: 0 0 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.login form {
  display: grid;
  gap: 14px;
}

.error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

/* ------------------------------------------------------------ toasts --- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(92vw, 460px);
  pointer-events: none;
}

.toast {
  background: #1c2a25;
  color: #f2f7f4;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}

.toast--error {
  background: #7a2320;
}

.toast__action {
  margin-left: auto;
  font-weight: 700;
  color: var(--green-400);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* -------------------------------------------------------- offline bar -- */

.offlinebar {
  background: var(--warning);
  color: #1c1405;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
}

.updatebar {
  background: var(--accent);
  color: var(--accent-contrast);
  text-align: center;
  font-size: 0.82rem;
  padding: 8px 12px;
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
}

.updatebar button {
  color: inherit;
  text-decoration: underline;
  font-weight: 700;
}

@media (min-width: 760px) {
  .composer {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(720px, 100%);
    border: 1px solid var(--border);
    border-bottom: none;
  }
}
