:root {
  color-scheme: light;
  --bg: #eef3f5;
  --panel: #ffffff;
  --panel-2: #f7fafb;
  --ink: #16232b;
  --muted: #60717b;
  --border: #d7e1e5;
  --accent: #0d8f9e;
  --accent-2: #0c6f82;
  --blue: #2868c7;
  --green: #1f9d68;
  --amber: #b7791f;
  --red: #c73737;
  --shadow: 0 16px 40px rgba(22, 35, 43, 0.10);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

a {
  color: var(--accent-2);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.context,
.section-label {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.header-actions,
.panel-heading,
.fuel-controls,
.legend {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.75fr) minmax(580px, 1.45fr) minmax(420px, 1fr);
  grid-template-areas:
    "profile loading chart"
    "summary summary chart";
  gap: 18px;
  padding: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.profile-panel {
  grid-area: profile;
}

.loading-panel {
  grid-area: loading;
}

.summary-panel {
  grid-area: summary;
}

.chart-panel {
  grid-area: chart;
}

.panel-heading {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.field-grid {
  display: grid;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 143, 158, 0.16);
}

.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.icon-button:hover {
  transform: translateY(-1px);
}

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

.icon-button.primary:hover {
  background: var(--accent-2);
}

.icon-button.secondary {
  background: #edf5f6;
  color: var(--accent-2);
  border-color: #c8e1e5;
}

.icon-button.compact {
  min-height: 34px;
  padding: 7px 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 6px;
  padding: 5px 9px;
  color: #ffffff;
  background: var(--amber);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.good {
  background: var(--green);
}

.status-pill.bad {
  background: var(--red);
}

.source-box {
  margin-top: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.source-box summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 850;
}

.source-box p {
  margin: 12px 0;
}

.source-box ul {
  margin: 0;
  padding-left: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.load-table {
  table-layout: fixed;
}

.load-table th,
.load-table td,
.sheet th,
.sheet td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}

.load-table th,
.sheet th {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.load-table th:nth-child(1),
.load-table td:nth-child(1) {
  width: 28%;
}

.load-table th:nth-child(2),
.load-table td:nth-child(2) {
  width: 15%;
}

.load-table th:nth-child(3),
.load-table td:nth-child(3),
.load-table th:nth-child(4),
.load-table td:nth-child(4) {
  width: 14%;
}

.load-table th:nth-child(5),
.load-table td:nth-child(5) {
  width: 15%;
}

.load-table th:nth-child(6),
.load-table td:nth-child(6) {
  width: 46px;
}

.load-table input,
.load-table select {
  min-height: 34px;
  font-size: 13px;
}

.moment-cell {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.row-remove {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #f0caca;
  border-radius: 6px;
  background: #fff3f3;
  color: var(--red);
  cursor: pointer;
}

.row-remove svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fuel-controls {
  gap: 14px;
  justify-content: space-between;
  padding-top: 14px;
}

.fuel-input {
  max-width: 170px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 94px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 26px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.sheet {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sheet tbody tr:nth-child(odd) {
  background: #fbfdfe;
}

.sheet tfoot th {
  color: var(--ink);
  background: #edf5f6;
}

.alerts {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.alert {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
}

.alert.good {
  color: #145c3e;
  background: #edf8f3;
  border-color: #b9e5d1;
}

.alert.warn {
  color: #74500d;
  background: #fff8e8;
  border-color: #f0d28c;
}

.alert.bad {
  color: #7e2424;
  background: #fff1f1;
  border-color: #efbbbb;
}

.legend {
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dot,
.line {
  display: inline-block;
  vertical-align: middle;
  margin-right: 5px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.takeoff {
  background: var(--green);
}

.dot.zfm {
  background: var(--blue);
}

.line {
  width: 22px;
  height: 2px;
  background: var(--red);
}

.canvas-frame {
  min-height: 520px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafdff;
  padding: 8px;
}

#cgCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: minmax(320px, 0.9fr) minmax(460px, 1.1fr);
    grid-template-areas:
      "profile loading"
      "summary summary"
      "chart chart";
  }

  .canvas-frame {
    min-height: 470px;
  }
}

@media (max-width: 820px) {
  .app-header {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

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

  .header-actions .icon-button {
    flex: 1 1 120px;
  }

  .layout {
    display: block;
    padding: 12px;
  }

  .panel {
    margin-bottom: 12px;
    padding: 14px;
  }

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

  .fuel-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .fuel-input {
    max-width: none;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  .load-table,
  .load-table tbody,
  .load-table tr,
  .load-table td {
    display: block;
    width: 100%;
  }

  .load-table thead {
    display: none;
  }

  .load-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 44px;
    gap: 10px;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
  }

  .load-table td {
    padding: 0;
    border: 0;
    min-width: 0;
  }

  .load-table td:nth-child(1),
  .load-table td:nth-child(2),
  .load-table td:nth-child(3),
  .load-table td:nth-child(4),
  .load-table td:nth-child(5),
  .load-table td:nth-child(6) {
    width: auto;
  }

  .load-table td::before {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.1;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .load-table td:nth-child(1) {
    grid-column: 1 / -1;
  }

  .load-table td:nth-child(1)::before {
    content: "Poste";
  }

  .load-table td:nth-child(2)::before {
    content: "Cat.";
  }

  .load-table td:nth-child(3)::before {
    content: "Masse";
  }

  .load-table td:nth-child(4)::before {
    content: "Bras";
  }

  .load-table td:nth-child(5)::before {
    content: "Moment";
  }

  .load-table td:nth-child(6) {
    align-self: end;
  }

  .load-table td:nth-child(6)::before {
    content: "";
    display: none;
  }

  .load-table input,
  .load-table select {
    min-width: 0;
  }

  .moment-cell {
    min-height: 34px;
    display: flex;
    align-items: center;
  }

  .canvas-frame {
    min-height: 360px;
  }
}

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

  .app-header,
  .profile-panel,
  .loading-panel,
  .source-box,
  .row-remove,
  .header-actions,
  #addRowButton,
  #maxFuelButton {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .panel {
    border: 0;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .summary-panel,
  .chart-panel {
    padding: 8mm;
  }

  .metric-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .alerts {
    break-inside: avoid;
  }
}
