/* home-app · mobile-first */

:root {
  --bg: #f5f4f0;
  --bg-elev: #ffffff;
  --bg-elev-2: #faf9f5;
  --text: #1a1f1c;
  --text-muted: #6b6f6c;
  --text-faint: #9a9d99;
  --accent: #1f6b4a;
  --accent-soft: #d6efde;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-lg: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --bg-elev: #1c2123;
    --bg-elev-2: #232a2c;
    --text: #ecefee;
    --text-muted: #a4a9a7;
    --text-faint: #6b6f6c;
    --accent: #4caa7d;
    --accent-soft: #1f3a2d;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; font-size: inherit; color: inherit; }

#app { min-height: 100%; display: flex; flex-direction: column; }

.view { display: flex; flex-direction: column; flex: 1; min-height: 100vh; min-height: 100dvh; }
.view-center { align-items: center; justify-content: center; padding: 24px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.topbar-title {
  flex: 1; text-align: center; font-weight: 600; font-size: 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.iconbtn, .iconbtn-placeholder {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 12px;
  font-size: 22px; cursor: pointer; color: var(--text);
}
.iconbtn:active { background: var(--accent-soft); }

/* ---------- page container ---------- */
.page {
  padding: 16px;
  padding-bottom: calc(var(--safe-bot) + 32px);
  max-width: 640px; width: 100%; margin: 0 auto;
}

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-inline { flex-direction: row; }
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.field > input, .form-inline > input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  outline: none;
  transition: border-color 120ms;
  min-width: 0; /* allows flex to shrink */
}
.field > input:focus, .form-inline > input:focus { border-color: var(--accent); }

.form-inline > input { flex: 1; }
.form-inline > .qty { flex: 0 0 70px; }
.form-add { gap: 8px; align-items: stretch; }
.form-add .btn { padding-left: 18px; padding-right: 18px; }

.form-error {
  background: rgba(179, 38, 30, 0.1);
  color: var(--danger);
  padding: 10px 12px; border-radius: var(--radius); font-size: 14px;
}

.btn {
  padding: 12px 18px;
  border: none; border-radius: var(--radius);
  font-weight: 600; cursor: pointer;
  background: var(--bg-elev-2); color: var(--text);
  transition: transform 80ms, opacity 120ms;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); }
.btn-google {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; text-decoration: none; padding: 11px 18px;
}
.btn-google svg { flex: 0 0 18px; }
.auth-tertiary { margin-top: 14px; }

.linklike {
  background: none; border: none; color: var(--accent);
  font-weight: 500; cursor: pointer; padding: 4px 0;
}
.linklike:disabled { color: var(--text-faint); cursor: not-allowed; }

/* ---------- auth view ---------- */
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev); border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-title { margin: 0 0 4px; font-size: 28px; font-weight: 700; }
.auth-sub { margin: 0 0 18px; color: var(--text-muted); }
.auth-switch { margin-top: 18px; font-size: 14px; color: var(--text-muted); text-align: center; }
.auth-switch button { font-size: 14px; padding: 0 0 0 4px; }
.auth-tertiary { text-align: center; font-size: 13px; color: var(--text-faint); }
.dot { margin: 0 6px; color: var(--text-faint); }

/* ---------- card lists ---------- */
.cards { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }
.cards li {
  background: var(--bg-elev); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 100ms;
}
.cards li:active { background: var(--bg-elev-2); }
.cards .card-title { font-weight: 600; flex: 1; }
.cards .card-sub { color: var(--text-muted); font-size: 13px; }
.cards .role-pill {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 8px; border-radius: 999px;
}

/* ---------- dashboard tiles ---------- */
.tiles {
  list-style: none; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.tile {
  background: var(--bg-elev); border-radius: var(--radius-lg);
  padding: 18px 16px; box-shadow: var(--shadow);
  cursor: pointer; min-height: 130px;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform 80ms, background 120ms;
  border: none; text-align: left; color: var(--text); font: inherit;
}
.tile:active { transform: scale(0.98); background: var(--bg-elev-2); }
.tile-icon { font-size: 28px; margin-bottom: 2px; }
.tile-title { font-weight: 700; font-size: 16px; }
.tile-sub   { color: var(--text-muted); font-size: 13px; }

/* ---------- shopping ---------- */
.form-add { gap: 8px; }
.form-add .form-row { display: flex; gap: 8px; align-items: stretch; }
.form-add .form-row > input[name="text"] { flex: 1; min-width: 0; }
.form-add .form-row > input.qty { flex: 0 0 70px; }
.form-add .form-row > .btn { padding-left: 18px; padding-right: 18px; }
.form-add .select-section {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font-size: 14px;
}
.form-add .select-section:focus { border-color: var(--accent); outline: none; }
.linklike-strong { display: block; margin: 4px 0 14px; font-size: 14px; }

.section { margin-bottom: 18px; }
.section-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 6px;
}
.section-name {
  flex: 1; font-weight: 600; font-size: 14px; letter-spacing: 0.02em;
  text-transform: uppercase; color: var(--text-muted);
  background: none; border: none; padding: 4px 0; cursor: text;
  min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.section-name:focus { outline: none; color: var(--text); }
.section-del {
  background: none; border: none; color: var(--text-faint);
  font-size: 16px; cursor: pointer; padding: 4px 6px;
}
.section-del:active { color: var(--danger); }
.section-count { color: var(--text-faint); font-size: 12px; }

.items { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--bg-elev); border-radius: var(--radius);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.item.completed .item-text { text-decoration: line-through; color: var(--text-faint); }
.checkbox {
  width: 28px; height: 28px; flex: 0 0 28px;
  border: 2px solid var(--border); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 120ms, border-color 120ms;
  font-size: 16px; color: white;
}
.checkbox.checked { background: var(--accent); border-color: var(--accent); }
.checkbox.checked::after { content: "✓"; }
.item-text { flex: 1; min-width: 0; word-break: break-word; }
.item-qty { color: var(--text-muted); font-size: 14px; flex: 0 0 auto; }
.item-del {
  border: none; background: none; color: var(--text-faint);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}
.item-del:active { color: var(--danger); }

.item.readonly .checkbox { cursor: default; }
.item.readonly .item-del { display: none; }

.empty { text-align: center; padding: 32px 12px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.sync-status { text-align: center; }

/* ---------- spinner ---------- */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- view switching ---------- */
.view-loading [data-view="loading"] { display: flex; }
.view-loading [data-view]:not([data-view="loading"]) { display: none !important; }
