:root {
  color-scheme: light;
  --paper: #fffaf2;
  --ink: #26211b;
  --muted: #766f66;
  --line: #e8ded0;
  --work: #c75f4a;
  --study: #2f74b8;
  --event: #8b6fcb;
  --free: #3d8b63;
  --weekend: #d92929;
  --soft-weekend: #fff0ec;
  --soft-free: #e4f3e9;
  --soft-work: #fbe7df;
  --soft-study: #e4eef9;
  --soft-event: #f0eaf8;
  --fill-work-day: #cde8ff;
  --fill-work-night: #0d4773;
  --fill-study: #e5d7ff;
  --fill-event: #ffd3e5;
  --shadow: 0 18px 45px rgba(66, 47, 26, 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171512;
  --ink: #f5efe5;
  --muted: #b8aa99;
  --line: #3d352d;
  --work: #ff9c84;
  --study: #8fbeff;
  --event: #cbb7ff;
  --free: #79d69d;
  --weekend: #ff7777;
  --soft-weekend: #3a1d1a;
  --soft-free: #153625;
  --soft-work: #40231e;
  --soft-study: #172b43;
  --soft-event: #302541;
  --fill-work-day: #2f6588;
  --fill-work-night: #061f36;
  --fill-study: #5a4780;
  --fill-event: #71344f;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(120deg, rgba(255, 250, 242, 0.95), rgba(239, 248, 241, 0.82)),
    repeating-linear-gradient(0deg, rgba(38, 33, 27, 0.035) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, rgba(38, 33, 27, 0.03) 0 1px, transparent 1px 48px);
}

[data-theme="dark"] body {
  background:
    linear-gradient(120deg, rgba(23, 21, 18, 0.98), rgba(19, 31, 27, 0.9)),
    repeating-linear-gradient(0deg, rgba(245, 239, 229, 0.035) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, rgba(245, 239, 229, 0.03) 0 1px, transparent 1px 48px);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  padding: 26px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(42px, 7vw, 92px);
  line-height: 0.92;
  letter-spacing: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(118px, 1fr));
  justify-self: end;
  gap: 10px;
}

.summary-card,
.best-card,
.day-card,
.drawer {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

[data-theme="dark"] .summary-card,
[data-theme="dark"] .best-card,
[data-theme="dark"] .day-card,
[data-theme="dark"] .drawer,
[data-theme="dark"] .month-editor-grid,
[data-theme="dark"] .quick-fill {
  background: rgba(28, 25, 22, 0.82);
}

.summary-card {
  min-height: 78px;
  padding: 13px 14px;
  border-radius: 8px;
}

.summary-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.summary-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sync-status {
  display: inline-flex;
  max-width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 800;
}

.sync-status.is-online {
  border-color: rgba(61, 139, 99, 0.35);
  color: var(--free);
  background: var(--soft-free);
}

.sync-status.is-error {
  border-color: rgba(199, 95, 74, 0.35);
  color: var(--work);
  background: var(--soft-work);
}

.controls {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  background: rgba(255, 250, 242, 0.88);
  backdrop-filter: blur(18px);
}

[data-theme="dark"] .controls,
[data-theme="dark"] .weekday-row {
  background: rgba(23, 21, 18, 0.88);
}

.segmented,
.people-filter,
.sync-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: thin;
}

.segmented button,
.person-chip,
.ghost-button,
.save-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  white-space: nowrap;
}

[data-theme="dark"] .segmented button,
[data-theme="dark"] .person-chip,
[data-theme="dark"] .ghost-button {
  background: rgba(31, 28, 24, 0.82);
}

.segmented button[aria-pressed="true"],
.person-chip[aria-pressed="true"] {
  border-color: #2d2a25;
  color: #fff;
  background: #2d2a25;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.62);
}

.danger-button {
  color: var(--work);
}

.save-button {
  width: 100%;
  margin-top: 12px;
  border-color: #2d2a25;
  color: #fff;
  background: #2d2a25;
}

.spotlight {
  padding: 24px 0;
}

.month-editor {
  padding: 18px 0 24px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 26px;
}

.section-heading p {
  margin-bottom: 2px;
  color: var(--muted);
  text-align: right;
}

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

.month-editor-grid {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.bulk-table {
  display: grid;
  min-width: 980px;
}

.bulk-row {
  display: grid;
  grid-template-columns: var(--grid-template);
  min-height: var(--row-height, 54px);
}

.bulk-row + .bulk-row {
  border-top: 1px solid var(--line);
}

.bulk-cell {
  position: relative;
  min-height: var(--row-height, 54px);
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  overflow: visible;
}

.bulk-cell:last-child {
  border-right: 0;
}

.bulk-head,
.bulk-person {
  position: sticky;
  left: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  padding: 9px 10px;
  color: var(--ink);
  background: rgba(255, 250, 242, 0.96);
  font-size: 12px;
  font-weight: 900;
}

.bulk-head {
  z-index: 3;
  min-height: 54px;
}

.bulk-day {
  display: grid;
  gap: 2px;
  place-items: center;
  min-height: 54px;
  padding: 7px 4px;
  color: var(--muted);
  background: rgba(255, 250, 242, 0.78);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.col-resizer,
.row-resizer {
  position: absolute;
  z-index: 8;
  background: transparent;
}

.col-resizer {
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.row-resizer {
  right: 0;
  bottom: -4px;
  left: 0;
  height: 8px;
  cursor: row-resize;
}

.col-resizer:hover,
.row-resizer:hover {
  background: rgba(61, 139, 99, 0.28);
}

.bulk-day strong {
  color: var(--ink);
  font-size: 15px;
}

.bulk-day.is-weekend,
.day-card.is-weekend .day-num,
.day-card.is-weekend .dow {
  color: var(--weekend);
}

.bulk-day.is-weekend {
  background: var(--soft-weekend);
}

.bulk-day.is-weekend strong,
.bulk-day.is-weekend span:not(.col-resizer) {
  color: var(--weekend);
}

.bulk-input {
  width: 100%;
  height: 100%;
  min-height: 48px;
  min-width: 100%;
  resize: none;
  border: 0;
  padding: 7px 6px;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
}

.bulk-input:focus {
  position: relative;
  z-index: 4;
  width: 100%;
  min-height: 100%;
  border: 2px solid rgba(61, 139, 99, 0.62);
  border-radius: 6px;
  outline: 2px solid rgba(61, 139, 99, 0.34);
  outline-offset: -2px;
  background: #fff;
  box-shadow: 0 16px 38px rgba(38, 33, 27, 0.16);
}

[data-theme="dark"] .bulk-cell,
[data-theme="dark"] .bulk-input,
[data-theme="dark"] .bulk-day,
[data-theme="dark"] .bulk-head,
[data-theme="dark"] .bulk-person,
[data-theme="dark"] .legend-item,
[data-theme="dark"] .detail-list li,
[data-theme="dark"] .edit-list label {
  background: rgba(28, 25, 22, 0.74);
}

[data-theme="dark"] .fill-work-day {
  background: var(--fill-work-day);
}

[data-theme="dark"] .fill-work-night {
  background: var(--fill-work-night);
}

[data-theme="dark"] .fill-study {
  background: var(--fill-study);
}

[data-theme="dark"] .fill-event {
  background: var(--fill-event);
}

[data-theme="dark"] .bulk-day.is-weekend {
  background: var(--soft-weekend);
}

.bulk-input:not(:placeholder-shown) {
  background: transparent;
}

.fill-work-day .bulk-input,
.fill-study .bulk-input,
.fill-event .bulk-input {
  color: #1f1a15;
}

[data-theme="dark"] .fill-work-day .bulk-input,
[data-theme="dark"] .fill-study .bulk-input,
[data-theme="dark"] .fill-event .bulk-input {
  color: #fff8ef;
}

.fill-work-day .bulk-input,
.fill-work-night .bulk-input,
.fill-study .bulk-input,
.fill-event .bulk-input,
.fill-free .bulk-input {
  background: transparent;
}

.month-save {
  width: auto;
  min-width: 220px;
}

.fill-work-day {
  background: var(--fill-work-day);
}

.fill-work-night {
  background: var(--fill-work-night);
}

.fill-work-night .bulk-input {
  color: #fff;
}

.fill-study {
  background: var(--fill-study);
}

.fill-event {
  background: var(--fill-event);
}

.fill-free {
  background: rgba(255, 255, 255, 0.56);
}

.legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 3px 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.72);
}

.legend-item strong {
  font-size: 12px;
}

.legend-item em {
  grid-column: 2;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  line-height: 1.25;
}

.swatch {
  grid-row: span 2;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.swatch-work-day {
  background: var(--fill-work-day);
}

.swatch-work-night {
  background: var(--fill-work-night);
}

.swatch-study {
  background: var(--fill-study);
}

.swatch-event {
  background: var(--fill-event);
}

.quick-fill {
  position: fixed;
  z-index: 30;
  display: none;
  max-width: min(520px, calc(100vw - 24px));
  gap: 6px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.quick-fill.is-open {
  display: flex;
}

.quick-fill button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.quick-fill button:hover {
  border-color: #c9b79d;
  background: var(--paper);
}

.best-card {
  min-height: 128px;
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
}

.best-card .date {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.best-card .number {
  font-size: 36px;
  font-weight: 900;
  line-height: 0.9;
}

.best-card .month {
  color: var(--muted);
  font-weight: 800;
}

.score {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #f0e8dc;
}

.score span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--free), #d5a946);
}

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

.weekday-row {
  position: sticky;
  top: 62px;
  z-index: 4;
  padding: 8px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
  background: rgba(255, 250, 242, 0.86);
  backdrop-filter: blur(14px);
}

.day-card {
  position: relative;
  min-height: 154px;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.day-card:hover,
.day-card:focus-visible {
  outline: none;
  transform: translateY(-2px);
  border-color: #c9b79d;
}

.day-card.is-empty {
  visibility: hidden;
}

.day-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.day-num {
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
}

.dow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.availability {
  margin: 10px 0;
  color: var(--free);
  font-size: 13px;
  font-weight: 850;
}

.mini-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mini-list li {
  overflow: hidden;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-work,
.tag-work-day {
  color: var(--work);
  background: var(--soft-work);
}

.tag-work-night {
  color: #fff;
  background: var(--fill-work-night);
}

.tag-study {
  color: var(--study);
  background: var(--soft-study);
}

.tag-event {
  color: var(--event);
  background: var(--soft-event);
}

.tag-free {
  color: var(--free);
  background: var(--soft-free);
}

.drawer {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  width: min(420px, calc(100vw - 36px));
  max-height: min(680px, calc(100vh - 36px));
  overflow: auto;
  display: none;
  border-radius: 8px;
  padding: 18px;
}

.drawer.is-open {
  display: block;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
}

.drawer h3 {
  margin: 0;
  font-size: 26px;
}

.close-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-list li {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.86);
}

.detail-list strong {
  overflow-wrap: anywhere;
}

.detail-list span {
  overflow-wrap: anywhere;
}

.edit-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.edit-list label {
  display: grid;
  gap: 7px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.86);
}

.edit-list strong {
  font-size: 13px;
}

.edit-list textarea {
  width: 100%;
  min-height: 54px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

.drawer-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100vw - 18px, 1180px);
  }

  h1 {
    font-size: clamp(44px, 16vw, 72px);
  }

  .topbar,
  .controls,
  .section-heading {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-heading {
    align-items: start;
  }

  .summary-strip,
  .best-days {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-heading p {
    text-align: left;
  }

  .sync-actions,
  .people-filter,
  .segmented {
    flex-wrap: wrap;
    overflow: visible;
  }

  .controls {
    position: static;
  }

  .bulk-table {
    min-width: 780px;
  }

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

  .month-save {
    width: 100%;
  }

  .weekday-row {
    display: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100vw - 18px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    padding-top: 14px;
  }

  .summary-card {
    min-height: 66px;
  }

  .summary-strip,
  .best-days,
  .calendar-grid,
  .legend {
    grid-template-columns: 1fr;
  }

  .segmented button,
  .person-chip,
  .ghost-button,
  .save-button {
    min-height: 42px;
    padding: 9px 12px;
  }

  .month-editor-grid {
    margin-inline: -4px;
    max-height: 70vh;
  }

  .bulk-table {
    min-width: 720px;
  }

  .bulk-row {
    grid-template-columns: var(--grid-template);
  }

  .quick-fill {
    right: 10px;
    bottom: 10px;
    left: 10px !important;
    top: auto !important;
    max-width: none;
  }

  .day-card {
    min-height: 132px;
  }
}
