@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --color-bg: #161826;
  --color-surface: #232532;
  --color-text: #e9e9ed;
  --color-accent: #9184d9;
  --color-accent-2: #a7a1db;
  --color-divider: color-mix(in srgb, #e9e9ed 16%, transparent);

  --color-neutral-100: #f3f5fe;
  --color-neutral-200: #e4e7f5;
  --color-neutral-300: #cfd3e5;
  --color-neutral-400: #b2b6ca;
  --color-neutral-500: #9397ab;
  --color-neutral-600: #75798c;
  --color-neutral-700: #595d6c;
  --color-neutral-800: #3f424d;
  --color-neutral-900: #292b31;

  --color-accent-100: #f5f4ff;
  --color-accent-800: #423a6a;

  --font-heading: "Inter", system-ui, sans-serif;
  --font-heading-weight: 500;
  --font-body: "Inter", system-ui, sans-serif;

  --space-1: 2.8px;
  --space-2: 5.6px;
  --space-3: 8.4px;
  --space-4: 11.2px;
  --space-6: 16.8px;
  --space-8: 22.4px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;

  --shadow-sm: 0 0 0 1px #3f424d;
  --shadow-md: 0 0 0 1px #595d6c, 0 6px 18px rgba(0,0,0,0.55);
  --shadow-lg: 0 0 0 1px #9397ab, 0 16px 40px rgba(0,0,0,0.65);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2);
}
p { margin: 0 0 var(--space-3); }
a { color: var(--color-accent); text-underline-offset: 3px; }
a:hover { color: var(--color-accent-2); }
img { display: block; max-width: 100%; }
input[type="text"], input[type="email"] { font: inherit; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--color-accent) 30%, transparent); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; text-decoration: none;
  font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  font-size: 14px; line-height: 1.2; color: var(--color-text);
  background: transparent; border: 1px solid transparent;
  padding: var(--space-2) calc(var(--space-3) * 1.2);
  border-radius: var(--radius-md);
  transition: background 0.15s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { color: var(--color-accent); border-color: var(--color-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
.btn-primary:active { background: color-mix(in srgb, var(--color-accent) 22%, transparent); }
.btn-secondary { border-color: var(--color-divider); }
.btn-secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.btn-ghost { color: var(--color-accent); padding-inline: var(--space-1); }
.btn-ghost:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.btn-ghost:active { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-danger { border-color: #ef4444; color: #ef4444; }
.btn-danger:hover { background: color-mix(in srgb, #ef4444 12%, transparent); }

/* ── Forms ── */
.field > label {
  display: block; font-size: 12px; margin-bottom: 5px;
  color: color-mix(in srgb, var(--color-text) 70%, transparent);
}
.input {
  width: 100%; min-height: 36px; padding: 6px 10px; font: inherit;
  font-size: 14px; color: var(--color-text); caret-color: var(--color-accent);
  background: var(--color-surface);
  border: 1px solid var(--color-divider); border-radius: var(--radius-md);
}
.input:hover { border-color: color-mix(in srgb, var(--color-text) 45%, transparent); }
.input:focus-visible { border-color: var(--color-accent); outline-offset: 0; }

/* ── Tags ── */
.tag {
  display: inline-flex; align-items: center; font-size: 11px;
  letter-spacing: 0.02em; padding: 3px 10px;
  border-radius: calc(var(--radius-md) * 0.75);
}
.tag-neutral { background: var(--color-neutral-800); color: var(--color-neutral-100); }

/* ── Dialog ── */
.dialog-backdrop {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: var(--space-4);
  background: color-mix(in srgb, var(--color-neutral-900) 50%, transparent);
  z-index: 50;
  animation: fadeIn 0.15s ease;
}
.dialog {
  width: min(440px, 100%); display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--color-surface); box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
}
.dialog-title {
  font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  font-size: 20px;
}
.dialog-body { font-size: 14px; opacity: 0.85; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-2); }

/* ── App Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  min-height: 56px;
  flex-shrink: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-text) 8%, transparent);
}

.app-header-title {
  font: 500 18px/1.2 var(--font-heading);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-nav {
  display: flex;
  border-top: 1px solid color-mix(in srgb, var(--color-text) 10%, transparent);
  flex-shrink: 0;
  background: var(--color-bg);
}

.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 11px;
  min-height: 52px;
  color: var(--color-neutral-500);
  transition: background 0.15s ease;
}
.bottom-nav button:hover {
  background: color-mix(in srgb, var(--color-accent) 6%, transparent);
}
.bottom-nav button.active { color: var(--color-accent); }

/* ── Login Screen ── */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: var(--space-8);
  text-align: center;
  animation: fadeIn 0.5s ease;
}
.login-icon {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-6);
  opacity: 0.9;
}
.login-title {
  font: 600 28px/1.2 var(--font-heading);
  margin-bottom: var(--space-2);
}
.login-subtitle {
  font-size: 14px;
  color: var(--color-neutral-400);
  margin-bottom: var(--space-8);
}
.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  font: 500 15px/1.2 var(--font-heading);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.login-btn:hover {
  background: color-mix(in srgb, var(--color-surface) 80%, var(--color-accent) 20%);
  border-color: var(--color-accent);
}
.login-btn svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Loading ── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-4);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-neutral-700);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Trips View ── */
.trips-list {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.trip-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  cursor: pointer;
  animation: slideUp 0.25s ease both;
  transition: background 0.15s ease;
}
.trip-card:hover {
  background: color-mix(in srgb, var(--color-surface) 80%, var(--color-accent) 20%);
}

.trip-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}
.trip-card-name { font: 500 16px/1.2 var(--font-heading); }

.progress-track {
  height: 4px;
  background: var(--color-neutral-800);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.trip-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
}
.trip-card-date {
  font-size: 12px;
  color: color-mix(in srgb, var(--color-text) 50%, transparent);
}
.trip-card-actions {
  display: flex;
  gap: var(--space-1);
}

.empty-state {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-neutral-500);
  font-size: 14px;
}
.empty-state i {
  font-size: 40px;
  display: block;
  margin-bottom: var(--space-3);
}

/* ── Trip Detail View ── */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-bg);
  padding: var(--space-3) var(--space-6);
  display: flex;
  gap: var(--space-2);
  align-items: center;
}
.filter-bar .btn { font-size: 12px; padding: 4px 12px; flex: none; }

.trip-content {
  padding: 0 var(--space-6) var(--space-6);
}

.cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  cursor: pointer;
  user-select: none;
}
.cat-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.cat-name {
  font: 500 13px/1.2 var(--font-heading);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-neutral-400);
}
.cat-progress {
  font-size: 11px;
  color: var(--color-neutral-500);
}
.cat-actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
}

.item-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-bottom: 1px solid color-mix(in srgb, var(--color-text) 6%, transparent);
  min-height: 44px;
}
.item-name {
  flex: 1;
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-name.dimmed { opacity: 0.35; }

/* ── Checkbox ── */
.checkbox {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  border: 1.5px solid var(--color-neutral-600);
  background: transparent;
}
.checkbox.checked {
  border-color: var(--color-accent);
  background: var(--color-accent);
}
.checkbox.placeholder {
  border: 1.5px dashed var(--color-neutral-700);
  opacity: 0.4;
  cursor: default;
}

/* ── Stepper ── */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.stepper button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-neutral-700);
  background: transparent;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.stepper button:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.stepper-value {
  width: 28px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}
.stepper-value.zero { color: var(--color-neutral-600); }

/* ── Items Management ── */
.mgmt-list {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.mgmt-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.mgmt-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}
.mgmt-card-name {
  font: 500 14px/1.2 var(--font-heading);
  color: var(--color-accent);
}
.mgmt-card-actions {
  display: flex;
  gap: var(--space-1);
}

.mgmt-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid color-mix(in srgb, var(--color-text) 6%, transparent);
  min-height: 40px;
}
.mgmt-item-name {
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mgmt-item-actions {
  display: flex;
  gap: var(--space-1);
}

/* ── User avatar ── */
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 1.5px solid var(--color-neutral-700);
  flex-shrink: 0;
  transition: border-color 0.15s ease;
  object-fit: cover;
}
.user-avatar:hover { border-color: var(--color-accent); }

/* ── Safe area for PWA ── */
@supports (padding: env(safe-area-inset-top)) {
  .app-header { padding-top: calc(var(--space-3) + env(safe-area-inset-top)); }
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}
