:root {
  --bg: #ffffff;
  --bg-light: #f8f9fa;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --primary: #1f73e6;
  --primary-hover: #1765cc;
  --danger: #d33b27;
  --danger-hover: #ba3823;
  --ok: #188038;
  --warn: #f57c00;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.12);
  --section-title-bg: rgba(31, 115, 230, 0.12);
  --section-title-border: rgba(31, 115, 230, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg-light);
  line-height: 1.5;
  overflow-x: hidden;
  max-width: 100vw;
}

html {
  overflow-x: hidden !important;
  max-width: 100vw;
  width: 100vw;
  position: relative;
  overscroll-behavior-x: none;
}

body {
  overflow-x: hidden !important;
  max-width: 100vw;
  width: 100vw;
  position: relative;
}

@media (max-width: 800px) {
  html, body {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative;
  }
  #app, .app-shell, main, .page-bg, .modal-backdrop, .modal-panel {
    max-width: 100vw !important;
    width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box;
  }
}

@viewport {
  width: device-width;
  viewport-fit: cover;
}
}
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg-light);
}

  .app-shell {
    width: min(1200px, 100vw);
    margin: 1rem auto 0;
    display: grid;
    gap: 0.5rem;
    max-width: 100vw;
  }
}

.hero {
  padding: 0;
  animation: rise 500ms ease-out;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.5px;
}

.hero p {
  margin: 0.5rem 0 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
  white-space: nowrap;
}

.hero-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hero-title-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.hero-logo {
  width: 128px;
  height: 128px;
}

.locale-switcher {
  display: flex;
  gap: 0.4rem;
  position: relative;
}

.locale-auth-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.auth-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.auth-user-text {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-btn {
  min-width: 2rem;
  height: 2rem;
  font-size: 0.95rem;
}

.locale-btn {
  min-width: 2.2rem;
  padding: 0.3rem;
  font-size: 1.1rem;
  border: 1px solid var(--border);
}

.locale-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(31, 115, 230, 0.12);
}

.menu-btn {
  min-width: 2.2rem;
  padding: 0.3rem;
  border: 1px solid var(--border);
}

.menu-btn svg {
  display: block;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 170px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-hover);
  padding: 0.25rem;
  z-index: 20;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  color: var(--text);
  cursor: pointer;
}

.menu-item:hover {
  background: rgba(31, 115, 230, 0.08);
}

.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-panel {
  width: min(560px, calc(min(1200px, 95vw) - 2rem));
  max-width: 100%;
  max-height: 80vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-hover);
  padding: 1rem;
}

.modal-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.modal-panel h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.modal-panel p {
  margin: 0.45rem 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.modal-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: var(--shadow);
  animation: rise 500ms ease-out;
}

.panel h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  font-weight: 500;
  background: var(--section-title-bg);
  border: 1px solid var(--section-title-border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

.profile-controls {
  display: grid;
  grid-template-columns: 1.25fr 1fr auto;
  gap: 0.5rem;
}

.profile-actions {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

#saveProfileBtn {
  margin-left: 0;
}

#saveProfileBtn svg {
  width: 1rem;
  height: 1rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#deleteProfileBtn {
  grid-column: 3;
  justify-self: end;
}

.status-text {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  align-self: center;
  flex: 1;
  text-align: center;
}

.grid-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

input,
select,
button {
  font: inherit;
  letter-spacing: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 200ms, box-shadow 200ms;
}

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

input:focus,
select:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 115, 230, 0.1);
}

.btn {
  border: 0;
  border-radius: 4px;
  padding: 0.625rem 1rem;
  background: #f8f9fa;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 200ms, box-shadow 200ms, color 200ms;
  border: 1px solid var(--border);
}

.btn:hover {
  background: #f1f3f4;
  box-shadow: var(--shadow-hover);
}

.btn:disabled,
.btn[disabled] {
  background: #e5e7eb;
  color: #9ca3af;
  border-color: #d1d5db;
  cursor: not-allowed;
  opacity: 1;
  box-shadow: none;
  filter: grayscale(100%);
}

.btn:disabled:hover,
.btn[disabled]:hover {
  background: #e5e7eb;
  color: #9ca3af;
  box-shadow: none;
}

.btn.accent {
  background: var(--primary);
  color: #fff;
  border: 0;
}

.btn.accent:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-hover);
}

.btn.danger {
  background: #f8f9fa;
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn.danger.btn-icon {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f5e8e6;
}

.btn.danger:hover {
  background: #fce4e1;
  box-shadow: var(--shadow-hover);
}

.btn.danger:disabled,
.btn.danger[disabled] {
  background: #e5e7eb;
  color: #9ca3af;
  border-color: #d1d5db;
}

.btn.small {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}

.btn-icon {
  min-width: 2rem;
  padding: 0.4rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.heading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.aircraft-entries-heading {
  margin-top: 1.5rem;
}

.aircraft-entries-heading h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
}

.table-wrap {
  overflow-x: auto;
}

.permanent-stations {
  margin-top: 1rem;
}

.permanent-stations summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  background: var(--section-title-bg);
  border: 1px solid var(--section-title-border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
}

.aircraft-setup summary {
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: -0.75rem -0.75rem 0.75rem -0.75rem;
  padding: 0.75rem;
  list-style: none;
  background: var(--section-title-bg);
  border-bottom: 1px solid var(--section-title-border);
}

.aircraft-setup-title {
  line-height: 1.2;
}

.setup-toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.setup-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.setup-toggle-track {
  position: relative;
  width: 2.2rem;
  height: 1.25rem;
  border-radius: 999px;
  background: #cbd5e1;
  border: 1px solid #b6c2d2;
  transition: background 160ms ease, border-color 160ms ease;
}

.setup-toggle-track::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 160ms ease;
}

.setup-toggle input:checked + .setup-toggle-track {
  background: #66a7f0;
  border-color: #4c95e7;
}

.setup-toggle input:checked + .setup-toggle-track::after {
  transform: translateX(0.95rem);
}

.setup-toggle input:focus-visible + .setup-toggle-track {
  box-shadow: 0 0 0 3px rgba(31, 115, 230, 0.18);
}

.aircraft-setup summary::-webkit-details-marker {
  display: none;
}

.aircraft-setup summary::before {
  content: "▶ ";
  display: inline-block;
  margin-right: 0.5rem;
  transition: transform 200ms ease;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.aircraft-setup[open] summary::before {
  transform: rotate(90deg);
}

.aircraft-setup.locked .grid-fields,
.aircraft-setup.locked .heading-row,
.aircraft-setup.locked .table-wrap {
  opacity: 0.6;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

th,
td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--bg-light);
}

#itemDefinitionsBody tr {
  cursor: grab;
}

#itemDefinitionsBody tr.dragging {
  opacity: 0.6;
}

tr:hover {
  background: var(--bg-light);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 1rem;
}

.result-card.span-full {
  grid-column: 1 / -1;
}

.result-card.inline-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.results-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(380px, 1.35fr);
  gap: 1.5rem;
  align-items: stretch;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.result-card span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-card strong {
  margin-top: 0.5rem;
  display: block;
  font-family: "Roboto Mono", monospace;
  font-size: 1.25rem;
  font-weight: 500;
}

.result-card.status.ok strong {
  color: var(--ok);
}

.result-card.status.warn strong {
  color: var(--warn);
}

.result-card.status.bad strong {
  color: var(--danger);
}

#envelopeCanvas {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .profile-controls {
    grid-template-columns: 1fr 1fr;
  }

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

  #envelopeCanvas {
    min-height: 260px;
  }
}

@media (max-width: 560px) {
  .hero-header {
    align-items: flex-start;
  }

  .hero p {
    white-space: normal;
  }

  .hero-title-wrap {
    gap: 0.5rem;
  }

  .hero-logo {
    width: 64px;
    height: 64px;
  }

  .grid-fields,
  .result-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .modal-backdrop {
    padding: calc(0.75rem + env(safe-area-inset-top)) calc(0.75rem + env(safe-area-inset-right)) calc(0.75rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left));
  }

  .modal-panel {
    width: min(560px, calc(100dvw - 1.5rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: 80vh;
    max-height: calc(80dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .results-layout .result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

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

  .panel {
    padding: 0.75rem 0.5rem;
  }

  .aircraft-setup summary {
    font-size: 1rem;
    margin: -0.75rem -0.5rem 0.5rem -0.5rem;
    padding: 0.65rem 0.5rem;
    line-height: 1.25;
  }

  .setup-toggle-track {
    width: 2rem;
    height: 1.15rem;
  }

  .setup-toggle-track::after {
    width: 0.85rem;
    height: 0.85rem;
  }

  .setup-toggle input:checked + .setup-toggle-track::after {
    transform: translateX(0.82rem);
  }

  table {
    font-size: 0.85rem;
  }

  th,
  td {
    padding: 0.5rem 0.25rem;
  }

  .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
  }

  .profile-controls {
    grid-template-columns: 1fr 1fr auto;
    gap: 0.4rem;
  }

  .profile-actions {
    gap: 0.4rem;
  }

  #profileName,
  #profileSelect {
    font-size: 0.875rem;
  }
}
