/* ===== Japan Trip Planner — RTL, desktop-first, print-friendly ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f7f5f2;
  --card: #ffffff;
  --ink: #2b2b33;
  --muted: #6f6f7a;
  --line: #e6e2db;
  --accent: #c0392b;        /* torii red */
  --accent-soft: #fdf0ee;
  --fixed: #8e44ad;
  --planned: #2c7a4b;
  --optional: #8a7b56;
  --unresolved: #c0392b;
  --warn-bg: #fff6e8;
  --warn-ink: #9a6a1e;
  --ok: #2c7a4b;
  --radius: 10px;
  font-size: 15px;
}

body {
  font-family: -apple-system, "Segoe UI", "Heebo", "Arial Hebrew", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}

/* ---- header ---- */
#topbar {
  background: var(--card);
  border-bottom: 3px solid var(--accent);
  padding: 14px 22px 0;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 1.35rem; }
.brand .dates { color: var(--muted); font-size: .9rem; }
#tabs { display: flex; gap: 2px; margin-top: 10px; flex-wrap: wrap; }
#tabs button {
  border: none; background: none; cursor: pointer;
  padding: 8px 14px; font-size: .95rem; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -3px;
  font-family: inherit;
}
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
#tabs button:hover { color: var(--ink); }

#content { max-width: 980px; margin: 0 auto; padding: 22px 18px 60px; }

/* ---- generic ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
}
h2 { font-size: 1.15rem; margin-bottom: 10px; }
h3 { font-size: 1rem; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: .86rem; }
.src { color: #b3aca2; font-size: .74rem; }

.chip {
  display: inline-block; padding: 1px 9px; border-radius: 20px;
  font-size: .74rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.chip.fixed      { background: #f5edfa; color: var(--fixed); border-color: #e2cfee; }
.chip.planned    { background: #ecf6ef; color: var(--planned); border-color: #cfe6d7; }
.chip.optional   { background: #f7f3e8; color: var(--optional); border-color: #e8dfc6; }
.chip.unresolved { background: var(--accent-soft); color: var(--unresolved); border-color: #f2cfc9; }
.chip.type { background: #f1f0f4; color: var(--muted); border-color: var(--line); font-weight: 400; }

.flag {
  display: inline-block; padding: 2px 9px; border-radius: 6px;
  font-size: .78rem; margin-top: 4px;
}
.flag.high   { background: var(--accent-soft); color: var(--accent); }
.flag.warn   { background: var(--warn-bg); color: var(--warn-ink); }
.flag.ok     { background: #ecf6ef; color: var(--ok); }
.flag.info   { background: #eef2f7; color: #46617e; }

button.action {
  font-family: inherit; font-size: .82rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--card);
  border-radius: 6px; padding: 3px 10px; color: var(--ink);
}
button.action:hover { border-color: var(--accent); color: var(--accent); }
select, input[type="text"], input[type="time"] {
  font-family: inherit; font-size: .84rem; padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink);
}

/* ---- dashboard ---- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat .num { font-size: 1.7rem; font-weight: 700; color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: .84rem; }
.city-strip { display: flex; gap: 6px; flex-wrap: wrap; }
.city-block {
  flex: 1 1 130px; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; text-align: center;
}
.city-block b { display: block; }
.qitem { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.qitem:last-child { border-bottom: none; }
.qitem input[type="checkbox"] { margin-top: 5px; }
.qitem.done .qtext { text-decoration: line-through; color: var(--muted); }

/* ---- day planner ---- */
.day-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.day-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; cursor: pointer; gap: 10px; flex-wrap: wrap;
  border-right: 5px solid var(--accent);
}
.day-head:hover { background: #fbfaf8; }
.day-head .d-title { font-weight: 700; }
.day-head .d-meta { color: var(--muted); font-size: .85rem; }
.city-badge {
  background: #f1f0f4; color: var(--ink); border-radius: 20px;
  padding: 1px 10px; font-weight: 600; font-size: .8rem; border: 1px solid var(--line);
}
.route-info { font-size: .8rem; color: var(--muted); }
.route-info a { color: #46617e; }
.day-body { border-top: 1px solid var(--line); padding: 6px 16px 12px; }
.day-note-row { padding: 8px 0 2px; }
.day-note-row input { width: 100%; }

.it {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 14px;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.it:last-child { border-bottom: none; }
.it .t-line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.it .t-title { font-weight: 600; }
.it.status-optional .t-title { font-weight: 400; }
.it.status-unresolved { background: #fffafa; }
.it .t-desc { color: #55555f; font-size: .88rem; }
.it .t-time { color: var(--accent); font-size: .8rem; font-weight: 600; }
.it .controls { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; min-width: 170px; }
.it .ctl-row { display: flex; gap: 5px; align-items: center; }
.it .note-in { width: 175px; }
.it .ctl-row input[type="time"] { font-size: .78rem; padding: 1px 4px; }
.user-note { color: #46617e; font-size: .84rem; background: #eef2f7; border-radius: 6px; padding: 2px 8px; margin-top: 3px; display: inline-block; }
.bk-details summary { display: block; color: var(--ok); font-size: .82rem; cursor: pointer; font-weight: 600; }
.bk-details[open] summary { margin-bottom: 2px; }
.bk-details div { font-size: .8rem; }

/* ---- travel legs ---- */
.leg {
  font-size: .8rem; color: var(--muted);
  padding: 3px 22px; border-right: 2px dotted #c9c2b6; margin-right: 6px;
}
.leg.origin { border-right: none; padding-right: 4px; font-weight: 600; color: #55555f; }
.leg.anchor-line { color: var(--fixed); font-weight: 600; border-right-color: var(--fixed); }
.leg input[type="time"] { font-size: .78rem; padding: 1px 4px; margin-right: 6px; }
.leg a { color: #46617e; }

/* ---- source text & POI links ---- */
.src-text summary { cursor: pointer; color: var(--muted); font-size: .84rem; }
.src-text pre { white-space: pre-wrap; font-family: inherit; font-size: .86rem; background: #faf8f5; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 6px; line-height: 1.7; }
.poi-links { margin-top: 2px; }
.poi-links a { font-size: .76rem; color: #46617e; background: #eef2f7; border-radius: 10px; padding: 1px 8px; margin-inline-end: 4px; text-decoration: none; }
.poi-links a:hover { background: #dde6f0; }

/* ---- bookings ---- */
table.bk { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.bk th, table.bk td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); font-size: .89rem; vertical-align: top; }
table.bk th { background: #faf8f5; color: var(--muted); font-size: .8rem; }
table.bk tr:last-child td { border-bottom: none; }
table.bk tr.done td { opacity: .55; }

/* ---- food / stands / tips ---- */
.food-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 18px; }
.food-item { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .89rem; }
.food-item b { font-weight: 600; }
.tip-list li { margin: 8px 0 8px 18px; }

/* ---- export / print ---- */
.print-day { margin-bottom: 18px; page-break-inside: avoid; }
.print-day h3 { border-bottom: 2px solid var(--accent); padding-bottom: 3px; margin-bottom: 6px; }
.print-item { padding: 4px 0; border-bottom: 1px dotted var(--line); font-size: .9rem; }
.print-item .pi-flags { color: var(--muted); font-size: .78rem; }

@media print {
  #topbar, #foot, .no-print { display: none !important; }
  body { background: #fff; font-size: 12px; }
  #content { max-width: none; padding: 0; }
  .card { border: none; padding: 4px 0; }
  a { text-decoration: none; color: inherit; }
}



/* ---- footer ---- */
#foot {
  max-width: 980px; margin: 0 auto; padding: 10px 18px 30px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  color: var(--muted); font-size: .8rem;
}
.foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.foot-actions button {
  font-family: inherit; font-size: .8rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--card);
  border-radius: 6px; padding: 3px 10px; color: var(--muted);
}
.foot-actions button:hover { color: var(--accent); border-color: var(--accent); }

/* ---- sync widget ---- */
#sync-widget { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; margin-inline-start: 8px; }
#sync-widget button { border: 1px solid var(--line); background: var(--card); border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: .9rem; line-height: 1; }
#sync-widget.sync-ok span { color: var(--ok); }
#sync-widget.sync-update span { color: var(--accent); font-weight: 700; }
#sync-widget.sync-update button { border-color: var(--accent); color: var(--accent); animation: syncpulse 1.6s infinite; }
#sync-widget.sync-busy button { animation: syncspin 1s linear infinite; }
#sync-widget.sync-off span { color: var(--muted); }
@keyframes syncspin { to { transform: rotate(360deg); } }
@keyframes syncpulse { 50% { box-shadow: 0 0 0 4px rgba(192,57,43,.15); } }

/* ---- Today + More ---- */
.today-banner { font-size: 1.05rem; }
.more-item { display: block; width: 100%; text-align: right; font-family: inherit; font-size: 1rem; padding: 14px 10px; background: none; border: none; border-bottom: 1px dashed var(--line); cursor: pointer; color: var(--ink); }
.more-item:last-of-type { border-bottom: none; }
.bk-card.done { opacity: .6; }

/* ---- bottom mobile nav (hidden on desktop) ---- */
#mnav { display: none; }
.edit-toggle { display: none; }

/* ================= phone-first layout (≤640px) ================= */
@media (max-width: 640px) {
  :root { font-size: 16px; }
  body { padding-bottom: 64px; } /* room for bottom nav */

  /* compact top header, not sticky (day headers take that role) */
  #topbar { position: static; padding: 10px 14px 8px; }
  .brand h1 { font-size: 1.1rem; }
  .brand .dates { display: none; }
  #tabs { display: none; }

  #content { padding: 12px 10px 70px; }

  /* bottom navigation */
  #mnav {
    display: flex; position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
    background: var(--card); border-top: 2px solid var(--accent);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  }
  #mnav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
    border: none; background: none; font-family: inherit; cursor: pointer;
    font-size: 1.15rem; color: var(--muted); padding: 4px 0; min-height: 48px;
  }
  #mnav button span { font-size: .68rem; }
  #mnav button.active { color: var(--accent); font-weight: 700; }

  /* day cards: sticky compact day header while scrolling */
  .day-head { position: sticky; top: 0; z-index: 20; background: var(--card); }
  .day-head .d-title { font-size: .95rem; }

  /* item rows: single column, data first, controls behind ✏️ */
  .it { grid-template-columns: 1fr; gap: 4px; }
  .edit-toggle { display: inline-block; margin-inline-start: auto; min-width: 40px; min-height: 32px; }
  .it .controls { display: none; }
  .it .controls.show {
    display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
    background: #faf8f5; border: 1px dashed var(--line); border-radius: 8px; padding: 8px;
  }
  .it .controls select, .it .controls button.action, .it .controls input { min-height: 40px; }
  .it .note-in { width: 100%; }

  /* touch targets + no horizontal overflow */
  button.action { min-height: 36px; }
  select, input[type="text"], input[type="time"] { min-height: 36px; }
  .qitem input[type="checkbox"] { width: 20px; height: 20px; }
  .leg { padding: 4px 14px; }
  .stat-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 10px 6px; }
  .stat .num { font-size: 1.3rem; }
  .city-strip { flex-direction: column; }
  .food-grid { grid-template-columns: 1fr; }
  #foot { flex-direction: column; align-items: flex-start; padding-bottom: 84px; }
}
