:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --line: #e2e8ed;
  --line-soft: #edf1f4;
  --ink: #14202b;
  --muted: #5f6e7a;
  --brand: #002b49;
  --brand-2: #073a5f;
  --brand-soft: #eef3f6;
  --accent: #ef7b00;
  --accent-soft: #fff3e8;
  --danger: #b83232;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 43, 0.05), 0 6px 18px rgba(20, 32, 43, 0.06);
  --font: "Poppins", "Century Gothic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-num: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

body.access-locked #app {
  display: none;
}

body:not(.access-locked) .access-gate {
  display: none;
}

/* ---------- Access Gate ---------- */

.access-gate {
  min-height: auto;
  display: grid;
  place-items: start center;
  padding: 28px 18px 48px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(245, 247, 249, 0.96)),
    linear-gradient(135deg, var(--brand-soft), #fff 52%, var(--accent-soft));
}

.access-card {
  width: min(100%, 520px);
  background: #fff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
}

.access-brand {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  color: var(--brand);
  font-weight: 800;
  font-size: 28px;
  margin-bottom: 18px;
}

.access-brand sup {
  font-size: 0.62em;
  line-height: 1;
  position: relative;
  top: -0.48em;
}

.access-card h1 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.2;
}

.access-card p {
  margin: 10px 0 22px;
  color: var(--muted);
}

.access-form {
  display: grid;
  gap: 14px;
}

.access-form label {
  display: grid;
  gap: 7px;
  color: var(--brand);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.4px;
}

.access-form input[type="email"],
.access-form input[type="text"] {
  width: 100%;
  height: 48px;
  border: 1px solid #cbd5dd;
  border-radius: 8px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  letter-spacing: 0;
}

.access-form input[type="email"]:focus,
.access-form input[type="text"]:focus {
  outline: 2px solid rgba(239, 123, 0, 0.22);
  border-color: var(--accent);
}

.access-check {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--ink) !important;
  font-weight: 500 !important;
  letter-spacing: 0 !important;
}

.access-check input {
  margin: 0;
}

.access-button {
  height: 46px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 43, 73, 0.18);
  transition: transform 0.12s ease, background 0.12s ease;
}

.access-button:hover:not(:disabled) {
  background: var(--brand-2);
  transform: translateY(-1px);
}

.access-button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.access-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
}

/* ---------- Header ---------- */

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand) 55%, var(--accent));
}

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

.brand-logo {
  height: 46px;
  width: auto;
  display: block;
}

.brand-wordmark {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: 0.5px;
  color: var(--brand);
}

.brand-wordmark sub,
.brand-wordmark sup {
  font-size: 0.62em;
  font-weight: 700;
  color: var(--brand-2);
}

.brand-wordmark sup {
  line-height: 0;
  position: relative;
  top: -0.42em;
}

.brand-divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 2px 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.1px;
}

.brand-text p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-spacer {
  flex: 1;
}

.polito-mark {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

/* Dark-blue pill so the white logo is visible on the white header */
.polito-logo-wrap {
  background: var(--brand);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.polito-logo {
  height: 30px;
  width: auto;
  display: block;
}

.polito-fallback {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: right;
  color: var(--brand);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.polito-fallback small {
  color: var(--muted);
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

/* ---------- Layout ---------- */

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 432px minmax(0, 1fr);
  gap: 20px;
  padding: 22px 26px;
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
}

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

.setup-panel {
  padding: 20px;
  align-self: start;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.setup-panel .panel-heading {
  padding: 0 0 16px;
}

.setup-panel .panel-heading select {
  flex: 0 0 auto;
  width: 88px;
}

h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

/* ---------- Solver switcher ---------- */

.solver-switcher {
  display: flex;
  gap: 6px;
  margin: 14px 0 4px;
}

.solver-tab-btn {
  flex: 1;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.solver-tab-btn:hover {
  background: var(--brand-soft);
  border-color: #b6c3cc;
}

.solver-tab-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Form ---------- */

fieldset {
  margin: 16px 0 0;
  padding: 16px 14px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

fieldset:first-of-type {
  margin-top: 0;
}

legend {
  padding: 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

input,
select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #c6d0d8;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

select {
  cursor: pointer;
}

input:hover,
select:hover {
  border-color: #a9b7c1;
}

input:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(7, 58, 95, 0.18);
}

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

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.checks label:hover {
  border-color: #b6c3cc;
  background: var(--brand-soft);
}

.checks input {
  width: 15px;
  height: 15px;
  accent-color: var(--brand);
  cursor: pointer;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

#laminateCanvas {
  width: 100%;
  aspect-ratio: 1.65 / 1;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfdfe, #eef3f6);
}

.legend-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--brand);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.icon-btn:hover {
  background: var(--brand-soft);
  border-color: #b6c3cc;
}

.layer-table,
.result-tables table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  font-size: 12px;
}

thead th {
  color: var(--muted);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

.layer-table input,
.layer-table select {
  height: 32px;
  padding: 0 7px;
  font-size: 12.5px;
}

.remove-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.remove-btn:hover {
  color: var(--danger);
  border-color: #e0b4b4;
}

.error-line {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  margin: 8px 0 4px;
}

.run-button {
  width: 100%;
  height: 46px;
  margin-top: 18px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.05s ease;
}

.run-button:hover:not(:disabled) {
  background: var(--brand-2);
}

.run-button:active:not(:disabled) {
  transform: translateY(1px);
}

.run-button:disabled,
#exportButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Results ---------- */

.results {
  display: grid;
  gap: 20px;
  min-width: 0;
  align-content: start;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.metric {
  padding: 15px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric span {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.metric span::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot, var(--brand));
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab,
#exportButton {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.tab:hover,
#exportButton:hover:not(:disabled) {
  background: var(--brand-soft);
  border-color: #b6c3cc;
}

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

#plotCanvas {
  width: 100%;
  height: auto;
  display: block;
  padding: 14px 16px 20px;
}

.table-wrap {
  max-height: 560px;
  overflow: auto;
  padding: 16px 18px;
}

.result-tables {
  display: grid;
  gap: 18px;
}

.table-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.table-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--brand-soft);
  border-bottom: 1px solid var(--line);
}

.table-title strong {
  font-size: 13px;
  color: var(--brand);
}

.table-title span {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.table-card thead th {
  position: sticky;
  top: 0;
  background: #fff;
  box-shadow: inset 0 -1px 0 var(--line);
}

.table-card tbody td {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: #2a3744;
}

.table-card tbody tr:nth-child(even) {
  background: #fafbfc;
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 26px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.site-footer strong {
  color: var(--brand);
  font-weight: 700;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ---------- Responsive ---------- */

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

  .setup-panel {
    align-self: stretch;
  }
}

@media (max-width: 620px) {
  .topbar,
  .shell,
  .site-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand-text p {
    display: none;
  }

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