:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2230;
  --ink-soft: #5b6678;
  --line: #e3e8ef;
  --accent: #0f766e;        /* deep teal */
  --accent-dark: #0c5d56;
  --accent-soft: #e6f3f1;
  --pos: #15803d;
  --neg: #b91c1c;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.page-header { margin-bottom: 28px; }

h1 {
  font-size: 1.7rem;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
  max-width: 60ch;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

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

/* Fields */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Shares table-ish layout */
.shares-head, .share-row {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 1.4fr 0.9fr 36px;
  gap: 10px;
  align-items: center;
}

.shares-head {
  padding: 0 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.shares { display: flex; flex-direction: column; gap: 10px; }
.share-row { padding: 2px; }

/* Segmented control (Annual / Overall) */
.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 6px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.btn-remove {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-remove:hover:not(:disabled) { background: #fdecec; color: var(--neg); border-color: #f5c2c2; }
.btn-remove:disabled { opacity: 0.35; cursor: not-allowed; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 12px 28px;
  font-size: 1rem;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 0.85rem;
}
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.actions { display: flex; align-items: center; gap: 16px; margin-top: 4px; }

.form-error {
  margin: 0;
  color: var(--neg);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Results */
.results { margin-top: 28px; }

.context-line {
  font-size: 0.9rem;
  color: var(--ink-soft);
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 18px;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
  table-layout: fixed;
}
.result-table th, .result-table td {
  text-align: right;
  padding: 12px 8px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

/* Column headers (Existing / New / Δ) */
.result-table thead th {
  vertical-align: bottom;
  border-top: 0;
  padding-bottom: 14px;
}
.result-table thead .corner { border-top: 0; }
.col-title {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}
.col-note {
  display: block;
  margin-top: 3px;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.3;
}
.delta-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Row labels */
.result-table th[scope="row"] {
  text-align: left;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.result-table td { font-size: 1.05rem; font-weight: 600; }
.result-table td.delta { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.delta.pos { color: var(--pos); }
.delta.neg { color: var(--neg); }

/* Fixed column widths so headers sit directly above their values */
.result-table th[scope="row"] { width: 30%; }
.result-table thead th:not(.delta-head),
.result-table tbody td:not(.delta) { width: 24%; }
.delta-head, .result-table td.delta { width: 22%; }

.disclaimer {
  margin: 18px 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

/* Responsive */
@media (max-width: 680px) {
  .grid-3 { grid-template-columns: 1fr; }
  .shares-head { display: none; }
  .share-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
  }
  .share-row .s-name { grid-column: 1 / -1; }
  .share-row .seg { grid-column: 1 / 2; }
  .share-row .btn-remove { grid-column: 2 / 3; justify-self: end; }
  .result-table td.delta, .result-table .delta-head { display: none; }
  .result-table th[scope="row"] { width: 46%; }
  .result-table thead th:not(.delta-head),
  .result-table tbody td:not(.delta) { width: 27%; }
}
