:root {
  --bg: #0f172a;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --shadow: 0 8px 24px rgba(2, 8, 23, 0.08);

  /* Stable chart placeholder sizes */
  --chart-h: 320px;
  --chart-h-mobile: 240px;

  /* Field-demo carousel viewport */
  --fd-h: 420px;
  --fd-h-mobile: 260px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: url('public/assets/f01.png') no-repeat center center fixed;
  background-size: cover;
}

/* -------------------------------------------------- */
/* SECTION TITLES: Utopia 12pt bold (every section)   */
/* -------------------------------------------------- */
.card > h2,
.card > h3,
.card > h4,
.section-header h2,
.section-header h3,
.section-header h4,
.collapsible-summary {
  font-family: "Utopia", "Utopia Std", "Utopia Regular", serif !important;
  font-size: 12pt !important;
  font-weight: 700 !important;
  letter-spacing: 0 !important;
}

/* -------------------------------------------------- */
/* HERO: main title only (Palatino)                   */
/* -------------------------------------------------- */
.hero h1{
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", "Utopia", serif;
  font-size: 30px;      /* desktop */
  font-weight: 700;
  letter-spacing: 0.4px;
  line-height: 1.1;
  margin: 0 0 6px 0;
  color: #ffffff;
  text-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
@media (max-width: 600px){
  .hero h1{ font-size: 15px; }  /* mobile */
}

/* Hero */
.hero {
  padding: 48px 20px;
  background: linear-gradient(180deg, rgba(14,165,233,0.15), rgba(14,165,233,0) 60%);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.hero__content {
  max-width: 950px;
  margin: 0 auto;
  color: #e5e7eb;
}
.subtitle {
  margin: 0;
  font-size: 18px;
  color: #cbd5e1;
}

/* Layout */
.container {
  max-width: 950px;
  margin: 24px auto;
  padding: 0 20px;
}
.card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* Forms */
.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
label span {
  display: inline-block;
  min-width: 80px;
  color: var(--muted);
}
input,
select,
button {
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.95em;
}
input,
select {
  flex: 1 1 240px;
}
button {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
button:hover {
  background: var(--primary-dark);
}
button:active {
  transform: translateY(1px);
}
.hint {
  color: var(--muted);
  margin-top: 8px;
}

/* Section header (used in non-collapsible sections if any remain) */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.actions a {
  color: var(--primary-dark);
  text-decoration: none;
}
.actions a:hover {
  text-decoration: underline;
}

/* -------------------------------------------------- */
/* DPP JSON: white background + dark gray text         */
/* -------------------------------------------------- */
.code {
  background: #ffffff !important;
  color: #3a3a3a !important;
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
  border: 1px solid #ededed;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
#jsonOut.code,
#jsonOut.json-box {
  background: #ffffff !important;
  color: #3a3a3a !important;
  max-height: 420px;
  overflow: auto;
}

/* Badges */
.badge {
  padding: 4px 8px;
  border-radius: 16px;
  color: #fff;
  font-weight: 600;
  font-size: 0.78em;
}
.b-blue { background-color: #0ea5e9; }
.b-yellow { background-color: #f59e0b; color: #000; }
.b-red { background-color: #ef4444; }
.b-purple { background-color: #8b5cf6; }

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 10px;
  overflow: hidden;
}
thead th {
  background: #f3f4f6;
  color: #111827;
  font-weight: 600;
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
}
tbody tr:hover {
  background: #f9fafb;
}

.muted { color: var(--muted); }
.hidden { display: none; }

/* Meta grid */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.meta-item {
  border: 1px solid #eef2f7;
  border-radius: 10px;
  padding: 12px;
  background: #fcfdff;
}
.meta-label {
  color: var(--muted);
  font-size: 0.85em;
  margin-bottom: 4px;
}
.meta-value {
  font-weight: 600;
}

/* Footer */
.footer {
  color: #93c5fd;
  text-align: center;
  padding: 24px 20px 40px;
  font-size: 0.9em;
}

/* Footer logo */
.footer-logo {
  margin-top: 12px;
  text-align: center;
}
.footer-logo img {
  height: 50px;
  width: auto;
  display: inline-block;
}

/* -------------------------------------------------- */
/* COLLAPSIBLE (triangle) — FIXED LEFT TITLE ALIGNMENT */
/* -------------------------------------------------- */
.collapsible { padding: 0; }

.collapsible-summary{
  list-style: none;
  cursor: pointer;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  flex-wrap: wrap;
  user-select: none;
}
.collapsible-summary::-webkit-details-marker{ display:none; }

.collapsible-summary::before{
  content: "▶";
  font-size: 12px;
  color: #555;
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}
.collapsible-summary > span{ flex: 0 1 auto; }

.collapsible-summary .legend,
.collapsible-summary .actions{
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.collapsible-body {
  padding: 0 20px 20px 20px;
}

/* Logs scroll area */
.table-scroll {
  max-height: 520px;
  overflow: auto;
  border: 1px solid #ededed;
  border-radius: 12px;
}
.table-scroll thead th {
  position: sticky;
  top: 0;
  background: #f3f4f6;
  z-index: 2;
}

/* ----------------------------------- */
/* PERFORMANCE / GRAPH STYLING (FINAL) */
/* ----------------------------------- */
.graph-wrapper {
  width: 100%;
  min-height: var(--chart-h);
  height: var(--chart-h);
  margin: 20px 0;
  position: relative;
}
.graph-wrapper canvas {
  display: block;
  width: 100% !important;
}
#uDynSection .collapsible-body,
#iCondSection .collapsible-body,
#iDynSection .collapsible-body,
#adaptiveScoreSection .collapsible-body{
  min-height: calc(var(--chart-h) + 40px);
}

/* ----------------------------------- */
/* Small loading popup */
/* ----------------------------------- */
.modal {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: rgba(15, 23, 42, 0.96);
  color: #e5e7eb;
  font-size: 0.9rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 9999;
  pointer-events: none;
}
.modal.hidden { display: none; }

/* Mobile adjustments */
@media (max-width: 600px) {
  .container {
    max-width: 100%;
    padding: 0 10px;
  }

  .card {
    padding: 10px;
    margin-bottom: 10px;
  }

  .subtitle { font-size: 13px; }

  .form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  input,
  select,
  button {
    width: 100%;
    padding: 4px 6px;
    font-size: 0.85em;
  }

  label span { min-width: auto; }

  .meta-item {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 0.85em;
  }
  .meta-label { flex: 1; font-weight: 500; }
  .meta-value { flex: 1; text-align: right; }

  #jsonOut {
    max-height: 200px;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8em;
  }

  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
  }

  th,
  td {
    white-space: nowrap;
    padding: 4px 6px;
  }

  #eventsTable { font-size: 0.8em; }

  .footer-logo img {
    height: 30px;
    width: auto;
  }

  .collapsible-summary { padding: 10px; }
  .collapsible-body { padding: 0 10px 10px 10px; }

  .graph-wrapper {
    min-height: var(--chart-h-mobile);
    height: var(--chart-h-mobile);
  }

  #uDynSection .collapsible-body,
  #iCondSection .collapsible-body,
  #iDynSection .collapsible-body,
  #adaptiveScoreSection .collapsible-body{
    min-height: calc(var(--chart-h-mobile) + 30px);
  }
}

/* ================================================== */
/* Field Demo Carousel (FIXED HEIGHT, INSIDE THE CARD) */
/* ================================================== */

#fieldDemoSection .collapsible-body{
  overflow: hidden;
}

#fieldDemoCarousel{
  position: relative;
  width: 100%;
  max-width: 100%;
  margin-top: 6px;
}

/* Fixed viewport height = prevents giant media */
#fieldDemoCarousel .carousel-viewport{
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #ededed;
  background: #fff;
  height: var(--fd-h);
  max-width: 100%;
}

#fieldDemoCarousel .carousel-track{
  display: flex;
  height: 100%;
  transition: transform 0.25s ease;
  will-change: transform;
}

#fieldDemoCarousel .carousel-slide{
  flex: 0 0 100%;
  height: 100%;
  margin: 0;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* Media fits inside the fixed viewport */
#fieldDemoCarousel img{
  flex: 1 1 auto;
  width: 100%;
  max-height: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  border: 1px solid #ededed;
  object-fit: contain;
}

/* Caption stays visible */
#fieldDemoCarousel figcaption{
  flex: 0 0 auto;
  margin-top: 8px;
  font-size: 0.92em;
  color: var(--muted);
}

/* YouTube embed fills available space */
#fieldDemoCarousel .embed-video{
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #ededed;

  /* override 16:9 trick here because we use fixed-height viewport */
  padding-top: 0;
  position: relative;
}

#fieldDemoCarousel .embed-video iframe{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Arrow buttons */
#fieldDemoCarousel .carousel-btn{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.92);
  color: #111827;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 8px 18px rgba(2, 8, 23, 0.12);
  font-size: 22px;
  line-height: 1;
}
#fieldDemoCarousel .carousel-btn:hover{ background: rgba(255,255,255,1); }
#fieldDemoCarousel .carousel-btn.prev{ left: 10px; }
#fieldDemoCarousel .carousel-btn.next{ right: 10px; }

/* Dots */
#fieldDemoSection .carousel-dots{
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
#fieldDemoSection .carousel-dot{
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.18);
  background: rgba(0,0,0,0.10);
  cursor: pointer;
}
#fieldDemoSection .carousel-dot.active{
  background: rgba(14,165,233,0.85);
  border-color: rgba(14,165,233,0.95);
}

/* Mobile tweaks */
@media (max-width: 600px){
  #fieldDemoCarousel .carousel-viewport{ height: var(--fd-h-mobile); }
  #fieldDemoCarousel .carousel-slide{ padding: 10px; }

  #fieldDemoCarousel .carousel-btn{
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
}
