:root {
  --bg: #f4e9d4;
  --paper: #fbf3e3;
  --surface: #fffaf1;
  --ink: #3c3228;
  --muted: #897a66;
  --line: #4a3b2c;
  --red: #e67d6d;
  --blue: #6fa8cf;
  --green: #8bc077;
  --yellow: #f0c44d;
  --pink: #ec9fbd;
  --purple: #b197d2;
  --orange: #ed9f52;
  --shadow: 3px 4px 0 rgba(74, 59, 44, 0.28);
  --shadow-soft: 0 6px 16px rgba(74, 59, 44, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150' viewBox='0 0 150 150'%3E%3Cg fill='none' stroke='%234a3b2c' stroke-opacity='0.06' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M28 26l4 9 9 1-6 6 2 9-9-4-9 4 2-9-6-6 9-1z'/%3E%3Cpath d='M120 38c-5-7-15-2-10 5l10 11 10-11c5-7-5-12-10-5z'/%3E%3Cpath d='M22 112c8-10 20-2 0 14-20-16-8-24 0-14z'/%3E%3Ccircle cx='112' cy='116' r='9'/%3E%3Cpath d='M104 116h16M112 108v16'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(circle at 18px 18px, rgba(74, 59, 44, 0.05) 2px, transparent 2px),
    linear-gradient(165deg, #f7eed9 0%, #f2e6cf 55%, #efdcc4 100%);
  background-size: 150px 150px, 34px 34px, auto;
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  letter-spacing: 0;
}

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

button {
  color: inherit;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 18px clamp(14px, 4vw, 42px);
  background: var(--paper);
  border-bottom: 3px solid var(--line);
}

.brand-mark,
.avatar {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.35);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  font-weight: 900;
}

h2 {
  margin-bottom: 0;
  font-size: 1.14rem;
  font-weight: 900;
}

.date-pill {
  min-width: 110px;
  padding: 10px 12px;
  background: var(--yellow);
  border: 3px solid var(--line);
  border-radius: 999px;
  font-weight: 900;
  text-align: center;
  box-shadow: var(--shadow);
}

.sync-pill {
  min-width: 132px;
  padding: 9px 12px;
  background: #fff;
  border: 2px solid rgba(106, 91, 80, 0.5);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
  text-align: center;
}

.sync-pill.is-live {
  color: #54703f;
  background: #e9efdd;
  border-color: rgba(106, 142, 90, 0.65);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  padding: 10px clamp(10px, 4vw, 42px);
  background: rgba(255, 248, 223, 0.94);
  border-bottom: 3px solid var(--line);
}

.tab,
.ghost-button,
.primary-button,
.quick-task,
.member-card,
.icon-button {
  min-height: 44px;
  border: 3px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

@media (hover: hover) {
  .ghost-button:hover,
  .primary-button:hover,
  .quick-task:hover,
  .member-card.clickable:hover,
  .subtab:hover {
    transform: translateY(-2px);
    box-shadow: 4px 6px 0 rgba(75, 68, 83, 0.22);
  }
}

.tab:active,
.ghost-button:active,
.primary-button:active,
.quick-task:active,
.member-card.clickable:active,
.icon-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(106, 91, 80, 0.35);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 4px;
  background: #fff;
  font-size: 0.92rem;
}

.tab-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.tab.active {
  background: var(--blue);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 3px 5px 0 rgba(74, 59, 44, 0.28);
  text-shadow: 0 1px 0 rgba(50, 70, 90, 0.3);
}

main {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 16px clamp(12px, 4vw, 34px) 42px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  margin: 8px 0 14px;
  background: var(--pink);
  border: 3px solid var(--line);
  border-radius: 26px 22px 24px 20px;
  box-shadow: var(--shadow);
}

.hero-strip h2 {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
}

.section {
  padding: 18px 0 10px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title.compact {
  margin-top: 18px;
}

#view-dashboard .section {
  padding-block: 12px;
}

.dashboard-hero {
  background: #fff3cf;
}

.reward-hero {
  background: #e9efdd;
}

.settings-hero {
  background: #e9efdd;
}

.hero-note {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 900;
}

.dashboard-announcements .form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.dashboard-announcements .item-list {
  gap: 10px;
}

.dashboard-announcements .item {
  min-height: 0;
  padding: 12px 14px;
  border-width: 2px;
  border-left-width: 8px;
  border-radius: 14px;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.22);
}

.dashboard-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 12px 0 4px;
}

.dashboard-action-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 112px;
  padding: 16px;
  background: rgba(255, 250, 240, 0.78);
  border: 2px solid rgba(106, 91, 80, 0.32);
  border-radius: 18px;
}

.dashboard-action-card:nth-child(1) {
  border-left: 8px solid var(--blue);
}

.dashboard-action-card:nth-child(2) {
  border-left: 8px solid var(--green);
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-row select {
  width: auto;
  min-width: 118px;
  min-height: 40px;
  padding-block: 7px;
}

#view-records.active {
  display: block;
}

#view-records .hero-strip {
  margin-bottom: 12px;
  background: #f8d8df;
}

.subtabs {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.subtab {
  flex: 1 1 0;
  min-height: 46px;
  padding: 0 14px;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.subtab:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(106, 91, 80, 0.35);
}

.subtab.active {
  background: var(--green);
  color: #fff;
}

.records-subview {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 16px;
  align-items: start;
}

.records-subview[hidden] {
  display: none;
}

#view-records .life-panel {
  height: 100%;
  padding: 14px;
  background: rgba(255, 250, 240, 0.72);
  border: 2px solid rgba(106, 91, 80, 0.28);
  border-radius: 18px;
}

#view-records .life-panel .section-title {
  margin-bottom: 10px;
}

#view-records .form-grid {
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
  border-width: 2px;
  border-radius: 14px;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.22);
}

#view-records .item-list {
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

#view-records .item {
  gap: 6px;
  padding: 12px;
  border-width: 2px;
  border-left-width: 8px;
  border-radius: 14px;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.22);
}

#view-records .item-title {
  align-items: flex-start;
}

#view-records .item-title span:last-child {
  flex: 0 0 auto;
  padding: 3px 8px;
  background: #fff3cf;
  border: 2px solid rgba(106, 91, 80, 0.45);
  border-radius: 999px;
  font-size: 0.78rem;
}

.member-grid,
.quick-task-grid,
.item-list,
.metric-grid {
  display: grid;
  gap: 12px;
}

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

.utility-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 12px;
}

.utility-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.78);
  border: 2px solid rgba(106, 91, 80, 0.24);
  border-radius: 14px;
}

.utility-card span {
  color: var(--muted);
  word-break: break-all;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.settings-card {
  min-height: 100%;
  padding: 16px;
  background: rgba(255, 250, 240, 0.78);
  border: 2px solid rgba(106, 91, 80, 0.28);
  border-radius: 18px;
}

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

.status-card {
  display: grid;
  gap: 6px;
  min-height: 82px;
  padding: 12px;
  background: #fff;
  border: 2px solid rgba(106, 91, 80, 0.35);
  border-radius: 14px;
}

.status-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.status-card strong {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.status-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.45;
}

.status-link strong {
  word-break: break-all;
}

.status-link .mini-button {
  justify-self: start;
  margin-top: 4px;
}

.backup-actions {
  display: grid;
  gap: 12px;
}

.file-picker {
  padding: 12px;
  background: #fff;
  border: 2px dashed rgba(106, 91, 80, 0.42);
  border-radius: 14px;
}

.file-picker input {
  margin-top: 8px;
  padding: 8px;
}

.compact-list .item {
  padding: 12px;
  border-width: 2px;
  border-left-width: 8px;
  border-radius: 14px;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.22);
}

.quick-task-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.member-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 138px;
  padding: 12px 8px;
  background: var(--surface);
  text-align: center;
}

.member-card[disabled] {
  cursor: default;
}

.member-card .avatar {
  position: relative;
  background: var(--member-color, var(--blue));
}

.avatar-emoji {
  position: absolute;
  right: -6px;
  bottom: -6px;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: #fffaf1;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: 1px 1px 0 rgba(74, 59, 44, 0.3);
}

.member-card strong {
  font-size: 1.1rem;
}

.member-card small,
.quick-task small,
.item-meta {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.member-card.selected {
  background: #f3efe0;
  border-color: var(--green);
  transform: rotate(-1.5deg);
  box-shadow: 4px 6px 0 rgba(74, 59, 44, 0.3);
}

.quick-task {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  min-height: 104px;
  padding: 14px 12px;
  background: #fff;
  text-align: center;
}

.quick-task-icon {
  font-size: 2rem;
  line-height: 1;
}

.quick-task-name {
  font-size: 1.05rem;
  font-weight: 900;
}

.suggestion-list {
  margin: 14px 0;
}

.ai-suggestion-list {
  padding: 14px;
  background: #f6ead2;
  border: 2px dashed rgba(74, 59, 44, 0.4);
  border-radius: 18px 16px 20px 16px;
}

.ai-provider-note.is-live {
  background: #e9f0e1;
  border-color: rgba(106, 142, 90, 0.5);
}

.ai-provider-note.is-live span {
  color: #4f6b3c;
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  border-width: 2px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--muted);
  font-size: 0.82rem;
  box-shadow: 2px 2px 0 rgba(106, 91, 80, 0.2);
}

.ai-suggestion-list .ai-provider-note {
  grid-column: 1 / -1;
}

.ai-provider-note {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  color: #6f6259;
  background: rgba(255, 250, 224, 0.86);
  border: 2px dashed rgba(106, 91, 80, 0.22);
  border-radius: 12px;
  font-size: 0.9rem;
}

.ai-provider-note span {
  font-weight: 700;
  color: var(--ink);
}

.ai-provider-note small {
  text-align: right;
}

.ai-status-note {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px 14px;
  color: #6f6259;
  background: rgba(255, 250, 224, 0.86);
  border: 2px solid rgba(106, 91, 80, 0.24);
  border-radius: 14px;
}

.ai-status-note strong {
  color: var(--ink);
}

.ai-status-note.is-live {
  background: #e9efdd;
  border-color: rgba(106, 142, 90, 0.45);
}

.ai-suggestion-card {
  background: #fffdf7;
  border-color: rgba(217, 130, 139, 0.45);
}

.suggestion-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(255, 248, 222, 0.72);
  border: 2px dashed rgba(106, 91, 80, 0.32);
  border-radius: 14px;
}

.compact-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.78);
  border: 2px solid rgba(106, 91, 80, 0.28);
  border-radius: 16px;
}

.collapsible-section {
  display: block;
  padding: 0;
  margin: 18px 0 10px;
}

.collapsible-section > summary {
  min-height: 52px;
  padding: 12px 16px;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 900;
}

.collapsible-section[open] > summary {
  margin-bottom: 14px;
  background: #fff3cf;
}

.quick-task:nth-child(4n + 1) {
  background: #e7eef1;
}

.quick-task:nth-child(4n + 2) {
  background: #f6ecd2;
}

.quick-task:nth-child(4n + 3) {
  background: #f3e2e0;
}

.quick-task:nth-child(4n) {
  background: #e7efe0;
}

.item {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  background: var(--surface);
  border: 3px solid var(--line);
  border-left: 11px solid var(--item-color, var(--green));
  border-radius: 20px 16px 22px 16px;
  box-shadow: var(--shadow);
}

.item.important {
  --item-color: var(--red);
  background: #fff2ef;
}

.item.completed {
  opacity: 0.68;
}

.item-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 900;
}

.item-icon {
  margin-right: 6px;
  font-size: 1.1rem;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 22px 18px 22px 18px;
  box-shadow: var(--shadow);
}

.compact-form {
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 900;
}

.full {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

/* iOS 的日期欄位預設會置中並撐開、超出卡片，這裡壓回靠左且不溢出 */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

textarea {
  resize: vertical;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.utility-panel[open] > summary {
  margin-bottom: 14px;
}

.utility-panel .input-action span {
  font-weight: 900;
  color: var(--ink);
}

.icon-button {
  min-width: 64px;
  padding: 0 10px;
  background: #fff3cf;
  font-size: 0.86rem;
}

.form-hint {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.5;
}

.form-hint.warning {
  color: #9b3c45;
}

.primary-button {
  padding: 0 16px;
  background: var(--red);
  color: #fff;
  text-shadow: 0 1px 0 rgba(120, 60, 50, 0.28);
}

.ghost-button {
  padding: 0 14px;
  background: #fff;
}

.danger-button {
  color: #9b3c45;
  background: #fff1f2;
}

.metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 14px;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.metric:nth-child(1) {
  background: #e7eef1;
}

.metric:nth-child(2) {
  background: #e9f0e1;
}

.metric:nth-child(3) {
  background: #f7ecd2;
}

.metric span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.metric strong {
  color: var(--blue);
  font-size: 1.7rem;
  font-weight: 900;
}

.chart-panel {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.78);
  border: 2px solid rgba(106, 91, 80, 0.28);
  border-radius: 16px;
}

.pie-chart {
  width: 180px;
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 999px;
  box-shadow: 3px 3px 0 rgba(106, 91, 80, 0.22);
}

.chart-legend {
  display: grid;
  gap: 8px;
}

.legend-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-weight: 900;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(106, 91, 80, 0.45);
  border-radius: 999px;
}

.report-history-item {
  display: block;
  --item-color: var(--blue);
}

.report-history-item > summary {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  cursor: pointer;
  font-weight: 900;
}

.report-history-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.report-history-content {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed rgba(74, 59, 44, 0.25);
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--ink);
}

.report-box {
  min-height: 180px;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.7;
  background: #fff;
  border: 3px solid var(--line);
  border-left: 10px solid var(--green);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: none;
  max-width: min(520px, calc(100vw - 24px));
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  border: 3px solid #fff;
  border-radius: 999px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

@media (max-width: 820px) {
  .member-grid,
  .quick-task-grid,
  .metric-grid,
  .dashboard-actions,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .records-subview {
    grid-template-columns: 1fr;
  }

  #view-records .item-list {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .topbar {
    grid-template-columns: auto 1fr;
  }

  .date-pill,
  .sync-pill {
    grid-column: 1 / -1;
    width: 100%;
  }

  .tabs {
    display: flex;
    gap: 6px;
    padding-inline: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    min-width: 66px;
    min-height: 54px;
    padding-inline: 12px;
    font-size: 0.88rem;
  }

  .hero-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .member-grid,
  .quick-task-grid,
  .metric-grid,
  .chart-panel,
  .settings-grid,
  .status-grid,
  .dashboard-actions,
  .dashboard-announcements .form-grid {
    grid-template-columns: 1fr;
  }

  .pie-chart {
    width: min(220px, 100%);
    justify-self: center;
  }

  .dashboard-action-card,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-row select {
    width: 100%;
  }

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