:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --line: #d9dee8;
  --text: #18202f;
  --muted: #637083;
  --strong: #101828;
  --teal: #08766f;
  --teal-dark: #065f5a;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --focus: #0c8f86;
  --shadow: 0 14px 36px rgba(24, 32, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  max-width: 100%;
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--strong);
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.04;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.top-badge {
  flex: 0 0 auto;
  border: 1px solid rgba(8, 118, 111, 0.22);
  border-radius: 999px;
  padding: 10px 14px;
  background: #effaf8;
  color: var(--teal-dark);
  font-weight: 800;
}

.install-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  border: 1px solid rgba(8, 118, 111, 0.22);
  border-radius: 8px;
  background: #effaf8;
  padding: 16px;
  margin-bottom: 18px;
}

.install-card h2 {
  margin-bottom: 6px;
}

.install-help {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.45;
}

.install-actions {
  display: grid;
  grid-template-columns: 150px 96px;
  gap: 8px;
}

.app-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px));
  gap: 10px;
  margin-bottom: 18px;
}

.tab-button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--strong);
  font-weight: 900;
}

.tab-button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.page.hidden,
.hidden {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(380px, 1.25fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel,
.output-panel {
  padding: 22px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  min-width: 0;
}

.heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.section-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.field,
.quote-box {
  display: grid;
  gap: 8px;
}

.full-width {
  margin-bottom: 14px;
}

.field span,
.quote-box span,
.summary-item span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--strong);
  outline: none;
}

input {
  min-height: 52px;
  padding: 12px 14px;
  font-size: 17px;
  font-weight: 700;
}

textarea {
  min-height: 380px;
  resize: vertical;
  padding: 14px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 15px;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(12, 143, 134, 0.16);
}

.year-block {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

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

.year-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(42px, 1fr));
  gap: 8px;
}

.year-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--strong);
  font-weight: 900;
}

.year-button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}

.summary-item strong {
  display: block;
  margin-top: 8px;
  color: var(--strong);
  font-size: 21px;
  line-height: 1.16;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
}

table {
  width: 100%;
  min-width: 540px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f1f5f9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

td {
  font-size: 16px;
  font-weight: 750;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.quote-box {
  margin-bottom: 14px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 900;
  white-space: normal;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  border-color: #d6b36f;
  background: var(--amber-soft);
  color: #6f4710;
}

.secondary-button:hover {
  border-color: var(--amber);
}

.danger-button {
  border-color: #f2c7c7;
  background: #fff5f5;
  color: #9b1c1c;
}

.danger-button:hover {
  border-color: #dc6b6b;
}

.ghost-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--strong);
}

.ghost-button.small {
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
}

.live-status {
  min-height: 22px;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 900;
  text-align: right;
}

.template-panel {
  padding: 22px;
}

.template-count {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 900;
}

.template-search {
  margin-bottom: 16px;
}

.template-list {
  display: grid;
  gap: 12px;
}

.template-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 16px;
}

.template-main h3 {
  margin: 0 0 12px;
  color: var(--strong);
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.template-main dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.template-main div {
  min-width: 0;
}

.template-main dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.template-main dd {
  margin: 4px 0 0;
  color: var(--strong);
  font-size: 16px;
  font-weight: 900;
}

.template-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
}

.small-action {
  min-height: 44px;
  padding: 0 12px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 22px;
  color: var(--muted);
  background: #fbfcff;
  font-weight: 800;
  text-align: center;
}

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

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

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

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

@media (max-width: 620px) {
  .app-shell {
    width: 100%;
    padding: 14px 10px 28px;
  }

  h1 {
    font-size: 28px;
    line-height: 1.08;
  }

  .input-panel,
  .output-panel,
  .template-panel {
    padding: 14px;
  }

  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-badge {
    display: none;
  }

  .install-card {
    grid-template-columns: 1fr;
  }

  .install-actions {
    grid-template-columns: 1fr;
  }

  .field-grid,
  .button-row {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .ghost-button {
    min-height: 50px;
    padding: 0 12px;
  }

  .summary-grid {
    gap: 10px;
    margin-bottom: 14px;
  }

  .summary-item {
    padding: 12px;
  }

  .summary-item strong {
    font-size: 19px;
    overflow-wrap: anywhere;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
    margin-bottom: 14px;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
    padding: 8px 12px;
  }

  td {
    display: grid;
    grid-template-columns: minmax(90px, 0.85fr) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  td::before {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
    text-align: left;
  }

  td:nth-child(1)::before {
    content: "Year";
  }

  td:nth-child(2)::before {
    content: "Monthly";
  }

  td:nth-child(3)::before {
    content: "Interest";
  }

  td:nth-child(4)::before {
    content: "Repayment";
  }

  tbody tr:last-child td,
  td:last-child {
    border-bottom: 0;
  }

  textarea {
    min-height: 320px;
    font-size: 14px;
    line-height: 1.45;
  }

  .year-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .year-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .heading-actions,
  .heading-actions .ghost-button {
    width: 100%;
  }

  .live-status {
    width: 100%;
    text-align: left;
  }

  .template-main dl,
  .template-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-right: 8px;
    padding-left: 8px;
  }

  .input-panel,
  .output-panel,
  .template-panel,
  .install-card {
    padding: 12px;
  }

  .year-grid {
    gap: 6px;
  }

  td {
    grid-template-columns: minmax(78px, 0.75fr) minmax(0, 1fr);
  }
}
