*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --touch: 44px;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.title {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.main {
  flex: 1;
}

.panel {
  animation: fade 0.25s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hidden {
  display: none !important;
}

.btn {
  font: inherit;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  min-height: var(--touch);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-large {
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-size: 1.05rem;
  border-radius: var(--radius);
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
}

.btn-ghost:hover {
  background: #475569;
}

.hint,
.copy-feedback {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 1rem;
}

.copy-feedback {
  color: var(--accent);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.live {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.15);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
}

.live.offline {
  color: var(--muted);
  background: var(--surface2);
}

.add-form {
  display: grid;
  grid-template-columns: 1fr minmax(4.5rem, 22%) auto;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

@media (max-width: 420px) {
  .add-form {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .add-form input:first-of-type {
    grid-column: 1 / -1;
  }

  .add-form .btn-primary {
    grid-column: 1 / -1;
  }
}

.add-form input {
  font: inherit;
  padding: 0.65rem 0.75rem;
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
}

.add-form input::placeholder {
  color: var(--muted);
}

.add-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.item-row {
  display: grid;
  grid-template-columns: var(--touch) 1fr minmax(3.5rem, 22%) auto;
  gap: 0.5rem;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.5rem;
  border: 1px solid transparent;
}

.item-picked-toggle {
  width: 1.25rem;
  height: 1.25rem;
  min-width: var(--touch);
  min-height: var(--touch);
  margin: 0;
  justify-self: center;
  cursor: pointer;
  accent-color: var(--accent);
}

.item-row.item-picked .item-name-field,
.item-row.item-picked .item-amount-field {
  color: var(--muted);
  text-decoration: line-through;
}

.item-row .item-name-field,
.item-row .item-amount-field {
  font: inherit;
  padding: 0.5rem 0.65rem;
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface2);
  background: #0f172a;
  color: var(--text);
  width: 100%;
}

.item-row .item-name-field:focus,
.item-row .item-amount-field:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-save {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  min-height: var(--touch);
  font-size: 0.875rem;
}

.btn-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Narrow viewports: one physical row (must follow field rules so width/min-height win) */
@media (max-width: 640px) {
  .item-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.45rem;
    min-width: 0;
  }

  .item-picked-toggle {
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    min-width: 2.25rem;
    min-height: 2.25rem;
  }

  .item-row .item-name-field {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    max-width: 100%;
    min-height: 40px;
    padding: 0.45rem 0.5rem;
  }

  .item-row .item-amount-field {
    flex: 0 0 3.25rem;
    min-width: 0;
    width: 3.25rem;
    min-height: 40px;
    padding: 0.45rem 0.3rem;
    text-align: center;
  }

  .item-row .item-actions {
    flex: 0 0 auto;
    flex-shrink: 0;
  }

  .item-row .btn-save {
    min-height: 40px;
    padding: 0.4rem 0.45rem;
    font-size: 0.8125rem;
  }
}

.empty {
  text-align: center;
  color: var(--muted);
  margin: 2rem 0;
  font-size: 0.95rem;
}

.error-text {
  color: var(--danger);
  text-align: center;
  margin-bottom: 1.25rem;
}

#home {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 2rem 0;
}

#notFound {
  text-align: center;
  padding: 2rem 0;
}

#notFound a {
  display: inline-block;
  text-decoration: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
