/* Nakup — mobile-first shared shopping list. No framework, no build step. */

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #1b2420;
  --text-dim: #6b7a72;
  --accent: #10b981;
  --accent-press: #0e9f70;
  --danger: #e05252;
  --border: #dde3df;
  --shadow: 0 1px 3px rgba(20, 35, 28, 0.08), 0 4px 14px rgba(20, 35, 28, 0.05);
  --radius: 14px;
  --touch: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --surface: #18201c;
    --surface-2: #1f2924;
    --text: #e6ece8;
    --text-dim: #8fa098;
    --accent: #2dd4a0;
    --accent-press: #25b98a;
    --danger: #f07373;
    --border: #2a352f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

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

/* --- landing / nickname pages ------------------------------------------- */

.centered-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.hero {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.hero-icon { font-size: 56px; margin-bottom: 8px; }

.hero h1 { margin: 0 0 8px; font-size: 1.7rem; }

.hero-sub { color: var(--text-dim); margin: 0 0 28px; }

.hero-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero-form input {
  height: var(--touch);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease;
}

.hero-form input:focus { border-color: var(--accent); }

.form-error { color: var(--danger); margin-top: 12px; }

/* --- buttons ------------------------------------------------------------- */

.btn-primary {
  min-height: var(--touch);
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:active { background: var(--accent-press); transform: scale(0.98); }

.btn-ghost {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-ghost:active { background: var(--surface-2); }

/* --- list page ------------------------------------------------------------ */

.list-page {
  max-width: 640px;
  margin: 0 auto;
  /* Space for the fixed add form + safe area. */
  padding: 0 12px calc(96px + env(safe-area-inset-bottom));
}

.list-header {
  padding: 16px 4px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.list-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-header h1 {
  margin: 0;
  font-size: 1.35rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.sync-indicator.syncing { background: var(--accent); }
.sync-indicator.error { background: var(--danger); }

.list-header-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.nickname-badge {
  color: var(--text-dim);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- categories and items -------------------------------------------------- */

.cat-section { margin-top: 18px; }

.cat-header {
  margin: 0 4px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.cat-emoji { font-size: 1rem; margin-right: 2px; }

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--touch);
  padding: 6px 8px 6px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: opacity 0.2s ease, background 0.2s ease;
}

.drag-handle {
  width: 36px;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.item-main {
  flex: 1;
  min-width: 0;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
}

.item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-by {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.item-qty {
  width: 76px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease;
  flex-shrink: 0;
}

.item-qty:focus { border-color: var(--accent); background: var(--surface); }

.row-btn {
  width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.row-btn:active { background: var(--surface-2); }

.delete-btn { color: var(--danger); font-size: 1.4rem; }

/* done = bought: strikethrough + dimmed, stays in place */
.item-row.done { opacity: 0.55; }
.item-row.done .item-name { text-decoration: line-through; }

.deferred-section .item-row { background: var(--surface-2); }
.deferred-section .cat-header { color: var(--text-dim); }
.deferred-section.drop-hint .item-list {
  min-height: 52px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

/* --- drag and drop ---------------------------------------------------------- */

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  opacity: 0.92;
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  list-style: none;
}

.drag-source { opacity: 0.35; }

body.dragging { user-select: none; -webkit-user-select: none; }

/* --- empty state, loading, toast --------------------------------------------- */

.empty-state {
  margin-top: 48px;
  text-align: center;
  color: var(--text-dim);
  padding: 0 24px;
}

.empty-icon { font-size: 44px; margin-bottom: 8px; }

.loading {
  margin-top: 48px;
  text-align: center;
  color: var(--text-dim);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  max-width: min(92vw, 480px);
  padding: 10px 18px;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- fixed add form (thumb zone) ---------------------------------------------- */

.add-form {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  display: grid;
  grid-template-columns: 1fr 84px 108px 52px;
  gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.add-form input,
.add-form select {
  height: var(--touch);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
  min-width: 0;
  transition: border-color 0.15s ease;
}

.add-form input:focus,
.add-form select:focus { border-color: var(--accent); }

.add-form .btn-primary {
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

@media (max-width: 420px) {
  .add-form { grid-template-columns: 1fr 104px 52px; }
  .add-form #add-name { grid-column: 1 / -1; }
}
