/* 手機優先，單欄直向堆疊；電腦（>= 768px）改雙欄 grid（左：統計卡片＋現金流圖表，
   右：輸入框＋持股清單），max-width 1200px 避免超寬螢幕拉太寬 */

:root {
  --bg: #f5f8f6;
  --card-bg: #ffffff;
  --card-bg-alt: #eef3ef;
  --accent: #a8721c;
  --accent-ink: #fffaf0;
  --text: #16241f;
  --text-dim: #55655d;
  --danger: #b3392f;
  --radius: 16px;
  --shadow-card: 0 1px 2px rgba(22, 36, 31, 0.04), 0 6px 20px rgba(22, 36, 31, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif;
  line-height: 1.5;
  padding-bottom: 40px;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.btn-icon {
  background: var(--card-bg-alt);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 8px;
  box-shadow: var(--shadow-card);
}

.hero-figure {
  display: flex;
  flex-direction: column;
}

.hero-label {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.hero-number {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
}

.hero-number.small {
  font-size: 1.5rem;
}

.hero-figure.secondary {
  border-top: 1px solid rgba(22,36,31,0.1);
  padding-top: 10px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 24px 0 10px;
  display: block;
}

.input-section, .timeline-section, .assets-section, .manual-section {
  margin-top: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
}

#nlInput {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(22,36,31,0.14);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(22,36,31,0.14);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

.full-width { width: 100%; }

.input-hint, .form-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin: 8px 0 0;
}

.parse-result {
  margin-top: 10px;
  background: var(--card-bg-alt);
  border-radius: var(--radius);
  padding: 14px;
}

.parse-result.hidden, .manual-form.hidden { display: none; }

.parse-summary { margin: 0 0 10px; font-weight: 600; }
.parse-fail { margin: 0; color: var(--danger); }

.parse-summary-header { margin: 0 0 8px; font-weight: 600; font-size: 0.9rem; color: var(--text-dim); }

.parse-item {
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 0.92rem;
}
.parse-item-known { background: rgba(22,36,31,0.04); }
.parse-item-unknown { background: rgba(179,57,47,0.1); color: var(--danger); }

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

/* 12個月現金流 — 長條圖（純CSS/SVG-less，用grid+flex手刻，無圖表函式庫） */

:root {
  --grid-line: rgba(22, 36, 31, 0.09);
  --chart-h: 180px;
}

.timeline {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 14px 12px;
  box-shadow: var(--shadow-card);
}

.chart-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  /* 手機窄版12根長條理論上不需要橫捲，這是極窄裝置的備案 */
}

.chart-inner {
  min-width: 100%;
}

.chart-plot {
  position: relative;
  height: var(--chart-h);
  margin-bottom: 4px;
}

.chart-gridlines {
  position: absolute;
  inset: 0;
}

.chart-gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--grid-line);
}

.chart-gridline-label {
  position: absolute;
  left: 0;
  top: -1px;
  transform: translateY(-100%);
  font-size: 0.62rem;
  color: var(--text-dim);
  padding-right: 4px;
  white-space: nowrap;
}

.chart-bars,
.chart-labels {
  display: grid;
  grid-template-columns: repeat(12, minmax(24px, 1fr));
  gap: 2px;
}

.chart-bars {
  position: absolute;
  inset: 0;
  align-items: end;
}

.chart-labels {
  margin-top: 6px;
}

.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
  cursor: pointer;
}

.chart-col:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.chart-bar {
  width: min(24px, 100%);
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 1px;
}

.chart-bar-label {
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  margin-bottom: 3px;
}

.chart-col-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  text-align: center;
  white-space: nowrap;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  background: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(22, 36, 31, 0.22);
}

.chart-tooltip.hidden { display: none; }

.chart-tooltip-amount {
  color: var(--bg);
  font-size: 1rem;
  font-weight: 700;
}

.chart-tooltip-month {
  color: var(--card-bg-alt);
  font-size: 0.75rem;
}

.asset-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.asset-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 14px 42px;
  position: relative;
  box-shadow: var(--shadow-card);
}

.asset-card-main {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.asset-card-meta {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
}

.btn-remove {
  position: absolute;
  bottom: 10px;
  right: 14px;
  background: rgba(22, 36, 31, 0.05);
  border: none;
  border-radius: 8px;
  padding: 5px 12px;
  color: var(--danger);
  font-size: 0.78rem;
  cursor: pointer;
}

.empty-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.manual-form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.manual-form input, .manual-form select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(22,36,31,0.14);
  background: var(--card-bg-alt);
  color: var(--text);
  font-size: 0.95rem;
}

.app-footer {
  margin-top: 30px;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-align: center;
}

@media (min-width: 768px) {
  main {
    max-width: 1200px;
    padding: 0 32px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 28px;
    row-gap: 0;
    grid-template-areas:
      "hero input"
      "timeline assets"
      "manual manual"
      "footer footer";
    align-items: start;
  }

  .app-header { max-width: 1200px; padding: 16px 32px; }

  .hero-number { font-size: 3rem; }

  .hero { grid-area: hero; flex-direction: row; align-items: center; justify-content: space-between; }
  .hero-figure.secondary {
    border-top: none;
    border-left: 1px solid rgba(22, 36, 31, 0.1);
    padding-top: 0;
    padding-left: 20px;
  }

  .input-section { grid-area: input; }
  .timeline-section { grid-area: timeline; }
  .assets-section { grid-area: assets; }
  .manual-section { grid-area: manual; margin-top: 16px; }
  .app-footer { grid-area: footer; }

  :root { --chart-h: 220px; }
}
