:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #1a73e8;
  --accent-dim: #1557b0;
  --today: rgba(26, 115, 232, 0.2);
  --other-month: #3d4d63;
  --danger: #f87171;
  --radius: 10px;
  --font: "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --sidebar-w: 260px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: #0c1018;
  color: var(--text);
}

.layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.9rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-head {
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-desc {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.category-sidebar {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.cat-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.cat-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.cat-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.cat-label {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-actions {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
}

.cat-actions button {
  padding: 0.2rem 0.4rem;
  font-size: 0.72rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.cat-actions button:hover {
  color: var(--text);
  border-color: var(--muted);
}

.btn-add-cal {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.88rem;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: rgba(26, 115, 232, 0.08);
  color: var(--accent);
  cursor: pointer;
}

.btn-add-cal:hover {
  background: rgba(26, 115, 232, 0.15);
  border-color: var(--accent);
}

.filter-summary {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  padding-top: 0.25rem;
}

.main {
  flex: 1;
  min-width: 0;
  background: linear-gradient(160deg, #0c1018 0%, #151d2e 50%, #0f1419 100%);
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.month-label {
  min-width: 10rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 500;
}

.month-nav button,
.btn-today {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.month-nav button {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0;
}

.month-nav button:hover,
.btn-today:hover {
  background: #243044;
  border-color: var(--muted);
}

.btn-today {
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-height: 0;
  max-height: 110px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 6px 6px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  transition: border-color 0.15s, background 0.15s;
}

.cell.cell-holiday {
  box-shadow: inset 3px 0 0 0 #e8b923;
}

.cell.cell-makeup:not(.cell-holiday) {
  box-shadow: inset 3px 0 0 0 #ea580c;
}

.cell.cell-holiday.cell-makeup {
  box-shadow: inset 3px 0 0 0 #e8b923, inset 6px 0 0 0 #ea580c;
}

.cell-makeup-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(234, 88, 12, 0.95);
  color: #fff;
  line-height: 1;
  z-index: 1;
}

.cell-holiday-tag {
  font-size: 0.58rem;
  line-height: 1.25;
  color: #e8d79a;
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  flex-shrink: 0;
}

.cell:hover {
  border-color: var(--accent);
  background: #1f2a3d;
}

.cell.other-month {
  opacity: 0.45;
}

.cell.other-month .cell-day {
  color: var(--other-month);
}

.cell.today {
  background: var(--today);
  border-color: var(--accent);
}

.cell-day {
  font-size: 0.9rem;
  font-weight: 600;
  flex-shrink: 0;
}

.cell-bars {
  margin-top: 4px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: flex-end;
  overflow: hidden;
}

.cell-bar {
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
  max-width: 100%;
}

.cell-more {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1;
}

.hint {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Modal */
#categoryModal.modal {
  z-index: 110;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal-panel-sm {
  max-width: 360px;
}

.modal-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.modal-holiday-banner {
  margin: -0.35rem 0 1rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: rgba(232, 185, 35, 0.12);
  border: 1px solid rgba(232, 185, 35, 0.35);
}

.modal-holiday-banner.hidden {
  display: none;
}

.modal-holiday-names {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.holiday-chip {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: rgba(232, 185, 35, 0.22);
  color: #f5e6a8;
  border: 1px solid rgba(232, 185, 35, 0.4);
}

.modal-makeup-note {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #fdba74;
}

.event-form label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.filter-day-label {
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.event-form input,
.event-form textarea,
.event-form select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #121a26;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.event-form input[type="color"] {
  height: 2.5rem;
  padding: 0.25rem;
  cursor: pointer;
}

.event-form input:focus,
.event-form textarea:focus,
.event-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn-primary,
.btn-secondary,
.btn-delete {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #243044;
}

.event-list-wrap {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.list-heading {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.event-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.event-item:last-child {
  border-bottom: none;
}

.event-item-body {
  flex: 1;
  min-width: 0;
  border-left: 3px solid var(--cat, var(--accent));
  padding-left: 0.55rem;
}

.event-item-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.event-cat-tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  margin-bottom: 0.25rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.event-item-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.event-item-note {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-delete {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-delete:hover {
  background: rgba(248, 113, 113, 0.12);
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 42vh;
  }
}

@media (max-width: 520px) {
  .cell {
    max-height: 72px;
    padding: 3px 4px 4px;
  }

  .cell-day {
    font-size: 0.78rem;
  }

  .cell-bar {
    height: 3px;
  }

  .header {
    flex-direction: column;
    align-items: stretch;
  }

  .month-nav {
    margin-left: 0;
    justify-content: center;
  }

  .btn-today {
    align-self: center;
  }
}
