:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #77726b;
  --line: #e8e6e1;
  --chip: #f4f2ed;
  /* category colors */
  --c-flight: #8b5cf6;
  --c-lodging: #3b82f6;
  --c-transport: #10b981;
  --c-segment: #f97316;
  --c-activity: #eab308;
  --c-placeholder: #b9b4ab;
  --warn: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
}
.trip-picker select {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chip);
  color: var(--fg);
}
.view-tabs {
  margin-left: auto;
  display: flex;
  gap: 4px;
  background: var(--chip);
  padding: 4px;
  border-radius: 10px;
}
.view-tab {
  border: none;
  background: transparent;
  padding: 6px 14px;
  font-size: 13.5px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
}
.view-tab.active {
  background: #fff;
  color: var(--fg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-weight: 500;
}

main { padding: clamp(14px, 3vw, 34px); max-width: 1180px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* Month header */
.month-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.month-title { font-size: 22px; font-weight: 650; margin: 0; }
.month-sub { color: var(--muted); font-size: 13.5px; }

/* active-date range box + popup */
.range-box {
  font-size: 13px;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 12px;
  background: #e5e2dc;
  cursor: pointer;
  font-weight: 500;
}
.range-box:hover { background: #dcd8d0; }
.range-popup {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  padding: 12px;
  width: 300px;
}
.range-popup-title { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.range-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.range-nav span { font-weight: 600; font-size: 14px; }
.range-nav button { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 15px; line-height: 1; }
.range-nav button:hover { background: var(--chip); }
.rp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.rp-dow { text-align: center; font-size: 11px; color: var(--muted); padding: 3px 0; }
.rp-cell {
  text-align: center;
  font-size: 12.5px;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  color: var(--fg);
}
.rp-cell:hover { background: var(--chip); }
.rp-cell.other { background: #faf9f7; color: #c4bfb6; }
.rp-cell.in-range { background: transparent; }
.rp-cell.start, .rp-cell.end { background: transparent; color: var(--fg); font-weight: 600; }
.rp-cell.pending { background: transparent; font-weight: 600; }

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 16px;
  align-items: center;
}
.legend .swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 10px;
}

/* Calendar — week-track layout (continuous bridged bars) */
.cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-head div {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 4px;
  text-align: center;
}
.cal-week {
  position: relative;
  border: 1px solid var(--line);
  margin-top: -1px;
  height: 94px;
}
.cal-week .cal-days {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-days .day-cell {
  border-left: 1px solid var(--line);
  padding: 4px 6px 0;
  font-size: 12px;
  color: var(--muted);
  position: relative;
  cursor: crosshair;
  overflow: visible;
}
.cal-days .day-cell:first-child { border-left: none; }
.cal-days .day-cell.other { background: #faf9f7; color: #b9b4ab; }
.cal-days .day-cell.today { background: transparent; }
.cal-days .day-cell.active { background: transparent; box-shadow: none; }
.cal-days .day-cell.add-target { background: transparent; }
.cal-days .half-line {
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 1px;
  background: repeating-linear-gradient(180deg, transparent 0 3px, #ece9e3 3px 5px);
  pointer-events: none;
}
.cal-week .cal-bars {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cal-bars .bar-track {
  position: absolute;
  width: 100%;
}
/* continuous bar: positioned in day-column units via left/width % */
.bar.bridge {
  position: absolute;
  border-radius: 7px;
  color: #fff;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 22px;
  padding: 0 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  touch-action: none;
  z-index: 2;
  display: flex;
  align-items: center;
}
.bar.bridge:active { cursor: grabbing; }
.bar.bridge.placeholder {
  opacity: 0.92;
}
.bar.bridge.dragging { box-shadow: 0 2px 8px rgba(0,0,0,0.18); z-index: 5; }
.bar.bridge.snapping { transition: left 0.18s ease, width 0.18s ease, top 0.18s ease; }
.bar-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 20px;
  cursor: ew-resize;
  background: rgba(255,255,255,0.0);
  border: none;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
  z-index: 3;
}
/* Handles are invisible hit areas only — resize by grabbing the very edge. */
.bar-handle.left { left: 0; border-radius: 7px 0 0 7px; }
.bar-handle.right { right: 0; border-radius: 0 7px 7px 0; }
.bar-handle.left::after, .bar-handle.right::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 3px; height: 15px;
  border-radius: 3px;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}

/* quick-add + editing hints */
.cal-actions { display: flex; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--fg);
  border-radius: 8px;
  padding: 6px 13px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #ece9e3; }
.btn.primary { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.cat-menu {
  position: absolute;
  top: 46px;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cat-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 12px;
  font-size: 13.5px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
}
.cat-menu button:hover { background: var(--chip); }
.cat-menu .dot { width: 11px; height: 11px; border-radius: 11px; }
.hint {
  font-size: 12.5px;
  color: var(--muted);
  background: #fffbe6;
  border: 1px solid #f0e5b0;
  padding: 7px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}
.hint b { color: var(--fg); }
.bar.bridge .bar-fade { position:absolute; right:4px; }

/* right-click add menu on a day cell */
.context-menu {
  position: fixed;
  z-index: 100;
  min-width: 165px;
  padding: 5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 7px 24px rgba(0,0,0,.18);
}
.context-menu .context-label {
  padding: 6px 10px 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.context-menu button {
  display: flex;
  width: 100%;
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.context-menu button:hover { background: var(--chip); }
.context-menu button.danger { color: #c0392b; }
.context-menu button.danger:hover { background: #fdecea; }
.context-menu .dot { width: 10px; height: 10px; border-radius: 50%; }

/* inline category picker on a day cell */
.cell-menu {
  position: absolute;
  left: 4px; top: 26px;
  z-index: 40;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
}
.cell-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 7px 11px;
  font-size: 13px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
}
.cell-menu button:hover { background: var(--chip); }
.cell-menu .dot { width: 11px; height: 11px; border-radius: 11px; }

/* Timeline (Gantt) */
.tl-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tl-title { font-size: 22px; font-weight: 650; margin: 0; }
.tl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.tl {
  position: relative;
  min-width: 100%;
}
.tl-row {
  display: flex;
  border-bottom: 1px solid var(--line);
  align-items: stretch;
}
.tl-row:last-child { border-bottom: none; }
.tl-label {
  flex: 0 0 190px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  border-right: 1px solid var(--line);
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tl-label small {
  color: var(--muted);
  font-weight: 400;
  font-size: 11.5px;
}
.tl-cat {
  flex: 0 0 150px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: #faf9f7;
  position: sticky;
  left: 190px;
  z-index: 2;
}
.tl-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 44px;
}
.tl-grid-lines { position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; }
.tl-grid-lines div { flex: 1 1 0; border-left: 1px solid #f0eeea; }
/*
 bars are positioned with inline left/width %
*/
.tl-bar {
  position: absolute;
  height: 26px;
  top: 9px;
  border-radius: 6px;
  color: #fff;
  font-size: 11.5px;
  font-weight: 500;
  padding: 0 9px;
  line-height: 26px;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  min-width: 10px;
  z-index: 1;
}
.tl-bar.placeholder {
  background: repeating-linear-gradient(45deg, var(--c-placeholder), var(--c-placeholder) 6px, #a9a299 6px, #a9a299 12px);
}
.tl-bar.flagged { box-shadow: 0 0 0 2px var(--warn); }

/* headers */
.tl-days {
  display: flex;
  background: #faf9f7;
  border-bottom: 1px solid var(--line);
}
.tl-days .tl-cat2 { flex: 0 0 190px; }
.tl-days .tl-cat3 { flex: 0 0 150px; }
.tl-day-labels {
  flex: 1 1 auto;
  display: flex;
  position: sticky;
  left: 340px;
}
.tl-day-labels div {
  flex: 1 1 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 8px 0;
  border-left: 1px solid #f0eeea;
}

/* Checklist */
.check-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.check-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
}
.check-badge {
  flex: 0 0 auto;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 9px;
  border-radius: 20px;
  font-weight: 600;
}
.check-badge.b-error { background: #fee2e2; color: #b91c1c; }
.check-badge.b-warn { background: #fef3c7; color: #92400e; }
.check-badge.b-ok { background: #d1fae5; color: #065f46; }
.check-badge.b-info { background: #e0e7ff; color: #3730a3; }
.check-text { font-size: 14px; line-height: 1.4; }
.check-text small { color: var(--muted); display: block; margin-top: 2px; }

/* Drawer */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: #fff;
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.24s ease;
  box-shadow: -6px 0 24px rgba(0,0,0,0.12);
  padding: 24px 26px;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  position: absolute;
  top: 16px; right: 18px;
  border: none; background: var(--chip);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
}
.drawer h2 { margin: 4px 0 2px; font-size: 21px; font-weight: 650; }
.drawer .cat-chip {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 20px;
  color: #fff;
  margin-bottom: 12px;
}
.drawer .kv {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.drawer .kv .k { color: var(--muted); }
.drawer .kv .v { text-align: right; font-weight: 500; }
.drawer .notes { margin-top: 16px; font-size: 13.5px; color: var(--fg); line-height: 1.5; }
.drawer .notes .nl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.drawer .flag {
  margin-top: 16px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
}
.drawer .flag.err { background: #fee2e2; color: #b91c1c; }

.empty { color: var(--muted); text-align: center; padding: 60px 20px; font-size: 15px; }

@media (max-width: 700px) {
  .topbar { gap: 12px; padding: 12px 14px; }
  .view-tabs { margin-left: 0; width: 100%; }
  .view-tab { flex: 1; }
  .cal td { height: 92px; }
  .tl-label { flex-basis: 120px; }
  .tl-cat { flex-basis: 110px; left: 120px; }
  .tl-days .tl-cat2 { flex-basis: 120px; }
  .tl-days .tl-cat3 { flex-basis: 110px; }
  .tl-day-labels { left: 230px; }
}
/* rename input in drawer */
.rename-input {
  width: 100%;
  box-sizing: border-box;
  font-size: 19px;
  font-weight: 600;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 5px 8px;
  margin: 2px 0 8px;
}
.rename-input:hover { border-color: var(--line); }
.rename-input:focus { border-color: var(--line); outline: none; background: #fff; }
