/* Lastoga · Listonic-inspired styles */

:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --ink: #1a1d1c;
  --ink-soft: #5b6360;
  --line: #e8e7e2;
  --accent: #1f7a5a;
  --accent-soft: #e8f5ee;
  --accent-ink: #145a41;
  --warn: #b8541a;
  --warn-soft: #fdebdc;
  --danger: #b3271a;
  --shadow: 0 1px 2px rgba(20, 30, 28, .04), 0 4px 12px rgba(20, 30, 28, .05);
  --radius: 14px;
  --radius-sm: 10px;
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body, #app {
  margin: 0; padding: 0;
  height: 100dvh;
  overflow: hidden;            /* body never scrolls — .main scrolls instead, so iOS chrome can't reflow */
  overscroll-behavior: none;
}
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.4;
  touch-action: manipulation;  /* disables pinch-zoom and double-tap-to-zoom in modern browsers */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* no long-press text-selection / share popover on iOS */
}
input, textarea {
  /* Re-enable text editing in form fields, otherwise typing/selecting in inputs breaks. */
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Splash + login ---------- */

.splash {
  display: grid; place-items: center; min-height: 100dvh;
  color: var(--ink-soft);
}
.login-screen {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: 22px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  width: 100%; max-width: 360px;
}
.login-card .brand { text-align: center; margin-bottom: 18px; }
.login-card .brand-mark {
  display: inline-grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--accent); color: white;
  font-weight: 700; font-size: 28px;
  margin-bottom: 8px;
}
.login-card h1 { margin: 4px 0 2px; font-size: 24px; }
.login-card p  { margin: 0; color: var(--ink-soft); font-size: 14px; }

.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-card form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.login-card input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}
.login-card .hint { color: var(--ink-soft); font-size: 13px; margin-top: 12px; text-align: center; }

/* ---------- Buttons ---------- */

button.primary, button.danger, button.ghost {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-weight: 600;
}
button.primary { background: var(--accent); color: white; }
button.primary:disabled { background: #9ec6b6; }
button.ghost   { background: transparent; border-color: var(--line); }
button.danger  { background: transparent; color: var(--danger); border-color: rgba(179,39,26,.25); }
button.small   { padding: 8px 10px; font-size: 14px; }

.error { color: var(--danger); font-size: 14px; }

/* ---------- App shell ---------- */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  /* leave room at the bottom for the fixed-positioned bottom-nav */
  padding-bottom: calc(56px + var(--safe-bot));
}
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px 10px;
  background: var(--bg);
  z-index: 5;
}
.topbar-title {
  font-size: 22px; font-weight: 700;
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sort-select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}

.conn-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
  user-select: none;
}
.conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.conn-badge.online     { background: #e6f5ec; color: #1f7a5a; border-color: #c7e7d3; }
.conn-badge.offline    { background: #fde9e9; color: #a92929; border-color: #f1c2c2; }
.conn-badge.connecting { background: #fff4e0; color: #a55a00; border-color: #f1d9a3; }
.conn-badge.connecting .conn-dot { animation: conn-pulse 1.1s ease-in-out infinite; }
@keyframes conn-pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

.main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 12px;
}

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 7;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
  /* ensure background actually extends through the home-indicator zone on iOS */
  box-shadow: 0 calc(var(--safe-bot) * -0) 0 0 var(--surface);
}
.bottom-nav::after {
  /* fills the home-indicator gap with the nav's surface color so there's no
     white/empty strip between the nav and the screen edge in standalone PWA. */
  content: '';
  position: absolute;
  left: 0; right: 0; top: 100%;
  height: var(--safe-bot);
  background: var(--surface);
}
.bottom-nav button {
  background: transparent; border: 0; padding: 12px 6px;
  color: var(--ink-soft); font-weight: 600;
}
.bottom-nav button.active { color: var(--accent); }

/* ---------- Trip header / banners ---------- */

.trip-header {
  padding: 4px 4px 14px;
  display: flex; align-items: baseline; justify-content: space-between;
}
.trip-title { font-size: 18px; font-weight: 700; }
.trip-meta { color: var(--ink-soft); font-size: 14px; }

.badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 12px; font-weight: 600;
}
.badge.muted { background: var(--line); color: var(--ink-soft); }
.badge.done  { background: #d6efdd; color: var(--accent-ink); }

.trip-finish-banner {
  margin: 12px 4px 0;
  padding: 12px 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 14px;
}
.trip-finish-banner.all-done {
  background: var(--accent);
  color: white;
  font-weight: 600;
}
.trip-finish-banner.all-done .primary {
  background: white; color: var(--accent-ink);
}

.all-done-tile {
  margin: 14px 4px 4px;
  padding: 18px 16px;
  background: linear-gradient(135deg, #d6efdd 0%, #e8f5ee 100%);
  color: var(--accent-ink);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.all-done-mark { font-size: 36px; }
.all-done-title { font-size: 20px; font-weight: 700; }
.all-done-sub { font-size: 13px; opacity: .8; }

.tag-new {
  display: flex; gap: 6px; margin-top: 8px;
}
.tag-new input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
}

.history-detail { padding: 4px; }
.back-link {
  background: transparent; border: 0;
  color: var(--accent-ink); font-weight: 600;
  padding: 8px 0;
  font-size: 14px;
}

/* ---------- Tag sections ---------- */

.tag-section { margin-top: 12px; }
.tag-header {
  margin: 8px 4px 6px;
  font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-soft);
}
.done-section {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 2px dashed var(--line);
}
.done-section .tag-header {
  color: var(--accent);
  margin-top: 0;
}

/* ---------- Item rows ---------- */

.item-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background .25s, opacity .25s, transform .25s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.item-row.catalog {
  /* fixed-width action column on the far right so the image always sits at
     the same horizontal position regardless of "+ Add" vs "Remove" width */
  grid-template-columns: 1fr 56px 84px;
}
.item-row.bought,
.item-row.unavailable {
  background: #f3f1ec;
  opacity: .7;
}
/* Strikethrough only on the active list. History rows keep clean names. */
.item-row.bought:not(.history) .item-name,
.item-row.unavailable:not(.history) .item-name { text-decoration: line-through; }
.item-row.locked { opacity: .55; }
.item-row.locked .item-name { font-style: italic; }

.thumb {
  width: 56px; height: 56px; border-radius: 12px;
  object-fit: cover; background: var(--accent-soft);
  cursor: zoom-in;
}
.thumb-letter {
  display: grid; place-items: center;
  font-weight: 700; font-size: 24px;
  cursor: default;
}
.item-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-name-row {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.item-name {
  font-weight: 600; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 0 1 auto; min-width: 0;
}
.item-qty {
  font-size: 13px; color: var(--ink-soft); font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.marked-by {
  display: inline-block;
  font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 2px;
  align-self: flex-start;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip {
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
}
.chip.inline {
  margin-top: 0;
  flex: 0 0 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}
.catalog-action {
  display: flex; align-items: center; justify-content: flex-end;
}
.catalog-action .full {
  width: 100%;
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
}

.status-mark {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--surface);
}
.status-mark.big {
  position: static;
  width: 32px; height: 32px;
  font-size: 18px;
  margin-left: 8px;
  box-shadow: none;
}
.status-mark.bought       { color: var(--accent); }
.status-mark.unavailable  { color: var(--warn); }
.item-row.history {
  grid-template-columns: 1fr 56px 32px;
  align-items: center;
  opacity: 1;
}
.item-row.history.bought,
.item-row.history.unavailable { background: var(--surface); opacity: 1; }

/* ---------- Image lightbox ---------- */

.lightbox-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 13, .9);
  display: grid; place-items: center;
  padding: 16px;
  animation: lightbox-in .15s ease-out;
}
.lightbox-img {
  max-width: 95vw;
  max-height: 95vh;
  width: auto; height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 30px 60px rgba(0,0,0,.5);
  cursor: default;
}
@keyframes lightbox-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Long-press menu */
.row-menu {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(4px);
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px;
  padding: 8px;
  box-shadow: var(--shadow);
  z-index: 2;
}
.row-menu button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  font-size: 13px; font-weight: 600;
}

/* ---------- Catalog ---------- */

.search-bar {
  display: flex; gap: 8px;
  margin: 6px 4px 8px;
}
.search-bar input {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.item-row.catalog { cursor: pointer; }

/* ---------- Floating + button ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(72px + var(--safe-bot));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent); color: white;
  font-size: 28px; font-weight: 600;
  box-shadow: 0 6px 18px rgba(31,122,90,.3);
  z-index: 4;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20,30,28,.5);
  display: grid; place-items: end center;
}
.modal {
  background: var(--surface);
  width: 100%; max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bot));
  display: grid; gap: 10px;
  max-height: 92dvh; overflow-y: auto;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.modal label.checkbox {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  color: var(--ink); font-size: 14px;
}
.modal input[type=text],
.modal input[type=password],
.modal input:not([type]),
.modal input[type=file] {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fff;
  width: 100%;
  color: var(--ink);
}
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }

/* ---------- History ---------- */

.history-row {
  background: var(--surface);
  padding: 12px 14px;
  margin: 8px 4px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  cursor: pointer;
}
.trip-stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Settings ---------- */

.settings-view { padding: 4px 4px; }
.settings-view section {
  background: var(--surface);
  padding: 14px;
  margin-top: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.settings-view section h3 { margin: 0 0 8px; font-size: 15px; }
.settings-view section .hint { color: var(--ink-soft); font-size: 13px; margin: 6px 0 0; }
.settings-view section form { display: grid; gap: 8px; }
.settings-view section input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- Tag picker (item editor) ---------- */

.tag-picker {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.tag-chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tag-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Tag reorder list ---------- */

.tag-order-list {
  list-style: none; padding: 0; margin: 8px 0 12px;
  display: grid; gap: 6px;
}
.tag-order-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px; align-items: center;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.tag-order-name { font-weight: 600; }
.tag-order-list button { padding: 4px 10px; min-width: 36px; }

/* ---------- Form messages + toast ---------- */

.form-msg { margin: 8px 0 0; font-size: 13px; }
.form-msg.ok  { color: var(--accent-ink); }
.form-msg.err { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bot));
  transform: translateX(-50%);
  background: rgba(20,30,28,.92); color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 20;
  animation: toast-in .2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- iOS install card ---------- */

.ios-install-card {
  margin: 8px;
  padding: 12px 14px;
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: var(--radius);
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.ios-install-card p { margin: 4px 0 0; font-size: 13px; }
.ios-share { font-weight: 700; }

/* ---------- Empty state ---------- */

.empty {
  text-align: center; color: var(--ink-soft);
  padding: 32px 16px;
}
.empty p { margin: 0 0 12px; }
