:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #f1f4f8;
  --ink: #171717;
  --muted: #6f7378;
  --subtle: #9aa0a6;
  --line: #e4e6ea;
  --accent: #e35242;
  --accent-deep: #c83e31;
  --accent-soft: #fff0ed;
  --accent-rgb: 227, 82, 66;
  --blue: #2f6fed;
  --blue-soft: #edf3ff;
  --green: #168a6f;
  --green-soft: #eaf7f2;
  --gold: #c58516;
  --gold-soft: #fff6df;
  --danger: #c6443b;
  --danger-soft: #fff0ed;
  --high: #d84a3a;
  --medium: #c58516;
  --low: #168a6f;
  --shadow: 0 12px 32px rgba(24, 24, 24, 0.08);
}

body[data-theme="blue"] {
  --accent: #2f6fed;
  --accent-deep: #2256c7;
  --accent-soft: #edf3ff;
  --accent-rgb: 47, 111, 237;
}

body[data-theme="green"] {
  --accent: #168a6f;
  --accent-deep: #0f6c57;
  --accent-soft: #eaf7f2;
  --accent-rgb: 22, 138, 111;
}

body[data-theme="purple"] {
  --accent: #7b61ff;
  --accent-deep: #6248d9;
  --accent-soft: #f1edff;
  --accent-rgb: 123, 97, 255;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  overflow-anchor: none;
  overscroll-behavior: contain;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  overflow-anchor: none;
  overscroll-behavior: contain;
}

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

input,
select,
textarea {
  font-size: 16px;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(227, 82, 66, 0.18);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(100%, 500px);
  margin: 0 auto;
  padding: 12px 12px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 12px;
  padding: 10px 0 12px;
  background: rgba(247, 247, 245, 0.94);
  backdrop-filter: blur(16px);
}

.title-block {
  display: grid;
  gap: 5px;
}

.eyebrow,
.section-label {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: 30px;
  line-height: 1.08;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.date-tools {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(24, 24, 24, 0.05);
}

.date-tools input {
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.date-tools #todayBtn {
  grid-column: 1 / -1;
}

.theme-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.theme-dot {
  width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: inset 0 0 0 4px #fff, 0 4px 12px rgba(24, 24, 24, 0.12);
}

.theme-dot[data-theme="tomato"] {
  background: #e35242;
}

.theme-dot[data-theme="blue"] {
  background: #2f6fed;
}

.theme-dot[data-theme="green"] {
  background: #168a6f;
}

.theme-dot[data-theme="purple"] {
  background: #7b61ff;
}

.theme-dot.active {
  border-color: var(--accent);
}

.icon-btn,
.text-btn,
.ghost-btn,
.primary-btn,
.mini-btn {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 900;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.14s ease, box-shadow 0.18s ease;
}

.icon-btn:active,
.text-btn:active,
.ghost-btn:active,
.primary-btn:active,
.mini-btn:active,
.theme-dot:active,
.tab:active {
  transform: scale(0.97);
}

.icon-btn {
  width: 44px;
  padding: 0;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.text-btn,
.ghost-btn,
.primary-btn {
  padding: 0 14px;
  font-size: 14px;
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(var(--accent-rgb), 0.2);
}

.text-btn.active,
.tab.active {
  border-color: var(--accent);
  color: var(--accent);
}

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

@media (hover: hover) and (pointer: fine) {
  button:hover {
    border-color: var(--accent);
    color: var(--accent);
  }

  .primary-btn:hover {
    border-color: var(--accent-deep);
    background: var(--accent-deep);
    color: #fff;
    transform: translateY(-1px);
  }

  .ghost-btn:hover,
  .text-btn:hover,
  .icon-btn:hover,
  .mini-btn:hover {
    background: var(--accent-soft);
  }

  .danger:hover {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
  }
}

.workspace {
  display: grid;
  gap: 14px;
  align-items: start;
  overflow-anchor: none;
  overscroll-behavior: contain;
}

.planner-panel,
.insight-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.planner-panel {
  padding: 14px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.add-plan-btn {
  width: 100%;
  min-height: 50px;
}

.list-actions,
.backup-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0 0;
}

.backup-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 8px;
}

.copy-status {
  min-height: 20px;
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.copy-status:not(:empty) {
  opacity: 1;
  transform: translateY(0);
}

.copy-status[data-tone="success"] {
  color: var(--green);
}

.copy-status[data-tone="warning"] {
  color: var(--gold);
}

.plan-list {
  display: grid;
  gap: 10px;
  overflow-anchor: none;
  overscroll-behavior: contain;
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 172px;
  padding: 24px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 16px;
}

.empty-state span {
  max-width: 280px;
  line-height: 1.6;
}

.plan-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--medium);
  border-radius: 8px;
  background: var(--surface);
  touch-action: manipulation;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.16s ease, opacity 0.2s ease;
}

.plan-item:active {
  transform: scale(0.99);
}

.plan-item.just-updated {
  animation: softPulse 0.7s ease both;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent), var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 44%, var(--line));
}

.plan-item[data-priority="high"] {
  border-left-color: var(--high);
}

.plan-item[data-priority="low"] {
  border-left-color: var(--low);
}

.plan-item.completed {
  background: #f6f7f7;
  color: var(--subtle);
  opacity: 0.76;
}

.plan-item.completed .plan-title {
  color: var(--subtle);
  text-decoration: line-through;
}

.check {
  width: 44px;
  height: 44px;
  margin-top: 1px;
  accent-color: var(--accent);
}

.plan-title {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.plan-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.plan-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.pill.priority-high {
  background: var(--danger-soft);
  color: var(--high);
}

.pill.priority-medium {
  background: var(--gold-soft);
  color: var(--medium);
}

.pill.priority-low {
  background: var(--green-soft);
  color: var(--low);
}

.pill.overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.mini-btn {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font-size: 13px;
}

.insight-panel {
  min-width: 0;
  padding: 12px;
}

.tabs {
  position: sticky;
  top: 114px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tab {
  min-height: 42px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.tab.active {
  border-color: var(--surface);
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 6px 14px rgba(24, 24, 24, 0.06);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 12px;
  animation: panelIn 0.2s ease both;
}

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

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

.metric-card {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card.success {
  background: var(--green-soft);
}

.metric-card.warning {
  background: var(--gold-soft);
}

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

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1.1;
}

.chart-grid,
.monthly-chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.chart-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow-x: auto;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 260px;
}

#monthlyLine {
  width: 100%;
  min-height: 320px;
  max-width: none;
}

#monthlyWeeks {
  width: 100%;
  min-height: 280px;
  max-width: none;
}

.report-surface {
  display: grid;
  gap: 12px;
}

.summary-text {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--blue-soft);
  color: #273244;
  font-size: 14px;
  line-height: 1.8;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(7, minmax(36px, 1fr));
  gap: 4px;
  min-width: 0;
}

.heat-cell {
  min-height: 44px;
  padding: 6px 4px;
  border: 1px solid rgba(228, 230, 234, 0.9);
  border-radius: 8px;
  background: #f3f6ef;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.heat-cell strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
  padding: 0;
  background: rgba(24, 24, 24, 0.38);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.18s ease both;
}

.modal-backdrop[hidden] {
  display: none;
}

.plan-modal {
  width: 100%;
  max-height: min(78vh, 620px);
  overflow: auto;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--surface);
  box-shadow: 0 -18px 42px rgba(24, 24, 24, 0.16);
  animation: sheetIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  overscroll-behavior: contain;
}

@keyframes softPulse {
  from {
    transform: scale(0.985);
  }
  45% {
    transform: scale(1.01);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sheetIn {
  from {
    opacity: 0.9;
    transform: translateY(28px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.plan-form {
  display: grid;
  gap: 14px;
}

.plan-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.plan-form input,
.plan-form textarea,
.plan-form select {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  outline: none;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding-top: 4px;
}

@media (min-width: 640px) {
  .app-shell {
    width: min(100%, 1180px);
    padding: 22px;
  }

  .topbar {
    position: static;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 24px;
    background: transparent;
    backdrop-filter: none;
  }

  h1 {
    font-size: 42px;
  }

  .date-tools {
    width: 470px;
    grid-template-columns: 48px minmax(0, 1fr) 48px 72px;
  }

  .date-tools #todayBtn {
    grid-column: auto;
  }

  .theme-tools {
    grid-column: 2;
    justify-content: flex-end;
  }

  .workspace {
    grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
    gap: 18px;
  }

  .planner-panel {
    position: sticky;
    top: 18px;
    padding: 16px;
  }

  .panel-head {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .add-plan-btn {
    width: auto;
  }

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

  .list-actions .danger {
    grid-column: 1 / -1;
  }

  .item-actions {
    display: flex;
    grid-column: auto;
    margin-top: 0;
  }

  .plan-item {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }

  .mini-btn {
    width: auto;
    min-width: 38px;
  }

  .insight-panel {
    padding: 16px;
  }

  .tabs {
    position: static;
    top: auto;
  }

  .range-tools {
    display: flex;
    flex-wrap: wrap;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(130px, 1fr));
  }

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

  .monthly-chart-grid {
    grid-template-columns: 1fr;
  }

  #monthlyLine {
    width: 1120px;
    min-height: 420px;
  }

  #monthlyWeeks {
    width: 760px;
    min-height: 340px;
  }

  .modal-backdrop {
    place-items: center;
    padding: 18px;
  }

  .plan-modal {
    width: min(520px, 100%);
    max-height: min(720px, 92vh);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(24, 24, 24, 0.22);
  }

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