:root {
  color-scheme: light;
  --ink: #15212d;
  --muted: #607080;
  --line: #dce3e8;
  --panel: #ffffff;
  --panel-soft: #f4f8fa;
  --surface: #eef3f5;
  --teal: #087f8c;
  --teal-dark: #075e6a;
  --green: #2b8757;
  --amber: #b76e00;
  --blue: #2b5d95;
  --shadow: 0 24px 70px rgba(22, 35, 45, 0.13);
  --radius: 8px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(8, 127, 140, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(43, 93, 149, 0.05) 1px, transparent 1px),
    #f7fafb;
  background-size: 34px 34px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
}

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

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(8, 127, 140, 0.24);
  border-radius: var(--radius);
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 38%),
    linear-gradient(145deg, #0a6f78, #163a51 62%, #c6801a);
  box-shadow: 0 14px 30px rgba(16, 66, 74, 0.18);
  font-weight: 800;
  letter-spacing: 0;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--teal-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 3px;
  font-size: clamp(1.9rem, 4vw, 3.6rem);
  line-height: 0.95;
}

h2 {
  margin-top: 6px;
  font-size: 1.2rem;
}

.status-pill,
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(8, 127, 140, 0.22);
  border-radius: 999px;
  color: var(--teal-dark);
  background: rgba(255, 255, 255, 0.78);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(43, 135, 87, 0.13);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 18px;
  align-items: stretch;
}

.calculator-panel,
.result-panel,
.history-section {
  border: 1px solid rgba(121, 141, 158, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.calculator-panel {
  padding: 24px;
}

.result-panel {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

.result-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: linear-gradient(90deg, var(--teal), var(--blue), #c6801a);
}

.panel-header,
.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-header.compact {
  align-items: center;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--panel-soft);
  font-size: 1.1rem;
}

.icon-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  border-color: rgba(8, 127, 140, 0.42);
  color: var(--teal-dark);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.field {
  display: grid;
  gap: 8px;
}

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

.field span:first-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
  outline: none;
}

input {
  padding: 0 14px;
}

select {
  padding: 0 38px 0 14px;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(8, 127, 140, 0.12);
}

.density-row,
.number-suffix,
.coefficient-row {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.density-row {
  grid-template-columns: minmax(0, 1fr) 118px;
}

.number-suffix,
.coefficient-row {
  grid-template-columns: minmax(0, 1fr) 78px;
}

.coefficient-row {
  grid-template-columns: minmax(0, 1fr) 94px;
}

.density-row input,
.density-row select,
.number-suffix input,
.coefficient-row input {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.density-row select,
.number-suffix span,
.coefficient-row span {
  display: grid;
  place-items: center;
  border-left: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 0.88rem;
  font-weight: 750;
}

.locked {
  background: #f8fafb;
}

.method-note,
.standard-note {
  margin: 18px 0 0;
  padding: 13px 14px;
  border: 1px solid rgba(183, 110, 0, 0.24);
  border-radius: var(--radius);
  color: #6f4d12;
  background: #fff8eb;
  font-size: 0.9rem;
  line-height: 1.45;
}

.standard-note {
  margin-top: auto;
}

.action-row,
.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--teal);
  box-shadow: 0 12px 24px rgba(8, 127, 140, 0.2);
}

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

.secondary-button {
  border-color: var(--line);
  color: var(--ink);
  background: #fff;
}

.ghost-button {
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.86rem;
}

.result-meter {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 30px;
}

.tube {
  position: relative;
  width: 72px;
  height: 168px;
  margin: 0 auto;
  border: 1px solid rgba(21, 33, 45, 0.18);
  border-radius: 28px 28px 8px 8px;
  background: linear-gradient(90deg, #eef4f6, #ffffff 35%, #dce7eb);
  overflow: hidden;
}

.tube::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 18px;
  width: 12px;
  height: 126px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  z-index: 2;
}

.tube-fill {
  position: absolute;
  inset: auto 5px 5px;
  height: 54%;
  border-radius: 22px 22px 5px 5px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 32%),
    linear-gradient(160deg, #d49127, #0f7f8b 65%, #14516b);
  transition: height 260ms ease;
}

.tube-line {
  position: absolute;
  left: 9px;
  right: 9px;
  z-index: 3;
  height: 1px;
  background: rgba(21, 33, 45, 0.28);
}

.tube-line.top {
  top: 42px;
}

.tube-line.bottom {
  bottom: 42px;
}

.temperature-bridge {
  display: grid;
  gap: 12px;
  align-content: center;
}

.temperature-bridge span {
  display: inline-flex;
  min-height: 34px;
  width: fit-content;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
}

.temperature-bridge strong {
  display: block;
  color: var(--green);
  font-size: 2rem;
  line-height: 1;
}

.primary-result {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 24px;
}

.result-value {
  font-size: clamp(3rem, 8vw, 5.6rem);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0;
}

.result-unit {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.result-details {
  display: grid;
  gap: 10px;
  margin: 22px 0;
}

.result-details div {
  display: grid;
  grid-template-columns: minmax(118px, 0.7fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.result-details dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.result-details dd {
  margin: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.history-section {
  margin-top: 18px;
  padding: 22px;
}

.history-header {
  align-items: center;
}

.history-actions {
  margin-top: 0;
}

.table-wrap {
  position: relative;
  margin-top: 18px;
  overflow-x: auto;
}

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

th,
td {
  padding: 13px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
  font-weight: 650;
}

.empty-state {
  display: none;
  margin: 16px 0 4px;
  color: var(--muted);
  font-weight: 700;
}

.empty-state.visible {
  display: block;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 13px 16px;
  border: 1px solid rgba(21, 33, 45, 0.08);
  border-radius: var(--radius);
  color: #fff;
  background: #172431;
  box-shadow: 0 18px 46px rgba(21, 33, 45, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .result-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .history-header {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 2.3rem;
  }

  .calculator-panel,
  .result-panel,
  .history-section {
    padding: 18px;
  }

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

  .density-row,
  .number-suffix,
  .coefficient-row {
    grid-template-columns: 1fr;
  }

  .density-row select,
  .number-suffix span,
  .coefficient-row span {
    min-height: 38px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .result-meter {
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 14px;
  }

  .tube {
    width: 60px;
    height: 138px;
  }

  .result-details div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .action-row button,
  .history-actions button {
    flex: 1 1 120px;
  }
}

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

  .app-shell {
    padding: 0;
  }

  .calculator-panel,
  .history-section,
  .toast,
  .icon-button,
  .action-row,
  .history-actions {
    display: none;
  }

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

  .result-panel {
    border: 0;
    box-shadow: none;
  }
}
