:root {
  --bg: #0b0d10;
  --bg-2: #14171c;
  --bg-3: #1c2028;
  --line: #242933;
  --text: #e7e9ee;
  --muted: #8a93a3;
  --accent: #4f9cff;
  --accent-2: #7c5cff;
  --ok: #2ec27e;
  --warn: #f0b429;
  --danger: #ef5350;
  --radius: 14px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  min-height: 100vh;
  min-height: 100svh;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100svh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 85%, transparent);
  z-index: 10;
  padding-top: calc(var(--safe-top) + 14px);
  margin-top: calc(-1 * var(--safe-top));
}

.top h1 {
  flex: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-width: 0;
}

.trip-title {
  outline: none;
  border-bottom: 1px dashed transparent;
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip-title:focus {
  border-color: var(--accent);
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  border-radius: 10px;
}

.icon-btn.back { font-size: 28px; line-height: 1; }
.icon-btn:hover { background: var(--bg-2); }

.saved-indicator {
  font-size: 12px;
  color: var(--muted);
  margin-right: 6px;
  min-width: 60px;
  text-align: right;
}

main {
  padding: 4px 16px 80px;
}

button {
  font: inherit;
  color: inherit;
}

.primary, .ghost, .danger {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: 0;
}
.primary:active { transform: scale(0.98); }

.ghost {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
}
.ghost:hover { background: var(--bg-3); }

.danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.full { width: 100%; }

.row {
  display: flex;
  gap: 10px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.row > button { flex: 1 1 auto; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: calc(var(--safe-top) + 58px);
  background: var(--bg);
  z-index: 9;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tabs button.active {
  color: var(--text);
  background: var(--bg-3);
}

.panel { display: none; }
.panel.active { display: block; }

.progress {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.progress-bar {
  height: 8px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--ok), var(--accent));
  width: 0%;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 13px;
  color: var(--muted);
}

.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters button {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.filters button.active {
  background: var(--bg-3);
  color: var(--text);
  border-color: var(--accent);
}

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

.category {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.category-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-3);
  cursor: pointer;
}
.category-head .chev {
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.2s;
}
.category.collapsed .chev { transform: rotate(-90deg); }
.category-head h3 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
  outline: none;
}
.category-head .count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
}
.category-head .cat-del {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  display: none;
}
.template-edit .category-head .cat-del,
.editing-cat .cat-del { display: inline-block; }

.items {
  display: flex;
  flex-direction: column;
}
.category.collapsed .items,
.category.collapsed .item-add { display: none; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  min-height: var(--tap);
}

.item.hidden { display: none; }

.state-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: transparent;
  transition: all 0.15s ease;
}

.item[data-state="taking"] .state-btn {
  border-color: var(--warn);
  color: var(--warn);
}
.item[data-state="taking"] .state-btn::after { content: "•"; font-size: 28px; line-height: 0.5; }

.item[data-state="packed"] .state-btn {
  background: var(--ok);
  border-color: var(--ok);
  color: white;
}
.item[data-state="packed"] .state-btn::after { content: "✓"; font-size: 16px; }

.item[data-state="skip"] .state-btn {
  background: transparent;
  border-color: var(--muted);
  color: var(--muted);
}
.item[data-state="skip"] .state-btn::after { content: "✕"; font-size: 14px; }

.item[data-state="packed"] .item-label {
  text-decoration: line-through;
  color: var(--muted);
}
.item[data-state="skip"] .item-label {
  opacity: 0.45;
  text-decoration: line-through;
}

.item-label {
  flex: 1;
  outline: none;
  padding: 2px 0;
  word-break: break-word;
}

.item-del {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0.6;
}
.item-del:hover { opacity: 1; color: var(--danger); }

.item-add {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.item-add input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 15px;
  padding: 8px 6px;
  outline: none;
}
.item-add input::placeholder { color: var(--muted); }
.item-add button {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 10px;
}

.add-category { margin-top: 16px; }

.trips-list {
  list-style: none;
  padding: 0;
  margin: 20px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trip-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.trip-card h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.trip-card .meta {
  font-size: 13px;
  color: var(--muted);
}
.trip-card .progress-mini {
  height: 4px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.trip-card .progress-mini > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--ok), var(--accent));
}
.trip-card .del-trip {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  opacity: 0.5;
}
.trip-card .del-trip:hover { opacity: 1; color: var(--danger); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}
.hidden { display: none !important; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.info-grid label:first-child { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

input, textarea, select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

main h3 {
  margin: 22px 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0 12px;
}

.flight, .hotel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  position: relative;
}
.flight > .full, .hotel > .full { grid-column: 1 / -1; }
.flight .del, .hotel .del {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
}
.flight .del:hover, .hotel .del:hover { color: var(--danger); }

.stats-box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--muted); font-size: 14px; }
.stat-row .v { font-weight: 600; }

#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal .row { margin-top: 16px; }

@media (max-width: 480px) {
  .info-grid { grid-template-columns: 1fr; }
  .flight, .hotel { grid-template-columns: 1fr; }
}
