/* === CSS Custom Properties === */
:root {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-header: #1e293b;
  --bg-modal: #ffffff;
  --bg-overlay: rgba(15, 23, 42, 0.5);
  --text: #334155;
  --text-light: #64748b;
  --text-heading: #1e293b;
  --text-inverse: #f1f5f9;
  --border: #e2e8f0;
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --accent-hover: #0f766e;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.2s ease;

  /* Who colors */
  --who-0: #0d9488;
  --who-1: #6366f1;
  --who-2: #ec4899;
  --who-3: #f59e0b;
  --who-4: #8b5cf6;
  --who-5: #ef4444;
  --who-6: #06b6d4;
  --who-7: #84cc16;
  --who-8: #f97316;
  --who-9: #a855f7;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Header === */
.header {
  background: var(--bg-header);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.logo { font-size: 1.2rem; font-weight: 600; white-space: nowrap; }
.logo i { color: var(--accent); }
.hamburger {
  display: none;
  background: none; border: none; color: var(--text-inverse);
  font-size: 1.25rem; cursor: pointer; padding: 0.25rem;
}
.header-search {
  position: relative; flex: 1; max-width: 400px;
}
.header-search input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.1);
  color: var(--text-inverse);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition);
}
.header-search input::placeholder { color: rgba(255,255,255,0.5); }
.header-search input:focus { background: rgba(255,255,255,0.15); border-color: var(--accent); }
.search-icon {
  position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
  color: rgba(255,255,255,0.4); font-size: 0.8rem;
}
.nav { display: flex; gap: 0.25rem; margin-left: auto; }
.nav-link {
  color: rgba(255,255,255,0.7); text-decoration: none;
  padding: 0.5rem 0.75rem; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  transition: var(--transition); white-space: nowrap;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-link.active { color: #fff; background: var(--accent); }

/* === Main === */
.main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* === View Toolbar === */
.view-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap;
}
.sort-controls { display: flex; align-items: center; gap: 0.5rem; }
.sort-controls label { font-size: 0.85rem; color: var(--text-light); font-weight: 500; }
.sort-controls select, select {
  padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); font-size: 0.85rem; color: var(--text);
  cursor: pointer; outline: none;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border: none; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  transition: var(--transition); text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-icon {
  background: none; border: none; cursor: pointer; color: var(--text-light);
  font-size: 1.1rem; padding: 0.25rem; transition: var(--transition);
}
.btn-icon:hover { color: var(--text); }

/* === Trip List === */
.trip-list { display: grid; gap: 0.75rem; }
.trip-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem;
  display: flex; align-items: flex-start; gap: 1rem;
  box-shadow: var(--shadow-sm); transition: var(--transition);
  cursor: pointer;
}
.trip-card:hover { box-shadow: var(--shadow); border-color: var(--accent); }
.trip-date {
  text-align: center; min-width: 52px; flex-shrink: 0;
  background: var(--accent-light); border-radius: var(--radius);
  padding: 0.4rem 0.5rem;
}
.trip-date .month { font-size: 0.7rem; text-transform: uppercase; font-weight: 600; color: var(--accent); letter-spacing: 0.5px; }
.trip-date .day { font-size: 1.1rem; font-weight: 700; color: var(--text-heading); line-height: 1.2; }
.trip-date .year { font-size: 0.65rem; color: var(--text-light); }
.trip-info { flex: 1; min-width: 0; }
.trip-location { font-weight: 600; color: var(--text-heading); font-size: 1rem; }
.trip-location .country { color: var(--text-light); font-weight: 400; }
.trip-caption { font-size: 0.85rem; color: var(--text-light); margin-top: 0.15rem; }
.trip-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; align-items: center; }
.trip-tag {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 999px;
  background: #f1f5f9; color: var(--text-light);
}
.who-pill {
  font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 999px;
  color: #fff; font-weight: 600;
}
.trip-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.trip-actions .btn-icon { font-size: 0.9rem; }
.trip-actions .btn-icon.delete:hover { color: var(--danger); }
.trip-duration {
  font-size: 0.7rem; color: var(--text-light);
  background: #f1f5f9; padding: 0.15rem 0.5rem; border-radius: 999px;
}

/* === Empty state === */
.empty-state { text-align: center; color: var(--text-light); padding: 3rem 1rem; font-size: 0.95rem; }

/* === Overlay / Modal === */
.overlay {
  position: fixed; inset: 0; background: var(--bg-overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1rem;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--bg-modal); border-radius: var(--radius-lg);
  width: 100%; max-width: 600px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 1rem 1.25rem; border-top: 1px solid var(--border);
}

/* === Form === */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-heading); margin-bottom: 0.3rem; }
.form-group input, .form-group select {
  width: 100%; padding: 0.5rem 0.7rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.875rem; color: var(--text); background: var(--bg-card);
  outline: none; transition: var(--transition);
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,0.1); }
.form-row { display: flex; gap: 0.75rem; }
.form-row > * { flex: 1; }
.form-row.compact { gap: 0.5rem; }

/* === Chips (who/tags toggles) === */
.chip-group { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  font-size: 0.8rem; cursor: pointer; border: 2px solid var(--border);
  background: var(--bg-card); color: var(--text); transition: var(--transition);
  user-select: none;
}
.chip.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); font-weight: 600; }
.chip i { font-size: 0.75rem; }

/* === Confirm Dialog === */
.confirm-dialog {
  background: var(--bg-modal); border-radius: var(--radius-lg);
  padding: 1.5rem; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg); text-align: center;
}
.confirm-dialog p { margin-bottom: 1.25rem; font-size: 0.95rem; }
.confirm-actions { display: flex; gap: 0.5rem; justify-content: center; }

/* === Toast === */
#toast-container {
  position: fixed; top: 72px; right: 1rem; z-index: 300;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  padding: 0.65rem 1rem; border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 500;
  box-shadow: var(--shadow-lg); color: #fff;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* === Map === */
.map-controls {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  margin-bottom: 1rem;
}
.map-container iframe {
  width: 100%; height: calc(100vh - 200px); min-height: 400px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
}

/* === Stats === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.stat-card h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); margin-bottom: 0.75rem; }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-list { list-style: none; }
.stat-list li { padding: 0.3rem 0; font-size: 0.85rem; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); }
.stat-list li:last-child { border: none; }
.stat-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.stat-bar-label { font-size: 0.8rem; min-width: 80px; color: var(--text); }
.stat-bar-track { flex: 1; height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.stat-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }
.stat-bar-count { font-size: 0.75rem; color: var(--text-light); min-width: 24px; text-align: right; }

/* === Settings === */
.settings-content { max-width: 700px; }
.settings-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: var(--shadow-sm);
}
.settings-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-heading); }
.settings-row {
  display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem;
}
.settings-row label { font-size: 0.8rem; min-width: 30px; font-weight: 600; color: var(--text-light); }
.settings-row input {
  flex: 1; padding: 0.4rem 0.6rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.85rem; outline: none;
}
.settings-row input:focus { border-color: var(--accent); }
.settings-color {
  width: 32px; height: 32px; border: none; border-radius: var(--radius);
  cursor: pointer; padding: 0;
}

/* === Mobile === */
@media (max-width: 768px) {
  .hamburger { display: block; }
  .nav {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    background: var(--bg-header); flex-direction: column;
    padding: 0.5rem; border-top: 1px solid rgba(255,255,255,0.1);
  }
  .nav.open { display: flex; }
  .header-search { max-width: none; }
  .form-row { flex-direction: column; gap: 0; }
  .trip-card { flex-wrap: wrap; }
  .main { padding: 1rem; }
}

.trip-others {
  font-size: 0.8rem;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 0.25rem;
}

/* === Edit Mode Indicator === */
.edit-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  user-select: none;
}
.edit-indicator.read-only {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
}
.edit-indicator.read-only:hover {
  background: rgba(100, 116, 139, 0.35);
  color: #cbd5e1;
}
.edit-indicator.edit-active {
  background: rgba(20, 184, 166, 0.2);
  color: var(--accent);
}
.edit-indicator.edit-active:hover {
  background: rgba(20, 184, 166, 0.35);
}

/* === Editor Readonly Banner === */
.editor-readonly-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.85rem;
  font-weight: 500;
  border-bottom: 1px solid #fde68a;
}
.editor-readonly-banner.hidden { display: none; }
.editor-readonly-banner input {
  padding: 0.2rem 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.4rem;
  font-size: 0.8rem;
  width: 110px;
}
.editor-readonly-banner .btn-sm {
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
}

/* === Password Input Box === */
.edit-password-box {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.edit-password-box.hidden {
  display: none;
}
.edit-password-box input {
  width: 120px;
  padding: 0.25rem 0.5rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 0.8rem;
  outline: none;
}
.edit-password-box input:focus {
  border-color: var(--accent);
}
.edit-password-box .btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
}

/* Hide edit-only elements in read-only mode */
.read-only-mode #btn-add-trip {
  display: none;
}
.read-only-mode #btn-save-settings {
  display: none;
}
