:root {
  --background: #f7f7f5;
  --foreground: #1a1a1a;
  --muted: #efefea;
  --muted-foreground: #6b6b66;
  --card: #ffffff;
  --border: #e2e2dc;
  --primary: #1e3a5f;
  --primary-foreground: #ffffff;
  --primary-soft: #e8eef5;
  --slot-1: #1e3a5f;
  --slot-2: #2f6fed;
  --slot-3: #0e7c66;
  --slot-4: #b45309;
  --shadow-sm: 0 1px 2px rgba(26, 26, 26, 0.06);
  --shadow-md: 0 8px 24px rgba(26, 26, 26, 0.08);
  --destructive: #b42318;
  --success: #067647;
  --warning: #b54708;
  --radius: 8px;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: inherit; }

.hidden { display: none !important; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-inner,
.tabs-inner,
.page {
  max-width: 1152px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.brand {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-link {
  text-decoration: none;
  color: var(--muted-foreground);
  font-size: 14px;
  font-weight: 600;
}

.topbar-link.active,
.tabs a.active {
  color: var(--foreground);
}

.tabs-inner {
  display: flex;
  gap: 4px;
}

.tabs a {
  text-decoration: none;
  padding: 10px 12px 12px;
  color: var(--muted-foreground);
  font-weight: 600;
  border-bottom: 2px solid transparent;
}

.tabs a.active {
  border-bottom-color: var(--primary);
}

.page { padding-top: 32px; padding-bottom: 64px; }

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.3;
}

h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.section-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.helper, .field-error {
  margin: 6px 0 0;
  font-size: 12px;
}

.helper { color: var(--muted-foreground); }

.field-error { color: var(--destructive); min-height: 0; }

.field-error:empty { display: none; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.narrow { max-width: 720px; }

.stack { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label, .set-card label {
  font-size: 14px;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="date"] {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 0 10px;
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input.invalid { border-color: var(--destructive); }

.mono { font-family: var(--mono); font-size: 13px; }

.btn {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  font-weight: 600;
}

.btn:disabled { opacity: 0.6; cursor: default; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.btn-danger {
  background: var(--destructive);
  border-color: var(--destructive);
  color: #fff;
}

.btn-ghost-danger {
  border-color: transparent;
  background: transparent;
  color: var(--destructive);
  padding: 0 8px;
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  padding: 0 8px;
}

.btn-row { display: inline-flex; align-items: center; gap: 4px; }

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow: auto;
  max-height: calc(100vh - 220px);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  background: var(--muted);
  padding: 0 12px;
  height: 40px;
  border-bottom: 1px solid var(--border);
}

td {
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr { cursor: pointer; }

tbody tr:hover { background: var(--muted); }

.empty {
  text-align: center;
  padding: 64px 24px;
}

.empty h2 { margin-bottom: 8px; }

.empty p { margin: 0 0 20px; color: var(--muted-foreground); }

.alert {
  border: 1px solid var(--destructive);
  background: #fef3f2;
  color: var(--destructive);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.set-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.set-list { display: flex; flex-direction: column; gap: 12px; }

.set-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(180px, 220px) auto auto;
  gap: 12px 16px;
  align-items: start;
}

.set-card > [data-remove] {
  margin-top: 26px;
}

.set-card .field-error { grid-column: 1 / -1; }

.segment {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.segment button {
  width: 44px;
  height: 36px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--card);
  font-family: var(--mono);
}

.segment button:last-child { border-right: none; }

.segment button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-foreground);
}

.form-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 16px;
  margin-top: 8px;
  background: linear-gradient(to top, var(--card) 70%, rgba(255, 255, 255, 0));
}

.form-actions .spacer { margin-left: auto; display: flex; gap: 8px; }

.secret-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(26, 26, 26, 0.08);
}

.toast-mark { color: var(--success); font-weight: 700; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26, 26, 26, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.dialog {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: 0 8px 24px rgba(26, 26, 26, 0.12);
}

.dialog h2 { margin-bottom: 8px; }

.dialog p { margin: 0; color: var(--muted-foreground); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card { width: min(420px, 100%); }

.gate-card h1 { margin: 0 0 8px; }

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -1px;
  margin-right: 6px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.stat-value {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-value.stat-date {
  font-size: 20px;
  font-family: var(--mono);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.toolbar input[type="search"] { width: min(320px, 100%); }

.toolbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-chip {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
}

.filter-chip[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.booking-list { display: flex; flex-direction: column; gap: 12px; }

.booking-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

.booking-card:hover { border-color: #cfcfc6; }

.booking-card.flash { background: var(--primary-soft); }

.booking-top { display: flex; gap: 12px; align-items: flex-start; }

.booking-main { flex: 1; min-width: 0; cursor: pointer; }

.booking-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.booking-name { margin: 0; font-size: 16px; font-weight: 600; }

.booking-meta { color: var(--muted-foreground); white-space: nowrap; }

.booking-hint { margin: 4px 0 0; }

.booking-actions { display: flex; gap: 4px; flex: none; }

.booking-expand {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.chip-more {
  align-self: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
}

.date-chip {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px 4px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.date-chip::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--slot-1);
  border-radius: 6px 0 0 6px;
}

.date-chip[data-slot="2"]::before { background: var(--slot-2); }
.date-chip[data-slot="3"]::before { background: var(--slot-3); }
.date-chip[data-slot="4"]::before { background: var(--slot-4); }

.date-chip-key,
.slot-key {
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 600;
}

.date-chip-line { font-family: var(--mono); }

.date-chip-warn { color: var(--warning); font-size: 12px; font-weight: 700; }

.date-chip-sub {
  color: var(--foreground);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

.date-chip.is-error {
  background: #fef3f2;
  border-color: var(--destructive);
  color: var(--destructive);
}

.date-chip.ghost { opacity: 0.45; }

.ghost-chips {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

td.prefs { height: auto; padding-top: 8px; padding-bottom: 8px; }

.info-banner {
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

.month-chip,
.next-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.dates-split,
.form-grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

.dates-split { grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); }

.form-grid { grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr); gap: 20px; }

.preview-sticky { position: sticky; top: 16px; }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.cal-nav h2 { font-size: 18px; margin-right: auto; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-dow {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
  padding: 4px 0;
}

.cal-empty { min-height: 4.5rem; }

button.cal-cell {
  appearance: none;
  width: 100%;
  min-height: 4.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  padding: 6px;
  text-align: left;
  position: relative;
  font: inherit;
  color: inherit;
}

button.cal-cell:hover,
button.cal-cell.is-selected { border-color: var(--primary); }

button.cal-cell.is-selected { box-shadow: 0 0 0 1px var(--primary); }

button.cal-cell.window-open {
  background: #eef8f3;
  box-shadow: inset 3px 0 0 rgba(6, 118, 71, 0.45);
}

button.cal-cell.window-open.is-selected {
  box-shadow: inset 3px 0 0 rgba(6, 118, 71, 0.45), 0 0 0 1px var(--primary);
}

button.cal-cell.window-closed {
  background: repeating-linear-gradient(
    -45deg,
    var(--muted),
    var(--muted) 4px,
    #f7f7f5 4px,
    #f7f7f5 8px
  );
}

button.cal-cell.is-past { opacity: 0.55; }

button.cal-cell.is-today .cal-num { color: var(--primary); }

.cal-num { font-family: var(--mono); font-size: 13px; font-weight: 600; }

.cal-unlock,
.cal-open-tag {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

.cal-unlock { color: var(--warning); font-family: var(--mono); }

.cal-open-tag { color: var(--success); }

.pref-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.slot-dots { display: flex; gap: 3px; margin-top: 6px; }

.slot-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--slot-1);
  display: block;
}

.slot-dot[data-slot="2"] { background: var(--slot-2); }
.slot-dot[data-slot="3"] { background: var(--slot-3); }
.slot-dot[data-slot="4"] { background: var(--slot-4); }

.cal-compact button.cal-cell,
.cal-compact .cal-empty { min-height: 3rem; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.swatch-open { background: #eef8f3; box-shadow: inset 3px 0 0 var(--success); }

.swatch-closed {
  background: repeating-linear-gradient(-45deg, var(--muted), var(--muted) 3px, #f7f7f5 3px, #f7f7f5 6px);
}

.swatch-pref { background: var(--primary); border-color: var(--primary); }

.day-panel { min-height: 280px; }

.day-when {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
}

.day-sub {
  margin: 4px 0 12px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
}

.day-entry {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.day-entry a { font-weight: 600; }

.rule-hint { margin-top: 12px; }

.edit-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.form-grid .set-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.form-grid .set-card .field { flex: 1 1 180px; }

.form-grid .set-card .slot-field { flex: 1 1 100%; }

.date-line { display: flex; align-items: center; gap: 8px; }

.date-line input[type="date"] { flex: 1; }

.weekday-note { color: var(--muted-foreground); font-weight: 600; white-space: nowrap; }

.slot-picker,
.slot-actions { display: flex; flex-direction: column; gap: 6px; }

.slot-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

.slot-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.slot-range { font-family: var(--mono); font-weight: 600; }

.slot-or {
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.slot-add {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.caller-list,
.caller-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.caller-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 8px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--primary-soft);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.caller-remove {
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.form-grid .set-card .field-error { flex-basis: 100%; }

.form-grid .set-card > [data-remove] { margin-top: 0; }

.set-card.set-focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

.settings-wrap { max-width: 720px; display: flex; flex-direction: column; gap: 16px; }

.status-strip { display: flex; gap: 16px; flex-wrap: wrap; }

.light {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 600;
}

.light::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c4c4be;
}

.light.on { color: var(--success); }
.light.on::before { background: var(--success); }

.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 13px;
}

.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; font-family: var(--mono); }

.skeleton {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--muted), #f4f4f0, var(--muted));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-lg { height: 28px; margin-top: 10px; }

@keyframes shimmer { to { background-position: -200% 0; } }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .stats,
  .dates-split,
  .form-grid { grid-template-columns: 1fr; }
  .preview-sticky { position: static; }
  .booking-title-row { flex-direction: column; }
}
