:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef1f5;
  --line: #d9dee7;
  --text: #17202a;
  --muted: #5b6675;
  --leave: #2563eb;
  --leave-bg: #dbeafe;
  --overnight: #0f766e;
  --overnight-bg: #ccfbf1;
  --linked: #c2410c;
  --linked-bg: #ffedd5;
  --focus: #111827;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 20px;
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px;
}

.controls-panel,
.calendar-panel {
  min-width: 0;
}

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

.title-block h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.title-block p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.field span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

textarea,
select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.12);
}

textarea {
  min-height: 220px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

input {
  height: 42px;
  padding: 0 10px;
}

select {
  height: 38px;
  padding: 0 8px;
}

.seniority-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-header span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.slim-button {
  width: auto;
  min-width: 86px;
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.seniority-blocks {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seniority-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.block-top {
  display: grid;
  grid-template-columns: minmax(54px, auto) minmax(90px, 120px) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.block-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.block-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.block-action {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.block-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.block-action.danger {
  color: #991b1b;
}

.block-names {
  min-height: 76px;
  padding: 9px;
  font-size: 14px;
}

.block-help {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.month-row {
  display: grid;
  grid-template-columns: 110px repeat(3, minmax(104px, 1fr));
  gap: 10px;
  align-items: end;
}

.compact-field {
  gap: 6px;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 42px;
}

.primary-button {
  border-color: #111827;
  background: #111827;
  color: #fff;
  font-weight: 800;
}

.ghost-button,
.icon-button {
  background: var(--surface);
  color: var(--text);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.legend-dot.leave,
.count-pill.leave {
  background: var(--leave-bg);
  color: var(--leave);
}

.legend-dot.overnight,
.count-pill.overnight {
  background: var(--overnight-bg);
  color: var(--overnight);
}

.legend-dot.linked,
.count-pill.linked {
  background: var(--linked-bg);
  color: var(--linked);
}

.legend-dot.leave {
  background: var(--leave);
}

.legend-dot.overnight {
  background: var(--overnight);
}

.legend-dot.linked {
  background: var(--linked);
}

.person-focus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 10px;
}

.person-focus.hidden {
  display: none;
}

#personFocusLabel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.focus-clear-button {
  flex: 0 0 auto;
  width: auto;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.calendar-panel .person-focus {
  margin-bottom: 10px;
}

.summary {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.summary-grid,
.type-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summary-grid span,
.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.summary-grid strong {
  margin-right: 4px;
  color: var(--text);
}

.type-counts {
  margin-top: 8px;
}

.count-pill {
  font-weight: 800;
}

.error-text {
  margin: 12px 0 0;
  border-left: 3px solid #dc2626;
  padding-left: 10px;
  color: #991b1b;
  font-size: 13px;
  line-height: 1.5;
}

.calendar-panel {
  display: flex;
  height: calc(100vh - 40px);
  min-height: 520px;
  max-height: 1800px;
  flex-direction: column;
  overflow: hidden;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.calendar-toolbar h2 {
  margin: 0;
  text-align: center;
  font-size: 28px;
}

.icon-button {
  font-size: 28px;
  line-height: 1;
}

.weekday-grid,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday-grid {
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--surface-soft);
}

.weekday-grid span {
  min-height: 34px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 34px;
  text-align: center;
}

.weekday-grid span:last-child {
  border-right: 0;
}

.calendar-grid {
  flex: 1;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: var(--line);
}

.calendar-resize-handle {
  height: 12px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background:
    linear-gradient(var(--line), var(--line)) center 4px / 42px 2px no-repeat,
    var(--surface-soft);
  cursor: ns-resize;
  flex: 0 0 auto;
  touch-action: none;
}

.calendar-resize-handle:focus {
  outline: 2px solid #111827;
  outline-offset: 2px;
}

.day-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 8px;
}

.day-cell.empty {
  background: #eef1f5;
}

.day-cell.today {
  box-shadow: inset 0 0 0 2px #111827;
}

.day-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-weight: 800;
}

.day-cell.sunday .day-heading {
  color: #dc2626;
}

.day-cell.saturday .day-heading {
  color: #2563eb;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  margin-top: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.event-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  border-left: 4px solid currentColor;
  border-radius: 7px;
  padding: 6px 7px;
  font-size: 12px;
  line-height: 1.2;
  transition:
    opacity 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
}

.event-chip.person-dimmed {
  opacity: 0.28;
}

.event-chip.person-highlighted {
  box-shadow:
    0 0 0 2px var(--person-color),
    0 2px 8px rgba(17, 24, 39, 0.16);
  transform: translateY(-1px);
}

.event-chip.clickable {
  cursor: pointer;
}

.event-chip.leave {
  background: var(--leave-bg);
  color: var(--leave);
}

.event-chip.overnight {
  background: var(--overnight-bg);
  color: var(--overnight);
}

.event-chip.linked {
  background: var(--linked-bg);
  color: var(--linked);
}

.event-name,
.event-kind,
.event-note {
  min-width: 0;
  overflow-wrap: anywhere;
}

.event-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-weight: 850;
}

.person-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--person-color);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
}

.event-kind {
  font-weight: 850;
}

.event-note {
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .calendar-panel {
    height: 760px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .month-row {
    grid-template-columns: 1fr;
  }

  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .section-actions {
    justify-content: stretch;
  }

  .slim-button {
    flex: 1 1 110px;
  }

  .block-top {
    grid-template-columns: minmax(54px, auto) minmax(86px, 1fr);
  }

  .block-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .calendar-toolbar h2 {
    font-size: 22px;
  }

  .weekday-grid span {
    min-height: 30px;
    line-height: 30px;
  }

  .day-cell {
    padding: 5px;
  }

  .day-heading {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  .event-list {
    gap: 4px;
  }

  .event-chip {
    border-left-width: 3px;
    padding: 5px 4px;
    font-size: 10px;
  }

  .event-note {
    font-size: 9px;
  }
}
