:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #13212f;
  --muted: #5a6673;
  --border: #dde3ec;
  --accent: #0d6efd;
  --good: #1f8f4e;
  --warn: #d98604;
  --live: #ce2b37;
  --bubble-h: 30px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #e8eef6 0%, var(--bg) 45%, #eef3fa 100%);
  color: var(--text);
}

.app {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 0.35rem 0.9rem 2.5rem;
}

.hero {
  padding: 0.05rem 0.2rem 0.25rem;
}

.hero h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.02em;
}

.hero p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 4px 14px rgba(20, 35, 60, 0.05);
}

#controls {
  display: grid;
  gap: 0.5rem;
}

.field {
  display: grid;
  gap: 0.25rem;
}

.field label,
.field-title {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.inline-field .field-title {
  min-width: 72px;
  flex: 0 0 72px;
  text-align: right;
}

.inline-field .radio-group {
  flex: 1;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.inline-delay {
  flex-wrap: nowrap;
  justify-content: space-between;
  width: 100%;
  gap: 0.4rem;
}

.delay-left {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.delay-left .field-title {
  min-width: 72px;
  flex: 0 0 72px;
  text-align: right;
}

.delay-value {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  height: var(--bubble-h);
  padding: 0 0.5rem;
  display: inline-flex;
  align-items: center;
}

.delay-value.delay-warning {
  background: #fff6db;
  border-color: #e0b24d;
}

.delay-value.delay-danger {
  background: #fdeaea;
  border-color: #d92d20;
  color: #8f1d1d;
}

.delay-right {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  min-width: 0;
}

select,
input:not([type="radio"]),
button {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  font-size: 1rem;
  min-height: 44px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  color: var(--text);
}

button {
  background: #f7f9fd;
  font-weight: 650;
  cursor: pointer;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  height: var(--bubble-h);
  padding: 0 0.62rem;
  font-size: 0.68rem;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
}

.radio-option input[type="radio"] {
  margin: 0;
  width: 14px;
  height: 14px;
}

.radio-option:has(input[type="radio"]:checked) {
  border-color: #3b82f6;
  background: #dbeafe;
  color: #1e3a8a;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.live-on {
  border-color: #3b82f6;
  background: #dbeafe;
  color: #1e3a8a;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.live-off {
  color: #4a5a6a;
}

.alarm-panel .kicker {
  margin: 0;
  font-size: 0.84rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

.alarm-panel {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

.alarm-row {
  margin-top: 0;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.alarm-options {
  display: flex;
  justify-content: center;
  flex: 1;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-size: 0.86rem;
  color: #4a5a6a;
  user-select: none;
  white-space: nowrap;
  line-height: 1;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  height: var(--bubble-h);
  padding: 0 0.65rem;
  cursor: pointer;
}

.toggle-line input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-line:has(input[type="checkbox"]:checked) {
  border-color: #3b82f6;
  background: #dbeafe;
  color: #1e3a8a;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.label {
  margin: 0;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.alarm-time {
  margin: 0;
  font-size: clamp(1.35rem, 6vw, 2rem);
  color: var(--live);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.alarm-subtime {
  margin: 0.02rem 0 0;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.05;
}

.clock {
  margin: 0.3rem 0 0;
  color: #234;
  font-weight: 600;
  font-size: 0.8rem;
}

.hidden {
  display: none;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: nowrap;
  position: relative;
}

.timeline-header h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.1;
}

.timeline-header-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.prep {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.timeline-live-btn {
  width: auto;
  min-height: 32px;
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.timeline {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.5rem;
}

.event {
  border: 1px solid #e2e8f0;
  border-left: 4px solid #8ea2b6;
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  background: #f8fafc;
  position: relative;
  overflow: hidden;
}

.event.target {
  border-left-color: var(--good);
  background: #effcf5;
}

.event.marker {
  border-left-color: var(--warn);
  background: #fff8ea;
}

.event.delay {
  border-left-color: #d97706;
  background: #fff3e6;
}

.event .bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(31, 143, 78, 0.17);
  width: 0;
  pointer-events: none;
  transition: width 0.8s linear;
}

.event-row {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
}

.time {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.06rem;
  font-weight: 700;
  min-width: 64px;
}

.name {
  margin: 0;
  text-align: right;
  font-weight: 600;
}

.meta {
  margin: 0.08rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
  line-height: 1.1;
  min-height: 1.1em;
  white-space: nowrap;
}

.api-status {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.15;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.api-status.status-error {
  color: #b42318;
  font-weight: 700;
}

#refreshWsf {
  width: auto;
  height: var(--bubble-h);
  min-height: var(--bubble-h);
  padding: 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}

@media (min-width: 700px) {
  #controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
