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

:root {
  --bg: #0f1420;
  --panel: #1a2233;
  --panel-2: #212c42;
  --text: #e8edf6;
  --muted: #8b98af;
  --accent: #4f8cff;
  --border: #33415e;
  --line: #26304a;
  --work: #34c07a;
  --awake: #d9a53a;
  --sleep: #3a4358;
  --work-dim: #1f3b2d;
  --work-dim-border: #2c5a43;
  --awake-dim: #3d3521;
  --now: #ffffff;
  --radius: 12px;
}

/* 亮色主题（手动选择） */
:root[data-theme="light"] {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --panel-2: #e9eef6;
  --text: #1b2433;
  --muted: #5c6a83;
  --accent: #3b76e8;
  --border: #ccd5e4;
  --line: #dfe4ee;
  --work: #2aab6d;
  --awake: #d99b1e;
  --sleep: #d5dbe7;
  --work-dim: #d9f0e4;
  --work-dim-border: #a8d8bf;
  --awake-dim: #f4e9cd;
  --now: #1b2433;
}

/* 跟随系统：未手动选择时按系统偏好套用亮色 */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f2f5f9;
    --panel: #ffffff;
    --panel-2: #e9eef6;
    --text: #1b2433;
    --muted: #5c6a83;
    --accent: #3b76e8;
    --border: #ccd5e4;
    --line: #dfe4ee;
    --work: #2aab6d;
    --awake: #d99b1e;
    --sleep: #d5dbe7;
    --work-dim: #d9f0e4;
    --work-dim-border: #a8d8bf;
    --awake-dim: #f4e9cd;
    --now: #1b2433;
  }
}

body {
  font-family: -apple-system, "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 26px 32px;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 30px; }
header .brand p { color: var(--muted); font-size: 15px; margin-top: 6px; }
.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; font-size: 15px; color: var(--muted); }
.controls label { display: flex; align-items: center; gap: 8px; }
.controls select, .controls input[type="date"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-family: inherit; font-size: 16px;
}
/* 日期输入放大：Chrome 弹出的日历会随 input 字号等比放大 */
.controls input[type="date"] {
  font-size: 18px; font-weight: 600; padding: 10px 12px; cursor: pointer;
}
.controls input[type="range"] { width: 150px; accent-color: var(--accent); }
.controls b {
  color: var(--text); font-size: 16px;
  width: 118px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.controls button {
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 10px 18px; cursor: pointer; font-size: 15px;
}
.controls button:hover { filter: brightness(1.1); }
.controls .theme-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px;
}
.controls .theme-btn:hover { border-color: var(--accent); filter: none; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 24px 40px; }

.add-city { position: relative; margin-bottom: 16px; }
.add-city input {
  width: 100%; padding: 12px 16px; font-size: 15px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  outline: none;
}
.add-city input:focus { border-color: var(--accent); }
.results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius);
  list-style: none; max-height: 260px; overflow-y: auto;
}
.results li { padding: 10px 16px; cursor: pointer; font-size: 14px; }
.results li:hover { background: var(--accent); }
.results li .tz { color: var(--muted); font-size: 12px; margin-left: 8px; }
.results li:hover .tz { color: #dbe7ff; }
.hidden { display: none !important; }

.summary {
  background: var(--panel); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 16px; font-size: 14px; line-height: 1.9;
}
.summary .good { color: var(--work); font-weight: 600; }
.summary .bad { color: var(--awake); }
.summary .range-chip {
  display: inline-block; background: var(--work-dim); color: var(--work);
  border: 1px solid var(--work-dim-border); border-radius: 20px;
  padding: 2px 12px; margin: 2px 6px 2px 0; font-weight: 600; cursor: pointer;
}
.summary .range-chip:hover { background: var(--work); color: #0e1a14; }

.timeline-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius); padding: 16px; }
#timeline { min-width: 900px; }
.tl-row { display: flex; align-items: center; margin-bottom: 6px; }
.tl-label {
  flex: 0 0 190px; font-size: 13px; padding-right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  color: var(--muted);
}
.tl-label .city-name { font-weight: 600; color: var(--text); }
.tl-label .city-now { color: var(--muted); font-size: 12px; display: block; }
.tl-label .rm {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px;
}
.tl-label .rm:hover { color: #ff6b6b; }

/* 小时刻度行 */
.tl-scale { display: grid; grid-template-columns: repeat(24, 1fr); flex: 1; }
.tl-scale span { font-size: 10px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 3px; }

/* 96 × 15 分钟槽位 */
.tl-cells {
  display: grid; grid-template-columns: repeat(96, 1fr); flex: 1;
  position: relative; height: 38px; border-radius: 6px; overflow: hidden;
  cursor: crosshair; touch-action: none;
}
.tl-row.header .tl-cells { height: 20px; }
.slot { height: 100%; }
.slot.work { background: var(--work); }
.slot.awake { background: var(--awake); }
.slot.sleep { background: var(--sleep); }
.slot.hour-mark { box-shadow: inset 1px 0 0 rgba(0,0,0,.28); }
.slot.all-work { background: var(--work-dim); box-shadow: inset 0 -2px 0 var(--work); }
.slot.all-awake { background: var(--awake-dim); }
.slot.none { background: var(--panel-2); }

/* 跨天标记（+1天 / -1天） */
.day-badge {
  position: absolute; top: 2px; z-index: 1; pointer-events: none;
  font-size: 9px; line-height: 1.5; padding: 0 5px; border-radius: 0 4px 4px 0;
  background: var(--text); color: var(--bg); opacity: .78; white-space: nowrap;
  border-left: 2px solid var(--now);
}

/* 当前时刻竖线 */
.now-line {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--now); opacity: .85; pointer-events: none; z-index: 3;
}

/* 会议选区色带 */
.sel-band {
  position: absolute; top: 0; bottom: 0;
  left: var(--sel-l, 0); width: var(--sel-w, 0);
  background: rgba(79, 140, 255, .30);
  border: 2px solid var(--accent); border-radius: 4px;
  z-index: 2; cursor: grab;
}
.sel-band .h {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 8px; height: 70%; max-height: 26px; border-radius: 3px;
  background: var(--accent); cursor: ew-resize;
}
.sel-band .hl { left: -5px; }
.sel-band .hr { right: -5px; }
.tl-row.header .sel-band .h { display: none; }

.tl-hint { margin-top: 10px; font-size: 12px; color: var(--muted); }
.tl-hint b { color: var(--text); }

.detail {
  margin-top: 16px; background: var(--panel); border-radius: var(--radius);
  padding: 16px 20px; font-size: 14px;
}
.detail h3 { font-size: 15px; margin-bottom: 10px; color: var(--accent); }
.detail table { width: 100%; border-collapse: collapse; }
.detail td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.detail td:last-child { text-align: right; color: var(--muted); }
.detail .tag { border-radius: 4px; padding: 1px 8px; font-size: 12px; margin-left: 8px; }
.detail .tag.work { background: var(--work-dim); color: var(--work); }
.detail .tag.awake { background: var(--awake-dim); color: var(--awake); }
.detail .tag.sleep { background: var(--panel-2); color: var(--muted); }
.detail .actions { margin-top: 12px; }
.detail .actions button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.detail .actions button:hover { border-color: var(--accent); color: var(--accent); }

footer {
  margin-top: 18px; display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  color: var(--muted); font-size: 12px;
}
.legend { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.work { background: var(--work); }
.sw.awake { background: var(--awake); }
.sw.sleep { background: var(--sleep); }
.sw.band-i { background: rgba(79, 140, 255, .3); border: 2px solid var(--accent); }
.hint { margin-left: auto; }
