:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --line: color-mix(in srgb, var(--hint) 30%, transparent);
  --accent: var(--tg-theme-button-color, #2481cc);
  --lane-h: 7px;
  --lane-gap: 2px;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, system-ui, "Noto Sans KR", sans-serif;
  padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

header { position: sticky; top: 0; background: var(--bg); z-index: 10; padding-bottom: 6px; }

.nav { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 6px 0; }
.nav h1 { font-size: 17px; font-weight: 600; min-width: 130px; text-align: center; }
.nav button {
  width: 36px; height: 32px; font-size: 20px; line-height: 1;
  background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--fg);
}

.view-toggle { display: flex; gap: 6px; justify-content: center; padding-bottom: 6px; }
.view-toggle button {
  font-size: 13px; padding: 4px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: none; color: var(--fg);
}
.view-toggle button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; font-size: 11px; color: var(--hint); }
.legend .item { display: flex; align-items: center; gap: 4px; }
.legend .dot { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- calendar view ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar .dow {
  text-align: center; font-size: 11px; color: var(--hint); padding: 4px 0;
}
.calendar .dow.sun { color: #e05747; }
.calendar .dow.sat { color: #4aa8d8; }

.day {
  position: relative;
  min-height: calc(24px + 6 * (var(--lane-h) + var(--lane-gap)) + 6px);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  padding-top: 2px;
  overflow: hidden;
}
.day:nth-of-type(7n + 1) { border-left: none; } /* 일요일 열은 왼쪽 선 생략 */
.day .num {
  font-size: 11px; line-height: 1.5; padding-left: 4px; color: var(--fg);
}
.day.other .num { color: var(--hint); opacity: 0.5; }
.day.today .num {
  display: inline-block; min-width: 17px; text-align: center;
  background: var(--accent); color: #fff; border-radius: 9px; padding: 0 2px; margin-left: 2px;
}
.day .num.sun { color: #e05747; }
.day .num.sat { color: #4aa8d8; }

.lanes { position: absolute; left: 0; right: 0; top: 22px; }
.lane { position: relative; height: var(--lane-h); margin-bottom: var(--lane-gap); }
.seg {
  position: absolute; top: 0; height: 100%;
  opacity: 0.95;
}
/* 체크인 시작(해당일 중간부터) → 왼쪽 둥글게, 체크아웃 끝 → 오른쪽 둥글게 */
.seg.start { left: 50%; right: 0; border-radius: 4px 0 0 4px; }
.seg.end { left: 0; right: 50%; border-radius: 0 4px 4px 0; }
.seg.full { left: 0; right: 0; }
.seg.single { left: 50%; right: 50%; min-width: 0; } /* same-day in/out guard */

.day.other .seg { opacity: 0.25; }

/* ---------- timeline view ---------- */
.timeline { overflow-x: auto; }
.timeline.hidden, .calendar.hidden { display: none; }

.tl-grid { display: grid; position: relative; }
.tl-head {
  font-size: 10px; color: var(--hint); text-align: center;
  border-left: 1px solid var(--line); padding: 2px 0 4px;
  white-space: nowrap;
}
.tl-head .d { font-size: 12px; color: var(--fg); display: block; }
.tl-head.sun .d { color: #e05747; }
.tl-head.sat .d { color: #4aa8d8; }
.tl-head.today { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.tl-room {
  position: sticky; left: 0; z-index: 2;
  background: var(--bg); font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 5px;
  padding: 0 6px; border-top: 1px solid var(--line);
  white-space: nowrap;
}
.tl-room .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

.tl-row { position: relative; height: 34px; border-top: 1px solid var(--line); }
.tl-cell { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); }
.tl-cell.today { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.tl-bar {
  position: absolute; top: 7px; height: 20px; border-radius: 10px;
  color: #fff; font-size: 10px; line-height: 20px;
  padding: 0 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.status { text-align: center; font-size: 12px; color: var(--hint); padding: 10px 0; }
