:root {
  --bg: #f6f2ec;
  --card: #fffaf4;
  --card-strong: #ffffff;
  --text: #221f1b;
  --muted: #756f66;
  --line: #e8ddd0;
  --accent: #d85a30;
  --accent-dark: #963b1d;
  --blue: #378add;
  --shadow: 0 14px 35px rgba(82, 55, 36, 0.12);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #fff4e7 0, #f6f2ec 44%, #f3f5f8 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: rgba(255, 250, 244, 0.9);
  border-bottom: 1px solid rgba(232, 221, 208, 0.9);
  backdrop-filter: blur(16px);
}

.eyebrow { margin: 0 0 2px; color: var(--accent-dark); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.app-header h1 { margin: 0; font-size: 21px; line-height: 1.15; }
.subtitle { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.sync-state {
  flex: none;
  margin-top: 3px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f2eadf;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.sync-state.ok { background: #eaf6ed; color: #217241; }
.sync-state.err { background: #fdeceb; color: #b42318; }

.app-shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 420px;
  gap: 16px;
}

.card {
  background: rgba(255, 250, 244, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.chart-card { min-width: 0; }
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.chart-head h2 { margin: 0; font-size: 18px; }
.chart-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.ghost-btn {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  font-weight: 700;
  cursor: pointer;
}

.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: 12px 0 8px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 99px; display: inline-block; }
.chart-box { position: relative; width: 100%; height: clamp(330px, 54vh, 520px); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.field { margin-bottom: 15px; }
.field label, .section summary { color: var(--muted); font-size: 13px; font-weight: 700; }
.field input[type="text"], .field input[type="date"], .row input {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card-strong);
  color: var(--text);
  outline: none;
}
.field input:focus, .row input:focus { border-color: rgba(216, 90, 48, .55); box-shadow: 0 0 0 3px rgba(216, 90, 48, .12); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; margin-top: 6px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.seg label { min-height: 42px; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.seg input { display: none; }
.seg label.active { background: #fff0e9; color: var(--accent-dark); }

.section { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.section summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; list-style: none; }
.section summary::-webkit-details-marker { display: none; }
.section summary span { font-size: 12px; font-weight: 500; color: var(--muted); }
.rows { margin-top: 10px; }
.row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.row input { margin-top: 0; min-width: 0; }
.row .value-wrap { position: relative; }
.row .unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.row .value-wrap input { padding-right: 58px; }
.del, .del-sm {
  border: none;
  background: #f2eadf;
  color: #967467;
  border-radius: 11px;
  cursor: pointer;
}
.del { width: 34px; height: 42px; font-size: 18px; }
.del-sm { width: 32px; height: 32px; font-size: 16px; }
.add-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
  border: 1px dashed #cdbdaa;
  border-radius: 13px;
  background: rgba(255,255,255,.62);
  color: var(--accent-dark);
  font-weight: 700;
  cursor: pointer;
}
.compare-list { margin-top: 10px; display: grid; gap: 8px; }
.compare-item {
  display: grid;
  grid-template-columns: 1fr 32px;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.compare-item label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.compare-empty { color: var(--muted); font-size: 13px; }

.bottom-tabs {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
  display: none;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(232, 221, 208, .95);
  border-radius: 22px;
  background: rgba(255, 250, 244, .94);
  box-shadow: 0 10px 30px rgba(52, 38, 25, .18);
  backdrop-filter: blur(16px);
}
.bottom-tabs button {
  min-height: 42px;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.bottom-tabs button.active, .bottom-tabs #quickSave { background: var(--accent); color: #fff; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .chart-card { order: 1; }
  .form-card { order: 2; }
  .bottom-tabs { display: grid; }
}

@media (max-width: 520px) {
  body { font-size: 14px; }
  .app-header { padding-left: 14px; padding-right: 14px; }
  .app-header h1 { font-size: 19px; }
  .subtitle { max-width: 230px; }
  .app-shell { padding: 10px; gap: 12px; }
  .card { border-radius: 18px; padding: 13px; }
  .chart-head { align-items: stretch; flex-direction: column; }
  .ghost-btn { width: 100%; }
  .chart-box { height: 360px; }
  .two-col { grid-template-columns: 1fr; }
  .row { grid-template-columns: 104px minmax(0, 1fr) 34px; gap: 7px; }
  .row input { font-size: 16px; }
}
