/* ===================================
   CSS Variables
   =================================== */

:root {
  --bg: #f6f7fb;
  --fg: #14161a;
  --accent: #2563eb;
  --optimal: #22c55e;
  --danger: #f87171;
  --warning: #fbbf24;
  --surface: #ffffff;
  --border: #e5e7eb;
  --danger-surface: #fef2f2;
  --danger-text: #991b1b;
  --res-height: 200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --fg: #f5f7fb;
    --accent: #3b82f6;
    --optimal: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --surface: #111827;
    --border: #1f2937;
    --danger-surface: #2a0b0b;
    --danger-text: #fecaca;
  }
}

/* ===================================
   Base Styles
   =================================== */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font:
    16px/1.4 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  height: 100vh;
  overflow: auto;
}

/* ===================================
   Loading Overlay
   =================================== */

#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.3s;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

#loading-overlay img {
  width: 120px;
  margin-bottom: 24px;
}

#loading-overlay .loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app-hidden {
  display: none !important;
}

/* ===================================
   Typography
   =================================== */

h1 {
  font-size: 1.5rem;
  margin: 14px 48px;
}

.content h1 {
  text-align: center;
  margin-top: 8px;
}

h2 {
  font-size: 1.15rem;
  margin: 16px 0 8px;
}

h2 label {
  font: inherit;
}

p {
  margin: 0 0 10px;
}

.subtitle,
.arm-note {
  font-size: 0.85rem;
  opacity: 0.7;
}

.subtitle {
  margin: 0 0 20px;
  text-align: center;
}

img {
  display: block;
}

/* ===================================
   Form Elements
   =================================== */

button,
select {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

button:disabled,
select:disabled {
  opacity: 0.6;
  cursor: default;
}

select {
  border-radius: 6px;
  width: 100%;
}

input[type="range"] {
  width: 100%;
  touch-action: none;
}

/* ===================================
   Utility Classes
   =================================== */

.text-danger {
  color: var(--danger);
  font-weight: 700;
}

.warning {
  margin: 10px auto;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--danger-surface);
  color: var(--danger-text);
  font-weight: bold;
  border: 1px solid var(--border);
}

/* ===================================
   Layout & Navigation
   =================================== */

.menu-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 14px;
  font-size: 1.2rem;
  border-radius: 12px;
}

.menu-toggle.pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
  }
}

.sidebar {
  position: fixed;
  left: -260px;
  width: 250px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 80px 20px;
  transition: left 0.25s ease;
  z-index: 999;
}

.sidebar.open {
  left: 0;
}

.sun-times {
  position: absolute;
  top: 12px;
  left: 20px;
  right: 20px;
  text-align: right;
}

.sun-times svg {
  margin-right: 0.35em;
  margin-bottom: -1px;
  vertical-align: baseline;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 0;
  font-size: 1.1rem;
  color: var(--fg);
}

.menu-item.active {
  color: var(--accent);
  font-weight: bold;
}

.content {
  padding: 12px;
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.section-content {
  padding-bottom: var(--res-height);
}

/* ===================================
   Cards
   =================================== */

.card {
  background: var(--surface);
  padding: 12px;
  border-radius: 12px;
  margin: 12px auto;
  border: 1px solid var(--border);
}

.title-image {
  width: 100%;
  height: auto;
  padding: 0;
}

.card h3 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 4px 0;
  font-size: 1.05rem;
}

.card p {
  margin: 4px 0;
}

/* ===================================
   CG Scale
   =================================== */

.cg-scale {
  position: relative;
  height: 20px;
  border-radius: 10px;
  background: linear-gradient(
    to right,
    var(--danger) 0%,
    var(--warning) 10%,
    var(--optimal) 60%,
    var(--warning) 90%,
    var(--danger) 100%
  );
}

.cg-marker {
  position: absolute;
  top: -6px;
  width: 12px;
  height: 32px;
  background: var(--accent);
  border-radius: 6px;
  transform: translateX(-50%);
}

.cg-marker-secondary {
  background: var(--fg);
}

.cg-plot {
  width: 100%;
  height: auto;
  aspect-ratio: 320 / 260;
  display: block;
}

.cg-grid {
  stroke: var(--border);
}

.cg-axis {
  stroke: var(--fg);
}

.cg-label {
  fill: var(--fg);
  opacity: 0.8;
}

.cg-axis-title {
  fill: var(--fg);
  font-weight: 500;
}

.cg-envelope {
  fill: rgba(37, 99, 235, 0.15);
  stroke: var(--accent);
}

.cg-point {
  stroke: #fff;
}

.cg-point.wet {
  fill: var(--accent);
}
.cg-point.dry {
  fill: var(--fg);
}
.cg-point.out {
  fill: transparent;
  stroke: var(--danger);
}

.cg-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.85rem;
  opacity: 0.8;
}

.cg-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

.cg-legend .dot.wet {
  background: var(--accent);
}
.cg-legend .dot.dry {
  background: var(--fg);
}

/* ===================================
   Checklists
   =================================== */

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.2s,
    opacity 0.2s;
}

.checklist-item:hover {
  background: var(--bg);
}
.checklist-item.checked {
  opacity: 0.6;
}
.checklist-item.checked span {
  text-decoration: line-through;
}

.checklist-item > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checklist-item img {
  max-width: min(100%, 400px);
  max-height: 400px;
  border-radius: 6px;
  background: #fff;
}

/* ===================================
   Footer
   =================================== */

.footer {
  background: var(--surface);
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  border-top: 1px solid var(--border);
  z-index: 100;
}

.footer-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 20px;
  padding-bottom: max(16px, calc(16px + env(safe-area-inset-bottom)));
}

.footer-warnings .warning {
  margin: 6px 0 8px;
  padding: 8px 12px;
}

/* Footer mit Grid (Checklisten Progress) */
.footer-container:has(.progress-bar) {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px 12px;
  align-items: center;
}

.footer-container:has(.progress-bar) > p {
  margin: 0;
}

.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  grid-column: 1 / 3;
  grid-row: 2;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.progress-fill.complete {
  background: var(--optimal);
}

.footer-container:has(.progress-bar) > button {
  font-size: 0.95rem;
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: stretch;
}

/* ===================================
   Start Page
   =================================== */

.global-logo {
  width: 48px;
  height: 48px;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 900;
  cursor: pointer;
}

.start-section .feature-card {
  margin-top: 16px;
  width: 100%;
}

.feature-card {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.feature-card svg {
  width: 100px;
  min-height: 100px;
  flex-shrink: 0;
  padding: 20px;
  color: var(--accent);
}

.feature-card div {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.feature-card h2,
.feature-card p {
  margin: 0;
}

.feature-card h2 {
  margin-bottom: 4px;
}

.feature-card p {
  opacity: 0.7;
  font-size: 0.875rem;
}

/* ===================================
   Animation
   =================================== */

#app {
  opacity: 0;
  animation: fadeIn 0.6s ease forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

/* ===================================
   Update Toast
   =================================== */

.update-banner {
  z-index: 2000;
  background: var(--accent);
  color: #fff;
  border: 0;
}

.update-banner .footer-container,
.banner-actions {
  display: flex;
  align-items: center;
}

.update-banner .footer-container {
  justify-content: space-between;
}

.banner-actions {
  gap: 12px;
}

.update-banner button {
  background: #fff;
  color: var(--accent);
  border: 0;
  font-weight: bold;
}

.update-banner .close-btn {
  background: none;
  color: inherit;
  font-size: 1.8rem;
  font-weight: normal;
  padding: 0 4px;
  opacity: 0.8;
  line-height: 0.8;
}

/* Desktop: Sidebar permanent anzeigen */
@media (min-width: 850px) {
  .menu-toggle {
    display: none;
  }

  .sidebar {
    left: 0;
  }

  #app {
    padding-left: 250px;
  }

  .footer {
    left: 250px;
    width: calc(100% - 250px);
  }

  .global-logo {
    position: fixed;
    right: auto;
    left: 12px;
    z-index: 1001;
  }
}
