:root {
  color-scheme: light;
  --bg: #f5faf7;
  --surface: #ffffff;
  --surface-soft: #eaf6f1;
  --ink: #10201c;
  --muted: #64756f;
  --line: #d8e7df;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #b45309;
  --warning: #9f1239;
  --shadow: 0 16px 42px rgba(16, 32, 28, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  font-size: 13px;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 0%, rgba(15, 118, 110, 0.12), transparent 28rem),
    linear-gradient(180deg, #fff 0%, var(--bg) 36%);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

input,
select {
  font-size: 16px;
}

.topbar {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 2.4vw, 1.8rem);
  line-height: 1.45;
  font-weight: 900;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

button {
  min-height: 36px;
  border-radius: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 850;
}

.ghost {
  background: rgba(255, 255, 255, 0.82);
  color: var(--brand-dark);
}

.icon-btn {
  width: 34px;
  padding: 0;
  color: var(--warning);
  font-size: 1.35rem;
  line-height: 1;
}

.app-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 24px);
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 12px;
}

.summary-panel,
.workspace,
.tab-page,
.table-wrap,
.reference-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.summary-panel {
  position: sticky;
  top: 10px;
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 12px;
}

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

.field span,
.total-box span,
.metric-list span,
.share-bars span,
.control-stats dt {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.8;
}

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

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.total-box {
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 12px;
}

.total-box span {
  color: rgba(255, 255, 255, 0.78);
}

.total-box strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.metric-list {
  display: grid;
  gap: 8px;
}

.metric-list div,
.control-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.metric-list strong,
.control-stats dd {
  display: block;
  margin: 2px 0 0;
  font-size: 0.98rem;
  line-height: 1.8;
}

.share-bars {
  display: grid;
  gap: 9px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.2s ease;
}

.control-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.control-stats dd {
  color: var(--brand-dark);
  font-weight: 850;
}

.workspace {
  min-width: 0;
  padding: 10px;
}

.tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  margin-bottom: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--brand);
  color: #fff;
  font-weight: 850;
}

.tab-page {
  display: none;
  padding: 12px;
  box-shadow: none;
}

.tab-page.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin-bottom: 2px;
  font-size: 1.05rem;
  line-height: 1.7;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.9;
}

.row-list {
  display: grid;
  gap: 10px;
}

.calc-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(16, 32, 28, 0.06);
  padding: 10px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.7;
}

.card-head strong {
  display: block;
  color: var(--brand-dark);
  font-size: 1.08rem;
  line-height: 1.8;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.fixed-field {
  display: grid;
  gap: 4px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 7px 10px;
}

.fixed-field span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.fixed-field strong {
  color: var(--brand-dark);
  font-size: 0.92rem;
  line-height: 1.8;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.8;
}

.tariff-title {
  flex-basis: 100%;
  color: var(--ink);
  font-weight: 750;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  box-shadow: none;
}

table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: right;
  vertical-align: top;
  font-size: 0.78rem;
  line-height: 1.8;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--brand-dark);
  font-weight: 850;
}

td input,
td select {
  min-width: 115px;
}

td output {
  display: block;
  min-width: 120px;
  color: var(--brand-dark);
  font-weight: 850;
  line-height: 2.2;
}

.readonly {
  display: block;
  min-width: 220px;
}

.muted-cell {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.warning {
  display: block;
  min-width: 110px;
  color: var(--warning);
  font-weight: 850;
}

.reference-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: 10px;
}

.reference-grid h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.reference-list {
  display: grid;
  gap: 8px;
  max-height: 62svh;
  overflow: auto;
  padding-inline-end: 2px;
}

.reference-item {
  display: grid;
  gap: 3px;
  padding: 9px;
  box-shadow: none;
}

.reference-item b {
  font-size: 0.86rem;
  line-height: 1.8;
}

.reference-item span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.8;
}

@media (max-width: 900px) {
  html {
    font-size: 12px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1 1 72px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    padding-inline: 10px;
  }

  .summary-panel {
    position: static;
  }

  .metric-list {
    grid-template-columns: 1fr;
  }

  .section-heading {
    flex-direction: column;
  }

  .section-heading .primary {
    width: 100%;
  }

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

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

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .topbar-actions,
  .tabs,
  .icon-btn,
  .section-heading .primary {
    display: none !important;
  }

  .topbar,
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .app-shell {
    display: block;
  }

  .summary-panel,
  .workspace,
  .tab-page,
  .table-wrap {
    box-shadow: none;
    border-color: #d1d5db;
  }

  .summary-panel {
    position: static;
    margin-bottom: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .share-bars,
  .control-stats {
    display: none;
  }

  .tab-page {
    display: block !important;
    page-break-inside: avoid;
    margin-bottom: 10px;
  }

  input,
  select {
    border: 0;
    min-height: 0;
    padding: 0;
  }
}
