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

:root {
  --color-accent: #1d9e75;
  --color-accent-surface: #e1f5ee;
  --color-accent-text: #085041;
  --color-text: #111111;
  --color-text-secondary: #6b7280;
  --color-surface: #f9fafb;
  --color-surface-panel: #ffffff;
  --color-border: #e5e7eb;
  --color-warning: #ef9f27;
  --color-danger: #e24b4a;
  --color-caption: #9ca3af;
  --radius: 8px;
  --accent: #1d9e75;
  --text: #111111;
  --muted: #6b7280;
  --surface: #ffffff;
  --surface2: #f9fafb;
  --border: #e5e7eb;
  --red: #e24b4a;
  --green: #1d9e75;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--color-surface-panel);
  color: var(--color-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
  min-height: 100vh;
  overflow-x: hidden;
}

p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text-secondary);
}

strong {
  font-weight: 600;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

header nav a:hover {
  color: var(--color-accent);
  background-color: var(--color-accent-surface);
}

/* Page wrapper */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 32px 64px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 24px;
}

header nav {
  margin-top: 16px;
}

header nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  margin: 0 auto;
  font-weight: 600;
  color: var(--color-accent);
  border-radius: var(--radius);
  word-break: break-word;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.logo {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.015em;
  color: var(--color-text);
}

.logo span {
  color: var(--color-accent);
}

.tagline {
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-top: 8px;
}

/* Cards */
.card,
.results-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
}

.section-title {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--color-text);
  margin-bottom: 8px;
}

.amort-subtitle {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--color-text-secondary);
  margin-bottom: 0;
  margin-top: 8px;
}

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field > label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}

.field .input-toggle {
  margin-bottom: 8px;
}

.optional {
  font-size: 12px;
  color: var(--color-caption);
  font-weight: 400;
}

.field input {
  background: var(--color-surface-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--color-text);
  font-size: 15px;
  outline: none;
}

.field input:focus {
  border-color: var(--color-accent);
}

.field input::placeholder {
  color: var(--color-caption);
}

.hint {
  font-size: 12px;
  color: var(--color-accent);
  min-height: 16px;
  margin-top: 8px;
}

/* Primary button */
button {
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 24px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--color-accent-surface);
  color: var(--color-accent-text);
}

button:active {
  background: var(--color-accent);
  color: #ffffff;
}

/* Results grid */
.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.result-item {
  background: var(--color-surface-panel);
  border-radius: var(--radius);
  border-bottom: 1px solid var(--color-border);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-item .label {
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.result-item .value {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.value.red {
  color: var(--color-danger);
}

.value.green {
  color: var(--color-accent);
}

/* Amortization table */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead tr {
  background: var(--color-surface);
}

thead th {
  padding: 12px 14px;
  text-align: right;
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

thead th:first-child {
  text-align: left;
}

tbody tr {
  border-top: 1px solid var(--color-border);
}

tbody tr:hover {
  background: var(--color-accent-surface);
}

tbody td {
  padding: 11px 14px;
  text-align: right;
  color: var(--color-text);
}

tbody td:first-child {
  text-align: left;
  color: var(--color-text-secondary);
}

tbody tr.year-row {
  background: var(--color-accent-surface);
}

tbody tr.year-row td {
  color: var(--color-accent-text);
  font-weight: 600;
}

.chart-wrap {
  width: 100%;
  min-height: 280px;
  max-width: 100%;
  position: relative;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 24px;
}

.chart-wrap canvas {
  max-width: 100%;
}

@media (max-width: 768px) {
  .page {
    padding: 16px 16px 40px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .section-title {
    font-size: clamp(1.25rem, 5vw, 1.65rem);
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    min-height: 240px;
    padding: 12px;
    margin-top: 16px;
  }

  button {
    min-height: 44px;
    white-space: normal;
    padding: 12px 18px;
  }
}

@media (max-width: 480px) {
  .field input,
  .field select,
  textarea {
    font-size: 16px;
  }

  thead th,
  tbody td {
    padding: 10px 10px;
    font-size: 12px;
  }
}
