/* 旅游计划小工具 —— 移动端优先样式（无框架、无 CDN）
 *
 * 布局思路：顶部「标题 + 日期标签页」合并在一个 sticky 容器里，
 * 免得手写 top 偏移量在窄屏换行时错位。列表一次只显示一天，靠标签页切换，
 * 但所有天都保留在 DOM 里（hidden），这样打印能一次打出完整行程。
 */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --fg: #1d2230;
  --muted: #7b8494;
  --line: #e5e8ef;
  --accent: #2f6fed;
  --accent-soft: #e9f0ff;
  --ok: #9aa3b2;
  --warn: #d97706;
  --warn-soft: #fff4e2;
  --danger: #d9484d;
  --done-bg: #f7f8fa;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 6px 18px rgba(20, 25, 40, .05);
  --bar-h: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --card: #1d2029; --fg: #e8eaf0; --muted: #949cad;
    --line: #2b2f3b; --accent: #5b8dff; --accent-soft: #1e2a45; --ok: #7d8798;
    --warn: #f0a437; --warn-soft: #33291a; --danger: #f2636a;
    --done-bg: #191c24; --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 12px 110px; }

/* ---------------- 顶部（标题 + 日期导航，整体 sticky） ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.top { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px 6px; }
.top-main { flex: 1; min-width: 0; }
.top h1 {
  margin: 0; font-size: 17px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top h1 a { color: inherit; }
.top .sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* 日期导航 */
.daynav { display: flex; align-items: center; gap: 4px; padding: 0 6px 6px; }
.daynav .arrow {
  flex: 0 0 auto; width: 28px; height: 44px; line-height: 1;
  font-size: 20px; color: var(--muted);
  background: none; border: none; cursor: pointer; border-radius: 8px;
}
.daynav .arrow:active { background: var(--line); }
.day-tabs {
  flex: 1 1 auto; display: flex; gap: 6px; overflow-x: auto;
  scrollbar-width: none; -ms-overflow-style: none; padding: 2px 0;
}
.day-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center;
  gap: 1px; min-width: 74px; padding: 5px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); cursor: pointer; position: relative;
}
.tab b { font-size: 13px; font-weight: 650; color: var(--fg); }
.tab span { font-size: 11px; white-space: nowrap; }
.tab i { font-size: 11px; font-style: normal; opacity: .8; }
.tab.active {
  border-color: var(--accent); background: var(--accent-soft);
}
.tab.active b, .tab.active i { color: var(--accent); }
.tab em {
  position: absolute; top: -6px; right: -4px;
  font-size: 10px; font-style: normal; padding: 0 4px; border-radius: 99px;
  background: var(--accent); color: #fff;
}
.tab.is-today b::after { content: ''; }

.today-jump {
  display: block; width: 100%; margin: 10px 0 0;
  padding: 8px; min-height: 40px; font-size: 14px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 10px; cursor: pointer;
}
.today-jump[hidden] { display: none !important; }

/* ---------------- 通用 ---------------- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin: 12px 0;
}
.btn {
  font-size: 14px; padding: 8px 12px; min-height: 40px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.sm { min-height: 36px; padding: 5px 10px; font-size: 13.5px; }
.btn.xs { min-height: 30px; min-width: 32px; padding: 2px 6px; font-size: 13px; border-radius: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

/* ---------------- 现在 / 下一站 ---------------- */

.now { padding: 0; overflow: hidden; }
.now-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 16px; background: var(--done-bg); border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.now-rel { font-weight: 600; }
.now-rel.is-today { color: var(--accent); }
.now-block { padding: 14px 16px; }
.now-block + .now-block { border-top: 1px dashed var(--line); }
.now-label { font-size: 12px; letter-spacing: .06em; color: var(--muted); }
.now-title { font-size: 22px; font-weight: 680; margin: 4px 0 2px; line-height: 1.25; }
.now-time { font-size: 14px; color: var(--muted); }
.now-time b { color: var(--fg); font-weight: 600; }
.now.is-active { border-color: var(--accent); }
.now.is-active .now-head { background: var(--accent-soft); }
.now.is-overtime { border-color: var(--warn); }
.now.is-overtime .now-head,
.now.is-overtime .now-block { background: var(--warn-soft); }
.now.is-idle .now-title { font-size: 18px; color: var(--muted); }

.bar { height: var(--bar-h); background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar > i.time { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.bar-wrap .bar + .bar { margin-top: 3px; }

.calib-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.calib-btns .btn { flex: 1 1 auto; min-width: 72px; }
.delay-line { font-size: 13px; color: var(--muted); margin-top: 8px; }
.delay-line b { color: var(--accent); }

/* ---------------- 天与行程项 ---------------- */

.day { margin: 14px 0 8px; scroll-margin-top: 120px; }
.day[hidden] { display: none !important; }
.day-head {
  display: flex; align-items: baseline; gap: 8px; padding: 4px 2px 8px;
}
.day-head h2 { margin: 0; font-size: 15px; font-weight: 650; }

.item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.item .time { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); padding-top: 1px; }
.item .time b { display: block; font-size: 15.5px; color: var(--fg); font-weight: 620; letter-spacing: -.01em; }
.item .body { min-width: 0; cursor: pointer; }
.item .name { font-weight: 600; font-size: 15.5px; line-height: 1.35; word-break: break-word; }
.item .idx {
  display: inline-block; min-width: 17px; height: 17px; line-height: 17px;
  margin-right: 5px; text-align: center; font-size: 11px; font-weight: 500;
  color: var(--muted); background: var(--line); border-radius: 5px; vertical-align: 1px;
}
.item .addr { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.item .note { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }
.item .live { font-size: 12.5px; color: var(--accent); margin-top: 3px; }
.item .ops { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.item .arrows { display: flex; gap: 6px; }
.item .arrows .btn { flex: 1; }

.item.s-done { background: var(--done-bg); }
.item.s-done .name { color: var(--muted); text-decoration: line-through; }
.item.s-skipped { opacity: .65; }
.item.s-skipped .name { text-decoration: line-through; }
.item.s-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.item.s-active .name { font-size: 17px; }
.item.s-overtime { border-color: var(--warn); background: var(--warn-soft); }
.item.s-overtime .live { color: var(--warn); }
.item.s-expired { border-style: dashed; }
.item.s-expired .name { color: var(--muted); }
.item.s-expired .live { color: var(--muted); }
.item.flag-overflow { border-color: var(--danger); }

.badge {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); margin-left: 5px; vertical-align: 1px;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.over { color: var(--danger); border-color: var(--danger); }

.empty { color: var(--muted); font-size: 14px; padding: 6px 2px 10px; }
.add-btn { width: 100%; border-style: dashed; }

/* ---------------- 计划列表 ---------------- */

.trip-card { display: block; color: inherit; }
.trip-card .name { font-size: 17px; font-weight: 650; }
.trip-card .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.pill {
  font-size: 11px; padding: 1px 7px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); margin-left: 6px;
}
.pill.finished { background: var(--line); color: var(--muted); }
.pill.upcoming { background: var(--ok); color: #fff; }

form.new { display: grid; gap: 8px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--fg);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px; min-height: 44px; width: 100%;
}
textarea { min-height: 64px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- 弹窗 ---------------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 18, 26, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
/* ★ 关键：上面的 display:flex 属于作者样式，会覆盖浏览器 UA 的
   [hidden]{display:none}，导致 hidden 属性失效、弹窗永远可见。
   必须显式声明，否则「添加行程项」表单会一直显示且日期下拉是空的。 */
.modal[hidden] { display: none !important; }
@media (min-width: 640px) { .modal { align-items: center; } }
.modal-box {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 16px 16px 0 0; padding: 16px;
  max-height: 92vh; overflow: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal-box { border-radius: 16px; } }
.modal-box h3 { margin: 0 0 12px; font-size: 17px; }
.form-grid { display: grid; gap: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.modal-actions .btn[hidden] { display: none !important; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; min-height: 0; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #22262f; color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 99px; z-index: 60;
  max-width: 90vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast[hidden] { display: none !important; }
@media (prefers-color-scheme: dark) { .toast { background: #e8eaf0; color: #14161c; } }

.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin: 24px 0; }
.footer-note .ver { opacity: .6; font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---------------- 打印：一次打出全部日期 ---------------- */

@media print {
  :root { --bg: #fff; --card: #fff; --line: #ccc; --muted: #555; --fg: #000; --shadow: none; }
  .top-actions, .calib-btns, .ops, .modal, .toast, .no-print, .btn,
  .daynav, .today-jump { display: none !important; }
  .topbar { position: static; background: none; border: 0; }
  .wrap { max-width: none; padding: 0; }
  .card, .item { box-shadow: none; break-inside: avoid; }
  .day, .day-body { break-inside: avoid; }
  .day[hidden] { display: block !important; }   /* 打印时展开所有天 */
  .item.s-active { box-shadow: none; border-color: #000; }
  a { color: #000; }
  .item .body { cursor: auto; }
}
