:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #161b22;
  --surface-hover: #1c2330;
  --surface-raised: #242d3a;
  --input-bg: #121820;
  --border: #2a3441;
  --text: #eef2f6;
  --text-muted: #8b9cb3;
  --text-dim: #5c6b80;
  --blue: #4d9fff;
  --green: #3ecf8e;
  --amber: #e3b341;
  --red: #f47067;
  --today: #4d9fff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}
button, input, select { font-family: inherit; }
button { cursor: pointer; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 24px;
}
.topbar { margin-bottom: 12px; }
.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.lead {
  margin: 6px 0 0;
  color: var(--text-muted);
  max-width: 640px;
  line-height: 1.45;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
}
.cal-nav h1 { margin: 0; font-size: 16px; min-width: 180px; text-align: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { background: var(--surface-raised); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #061018; }
.btn-icon { width: 32px; padding: 0; font-size: 18px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: 32px;
  grid-auto-rows: 120px;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}
.cal-dow {
  height: 32px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cal-cell {
  height: 120px;
  min-width: 0;
  padding: 6px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
}
.cal-cell:hover:not(.out):not(.past) { background: var(--surface-hover); }
.cal-cell.out { background: var(--bg); color: var(--text-dim); cursor: default; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--today); }
.cal-cell.past:not(.out) { opacity: 0.55; cursor: default; }
.cal-daynum { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.cal-event {
  font-size: 11px;
  color: var(--amber);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.busy { color: var(--amber); }

.cal-float {
  position: fixed;
  z-index: 70;
  min-width: 220px;
  max-width: min(440px, calc(100vw - 16px));
  max-height: min(360px, calc(100vh - 16px));
  overflow: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  padding: 8px 12px;
  pointer-events: none;
}
.cal-float.hidden { display: none; }
.cal-float-item {
  font-size: 13px;
  font-weight: 600;
  color: var(--amber);
  line-height: 1.35;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.cal-float-item:last-child { border-bottom: 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px 24px;
  z-index: 50;
  overflow: auto;
}
.hidden { display: none !important; }
.overlay.hidden { display: none; }
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15px; flex: 1; }
.modal-body { padding: 16px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.field input, .field select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
}
.harbor-list { display: grid; gap: 8px; }
.harbor-btn {
  text-align: left;
  width: 100%;
  height: auto;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  font-weight: 600;
}
.harbor-btn:hover, .harbor-btn.sel {
  border-color: var(--blue);
  background: var(--surface-raised);
}
.muted { color: var(--text-muted); font-size: 13px; }
.err { color: var(--red); font-size: 13px; margin: 0 0 10px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: 10px 16px;
  z-index: 80;
}
.toast.hidden { display: none; }

@media (max-width: 700px) {
  .cal-grid { grid-auto-rows: 88px; }
  .cal-cell { height: 88px; }
}
