* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 60px;
  color: #1a1a1a;
  background: #fafaf9;
  line-height: 1.5;
  font-size: 15px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  gap: 12px;
}
.app-header h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.goal-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.goal-select {
  font-size: 20px;
  font-weight: 500;
  padding: 4px 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px;
  max-width: 100%;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  -webkit-appearance: menulist;
  appearance: menulist;
}
.goal-select:hover { background: rgba(0,0,0,0.04); }
.goal-select:focus { outline: 1px solid #4a90e2; background: rgba(74,144,226,0.08); }
.icon-btn {
  padding: 4px 9px;
  font-size: 16px;
  background: transparent;
  border: 0;
  color: #888;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { color: #4a90e2; background: rgba(0,0,0,0.04); }
.icon-btn:active { background: rgba(0,0,0,0.08); }
.logout-link {
  font-size: 13px;
  color: #888;
  text-decoration: none;
}
.logout-link:hover { color: #555; }

/* Section */
.section {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid #e5e5e3;
}
.section h2 {
  font-size: 15px;
  margin: 0 0 14px;
  font-weight: 500;
  color: #555;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}
.section-header h2 { margin: 0; }

/* Inputs */
.input-row { margin-bottom: 14px; }
.input-row:last-child { margin-bottom: 0; }
.input-row.inline { display: flex; align-items: center; }
.input-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #666;
  margin-bottom: 6px;
  gap: 8px;
}
.input-row label b {
  font-weight: 500;
  color: #1a1a1a;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.input-row label .value-input {
  width: auto;
  min-width: 90px;
  max-width: 180px;
  padding: 2px 6px;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  color: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: text;
}
.input-row label .value-input:hover { border-color: rgba(0,0,0,0.12); }
.input-row label .value-input:focus {
  border-color: #4a90e2;
  background: rgba(74,144,226,0.06);
}
.input-row label.checkbox {
  margin: 0;
  font-size: 13px;
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-row label.checkbox input { width: 18px; height: 18px; }

input[type=range] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #e5e5e3;
  border-radius: 2px;
  outline: none;
  padding: 0;
  margin: 8px 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #4a90e2;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: #4a90e2; cursor: pointer; border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

input[type=number], input[type=text], input[type=email], input[type=password], input[type=date] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d4d4d2;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  font-variant-numeric: tabular-nums;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid #d4d4d2;
  background: white;
  color: inherit;
  cursor: pointer;
}
button.primary {
  background: #4a90e2;
  color: white;
  border-color: #4a90e2;
  width: 100%;
  padding: 12px;
  font-size: 15px;
  margin-top: 8px;
}
button.primary:active { background: #3a7fc2; }
button.primary:disabled { background: #c8c8c6; border-color: #c8c8c6; cursor: not-allowed; }
button.secondary {
  background: #f0f0ee;
  border: 1px solid #d4d4d2;
  color: #1a1a1a;
  font-size: 13px;
  padding: 8px 14px;
}
button.secondary:active { background: #e5e5e3; }

/* Snapshots */
.snapshots-list { display: flex; flex-direction: column; gap: 8px; }
.snapshot-entry {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #e5e5e3;
  border-radius: 8px;
  gap: 10px;
  background: #fcfcfa;
}
.snapshot-toggle { width: 18px; height: 18px; cursor: pointer; }
.snapshot-color {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}
.snapshot-info {
  flex: 1;
  min-width: 0;
}
.snapshot-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.snapshot-meta {
  font-size: 11px;
  color: #888;
  font-variant-numeric: tabular-nums;
}
.snapshot-actions { display: flex; gap: 6px; }
.snapshot-actions button {
  padding: 4px 8px;
  font-size: 13px;
  color: #888;
  background: transparent;
  border: 0;
}
.snapshot-actions button:active { background: #f0f0ee; }

.empty-hint {
  color: #888;
  font-size: 13px;
  font-style: italic;
  padding: 8px 0;
}

/* Result card */
.result-card {
  background: #e6f1fb;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 14px;
}
.result-headline {
  font-size: 19px;
  font-weight: 500;
  color: #185fa5;
  line-height: 1.3;
}
.result-sub {
  font-size: 13px;
  color: #185fa5;
  opacity: 0.85;
  margin-top: 4px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.result-stat {
  font-size: 11px;
  color: #185fa5;
  opacity: 0.85;
}
.result-stat b {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #185fa5;
  opacity: 1;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* Tax obligations panel */
.tax-obligations {
  background: #fef7ed;
  border: 1px solid #fdd9b6;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.tax-obligations-header {
  font-size: 12px;
  color: #a05028;
  margin-bottom: 8px;
  font-weight: 500;
}
.tax-obligations-sub {
  font-weight: 400;
  opacity: 0.75;
}
.tax-obligations-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tax-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  gap: 8px;
}
.tax-row-year { color: #555; }
.tax-row-amount {
  font-weight: 500;
  color: #c2410c;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  margin-right: 8px;
}
.tax-row-due { color: #888; font-size: 11px; }
.tax-row.total {
  border-top: 1px solid #fdd9b6;
  padding-top: 6px;
  margin-top: 4px;
  font-weight: 500;
}
.tax-row.total .tax-row-year { color: #a05028; }
.tax-row-formula {
  font-size: 11px;
  color: #a05028;
  opacity: 0.75;
  padding-left: 0;
  margin-top: -2px;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

/* Chart */
.chart-container { width: 100%; position: relative; }
#chart { width: 100%; height: auto; display: block; }
.chart-tooltip {
  position: absolute;
  background: rgba(26, 26, 26, 0.95);
  color: #f0f0ee;
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  min-width: 160px;
  transform: translate(8px, -100%);
}
.chart-tooltip .tt-date {
  font-weight: 500;
  font-size: 11px;
  color: #aaa;
  margin-bottom: 4px;
  text-transform: capitalize;
}
.chart-tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
}
.chart-tooltip .tt-row-name { color: #ccc; }
.chart-tooltip .tt-row-amount { font-weight: 500; }
.chart-tooltip .tt-fact .tt-row-name,
.chart-tooltip .tt-fact .tt-row-amount { color: #b5d4f4; }
.chart-tooltip .tt-color {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}
.chart-legend .legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend .legend-dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legend .legend-line {
  width: 18px;
  height: 2px;
  display: inline-block;
}
.chart-legend .legend-line.dashed {
  background-image: linear-gradient(to right, currentColor 50%, transparent 50%);
  background-size: 6px 2px;
  background-repeat: repeat-x;
  background-color: transparent;
  height: 2px;
}

.grid-line { stroke: #e5e5e3; stroke-width: 0.5; }
.target-line { stroke: #d85a30; stroke-width: 1.5; stroke-dasharray: 6 4; fill: none; }
.fact-line { stroke: #999; stroke-width: 2; fill: none; }
.fact-dot { stroke: white; stroke-width: 2; }
.axis-text { font-size: 11px; fill: #888; }

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
table th, table td {
  padding: 7px 6px;
  text-align: right;
  border-bottom: 1px solid #e5e5e3;
}
table th:first-child, table td:first-child {
  text-align: left;
  color: #666;
  font-weight: 400;
}
table th {
  font-size: 11px;
  color: #666;
  font-weight: 500;
  background: #fafaf9;
  position: sticky;
  top: 0;
}
table tr.hit td {
  background: #eaf3de;
  color: #3b6d11;
  font-weight: 500;
}
table .fact-cell { padding: 0; min-width: 90px; }
table .fact-input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 7px 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  font-size: 12px;
  color: inherit;
  outline: none;
}
table .fact-input:focus { background: #e6f1fb; }
table tr.has-fact td.fact-display { color: #185fa5; font-weight: 500; }
table .plan-fact-cell { color: #185fa5; font-style: italic; }
table .fact-delta-pos { color: #3b6d11; font-size: 11px; }
table .fact-delta-neg { color: #b54a1c; font-size: 11px; }
table .tax-cell { color: #c2410c; font-weight: 500; }
.table-wrap {
  max-height: 360px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px -16px;
  padding: 0 16px 16px;
}

/* Auth pages */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-card {
  max-width: 380px;
  width: 100%;
  background: white;
  padding: 24px;
  border-radius: 14px;
  border: 1px solid #e5e5e3;
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 16px;
  font-weight: 500;
}
.auth-card form label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 14px;
}
.auth-card form input { margin-top: 6px; }
.auth-footer {
  margin-top: 14px;
  font-size: 13px;
  color: #666;
  text-align: center;
}
.auth-footer a { color: #4a90e2; text-decoration: none; }
.err {
  background: #fde7e0;
  color: #b54a1c;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Note button in the table row */
.th-note { text-align: center !important; }
table td.note-cell { text-align: center; padding: 0 4px; }
.note-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px dashed #d4d4d2;
  background: transparent;
  color: #999;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.note-btn:hover { background: rgba(74,144,226,0.08); color: #4a90e2; border-color: #4a90e2; }
.note-btn.has-note {
  background: rgba(74,144,226,0.12);
  border: 1px solid #4a90e2;
  border-style: solid;
  color: #185fa5;
  font-weight: 600;
}
.note-btn.has-note:hover { background: rgba(74,144,226,0.2); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.modal-title {
  margin: 0 0 10px;
  font-size: 14px;
  color: #666;
  font-weight: 500;
}
.modal-textarea {
  width: 100%;
  min-height: 120px;
  padding: 10px 12px;
  border: 1px solid #d4d4d2;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  background: #fff;
  color: inherit;
  line-height: 1.5;
}
.modal-textarea:focus { outline: none; border-color: #4a90e2; }
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.modal-actions button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #d4d4d2;
  background: #f5f5f3;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.modal-actions .primary { background: #4a90e2; color: #fff; border-color: #4a90e2; }
.modal-actions .primary:hover { background: #3a7bc8; }
.modal-actions .danger {
  margin-right: auto;
  background: transparent;
  color: #b54a1c;
  border-color: transparent;
}
.modal-actions .danger:hover { background: #fde7e0; }

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body { background: #1a1a1a; color: #f0f0ee; }
  .section, .auth-card { background: #262626; border-color: #3a3a3a; }
  .section h2 { color: #aaa; }
  .input-row label { color: #aaa; }
  .input-row label b { color: #f0f0ee; }
  .input-row label.checkbox { color: #ccc; }
  input[type=number], input[type=text], input[type=email], input[type=password], input[type=date] {
    background: #1a1a1a; border-color: #444; color: #f0f0ee;
  }
  button { background: #2a2a2a; border-color: #444; color: #f0f0ee; }
  button.secondary { background: #2f2f2f; border-color: #444; color: #f0f0ee; }
  button.secondary:active { background: #383838; }
  button.primary { background: #4a90e2; }
  .snapshot-entry { background: #1f1f1f; border-color: #3a3a3a; }
  .snapshot-meta { color: #888; }
  .empty-hint { color: #888; }
  .result-card { background: #1a3a52; }
  .result-headline, .result-sub, .result-stat, .result-stat b { color: #b5d4f4; }
  .grid-line { stroke: #3a3a3a; }
  .fact-line { stroke: #666; }
  .fact-dot { stroke: #1a1a1a; }
  .axis-text { fill: #888; }
  table th { background: #1a1a1a; color: #aaa; border-bottom-color: #444; }
  table td { border-bottom-color: #333; }
  table tr.hit td { background: #1f3a10; color: #c0dd97; }
  table .fact-input:focus { background: #1a3a52; }
  table tr.has-fact td.fact-display { color: #b5d4f4; }
  table .plan-fact-cell { color: #b5d4f4; }
  table .tax-cell { color: #fb923c; }
  .tax-obligations { background: #2a1f15; border-color: #4a3520; }
  .tax-obligations-header { color: #d4986a; }
  .tax-row-year { color: #aaa; }
  .tax-row-amount { color: #fb923c; }
  .tax-row-due { color: #777; }
  .tax-row.total { border-top-color: #4a3520; }
  .tax-row.total .tax-row-year { color: #d4986a; }
  .tax-row-formula { color: #d4986a; opacity: 0.7; }
  .logout-link { color: #999; }
  .err { background: #3a1a10; color: #f4a07a; }
  .goal-select:hover { background: rgba(255,255,255,0.06); }
  .goal-select:focus { background: rgba(74,144,226,0.18); }
  .icon-btn:hover { background: rgba(255,255,255,0.06); }
  .icon-btn:active { background: rgba(255,255,255,0.10); }
  .input-row label .value-input:hover { border-color: rgba(255,255,255,0.15); }
  .input-row label .value-input:focus { background: rgba(74,144,226,0.15); }
  .note-btn { border-color: #444; color: #888; }
  .note-btn:hover { background: rgba(74,144,226,0.15); color: #4a90e2; border-color: #4a90e2; }
  .note-btn.has-note { background: rgba(74,144,226,0.2); color: #b5d4f4; border-color: #4a90e2; }
  .note-btn.has-note:hover { background: rgba(74,144,226,0.3); }
  .modal-card { background: #262626; box-shadow: 0 8px 32px rgba(0,0,0,0.6); }
  .modal-title { color: #aaa; }
  .modal-textarea { background: #1a1a1a; border-color: #444; color: #f0f0ee; }
  .modal-actions button { background: #2a2a2a; border-color: #444; color: #f0f0ee; }
  .modal-actions .primary { background: #4a90e2; border-color: #4a90e2; }
  .modal-actions .danger { background: transparent; border-color: transparent; color: #f4a07a; }
  .modal-actions .danger:hover { background: #3a1a10; }
}
