/* ===========================================================
   旅遊規劃 PWA — Stylesheet
   Mobile-first, responsive, light/dark aware, print-optimized
   =========================================================== */

:root{
  --bg: #f4f5f8;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --text: #14161a;
  --text-dim: #6b7280;
  --text-faint: #9aa1ac;
  --border: #e6e8ec;
  --accent: #2f6fed;
  --accent-2: #7c3aed;
  --accent-grad: linear-gradient(135deg,#2f6fed,#7c3aed);
  --success: #16a34a;
  --warn: #d97706;
  --danger: #e0364a;
  --danger-bg: #fdecef;
  --chip-bg: #eef0f4;
  --shadow: 0 1px 2px rgba(20,22,26,.04), 0 6px 20px rgba(20,22,26,.06);
  --shadow-sm: 0 1px 3px rgba(20,22,26,.08);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --header-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg: #0b0d12;
    --bg-elev: #12151c;
    --card: #171b24;
    --text: #f1f2f5;
    --text-dim: #a3aab8;
    --text-faint: #6b7280;
    --border: #242938;
    --chip-bg: #1c2130;
    --danger-bg: #35171c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

*{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html,body{ height:100%; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea{ font-family: inherit; }
h1,h2,h3{ margin:0; }
ul{ margin:0; padding:0; list-style:none; }
a{ color: var(--accent); }
input, select, textarea{
  font-size:16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--bg-elev);
}

/* ---------- App shell ---------- */
.app{
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display:flex;
  flex-direction:column;
  background: var(--bg);
  position: relative;
}

.safe-top{ padding-top: var(--safe-top); }
.safe-bottom{ padding-bottom: var(--safe-bottom); }

/* ---------- Header ---------- */
.app-header{
  background: var(--accent-grad);
  color:#fff;
  padding: 10px 16px 18px;
  border-radius: 0 0 24px 24px;
  box-shadow: var(--shadow);
  position: sticky;
  top:0;
  z-index: 20;
}
.header-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}
.icon-btn{
  width:40px;height:40px;
  display:flex;align-items:center;justify-content:center;
  background: rgba(255,255,255,.16);
  border:none;
  border-radius:50%;
  color:#fff;
  cursor:pointer;
  flex:none;
}
.icon-btn svg{ width:20px;height:20px;fill:currentColor; }
.icon-btn:active{ background: rgba(255,255,255,.3); }

.header-title{ text-align:center; flex:1; min-width:0; }
.trip-name{
  font-size:17px; font-weight:700;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.trip-dates{ font-size:12px; opacity:.85; margin-top:2px; }

.countdown-card{
  margin-top:14px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  backdrop-filter: blur(6px);
}
.countdown-label{ font-size:12px; opacity:.85; margin-bottom:8px; text-align:center; }
.countdown-timer{ display:flex; justify-content:center; gap:10px; }
.cd-unit{
  display:flex; flex-direction:column; align-items:center;
  background: rgba(255,255,255,.12);
  border-radius: 10px;
  min-width: 54px;
  padding: 6px 4px;
}
.cd-num{ font-size:22px; font-weight:800; font-variant-numeric: tabular-nums; line-height:1.1; }
.cd-unit-label{ font-size:10px; opacity:.85; margin-top:2px; }

/* ---------- Tab strip ---------- */
.tab-strip{
  display:flex;
  gap:8px;
  overflow-x:auto;
  padding: 10px 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top:0;
  z-index: 15;
  background: var(--bg);
}
.tab-strip::-webkit-scrollbar{ display:none; }
.tab-chip{
  flex:none;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight:600;
  white-space: nowrap;
  cursor:pointer;
}
.tab-chip.active{
  background: var(--accent-grad);
  border-color: transparent;
  color:#fff;
  box-shadow: var(--shadow-sm);
}

/* ---------- Content ---------- */
.content{
  flex:1;
  padding: 4px 14px 100px;
}
.pane{ display:none; animation: fadeIn .18s ease; }
.pane.active{ display:block; }
@keyframes fadeIn{ from{ opacity:0; transform: translateY(4px);} to{opacity:1; transform:none;} }

.section-block{ margin-top: 18px; }
.section-head{
  display:flex; align-items:center; justify-content:space-between;
  margin: 14px 2px 10px;
}
.section-head h2{ font-size:16px; font-weight:800; }
.add-btn{
  border:none;
  background: var(--accent);
  color:#fff;
  font-size:13px;
  font-weight:700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor:pointer;
}
.add-btn:active{ opacity:.85; }

/* ---------- Summary grid (dashboard) ---------- */
.summary-grid{
  display:grid;
  grid-template-columns: repeat(2,1fr);
  gap:10px;
  margin-top: 14px;
}
.summary-card{
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.summary-card .sc-icon{ font-size:20px; }
.summary-card .sc-value{ font-size:20px; font-weight:800; margin-top:6px; }
.summary-card .sc-label{ font-size:12px; color: var(--text-dim); margin-top:2px; }

.quick-actions{ display:flex; flex-wrap:wrap; gap:8px; }
.quick-btn{
  flex:1 1 calc(50% - 8px);
  border:none;
  background: var(--accent-grad);
  color:#fff;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight:700;
  font-size:13.5px;
  cursor:pointer;
}
.quick-btn.ghost{
  background: var(--chip-bg);
  color: var(--text);
  flex: 1 1 calc(50% - 8px);
}

.empty-hint{
  color: var(--text-faint);
  font-size: 13.5px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  text-align:center;
}

/* ---------- Cards / list items ---------- */
.list{ display:flex; flex-direction:column; gap:10px; }
.item-card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.item-card .ic-top{
  display:flex; align-items:flex-start; justify-content:space-between; gap:8px;
}
.item-card .ic-title{ font-weight:800; font-size:15px; }
.item-card .ic-sub{ font-size:12.5px; color: var(--text-dim); margin-top:2px; }
.item-card .ic-tag{
  font-size:11px;
  font-weight:700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--accent);
  white-space:nowrap;
}
.item-card .ic-body{ margin-top:10px; font-size:13.5px; color: var(--text); }
.item-card .ic-row{ display:flex; justify-content:space-between; gap:10px; padding:3px 0; border-top:1px dashed var(--border); }
.item-card .ic-row:first-of-type{ border-top:none; margin-top:2px; }
.item-card .ic-row .k{ color: var(--text-dim); }
.item-card .ic-row .v{ font-weight:600; text-align:right; }
.item-card .ic-notes{ margin-top:8px; font-size:12.5px; color: var(--text-dim); font-style: italic; }
.item-card .ic-actions{
  display:flex; gap:8px; margin-top:12px;
}
.mini-btn{
  border:none; background: var(--chip-bg); color: var(--text);
  padding: 7px 12px; border-radius: 999px; font-size:12.5px; font-weight:700; cursor:pointer;
}
.mini-btn.danger{ background: var(--danger-bg); color: var(--danger); }

/* Day grouping for itinerary */
.day-heading{
  font-weight:800;
  font-size:14px;
  margin: 18px 2px 8px;
  color: var(--accent);
  display:flex; align-items:baseline; gap:8px;
}
.day-heading .dh-date{ font-size:12px; color: var(--text-dim); font-weight:600; }
.timeline{ position:relative; padding-left: 18px; }
.timeline::before{
  content:""; position:absolute; left:5px; top:6px; bottom:6px; width:2px; background: var(--border);
}
.timeline .item-card{ margin-bottom:10px; }
.timeline .item-card::before{
  content:""; position:absolute; left:-17px; top:18px; width:10px; height:10px; border-radius:50%;
  background: var(--accent-grad); border: 2px solid var(--bg);
}

/* Packing */
.packing-progress{ margin: 6px 0 14px; }
.packing-progress-bar{
  height:8px; background: var(--chip-bg); border-radius:999px; overflow:hidden;
}
.packing-progress-fill{ height:100%; width:0%; background: var(--accent-grad); transition: width .25s; }
.packing-progress-text{ font-size:12px; color: var(--text-dim); margin-top:6px; text-align:right; }

.check-item{
  display:flex; align-items:center; gap:12px;
  background: var(--card); border:1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.check-item input[type=checkbox]{
  width:22px;height:22px; accent-color: var(--accent); flex:none;
}
.check-item .ci-label{ flex:1; font-size:14px; }
.check-item.checked .ci-label{ text-decoration: line-through; color: var(--text-faint); }
.check-item .ci-cat{ font-size:11px; color: var(--text-dim); background:var(--chip-bg); padding:2px 8px; border-radius:999px; flex:none; }
.check-item .mini-btn{ flex:none; }

.packing-group-title{ font-size:12.5px; font-weight:800; color: var(--text-dim); margin: 14px 2px 8px; text-transform:uppercase; letter-spacing:.03em; }

/* Budget */
.budget-summary{
  display:grid; grid-template-columns: repeat(3,1fr); gap:8px; margin-bottom:14px;
}
.budget-summary .bs-card{
  background: var(--card); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 8px; text-align:center;
}
.budget-summary .bs-val{ font-size:15px; font-weight:800; }
.budget-summary .bs-label{ font-size:11px; color: var(--text-dim); margin-top:4px; }
.budget-summary .bs-card.over .bs-val{ color: var(--danger); }
.budget-bar{ height:8px; background:var(--chip-bg); border-radius:999px; overflow:hidden; margin-bottom:14px; }
.budget-bar-fill{ height:100%; background: var(--accent-grad); }
.budget-bar-fill.over{ background: linear-gradient(135deg,#e0364a,#f97316); }

/* Emergency */
.contact-call{ color:#fff; background: var(--success); border:none; padding:8px 12px; border-radius:999px; font-size:12.5px; font-weight:700; text-decoration:none; display:inline-flex; align-items:center; gap:4px; }

/* ---------- Bottom nav ---------- */
.bottom-nav{
  position: fixed;
  left:50%; transform: translateX(-50%);
  bottom:0;
  width:100%;
  max-width: 640px;
  display:flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  z-index: 25;
}
.bn-btn{
  flex:1;
  border:none; background:transparent; color: var(--text-faint);
  display:flex; flex-direction:column; align-items:center; gap:3px;
  padding: 9px 2px 8px;
  cursor:pointer;
}
.bn-btn svg{ width:22px;height:22px; fill:currentColor; }
.bn-btn span{ font-size:10.5px; font-weight:600; }
.bn-btn.active{ color: var(--accent); }

/* ---------- Sheet (more menu) ---------- */
.sheet-backdrop{
  position:fixed; inset:0; background: rgba(0,0,0,.4);
  display:none; align-items:flex-end; justify-content:center; z-index: 50;
}
.sheet-backdrop.show{ display:flex; }
.sheet{
  width:100%; max-width:640px; background: var(--bg-elev);
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(20px + var(--safe-bottom));
  animation: slideUp .2s ease;
}
@keyframes slideUp{ from{ transform: translateY(30px); opacity:.4 } to { transform:none; opacity:1 } }
.sheet-handle{ width:40px; height:4px; background: var(--border); border-radius:99px; margin: 4px auto 14px; }
.sheet h3{ font-size:15px; margin-bottom:12px; }
.sheet-grid{ display:grid; grid-template-columns: repeat(3,1fr); gap:10px; }
.sheet-item{
  display:flex; flex-direction:column; align-items:center; gap:6px;
  background: var(--card); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 6px; font-size:12.5px; font-weight:600; color:var(--text); cursor:pointer;
}
.sheet-item span{ font-size:22px; }

/* ---------- Modal ---------- */
.modal-backdrop{
  position:fixed; inset:0; background: rgba(0,0,0,.45);
  display:none; align-items:center; justify-content:center; z-index: 60;
  padding: 16px;
}
.modal-backdrop.show{ display:flex; }
.modal{
  width:100%; max-width: 480px; max-height: 88vh; overflow-y:auto;
  background: var(--bg-elev); border-radius: var(--radius-lg); padding: 18px;
  box-shadow: var(--shadow);
  animation: pop .16s ease;
}
@keyframes pop{ from{ transform: scale(.96); opacity:0 } to { transform:none; opacity:1 } }
.modal-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.modal-head h3{ font-size:16.5px; font-weight:800; }
.modal-head .icon-btn{ background: var(--chip-bg); color: var(--text); }
.modal-form{ display:flex; flex-direction:column; gap:12px; }
.modal-form label{ display:flex; flex-direction:column; gap:6px; font-size:12.5px; font-weight:700; color: var(--text-dim); }
.modal-form input, .modal-form select, .modal-form textarea{
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; font-size:15px; color:var(--text); background: var(--bg-elev);
}
.modal-form textarea{ min-height: 64px; resize: vertical; font-family:inherit; }
.form-row{ display:flex; gap:10px; }
.form-row label{ flex:1; }
.modal-actions{ display:flex; gap:10px; margin-top:8px; }
.primary-btn{
  flex:1; border:none; background: var(--accent-grad); color:#fff; font-weight:800;
  padding: 13px; border-radius: var(--radius-sm); font-size:15px; cursor:pointer;
}
.danger-btn{
  border:none; background: var(--danger-bg); color: var(--danger); font-weight:800;
  padding: 13px 16px; border-radius: var(--radius-sm); font-size:14px; cursor:pointer;
}
.segmented{ display:flex; gap:6px; flex-wrap:wrap; }
.segmented button{
  border:1px solid var(--border); background: var(--card); color:var(--text-dim);
  padding: 8px 12px; border-radius: 999px; font-size:12.5px; font-weight:700; cursor:pointer;
}
.segmented button.active{ background: var(--accent-grad); color:#fff; border-color:transparent; }

/* ---------- Toast ---------- */
.toast{
  position: fixed; left:50%; bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #14161a; color:#fff; padding: 11px 20px; border-radius: 999px;
  font-size: 13.5px; font-weight:600; opacity:0; pointer-events:none;
  transition: all .25s ease; z-index: 80; max-width: 86%; text-align:center;
  box-shadow: var(--shadow);
}
.toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }

/* ---------- Larger screens (tablet/desktop) ---------- */
@media (min-width: 720px){
  .app{ border-left:1px solid var(--border); border-right:1px solid var(--border); }
  .summary-grid{ grid-template-columns: repeat(4,1fr); }
  .quick-btn, .quick-btn.ghost{ flex: 1 1 calc(25% - 8px); }
}

/* ===========================================================
   PRINT STYLES
   =========================================================== */
.print-area{ display:none; }

@media print{
  @page{ size: A4; margin: 14mm 12mm; }

  body{ background:#fff !important; }
  .app-header, .tab-strip, .bottom-nav, .sheet-backdrop, .modal-backdrop, .toast{
    display:none !important;
  }
  .app{ max-width:none; border:none; min-height:0; }
  .content{ display:none !important; }

  .print-area{
    display:block !important;
    color:#111; font-size: 12px; padding:0;
  }
  .print-area .p-header{
    display:flex; justify-content:space-between; align-items:flex-end;
    border-bottom: 2px solid #111; padding-bottom:10px; margin-bottom:16px;
  }
  .print-area .p-title{ font-size:22px; font-weight:800; }
  .print-area .p-sub{ font-size:12px; color:#444; margin-top:4px; }
  .print-area .p-meta{ text-align:right; font-size:11px; color:#444; }

  .print-area h2{
    font-size:14px; font-weight:800; margin: 18px 0 8px;
    border-left: 4px solid #111; padding-left:8px;
    break-after: avoid;
  }
  .print-area .p-day{ break-inside: avoid; margin-bottom: 10px; }
  .print-area table{ width:100%; border-collapse: collapse; margin-bottom: 6px; }
  .print-area th, .print-area td{
    text-align:left; padding: 5px 6px; border-bottom: 1px solid #ccc; font-size:11.5px; vertical-align: top;
  }
  .print-area th{ background:#f0f0f0; }
  .print-area .p-empty{ color:#888; font-size:11px; font-style:italic; }
  .print-area .p-section{ break-inside: avoid; }
  .print-area .p-footer{
    margin-top: 24px; padding-top:10px; border-top:1px dashed #999; font-size:10px; color:#777; text-align:center;
  }
  a{ color:#111; text-decoration:none; }
}
