/* Endurance Fueling Calculator — stylesheet */
:root {
  --bg: #0f1c2c;
  --panel: #152537;
  --panel-2: #1a2c41;
  --border: #243a55;
  --text: #e8eef6;
  --text-dim: #97a8bf;
  --text-mute: #6b7d96;
  --accent: #ff8a3d;
  --accent-2: #ffb578;
  --green: #44d39a;
  --red: #ef4f5e;
  --shadow: 0 4px 16px rgba(0,0,0,.25);
  --radius: 12px;
  --space: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="light"] {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f1f4f8;
  --border: #e0e6ee;
  --text: #1a2c41;
  --text-dim: #4d6485;
  --text-mute: #8696ad;
  --shadow: 0 4px 12px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .01em; }
h2 { font-size: 1.25rem; margin-bottom: 1rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 2rem; gap: 1rem;
  border-bottom: 1px solid var(--border);
}
.title { text-align: center; flex: 1; }
.title h1 { font-size: clamp(1.1rem, 2.5vw, 1.7rem); letter-spacing: .12em; }
.brand-1 { color: var(--text); }
.brand-2 { color: var(--accent); }
.subtitle { color: var(--text-dim); font-size: .9rem; margin-top: .25rem; }

.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.lang-switch { display: flex; background: var(--panel-2); border-radius: 999px; padding: 2px; }
.lang-btn {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 6px 12px; font-size: .8rem; font-weight: 600; cursor: pointer;
  border-radius: 999px; transition: all .15s;
}
.lang-btn.active { background: var(--accent); color: #fff; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--accent); }

.container {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
  max-width: 1400px; margin: 0 auto; padding: 1.5rem;
}
@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
  .topbar { padding: 1rem; flex-wrap: wrap; }
}

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 1.5rem; }
.outputs > .panel { margin-bottom: 1.5rem; }

.field { margin-bottom: 1rem; }
.field label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .85rem; color: var(--text-dim); margin-bottom: .35rem;
  font-weight: 500;
}
.field input[type="number"], .field input[type="search"], .field select {
  width: 100%; padding: .65rem .85rem;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-size: .95rem;
  appearance: none; -webkit-appearance: none;
  font-family: inherit;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,138,61,.2);
}
.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M6 8L0 0h12z' fill='%2397a8bf'/></svg>");
  background-repeat: no-repeat; background-position: right .85rem center;
  padding-right: 2rem;
}
.row { display: flex; gap: 1rem; }
.row.two-col > * { flex: 1; min-width: 0; }
.row.two-col > .field { margin-bottom: 0; }

.unit-toggle {
  display: inline-flex; background: var(--panel-2); border-radius: 999px;
  padding: 2px; border: 1px solid var(--border);
}
.unit-toggle button {
  background: transparent; border: 0; padding: 3px 10px;
  color: var(--text-dim); font-size: .75rem; cursor: pointer;
  border-radius: 999px; font-weight: 600;
}
.unit-toggle button.active { background: var(--accent); color: #fff; }

.temp-row { display: flex; align-items: center; gap: .75rem; }
.temp-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.temp-display {
  display: inline-block; padding: .35rem .65rem;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--accent); font-weight: 600; min-width: 50px;
  text-align: center; font-size: .85rem;
}

.hint { font-size: .8rem; color: var(--text-mute); }
.hint.small { font-size: .75rem; }
.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-mute); font-size: .65rem; font-style: italic;
  cursor: help; font-weight: 700;
}

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-of-type { border-bottom: 0; }
.toggle-row label { font-size: .9rem; color: var(--text); margin: 0; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 2px; bottom: 2px;
  background: var(--text-dim); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }

.btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: .7rem 1rem; border-radius: 8px; cursor: pointer;
  font-size: .9rem; font-weight: 600; font-family: inherit;
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }

.custom-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.custom-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .75rem; background: var(--panel-2); border-radius: 6px;
  margin-bottom: .35rem; font-size: .85rem;
}
.custom-list .del { background: none; border: 0; color: var(--red); cursor: pointer; font-size: .9rem; }

/* SUMMARY */
.summary-head { display: flex; align-items: flex-start; justify-content: space-between; }
.energy { text-align: right; }
.energy .lbl { display: block; font-size: .7rem; color: var(--text-mute); letter-spacing: .1em; }
.energy-val { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.energy .small { font-size: .7rem; }

.duration-big { text-align: center; padding: 1rem 0; }
.duration-big .lbl { display: block; font-size: .75rem; color: var(--text-dim); margin-bottom: .25rem; letter-spacing: .1em; }
.duration-big #duration-display { font-size: 2.5rem; font-weight: 800; letter-spacing: .03em; }

.gauges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: .5rem; }
@media (max-width: 600px) { .gauges { grid-template-columns: 1fr; } }
.gauge { text-align: center; padding: .5rem; }
.gauge .lbl { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: .35rem; }
.gauge-svg { width: 100%; max-width: 130px; height: auto; }
.gauge-bg { fill: none; stroke: var(--panel-2); stroke-width: 8; stroke-linecap: round; }
.gauge-fg { fill: none; stroke: var(--green); stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: 157; stroke-dashoffset: 157; transition: stroke-dashoffset .4s, stroke .4s; }
.gauge.low .gauge-fg { stroke: var(--red); }
.gauge.medium .gauge-fg { stroke: var(--accent); }
.gauge.high .gauge-fg { stroke: var(--green); }
.gauge-val { fill: var(--text); font-size: 18px; font-weight: 800; }
.gauge-unit { fill: var(--text-dim); font-size: 9px; }
.gauge .target { font-size: .8rem; color: var(--text-dim); margin: .25rem 0; }

/* TIMELINE */
.panel.timeline { display: flex; flex-direction: column; }
.panel.timeline > h2 { margin: 0 0 1rem; }
.timeline-wrap { padding: 1.5rem 1rem .5rem 0; overflow-x: auto; width: 100%; }
.timeline {
  position: relative; height: 80px; min-width: 600px;
  display: flex; align-items: center;
}
.timeline-line {
  position: absolute; top: 50%; left: 0; right: 0; height: 3px;
  background: var(--panel-2); border-radius: 999px;
}
.timeline-pt {
  position: absolute; transform: translate(-50%, -50%); top: 50%;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; box-shadow: 0 2px 4px rgba(0,0,0,.3);
  z-index: 1;
}
.timeline-pt.start { background: var(--green); }
.timeline-pt.finish { background: var(--red); }
.timeline-pt .badge {
  position: absolute; top: 60%; right: -8px;
  background: #1c82ec; color: #fff; font-size: 9px;
  border-radius: 999px; padding: 1px 5px; font-weight: 700;
}
.timeline-label {
  position: absolute; transform: translateX(-50%); top: 85%;
  font-size: .7rem; color: var(--text-dim);
}

/* SCHEDULE */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.panel-actions { display: flex; gap: .5rem; }
.schedule-table-wrap { overflow-x: auto; }
#schedule-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
#schedule-table th {
  text-align: left; padding: .65rem .5rem;
  color: var(--text-mute); font-weight: 600; font-size: .7rem; letter-spacing: .1em;
  border-bottom: 1px solid var(--border);
}
#schedule-table td {
  padding: .75rem .5rem; border-bottom: 1px solid var(--border);
  color: var(--text);
}
#schedule-table td:first-child { color: var(--text-dim); font-family: ui-monospace, "SF Mono", monospace; }
#schedule-table td.num { font-weight: 600; color: var(--accent); }

/* PLAYBOOK */
.playbook-item { padding: .85rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; line-height: 1.55; color: var(--text); }
.playbook-item:last-child { border-bottom: 0; }
.playbook-item strong { color: var(--accent); }
.playbook-item.warn strong { color: var(--red); }
.playbook-item.good strong { color: var(--green); }
.disclaimer { font-size: .75rem; color: var(--text-mute); margin-top: 1rem; font-style: italic; }

.footer { text-align: center; padding: 1.5rem; color: var(--text-mute); font-size: .8rem; border-top: 1px solid var(--border); margin-top: 2rem; }

/* TOOLTIP */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip-text);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: .5rem .75rem; border-radius: 6px; font-size: .75rem; white-space: pre-line;
  width: max-content; max-width: 260px; z-index: 10; box-shadow: var(--shadow);
}

/* MOBILE — sub-batch P1.5 */

/* P1.5-1: keep the summary visible while scrolling the inputs list */
@media (max-width: 900px) {
  .panel.summary {
    position: sticky; top: 0; z-index: 5;
    max-height: 45vh; overflow-y: auto;
    background: var(--panel);
  }
}

/* P1.5-2: tighter topbar layout on narrow screens */
@media (max-width: 600px) {
  .topbar { padding: .75rem; flex-direction: column; align-items: stretch; gap: .5rem; }
  .title h1 { font-size: 1rem; letter-spacing: .06em; }
  .subtitle { font-size: .75rem; }
  .topbar-actions { justify-content: center; }
}

/* P1.5-3: schedule table collapses into stacked cards (data-label set by renderSchedule) */
@media (max-width: 600px) {
  #schedule-table thead { display: none; }
  #schedule-table, #schedule-table tbody, #schedule-table tr, #schedule-table td { display: block; width: 100%; }
  #schedule-table tr {
    border-bottom: 1px solid var(--border);
    padding: .5rem .25rem .75rem;
    margin-bottom: .25rem;
  }
  #schedule-table td { padding: .15rem .25rem; border: 0; }
  #schedule-table td:first-child {
    font-weight: 700; color: var(--accent);
    font-size: .9rem; padding-top: .25rem;
  }
  #schedule-table td:not(:first-child)::before {
    content: attr(data-label) ": ";
    color: var(--text-mute); font-size: .7rem; font-weight: 500;
    margin-right: .35rem;
  }
  /* Empty cells (e.g. fluids=0 on a gel-only event) shouldn't show a stranded "Fluids: " label */
  #schedule-table td:not(:first-child):empty { display: none; }
}

/* P1.5-7: two-column rows stack on narrow screens, full width each */
@media (max-width: 600px) {
  .row.two-col { flex-direction: column; gap: 1rem; }
  .row.two-col > * { width: 100%; }
}

/* PRINT */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .footer, .panel-actions, .inputs { display: none !important; }
  .container { grid-template-columns: 1fr; padding: 0; }
  .panel { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
}
