:root {
  --bg: #f6f7f3;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #63706a;
  --line: #dfe5dc;
  --primary: #28765a;
  --primary-strong: #18513e;
  --blue: #2c6f9f;
  --amber: #b56b1d;
  --danger: #a93c32;
  --soft-green: #e7f3ed;
  --soft-blue: #e8f1f7;
  --soft-amber: #fbefdf;
  --shadow: 0 10px 28px rgba(31, 42, 35, 0.08);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0 16px;
}

.brand {
  min-width: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.15;
}

h2 {
  font-size: 18px;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.subline,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.subline {
  margin-top: 5px;
}

.status-cluster,
.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  background: #e7f3ed;
  color: #1e5b45;
  white-space: nowrap;
}

.status-pill.muted,
.pill.rest {
  background: #ece7dd;
  color: #5f5140;
}

.status-pill.error,
.pill.dirty {
  background: #f6e4e1;
  color: var(--danger);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: #edf1ec;
  color: var(--ink);
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:hover {
  border-color: #cbd5ca;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-strong);
  border-color: transparent;
}

.btn.danger {
  background: #f6e4e1;
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
}

.hidden {
  display: none !important;
}

.setup-band,
.auth-band,
.panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.setup-band,
.auth-band {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr);
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.setup-grid,
.auth-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
}

label span,
.label,
.toggle-title {
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd8d0;
  border-radius: var(--radius);
  outline: none;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(40, 118, 90, 0.14);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 104px;
  padding: 14px;
}

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

.metric.blue {
  background: var(--soft-blue);
}

.metric.amber {
  background: var(--soft-amber);
}

.metric .value {
  margin-top: 10px;
  font-size: 28px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0;
}

.metric .hint {
  margin-top: 9px;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: #dde5dc;
  overflow: hidden;
  margin-top: 12px;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel-title,
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 0;
}

.form {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5ca;
  transition: 0.18s ease;
}

.slider::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: 0.18s ease;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

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

.settings-box {
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}

details {
  overflow: hidden;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

summary {
  padding: 12px;
  cursor: pointer;
  font-weight: 650;
}

.settings-grid {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.main-stack {
  display: grid;
  gap: 14px;
}

.plan-panel {
  overflow: hidden;
}

.today-plan {
  display: grid;
  gap: 8px;
  padding: 14px 16px 12px;
}

.today-plan h3 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: 0;
}

.today-plan p {
  margin: 0;
}

.plan-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 10px;
  color: #1e5b45;
  background: #dff0e7;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.plan-meta-item {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  color: #33423c;
  background: #edf1ec;
  border-radius: 999px;
  font-size: 12px;
}

.backup-plan {
  margin: 0 16px 12px;
  padding: 10px 12px;
  color: #5f5140;
  background: #fbefdf;
  border: 1px solid #ead8be;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.45;
}

.weekly-plan {
  display: grid;
  gap: 6px;
  padding: 0 16px 16px;
}

.plan-day {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--ink);
  text-align: left;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.plan-day:hover,
.plan-day.active {
  border-color: var(--primary);
  background: #f4faf6;
}

.plan-day-left,
.plan-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.plan-day-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.plan-status {
  justify-self: end;
}

.plan-status.done {
  color: var(--primary);
  font-weight: 700;
}

.plan-status.logged {
  color: var(--amber);
  font-weight: 700;
}

.chart-panel {
  min-height: 352px;
}

.chart-head select {
  width: auto;
  min-width: 118px;
}

.chart-wrap {
  padding: 12px 16px 16px;
}

canvas {
  display: block;
  width: 100%;
  height: 260px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.history-panel {
  overflow: hidden;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 480px;
  overflow: auto;
  padding: 10px 16px 16px;
}

.record {
  display: grid;
  grid-template-columns: 102px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.record-date {
  font-weight: 700;
}

.record-main {
  min-width: 0;
}

.record-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pill.done {
  background: #dff0e7;
  color: #1e5b45;
}

.record-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.icon-buttons {
  display: flex;
  gap: 6px;
}

.small-btn {
  min-width: 34px;
  height: 34px;
  color: var(--ink);
  background: #eef2ed;
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.small-btn:hover {
  border-color: #cbd5ca;
}

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfa;
  border: 1px dashed #cbd5ca;
  border-radius: var(--radius);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 10;
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  color: #fff;
  text-align: center;
  pointer-events: none;
  background: #17201c;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.file-input {
  display: none;
}

@media (max-width: 920px) {
  .topbar,
  .setup-band,
  .auth-band {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .status-cluster,
  .top-actions {
    justify-content: flex-start;
  }

  .setup-grid,
  .auth-form {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

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

  .metrics {
    gap: 8px;
  }

  .metric {
    min-height: 96px;
    padding: 12px;
  }

  .metric .value {
    font-size: 23px;
  }

  .two,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .chart-head {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-head select {
    width: 100%;
  }

  canvas {
    height: 230px;
  }

  .record {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .plan-day {
    grid-template-columns: 74px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .icon-buttons {
    justify-content: flex-end;
  }
}
