:root {
  --bg: #dce3ee;
  --bg2: #e8eef6;
  --panel: #f3f6fb;
  --panel2: #eef2f8;
  --line: #c5d0e0;
  --text: #1a2332;
  --muted: #5c6b82;
  --accent: #2563eb;
  --good: #16a34a;
  --warn: #ca8a04;
  --danger: #dc2626;
  --slot-h: 34px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }

.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(232, 238, 246, .96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 8px;
}
.top-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 18px; font-weight: 900; letter-spacing: .03em; }
.grow { flex: 1; }
.btn {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); border-radius: 10px; padding: 8px 12px;
  font-weight: 700; cursor: pointer; min-height: 40px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.gold { background: linear-gradient(180deg, #fbbf24, #d97706); color: #111; border: 0; }
.btn.danger { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.on { outline: 2px solid var(--warn); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; }
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); border-radius: 999px; padding: 6px 14px; font-weight: 800; cursor: pointer;
}
.tab.on { background: var(--accent); color: #fff; border-color: transparent; }

.day-nav { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.day-nav .date-label { flex: 1; text-align: center; font-weight: 900; font-size: 15px; }

.board { flex: 1; overflow: auto; padding: 8px 10px 100px; }

.timeline {
  position: relative; border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; background: var(--panel);
  box-shadow: 0 2px 8px rgba(30,50,80,.06);
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
}
.timeline.selecting {
  touch-action: none;
}
.slot-row {
  display: grid; grid-template-columns: 58px 1fr;
  min-height: var(--slot-h); border-bottom: 1px solid #dde5f0;
  user-select: none; -webkit-user-select: none;
}
.slot-row:last-child { border-bottom: 0; }
.slot-time {
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 4px 8px 0 4px; font-size: 11px; color: var(--muted); font-weight: 700;
  border-right: 1px solid var(--line); background: var(--bg2);
}
.slot-cell { position: relative; cursor: pointer; touch-action: pan-y; min-height: var(--slot-h); }
.timeline.selecting .slot-cell { touch-action: none; }
.slot-cell.picking { background: rgba(37, 99, 235, .22); }
.slot-cell.now-line::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: var(--danger); z-index: 5; pointer-events: none;
}
.event-block {
  border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 800; color: #111;
  overflow: hidden; z-index: 2; border: 1.5px solid rgba(0,0,0,.28);
  box-shadow: 0 2px 5px rgba(0,0,0,.12); cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; line-height: 1.2;
}
.event-block .ev-name { font-size: 13px; }
.event-block .ev-time { font-size: 10px; opacity: .85; font-weight: 700; }

.month-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.month-head h2 { flex: 1; text-align: center; margin: 0; font-size: 18px; }
.weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px;
  text-align: center; font-size: 12px; color: var(--muted); font-weight: 800;
}
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-cell {
  min-height: 72px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.day-cell.out { opacity: .4; }
.day-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day-cell .n { font-size: 12px; font-weight: 800; }
.day-cell .mini {
  font-size: 9px; font-weight: 700; color: #111; border-radius: 3px;
  padding: 1px 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.modal-bg {
  position: fixed; inset: 0; background: rgba(30, 40, 60, .45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 12px;
}
.modal {
  width: min(480px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px; max-height: 85dvh; overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.modal h3 { margin: 0 0 12px; font-size: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text);
}
.act-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act-btn {
  border: 2px solid transparent; border-radius: 12px; padding: 12px 10px;
  font-weight: 800; cursor: pointer; color: #111; text-align: center; min-height: 48px;
}
.act-btn.on { outline: 3px solid #1a2332; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0; line-height: 1.5; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800;
  background: #dbe4f0; color: var(--muted);
}
.pill.ok { background: #dcfce7; color: #166534; }
.pill.warn { background: #fef3c7; color: #92400e; }

.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  display: flex; align-items: center; gap: 8px; padding: 8px; background: #fff;
  border-radius: 10px; border: 1px solid var(--line);
}
.color-dot { width: 18px; height: 18px; border-radius: 6px; border: 1px solid #333; flex: 0 0 auto; }
.settings-row input[type="text"] { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; }
.settings-row input[type="color"] { width: 40px; height: 36px; border: 0; background: transparent; padding: 0; }

.empty-day { text-align: center; padding: 16px; color: var(--muted); font-size: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
.card h2 { margin: 0 0 8px; font-size: 16px; }

/* PWA / mobile */
body.dragging-slots { overflow: hidden; touch-action: none; }
.install-banner {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  display: flex; align-items: center; gap: 10px;
}
.install-banner img { width: 40px; height: 40px; border-radius: 10px; }
.install-banner .txt { flex: 1; font-size: 13px; line-height: 1.35; }
.install-banner .txt b { display: block; font-size: 14px; }
