:root {
  --ink: #172033;
  --muted: #5f6f83;
  --line: #c7d2df;
  --panel: #ffffff;
  --page: #eef3f7;
  --navy: #173f63;
  --blue: #dcecf8;
  --green: #dceddf;
  --yellow: #fff0bd;
  --gray: #edf0f3;
  --warn: #f6d96f;
  --shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 22px 28px;
  background: var(--navy);
  color: #fff;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.app-header p {
  margin-top: 6px;
  color: #dce8f3;
}

.status-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip span {
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.26);
}

.term-switch {
  display: flex;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.08);
}

.term-toggle {
  min-height: 34px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.24);
  background: transparent;
  color: #eaf2f8;
  padding: 7px 10px;
  cursor: pointer;
}

.term-toggle:last-child {
  border-right: 0;
}

.term-toggle.is-active {
  background: #fff;
  color: var(--navy);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 28px;
  background: #d8e2eb;
  border-bottom: 1px solid var(--line);
}

button,
select,
input {
  font: inherit;
  touch-action: manipulation;
}

.tab,
.action,
.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.tab.is-active,
.action {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.secondary {
  background: var(--gray);
}

main {
  padding: 22px 28px 36px;
}

.panel {
  display: none;
  min-width: 0;
}

.panel.is-active {
  display: block;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.panel-head p {
  color: var(--muted);
}

.planner-grid,
.shearwater-grid,
.table-layout,
.measurement-layout,
.crib-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
  align-items: start;
}

.planner-grid {
  grid-template-columns: minmax(360px, 0.85fr) minmax(420px, 1fr) minmax(320px, 0.85fr);
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 9px 12px;
  align-items: center;
}

label {
  display: contents;
}

label span,
.field-label {
  color: var(--muted);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 8px;
}

input[type="number"] {
  text-align: right;
}

.summary-grid,
.strategy-grid,
.result-stack {
  display: grid;
  gap: 8px;
}

.metric {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 8px 10px;
  background: var(--gray);
  border-left: 4px solid var(--line);
}

.metric.important {
  background: var(--green);
  border-left-color: #4d8b61;
}

.metric.warn {
  background: var(--yellow);
  border-left-color: #c99b17;
}

.metric strong {
  font-size: 17px;
  text-align: right;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar label {
  display: grid;
  gap: 4px;
  min-width: 150px;
  color: var(--muted);
}

.measurement-layout {
  grid-template-columns: minmax(320px, 0.65fr) minmax(560px, 1.35fr);
}

.crib-grid {
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
}

.crib-steps {
  margin: 0;
  padding-left: 22px;
}

.crib-steps li {
  margin-bottom: 9px;
  line-height: 1.35;
}

.formula-stack {
  display: grid;
  gap: 8px;
}

.formula-note {
  padding: 8px 10px;
  background: var(--yellow);
  border-left: 4px solid #c99b17;
}

.formula-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.7fr) minmax(180px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--gray);
  border-left: 4px solid var(--line);
}

.formula-row span {
  color: var(--muted);
}

.formula-row code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: right;
  white-space: nowrap;
}

th {
  background: var(--blue);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

td:first-child,
th:first-child {
  text-align: left;
}

.copy-block {
  min-height: 420px;
  max-width: 100%;
  margin: 0;
  padding: 12px;
  background: #101826;
  color: #f2f7fb;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.crib-block {
  min-height: 0;
  max-width: 100%;
  margin: 0;
  padding: 12px;
  background: #101826;
  color: #f2f7fb;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.callout-stack {
  display: grid;
  gap: 8px;
}

.callout {
  padding: 9px 10px;
  background: var(--gray);
  border-left: 4px solid var(--line);
}

.callout.warn {
  background: var(--yellow);
  border-left-color: #c99b17;
}

.callout.important {
  background: var(--green);
  border-left-color: #4d8b61;
}

.notes {
  margin: 0;
  padding-left: 18px;
}

.notes li {
  margin-bottom: 10px;
}

.source-box {
  margin-top: 14px;
  padding: 10px;
  background: var(--gray);
  border: 1px solid var(--line);
  color: var(--muted);
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-header,
  .panel-head {
    display: block;
  }

  .status-strip {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .planner-grid,
  .shearwater-grid,
  .table-layout,
  .measurement-layout,
  .crib-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .app-header {
    padding: 16px 14px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 18px;
  }

  h3 {
    font-size: 15px;
  }

  .app-header p {
    line-height: 1.25;
  }

  .status-strip {
    gap: 7px;
  }

  .status-strip span,
  .term-toggle {
    min-height: 38px;
    padding: 8px 10px;
  }

  .term-switch {
    flex: 1 1 100%;
  }

  .term-toggle {
    flex: 1 1 0;
    font-size: 16px;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 5px;
    padding: 8px 12px;
  }

  .tab,
  .action,
  .secondary,
  input,
  select {
    min-height: 40px;
    font-size: 16px;
  }

  .tab,
  .action,
  .secondary {
    padding: 9px 11px;
  }

  main {
    padding: 14px 12px 28px;
  }

  .panel-head {
    margin-bottom: 12px;
  }

  .card {
    padding: 12px;
    box-shadow: none;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr) minmax(104px, 34vw);
    gap: 8px 10px;
  }

  .field-label {
    align-self: center;
    line-height: 1.2;
  }

  .metric {
    gap: 8px;
    padding: 8px;
  }

  .metric strong {
    font-size: 16px;
  }

  .toolbar {
    gap: 10px;
  }

  .toolbar label {
    flex: 1 1 148px;
    min-width: 0;
  }

  th,
  td {
    padding: 7px;
  }

  .copy-block {
    min-height: 300px;
    font-size: 12px;
  }

  .crib-block {
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  .formula-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .source-box {
    font-size: 13px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .tabs,
  .panel:not(#tables),
  .toolbar,
  .card h3 {
    display: none;
  }

  main {
    padding: 0;
  }

  #tables {
    display: block;
  }

  .table-layout {
    grid-template-columns: 1fr;
  }

  .card {
    box-shadow: none;
    border: 0;
  }
}
