*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f4;
  --bg-info: #e6f1fb;
  --bg-warning: #faeeda;
  --text: #1a1a18;
  --text-secondary: #5f5e5a;
  --text-tertiary: #888780;
  --text-info: #0c447c;
  --text-warning: #854f0b;
  --text-danger: #a32d2d;
  --text-success: #3b6d11;
  --border: rgba(0,0,0,0.13);
  --border-md: rgba(0,0,0,0.22);
  --radius: 8px;
  --radius-lg: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1a;
    --bg-secondary: #2a2a27;
    --bg-info: #042c53;
    --bg-warning: #412402;
    --text: #f0ede8;
    --text-secondary: #b4b2a9;
    --text-tertiary: #888780;
    --text-info: #85b7eb;
    --text-warning: #fac775;
    --text-danger: #f09595;
    --text-success: #97c459;
    --border: rgba(255,255,255,0.11);
    --border-md: rgba(255,255,255,0.20);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-secondary);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container { max-width: 700px; margin: 0 auto; }

header { margin-bottom: 1.5rem; }
header h1 { font-size: 22px; font-weight: 500; margin-bottom: 4px; }
header p { font-size: 14px; color: var(--text-secondary); }

.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.top-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 1.25rem;
  align-items: stretch;
  flex-wrap: wrap;
}

.toggle-row {
  display: flex;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex: 1;
  min-width: 260px;
}

.toggle-btn {
  flex: 1;
  padding: 9px 14px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--bg-secondary);
  color: var(--text);
  font-weight: 500;
}

.year-select-wrap {
  display: flex;
  align-items: center;
}

select {
  padding: 0 28px 0 12px;
  height: 100%;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.15s;
}

select:focus { border-color: #378add; box-shadow: 0 0 0 3px rgba(55,138,221,0.15); }

.year-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-weight: 500;
}

.year-badge.previous { background: var(--bg-secondary); color: var(--text-secondary); }
.year-badge.current { background: var(--bg-info); color: var(--text-info); }
.year-badge.next { background: var(--bg-warning); color: var(--text-warning); }

.inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 1.25rem;
}

@media (max-width: 500px) {
  .inputs { grid-template-columns: 1fr; }
  .top-controls { flex-direction: column; align-items: stretch; }
}

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

.field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.field input {
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: #378add; box-shadow: 0 0 0 3px rgba(55,138,221,0.15); }

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 500px) { .metrics { grid-template-columns: 1fr; } }

.metric {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 1rem;
}

.metric.highlight { background: var(--bg-info); }

.metric .mlabel { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.metric.highlight .mlabel { color: var(--text-info); }

.metric .mvalue { font-size: 22px; font-weight: 500; color: var(--text); }
.metric.highlight .mvalue { color: var(--text-info); }

.metric .msub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.metric.highlight .msub { color: var(--text-info); }

.breakdown-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.breakdown-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.breakdown-header h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
}

.col-heads {
  display: flex;
  padding-bottom: 8px;
  border-bottom: 0.5px solid var(--border-md);
  margin-bottom: 4px;
}

.col-heads span {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.col { width: 100px; text-align: right; flex-shrink: 0; }

.row {
  display: flex;
  align-items: center;
  padding: 7px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
}

.row:last-child { border-bottom: none; }

.row.subtotal {
  color: var(--text-secondary);
  font-size: 12px;
  background: var(--bg-secondary);
  margin: 2px -1.25rem;
  padding: 6px 1.25rem;
}

.row.total {
  font-weight: 500;
  font-size: 14px;
  padding-top: 12px;
}

.row-label { flex: 1; padding-right: 8px; }

.neg { color: var(--text-danger); }
.pos { color: var(--text-success); }

.note {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.6;
  padding: 0 0.25rem;
  margin-bottom: 1rem;
}

.rates-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 1rem;
}

@media (max-width: 500px) { .rates-grid { grid-template-columns: 1fr; } }

.rates-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}

.rates-card h4 {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rate-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-secondary);
}

.rate-row:last-child { border-bottom: none; }
.rate-row span:last-child { color: var(--text); font-weight: 500; }

footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  padding-bottom: 1rem;
  line-height: 2;
}

footer a {
  color: var(--text-info);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}
