/* ============================================
   旅行規劃 v2 - 樣式（墨綠簡約風）
   ============================================ */

:root {
  --primary: #2f5d50;
  --primary-dark: #244a40;
  --primary-light: #e8f1ed;
  --accent: #b5651d;
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang HK', 'Microsoft JhengHei', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, select, textarea {
  font-family: inherit; font-size: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  background: white;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 10px 18px; border-radius: 6px; font-weight: 500;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: white; color: var(--primary); border: 1px solid var(--primary);
  padding: 8px 16px; border-radius: 6px;
}
.btn-secondary:hover { background: var(--primary-light); }

.btn-danger {
  background: var(--danger); color: white; border: none;
  padding: 10px 18px; border-radius: 6px;
}

.btn-small {
  background: var(--primary); color: white; border: none;
  padding: 4px 10px; border-radius: 4px; font-size: 12px;
}

.btn-text {
  background: transparent; border: none; color: var(--primary);
  padding: 4px 8px;
}

.btn-icon {
  background: transparent; border: none; color: var(--text-light);
  padding: 2px 6px; border-radius: 4px;
}
.btn-icon:hover { background: var(--border); color: var(--text); }

/* ============ Toast ============ */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border-left: 4px solid var(--info);
  padding: 12px 18px; border-radius: 6px; box-shadow: var(--shadow-lg);
  min-width: 200px; max-width: 400px;
  animation: slideIn 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ Auth ============ */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg) 100%);
}
.auth-card {
  background: white; padding: 40px; border-radius: 16px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 400px;
}
.auth-card h1 { color: var(--primary); margin-bottom: 8px; font-size: 28px; }
.subtitle { color: var(--text-light); margin-bottom: 24px; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.auth-link { text-align: center; margin-top: 16px; color: var(--text-light); }
.auth-link a { color: var(--primary); text-decoration: none; }
.auth-hint { text-align: center; margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bg-soft, #f1f5f9); color: var(--text-light); font-size: 13px; line-height: 1.6; }
.auth-hint b { color: var(--primary); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ============ Dashboard ============ */
.dashboard { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 32px;
}
.page-header h1 { color: var(--primary); font-size: 28px; }

.dash-section { margin-bottom: 40px; }
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.section-title h2 { color: var(--primary); font-size: 18px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }

.trip-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.trip-card {
  background: white; border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); cursor: pointer;
  border-left: 4px solid var(--primary);
  transition: transform 0.2s, box-shadow 0.2s;
}
.trip-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.trip-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.trip-card h3 { color: var(--primary); font-size: 16px; }
.trip-role {
  background: var(--primary-light); color: var(--primary);
  padding: 2px 8px; border-radius: 4px; font-size: 12px;
}
.trip-dest { color: var(--text); font-size: 14px; }
.trip-date { color: var(--text-light); font-size: 13px; margin: 4px 0 8px; }
.trip-meta {
  display: flex; justify-content: space-between; padding-top: 8px;
  border-top: 1px dashed var(--border); font-size: 12px; color: var(--text-light);
}

.city-card {
  background: white; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.city-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.city-country { color: var(--text-light); font-size: 13px; }
.wish-items { list-style: none; }
.wish-items li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
}
.tag-place { background: #dbeafe; color: #1e40af; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.tag-food { background: #fce7f3; color: #9d174d; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.tag-activity { background: #d1fae5; color: #065f46; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.empty-small { color: var(--text-light); font-size: 13px; padding: 4px 0; }
.empty { color: var(--text-light); padding: 20px; text-align: center; }

/* ============ Trip Page ============ */
.trip-page { padding: 0; }
.trip-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px; background: white;
  border-bottom: 1px solid var(--border);
}
.trip-title-block { flex: 1; }
.trip-title-block h1 { color: var(--primary); font-size: 22px; }
.trip-subtitle { color: var(--text-light); font-size: 13px; }
.trip-actions { display: flex; align-items: center; gap: 12px; }
.role-badge {
  background: var(--primary-light); color: var(--primary);
  padding: 4px 10px; border-radius: 4px; font-size: 12px;
}
.share-code {
  background: #f3f4f6; padding: 4px 10px; border-radius: 4px;
  font-family: 'Courier New', monospace; color: var(--text);
}

.trip-tabs {
  display: flex; gap: 4px; padding: 0 24px;
  border-bottom: 1px solid var(--border); background: white;
}
.tab-btn {
  background: transparent; border: none; padding: 12px 20px;
  color: var(--text-light); border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--primary); border-bottom-color: var(--primary); font-weight: 500;
}

.trip-main { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ============ Itinerary Calendar ============ */
.itinerary-page { background: white; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.itinerary-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.itinerary-toolbar .hint { color: var(--text-light); font-size: 12px; }

.calendar-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.calendar {
  display: grid;
  grid-template-columns: 60px repeat(var(--days, 7), minmax(140px, 1fr));
  grid-auto-rows: 30px;
  position: relative;
  min-width: 100%;
}
.calendar-corner { background: var(--primary-light); border-bottom: 1px solid var(--border); }
.calendar-col-header {
  position: sticky; top: 0; z-index: 5;
  background: var(--primary-light); padding: 8px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
}
.calendar-col-header.today { background: #fef3c7; }
.day-week { font-size: 11px; color: var(--text-light); }
.day-date { font-weight: 500; color: var(--primary); }
.time-label {
  position: sticky; left: 0; z-index: 4;
  background: white; border-right: 1px solid var(--border);
  padding: 0 6px; font-size: 11px; color: var(--text-light);
  height: 60px; line-height: 30px;
}
.calendar-column {
  border-right: 1px solid var(--border);
  position: relative;
  height: 60px;
}
.hour-cell {
  border-bottom: 1px dashed var(--border);
  height: 60px;
}

.event-card {
  position: absolute; left: 4px; right: 4px;
  border-radius: 4px; padding: 4px 6px;
  font-size: 12px; overflow: hidden;
  cursor: move; z-index: 3;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.event-card.dragging { opacity: 0.5; }
.event-card-title { font-weight: 600; }
.event-card-loc { font-size: 11px; opacity: 0.85; }
.event-card-time { font-size: 10px; opacity: 0.7; margin-top: 2px; }
.resize-handle {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 6px; cursor: ns-resize;
}

.accommodation-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 60px repeat(var(--days, 7), minmax(140px, 1fr));
  border-top: 2px solid var(--primary);
  background: var(--primary-light);
  padding: 8px;
  position: sticky; bottom: 0;
}
.acc-title {
  display: flex; align-items: center;
  font-weight: 600; color: var(--primary);
}
.acc-cell {
  padding: 0 8px; font-size: 12px; color: var(--text);
}

/* ============ Events Library ============ */
.events-page { background: white; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.events-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.filter-group { display: flex; gap: 4px; }
.filter-btn {
  background: white; border: 1px solid var(--border); padding: 4px 12px;
  border-radius: 16px; color: var(--text-light);
}
.filter-btn.active {
  background: var(--primary); color: white; border-color: var(--primary);
}
.events-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.event-library-card {
  border-radius: var(--radius); padding: 14px; cursor: pointer;
  border: 1px solid;
  transition: transform 0.2s;
}
.event-library-card:hover { transform: translateY(-2px); }
.event-library-type {
  font-size: 12px; font-weight: 500; margin-bottom: 6px;
}
.event-library-card h3 { font-size: 16px; margin-bottom: 4px; }
.event-sub { color: var(--text-light); font-size: 13px; }
.event-meta { font-size: 12px; color: var(--text); margin-top: 4px; }
.event-meta a { color: var(--info); }
.event-note {
  font-size: 12px; color: var(--text);
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
}

/* ============ Packing & Expenses ============ */
.packing-page {}
.two-columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
.packing-col, .expense-col {
  background: white; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
@media (max-width: 900px) { .two-columns { grid-template-columns: 1fr; } }

.container-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px;
  background: #fcfcfb;
}
.container-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}
.container-body {
  padding: 8px 14px; min-height: 60px;
}
.packing-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
}
.packing-item .item-name { flex: 1; }
.packing-item .item-name.packed { text-decoration: line-through; color: var(--text-light); }
.packing-item .item-category {
  background: var(--border); color: var(--text); font-size: 11px;
  padding: 1px 6px; border-radius: 3px;
}
.add-item-form {
  display: flex; gap: 4px; padding: 8px 14px;
  border-top: 1px solid var(--border); background: #fafaf7;
}
.add-item-form input { font-size: 12px; padding: 4px 8px; }

.expense-summary-card {
  background: var(--primary-light); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; color: var(--primary); margin-bottom: 12px;
}
.summary-row strong { font-size: 22px; }
.summary-bars {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
}
.summary-bar {
  padding: 6px 10px; border-radius: 4px; color: white;
  display: flex; justify-content: space-between; font-size: 12px;
}
.summary-currencies {
  display: flex; gap: 8px; margin-top: 8px; font-size: 12px;
  color: var(--text-light); flex-wrap: wrap;
}

.expense-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.expense-table th, .expense-table td {
  text-align: left; padding: 8px; border-bottom: 1px solid var(--border);
}
.expense-table th { background: var(--primary-light); color: var(--primary); }
.status-badge {
  color: white; padding: 2px 8px; border-radius: 4px; font-size: 11px;
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: white; border-radius: 12px; padding: 24px;
  width: 90%; max-width: 480px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 720px; }
.modal h2 { color: var(--primary); margin-bottom: 16px; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal label {
  display: flex; flex-direction: column; gap: 4px; font-weight: 500;
}
.modal label[style*="block"], .modal label > div { display: flex; }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px;
}
.modal-actions .btn-danger { margin-right: auto; }