:root {
  --bg: #d8bd96;
  --panel: #ead8b8;
  --panel-2: #d7ba8f;
  --line: #8c6848;
  --line-soft: #c1a27b;
  --text: #3b2416;
  --muted: #765b43;
  --muted-2: #a58a6b;
  --blue: #765269;
  --blue-soft: rgba(118, 82, 105, 0.16);
  --early: #688b82;
  --late: #87627b;
  --full: #ad7d3f;
  --unknown: #8f765c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 247, 224, 0.34), transparent 34%),
    radial-gradient(circle at 86% 84%, rgba(118, 75, 42, 0.12), transparent 38%),
    var(--bg);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(216, 189, 150, 0.96);
}

.site-brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 0.04em;
}

.page-nav {
  display: flex;
  align-items: stretch;
  gap: 8px;
  height: 68px;
}

.page-nav-toggle {
  display: none;
}

.page-nav-menu {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.page-link {
  position: relative;
  min-width: 76px;
  padding: 0 14px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
}

.page-link:hover,
.page-link.is-active {
  color: var(--text);
}

.page-link.is-active::after {
  position: absolute;
  right: 14px;
  bottom: 0;
  left: 14px;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: var(--blue);
  content: "";
}

.page-panel[hidden] {
  display: none;
}

.page-placeholder {
  min-height: calc(100vh - 108px);
  margin: 20px;
  padding: clamp(28px, 6vw, 80px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
}

.page-placeholder h1 {
  margin: 0 0 12px;
  font-size: clamp(32px, 5vw, 56px);
}

.page-placeholder p {
  color: var(--muted);
}

.page-placeholder .placeholder-kicker {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
}

.theme-settings {
  max-width: 760px;
  margin-top: 30px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
}

.theme-settings h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  text-align: left;
}

.theme-option.is-active {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.theme-option strong,
.theme-option small {
  display: block;
}

.theme-option small {
  margin-top: 4px;
  color: var(--muted);
}

.theme-swatch {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settings-switch {
  max-width: 760px;
  margin-top: 14px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.switch-label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  display: flex;
  align-items: center;
  width: 44px;
  height: 24px;
  padding: 3px;
  border-radius: 999px;
  background: var(--muted-2);
  transition: background 0.2s ease;
}

.switch-thumb {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--panel);
  transition: transform 0.2s ease;
}

.switch-label input:checked + .switch-track {
  background: var(--blue);
}

.switch-label input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch-label strong,
.switch-label small {
  display: block;
}

.switch-label small {
  margin-top: 4px;
  color: var(--muted);
}

.vintage-swatch {
  background: linear-gradient(135deg, #d8bd96 0 52%, #765269 52% 72%, #3b2416 72%);
}

.dark-swatch {
  background: linear-gradient(135deg, #111 0 52%, #2f9df4 52% 72%, #f5f5f7 72%);
}

.people-page {
  min-height: calc(100vh - 108px);
  margin: 20px;
  padding: clamp(24px, 4vw, 52px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  overflow: auto;
}

.people-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.people-header h1 {
  margin: 0 0 10px;
  font-size: clamp(32px, 5vw, 56px);
}

.people-header p:not(.placeholder-kicker) {
  margin: 0;
  color: var(--muted);
}

.primary-button,
.secondary-button {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--blue);
  color: #fffaf0;
  background: var(--blue);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
}

.person-form {
  display: grid;
  gap: 14px;
  margin-bottom: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #e8d2ad;
}

.person-dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--text);
  background: transparent;
}

.person-dialog::backdrop {
  background: rgba(59, 36, 22, 0.62);
}

.person-dialog .person-form {
  max-height: calc(100vh - 28px);
  margin: 0;
  overflow: auto;
}

.person-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.person-dialog-header h2 {
  margin: 0;
  font-size: 22px;
}

.month-dialog {
  width: min(360px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--text);
  background: transparent;
}

.month-dialog::backdrop {
  background: rgba(59, 36, 22, 0.62);
}

.month-picker-form {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.month-picker-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.month-picker-form select {
  min-height: 42px;
}

.person-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.person-form input,
.person-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #f5e8ce;
  font: inherit;
  resize: vertical;
}

.person-form input:focus,
.person-form textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.form-actions {
  display: flex;
  gap: 8px;
}

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

.person-card {
  position: relative;
  display: block;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #e8d2ad;
}

.person-card-main {
  width: 100%;
  min-width: 0;
}

.person-card-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-right: 76px;
}

.person-card h2 {
  margin: 0;
  font-size: 20px;
}

.person-card-title span,
.person-card p {
  color: var(--muted);
  font-size: 13px;
}

.person-card p {
  margin: 8px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.instagram-link {
  display: inline-block;
  padding: 0;
  border: 0;
  margin-top: 8px;
  color: #754f64;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.instagram-link:hover {
  text-decoration: underline;
}

.instagram-embed {
  width: 100%;
  height: clamp(320px, 88vw, 400px);
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8edda;
}

.instagram-embed iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.person-card .person-socials {
  color: #765269;
}

.person-card > .secondary-button {
  position: absolute;
  z-index: 1;
  top: 16px;
  right: 16px;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(340px, 420px);
  gap: 18px;
  min-height: calc(100vh - 108px);
  height: calc(100vh - 108px);
  padding: 20px;
}

.calendar-panel,
.detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
}

.calendar-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 64px 1fr 64px 64px;
  align-items: center;
  gap: 18px;
  padding: 0 12px 12px;
}

.icon-button,
.month-button {
  min-height: 56px;
  border: 0;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  font-size: 44px;
  line-height: 1;
}

.month-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text);
  font-size: clamp(28px, 3.2vw, 42px);
  letter-spacing: 0;
  white-space: nowrap;
}

.caret {
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 13px solid var(--blue);
}

.filter-button {
  display: grid;
  gap: 6px;
  align-content: center;
  justify-items: center;
}

.filter-button span {
  display: block;
  height: 5px;
  border-radius: 999px;
  background: var(--blue);
}

.filter-button span:nth-child(1) {
  width: 42px;
}

.filter-button span:nth-child(2) {
  width: 30px;
}

.filter-button span:nth-child(3) {
  width: 12px;
}

.calendar-divider {
  width: 64%;
  height: 1px;
  margin: 0 auto 12px;
  background: var(--line);
}

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

.weekday-row {
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
  color: #604733;
  font-size: clamp(18px, 2.5vw, 30px);
  font-weight: 700;
  text-align: center;
}

.calendar-grid {
  gap: 12px;
  min-height: 0;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding-top: 10px;
}

.day-cell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: start;
  min-height: 0;
  padding: 8px 6px 6px;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.day-cell:hover {
  border-color: #76583d;
  background: #e2c9a2;
}

.day-cell.is-outside {
  color: var(--muted-2);
}

.day-cell.is-selected {
  border-color: transparent;
}

.day-number {
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  width: clamp(24px, 2.25vw, 36px);
  height: clamp(24px, 2.25vw, 36px);
  border-radius: 999px;
  font-size: clamp(14px, 1.55vw, 21px);
  line-height: 1;
}

.day-cell > span:last-child {
  position: absolute;
  right: 8px;
  bottom: 6px;
  text-align: right;
}

.day-cell.is-selected .day-number {
  background: var(--blue);
  color: #fffaf0;
}

.day-count {
  min-height: 20px;
  color: #765269;
  font-size: clamp(13px, 1.4vw, 18px);
  font-weight: 700;
}

.day-markers {
  display: flex;
  gap: 4px;
  min-height: 12px;
  margin-top: 3px;
}

.marker {
  width: 7px;
  height: 7px;
  border-radius: 999px;
}

.marker.early {
  background: var(--early);
}

.marker.late {
  background: var(--late);
}

.marker.full {
  background: var(--full);
}

.marker.unknown {
  background: var(--unknown);
}

.detail-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  max-height: calc(100vh - 40px);
  overflow: hidden;
}

.detail-header {
  padding: 28px 26px 16px;
  border-bottom: 1px solid var(--line);
}

.detail-header p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.detail-header h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* The compact detail view no longer shows summary pills or filters. */
.detail-stats,
.filters {
  display: none;
}

.stat-pill,
.shift-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.stat-pill {
  color: var(--text);
  background: #d2b48a;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #f5e8ce;
}

.detail-content {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 18px;
  overflow: auto;
}

.shift-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.shift-heading {
  display: flex;
  justify-content: space-between;
  padding: 11px 12px;
  background: var(--panel-2);
  font-weight: 700;
}

.entry-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.entry {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #e8d2ad;
}

.thumb {
  width: 54px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #c9aa7c;
  cursor: pointer;
}

.entry-name {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-weight: 800;
}

.entry-time,
.entry-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.shift-badge.early {
  color: #071b20;
  background: var(--early);
}

.shift-badge.late {
  color: #120b22;
  background: var(--late);
}

.shift-badge.full {
  color: #261901;
  background: var(--full);
}

.shift-badge.unknown {
  color: #111;
  background: var(--unknown);
}

.empty {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

#imageDialog {
  width: min(520px, calc(100vw - 24px));
  padding: 16px;
  border: 0;
  border-radius: 12px;
  color: var(--text);
  background: #e8d2ad;
}

#imageDialog::backdrop {
  background: rgba(59, 36, 22, 0.62);
}

.dialog-close {
  float: right;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #d2b48a;
  cursor: pointer;
}

#dialogImage {
  width: 100%;
  max-height: 78vh;
  object-fit: contain;
  margin-top: 10px;
  background: #4a2b1c;
}

#dialogCaption {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

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

  .calendar-panel {
    min-height: 680px;
  }

  .detail-panel {
    max-height: none;
  }
}

@media (max-width: 767px) {
  .topbar {
    min-height: 58px;
    padding: 0 14px;
  }

  .site-brand {
    font-size: 16px;
  }

  .page-nav {
    position: relative;
    display: block;
    height: auto;
  }

  .page-nav-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    background: var(--panel-2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
  }

  .nav-caret {
    width: 0;
    height: 0;
    border-top: 5px solid var(--muted);
    border-right: 5px solid transparent;
    border-left: 5px solid transparent;
  }

  .page-nav.is-open .nav-caret {
    transform: rotate(180deg);
  }

  .page-nav-menu {
    position: absolute;
    z-index: 10;
    top: calc(100% + 8px);
    right: 0;
    display: none;
    min-width: 132px;
    height: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #e8d2ad;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  }

  .page-nav.is-open .page-nav-menu {
    display: grid;
    gap: 2px;
  }

  .page-link {
    min-width: 0;
    min-height: 38px;
    padding: 0 12px;
    border-radius: 7px;
    text-align: left;
    font-size: 13px;
  }

  .page-link.is-active {
    background: var(--blue-soft);
  }

  .page-link.is-active::after {
    right: auto;
    bottom: 8px;
    left: 4px;
    width: 3px;
    height: 22px;
    border-radius: 0 999px 999px 0;
  }

  .app-shell {
    padding: 10px;
  }

  .people-page {
    min-height: calc(100vh - 98px);
    margin: 10px;
    padding: 20px;
    border-radius: 18px;
  }

  .people-list {
    grid-template-columns: 1fr;
  }

  .people-header {
    display: grid;
  }

  .people-header .primary-button {
    width: 100%;
  }

  .person-card {
    display: block;
  }

  .person-card .secondary-button {
    width: auto;
  }

  .instagram-embed {
    max-width: none;
    height: clamp(300px, 105vw, 390px);
  }

  .calendar-panel,
  .detail-panel {
    border-radius: 18px;
  }

  .calendar-toolbar {
    grid-template-columns: 44px 1fr 44px 44px;
    gap: 8px;
    padding: 0 8px 16px;
  }

  .icon-button {
    min-height: 44px;
    font-size: 38px;
  }

  .weekday-row {
    font-size: 20px;
  }

  .calendar-grid {
    gap: 6px;
  }

  .day-cell {
    min-height: 72px;
    padding: 10px 3px 8px;
  }

  .day-number {
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    font-size: 16px;
  }

  .filters {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 768px) and (max-width: 991px) {
  .people-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 992px) and (max-width: 1199px) {
  .people-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Restore the original dark theme when selected in Settings. */
body[data-theme="dark"] {
  --bg: #111;
  --panel: #1d1d1f;
  --panel-2: #242426;
  --line: #303033;
  --line-soft: #262629;
  --text: #f5f5f7;
  --muted: #8e8e93;
  --muted-2: #57575c;
  --blue: #2f9df4;
  --blue-soft: rgba(47, 157, 244, 0.16);
  --early: #40b3c8;
  --late: #8f75d6;
  --full: #d2a13a;
  --unknown: #777b84;
  background: #111;
}

body[data-theme="dark"] .topbar {
  background: rgba(17, 17, 17, 0.96);
}

body[data-theme="dark"] .calendar-panel,
body[data-theme="dark"] .detail-panel,
body[data-theme="dark"] .page-placeholder,
body[data-theme="dark"] .people-page,
body[data-theme="dark"] .theme-option {
  background: #1d1d1f;
}

body[data-theme="dark"] .person-card,
body[data-theme="dark"] .person-form,
body[data-theme="dark"] .entry,
body[data-theme="dark"] #imageDialog,
body[data-theme="dark"] .person-dialog .person-form {
  background: #18181a;
}

body[data-theme="dark"] .theme-settings,
body[data-theme="dark"] .stat-pill {
  background: #242426;
}

body[data-theme="dark"] select,
body[data-theme="dark"] .person-form input,
body[data-theme="dark"] .person-form textarea {
  background: #151517;
}

body[data-theme="dark"] .thumb {
  background: #0d0d0e;
}

body[data-theme="dark"] .day-cell:hover {
  border-color: #3e3e43;
  background: #202023;
}

body[data-theme="dark"] .instagram-link {
  color: #ff8ac5;
}

body[data-theme="dark"] .dialog-close {
  background: #222;
}
