:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; background: var(--bg); }

.header {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.25rem; font-weight: 600; }
.icon-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.view { display: none; padding: 16px; }
.view.active { display: block; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}
.section-header h2 { font-size: 1.15rem; flex: 1; }

.join-box {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.join-box input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  letter-spacing: 2px;
}

.trip-code-bar {
  background: #e0e7ff;
  color: #3730a3;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: 56px;
  padding: 10px 6px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--primary);
  color: white;
  font-weight: 500;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}
.btn.primary { background: var(--primary); color: white; }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: white; }
.btn.full { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }

.action-bar { margin-bottom: 12px; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.card-meta {
  font-size: 0.85rem;
  color: var(--text-light);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card-amount {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  white-space: nowrap;
}
.card-actions { display: flex; gap: 6px; margin-top: 8px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  background: #e0e7ff;
  color: #3730a3;
}
.badge.cat { background: #fef3c7; color: #92400e; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal.open { display: flex; }
.modal-content {
  background: white;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
}
.modal-content h3 { margin-bottom: 20px; font-size: 1.2rem; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.form-actions .btn { flex: 1; }
.hint { font-size: 0.85rem; color: var(--text-light); margin-top: 6px; }

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.checkbox-item { display: flex; align-items: center; gap: 8px; }
.checkbox-item input { width: 18px; height: 18px; }

.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.summary-card h4 { margin-bottom: 12px; font-size: 1rem; }
.balance-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.balance-row:last-child { border-bottom: none; }
.balance-positive { color: var(--success); font-weight: 600; }
.balance-negative { color: var(--danger); font-weight: 600; }
.settlement-item {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.total-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.1rem;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px solid var(--border);
}

.filter-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-card h4 {
  margin-bottom: 12px;
  font-size: 0.95rem;
  color: var(--text);
}

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-content { border-radius: 16px; max-height: 85vh; }
}

.split-type-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.radio-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
.radio-item input { width: 16px; height: 16px; }
.split-share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.split-share-row input[type="number"] {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
} 
.split-share-unit {
  font-size: 0.85rem;
  color: var(--text-light);
  min-width: 24px;
}

/* 針對日期時間 input 進行修正 */
input[type="datetime-local"],
input[type="date"],
input[type="time"] {
  /* 1. 確保寬度繼承父容器，不會超出 */
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;

  /* 2. 移除 iOS 預設的內建高度與外觀 Override */
  -webkit-appearance: none;
  appearance: none;
  
  /* 3. 統一高度與內邊距，跟其他 input 一致 */
  min-height: 42px; /* 根據你項目名稱 input 的高度調整 */
  padding: 8px 12px;
  
  color: black;
}