:root {
  --panel: #ffffff;
  --line: rgba(32, 48, 39, 0.12);
  --text: #1d2a22;
  --muted: #6b756f;
  --green-soft: #f4faf6;
  --blue-soft: #f4f8fc;
  --mint-soft: #f6fbf7;
  --sky-soft: #f5f9fd;
  --leaf-soft: #f7fbf5;
  --green-strong: #365f49;
  --blue-strong: #486d94;
  --danger: #b14a4a;
  --danger-soft: #f7dddd;
  --accent-soft: #f3f0e6;
  --accent-strong: #8b7a4f;
  --shadow: 0 10px 30px rgba(26, 34, 29, 0.06);
  --radius-lg: 26px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font-display: "Noto Serif TC", "Microsoft JhengHei", serif;
  --font-body: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: #ffffff;
}

.page-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  display: grid;
  gap: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(32, 48, 39, 0.06);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
}

.topbar,
.panel-header,
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.panel-desc {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.no-margin { margin: 0; }
.mt-10 { margin-top: 10px; }

.nav-tabs,
.filter-pills {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
}

button,
input {
  font: inherit;
}

.nav-btn,
.filter-pill {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
  font-weight: 700;
  background: rgba(93, 132, 171, 0.1);
  color: var(--blue-strong);
  padding: 10px 16px;
}

.nav-btn.active,
.filter-pill.active {
  background: var(--green-strong);
  color: #fff;
}

.status-banner {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: #f7f9fb;
  color: var(--blue-strong);
  line-height: 1.6;
}

.status-banner.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.screen { display: none; }
.screen.active { display: block; }

.matrix-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.matrix-table {
  width: 100%;
  min-width: 1160px;
  border-collapse: collapse;
  table-layout: fixed;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid rgba(93, 132, 171, 0.22);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.matrix-frequency {
  width: 72px;
  font-weight: 700;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.12em;
  padding: 18px 10px;
}

.matrix-label {
  width: 110px;
  font-weight: 700;
  background: #fcfcfc;
  padding: 16px 10px;
}

.matrix-group-weekly .matrix-frequency,
.matrix-group-weekly .item-cell { background: var(--green-soft); }
.matrix-group-biweekly .matrix-frequency,
.matrix-group-biweekly .item-cell { background: var(--blue-soft); }
.matrix-group-monthly .matrix-frequency,
.matrix-group-monthly .item-cell { background: var(--mint-soft); }
.matrix-group-bimonthly .matrix-frequency,
.matrix-group-bimonthly .item-cell { background: var(--sky-soft); }
.matrix-group-quarterly .matrix-frequency,
.matrix-group-quarterly .item-cell { background: var(--leaf-soft); }

.item-cell,
.date-cell {
  min-width: 176px;
}

.item-box {
  min-height: 118px;
  padding: 14px 10px;
  display: grid;
  gap: 8px;
  place-items: center;
  text-align: center;
  position: relative;
  user-select: none;
}

.item-box.draggable { cursor: grab; }
.item-box.dragging { opacity: 0.45; }
.item-box.drop-before { box-shadow: inset 4px 0 0 var(--green-strong); }
.item-box.drop-after { box-shadow: inset -4px 0 0 var(--green-strong); }

.item-name {
  font-weight: 700;
  line-height: 1.6;
  white-space: pre-line;
  word-break: break-word;
}

.item-editor {
  width: 100%;
  display: grid;
  gap: 8px;
  place-items: center;
}

.item-editor-input {
  width: 100%;
  max-width: 148px;
  text-align: center;
  border: 1px solid rgba(93, 132, 171, 0.22);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.94);
}

.item-editor-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.item-editor-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 700;
}

.item-editor-btn.primary {
  background: var(--green-strong);
  color: #fff;
}

.item-editor-btn.secondary {
  background: rgba(93, 132, 171, 0.12);
  color: var(--blue-strong);
}

.item-editor-btn.danger {
  background: rgba(177, 74, 74, 0.12);
  color: var(--danger);
}

.date-box {
  position: relative;
  padding: 16px 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 78px;
  background: #ffffff;
}

.date-box.complete-mode {
  min-height: 66px;
  padding: 12px 10px;
}

.date-box.next-mode {
  min-height: 88px;
  padding: 18px 10px;
}

.date-input {
  width: 100%;
  max-width: 128px;
  text-align: center;
  border: 1px solid rgba(93, 132, 171, 0.2);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
}

.date-box.complete-mode .date-input {
  max-width: 116px;
  font-size: 0.92rem;
  padding: 7px 8px;
}

.date-box.next-mode .date-input {
  max-width: 144px;
  font-size: 1.06rem;
  padding: 10px 12px;
  font-weight: 700;
}

.date-input:focus {
  outline: 2px solid rgba(86, 120, 98, 0.22);
  border-color: rgba(86, 120, 98, 0.4);
}

.date-input.error {
  border-color: var(--danger);
  background: rgba(247, 221, 221, 0.8);
}

.date-picker-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: #f2f5f8;
  cursor: pointer;
}

.native-date-input {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.date-weekday {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.date-box.next-mode .date-weekday {
  font-size: 0.86rem;
}

.add-box {
  min-height: 118px;
  display: grid;
  place-items: center;
  background: #fafafa;
  border: 1px dashed rgba(93, 132, 171, 0.28);
}

.add-btn {
  border: none;
  background: transparent;
  color: var(--blue-strong);
  font-weight: 700;
  cursor: pointer;
  padding: 12px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  padding: 13px 10px;
  border-bottom: 1px solid rgba(84, 106, 93, 0.12);
  text-align: center;
  vertical-align: top;
}

.history-table th {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.item-history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(93, 132, 171, 0.08);
  color: var(--muted);
}

.history-chip-label[contenteditable="true"] {
  outline: 2px solid rgba(86, 120, 98, 0.22);
  border-radius: 8px;
  padding: 2px 4px;
  background: rgba(255, 255, 255, 0.9);
}

.history-chip-delete {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0;
}

.history-count {
  font-weight: 700;
  color: var(--green-strong);
}

.empty-state {
  padding: 22px;
  border: 1px dashed rgba(84, 106, 93, 0.22);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  text-align: center;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.6;
}

.auth-shell {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(255, 255, 255, 0.96);
  z-index: 20;
}

.auth-shell.active {
  display: grid;
}

.auth-card {
  width: min(360px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid rgba(32, 48, 39, 0.08);
  border-radius: 22px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.8rem;
}

.auth-desc {
  margin: 10px 0 18px;
  color: var(--muted);
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(32, 48, 39, 0.14);
  border-radius: 12px;
  text-align: center;
}

.auth-button {
  margin-top: 12px;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--green-strong);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.auth-error {
  margin: 12px 0 0;
  color: var(--danger);
}

@media (max-width: 720px) {
  .page-shell {
    padding: 16px 12px 32px;
  }

  .panel {
    padding: 18px;
  }
}
