:root {
  color-scheme: light;
  --bg: #eef3f0;
  --surface: #ffffff;
  --surface-alt: #f6f8fa;
  --text: #172026;
  --muted: #64727d;
  --line: #d6dee4;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #d9f2ef;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 50px rgba(27, 40, 47, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.11), transparent 32%),
    linear-gradient(315deg, rgba(41, 98, 146, 0.10), transparent 28%),
    var(--bg);
}

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

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.header-summary {
  max-width: 360px;
  margin-bottom: 4px;
  color: var(--muted);
  line-height: 1.5;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 18px;
}

.section-heading {
  margin: 34px 0 18px;
}

.section-heading-first {
  margin-top: 0;
}

.section-heading h2 {
  margin-bottom: 8px;
  font-size: 2.25rem;
  line-height: 1.1;
}

.section-heading p:not(.eyebrow) {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid rgba(214, 222, 228, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.panel-wide {
  grid-column: 1 / -1;
}

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

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.calc-form {
  display: grid;
  gap: 10px;
}

.vlsm-form {
  grid-template-columns: 1fr 1.3fr auto;
  align-items: start;
}

.vlsm-form button {
  align-self: end;
}

.vlsm-form .error,
.vlsm-form .helper-note {
  grid-column: 1 / -1;
}

label {
  display: block;
  color: #34434d;
  font-size: 0.86rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  background: #fbfcfd;
  font: inherit;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

.error {
  min-height: 21px;
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
  line-height: 1.45;
}

.error:not(:empty) {
  padding: 9px 10px;
  border: 1px solid #ffd0c8;
  border-radius: 6px;
  background: var(--danger-soft);
}

.helper-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  max-width: 34rem;
}

.results {
  margin-top: 14px;
  overflow-x: auto;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 10px;
}

.copy-table-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  background: #ffffff;
  font-size: 0.88rem;
}

.copy-table-button:hover {
  color: #ffffff;
  background: var(--accent);
}

.copy-table-button.copied {
  color: #ffffff;
  background: var(--accent-dark);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.metric span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

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

th {
  color: #34434d;
  background: #e9f1f0;
  font-size: 0.78rem;
  text-transform: uppercase;
}

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

.note {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 980px) {
  .app-header {
    align-items: start;
    flex-direction: column;
  }

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

  .vlsm-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .panel {
    padding: 16px;
  }

  .section-heading h2 {
    font-size: 1.8rem;
  }

  .panel-heading,
  .input-row {
    grid-template-columns: 1fr;
  }

  .input-row {
    display: grid;
  }

  button {
    width: 100%;
  }

  .result-actions {
    justify-content: stretch;
  }

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