/* dRehmFlight PWA Configurator — BF/INAV-style layout, dRehmFlight theme */

:root {
  --bg-body: #2a2a2a;
  --bg-header: #1a1a1e;
  --bg-sidebar: #222222;
  --bg-content: #303030;
  --bg-panel: #3a3a3a;
  --red: #cc0000;
  --red-bright: #e60000;
  --red-dark: #990000;
  --text: #e0e0e0;
  --text-dim: #999999;
  --text-muted: #666666;
  --green: #59aa29;
  --yellow: #ffa502;
  --border: #444444;
  --radius: 6px;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ─── */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-header);
  border-bottom: 1px solid #333;
  min-height: 72px;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-jet {
  width: 72px;
  height: 64px;
}

.logo-name {
  color: #ffffff;
}

.logo-vtol {
  color: var(--red);
  font-weight: 900;
  letter-spacing: 1px;
  margin-left: 2px;
}

.header-sub {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sub-label {
  opacity: 0.6;
}

.configurator-version {
  font-family: var(--mono);
  color: var(--text-dim);
}

.fc-info {
  font-family: var(--mono);
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Connection badge */

.conn-badge {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.conn-badge.disconnected {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.conn-badge.connected {
  background: rgba(89, 170, 41, 0.15);
  color: var(--green);
}

.conn-badge.reconnecting {
  background: rgba(255, 180, 40, 0.18);
  color: #ffb428;
  animation: pulse-badge 0.8s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Port selector */

.port-select {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 0.82rem;
  font-family: var(--mono);
  cursor: pointer;
  outline: none;
  min-width: 140px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.port-select:focus {
  border-color: var(--red);
}

.port-select:disabled {
  opacity: 0.5;
  cursor: default;
}

.port-select option {
  background: var(--bg-panel);
  color: var(--text);
}

/* Connect button */

.btn-connect {
  background: var(--red);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-connect:hover:not(:disabled) {
  background: var(--red-bright);
}

.btn-connect:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ─── Log panel ─── */

.log-panel {
  background: #1e1e24;
  border-bottom: 1px solid #333;
  position: relative;
  min-height: 24px;
}

.log-content {
  max-height: 72px;
  overflow-y: auto;
  padding: 6px 90px 6px 12px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.log-panel.collapsed .log-content {
  display: none;
}

.log-toggle {
  position: absolute;
  top: 6px;
  right: 26px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  font-family: inherit;
}

.log-toggle:hover {
  color: var(--text);
}

/* ─── App body: sidebar + content ─── */

.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Sidebar ─── */

.sidebar {
  width: 160px;
  min-width: 160px;
  background: var(--bg-sidebar);
  border-right: 3px solid var(--red);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}

.hidden {
  display: none !important;
}

.sidebar.hidden {
  display: none;
}

.sidebar .tab {
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-dim);
  padding: 12px 16px;
  text-align: left;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar .tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.sidebar .tab.active {
  color: #ffffff;
  background: rgba(204, 0, 0, 0.2);
  border-left-color: var(--red);
}

/* ─── Main content ─── */

main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-content);
  display: flex;
  flex-direction: column;
}

/* Tab content visibility */

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Terminal tab fills main area as flex column (default vertical) */
#tab-terminal.active {
  display: flex;
  flex-direction: column;
  height: 100%;
}


/* ─── Panels (BF-style gui_box with floating title) ─── */

.panel {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px 16px;
  margin-bottom: 16px;
}

.panel-title {
  position: absolute;
  top: -10px;
  left: 16px;
  background: var(--red);
  color: white;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 12px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-clear-term {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: none;
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn-clear-term:hover {
  color: white;
}

/* ─── Status grid ─── */

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-item label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-item .val {
  font-size: 1.3rem;
  font-weight: 600;
  font-family: var(--mono);
}

.val.armed {
  color: var(--red);
}

.val.disarmed {
  color: var(--green);
}

/* ─── RC Channel bars ─── */

.channel-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ch-name {
  width: 70px;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

.ch-bar {
  flex: 1;
  height: 22px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.ch-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.15);
}

.ch-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.15s ease-out;
  min-width: 2px;
}

/* BF-style distinct channel colors */
.ch-fill.ch-1 { background: #f1453d; }
.ch-fill.ch-2 { background: #673fb4; }
.ch-fill.ch-3 { background: #2b98f0; }
.ch-fill.ch-4 { background: #1fbcd2; }
.ch-fill.ch-5 { background: #50ae55; }
.ch-fill.ch-6 { background: #ffa502; }

.ch-value {
  width: 50px;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
}

/* ─── Sensor sub-tabs ─── */

.sensor-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.sensor-subtabs {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 3px;
  width: fit-content;
}

.sensor-refresh-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sensor-subtab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.sensor-subtab:hover {
  color: var(--text);
}

.sensor-subtab.active {
  background: var(--red);
  color: white;
}

/* ─── Sensor graphs ─── */

.graph-panel {
  position: relative;
}

.graph-row {
  display: flex;
  gap: 12px;
}

.sensor-canvas {
  flex: 1;
  height: 140px;
  min-width: 0;
  display: block;
  border-radius: 4px;
  background: #0a0a15;
}

.graph-sidebar {
  width: 110px;
  min-width: 110px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.graph-scale-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.graph-scale-label {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.graph-scale-select {
  flex: 1;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  font-family: var(--mono);
  font-size: 0.75rem;
  outline: none;
  cursor: pointer;
}

.graph-scale-select:focus {
  border-color: var(--red);
}

.graph-val {
  display: flex;
  align-items: center;
  gap: 4px;
}

.graph-val span:last-child {
  font-weight: 600;
  color: var(--text);
}

.legend-x { color: #f1453d; font-weight: 700; }
.legend-y { color: #59aa29; font-weight: 700; }
.legend-z { color: #2b98f0; font-weight: 700; }

/* ─── Sensor readouts ─── */

.sensor-axes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.sensor-axis {
  text-align: center;
  padding: 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
}

.sensor-axis label {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.sensor-axis .val {
  font-size: 1.2rem;
  font-family: var(--mono);
  font-weight: 600;
  display: block;
}

.sensor-axis .unit {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

/* ─── Status bar (footer) ─── */

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: var(--bg-header);
  border-top: 1px solid #333;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.status-bar.hidden {
  display: none;
}

.status-bar.stale {
  opacity: 0.35;
}

.status-bar strong {
  color: var(--text);
  font-weight: 600;
}

.status-bar .sep {
  color: var(--text-muted);
  margin: 0 2px;
}

.status-bar .spacer {
  flex: 1;
}

/* ─── Link quality indicator ─── */

.link-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.link-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.link-indicator.active .link-dot { background: var(--green); }
.link-indicator.active .link-label { color: var(--green); }

.link-indicator.stale .link-dot {
  background: var(--yellow);
  animation: pulse-link 1s ease-in-out infinite;
}
.link-indicator.stale .link-label { color: var(--yellow); }

.link-indicator.dead .link-dot {
  background: var(--red-bright);
  animation: pulse-link 0.5s ease-in-out infinite;
}
.link-indicator.dead .link-label { color: var(--red-bright); }

@keyframes pulse-link {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─── Terminal ─── */

.terminal-panel {
  padding-bottom: 0;
}

.terminal {
  background: #0a0a15;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow: hidden;
}

.terminal-output {
  height: 280px;
  overflow-y: auto;
  padding: 12px;
  white-space: pre-wrap;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.terminal-input-row {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
}

.terminal-prompt {
  padding: 8px 4px 8px 12px;
  color: var(--red);
  font-weight: 700;
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: inherit;
  padding: 8px;
  outline: none;
}

.terminal-input::placeholder {
  color: var(--text-muted);
}

/* ─── Settings Editor ─── */

.settings-panel {
  padding-bottom: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.settings-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.btn-settings {
  background: var(--bg-content);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-settings:hover {
  background: var(--border);
}

.btn-settings.btn-save {
  background: var(--red-dark);
  border-color: var(--red);
  color: white;
}

.btn-settings.btn-save:hover {
  background: var(--red);
}

.settings-form {
  flex: 1;
  overflow-y: auto;
  min-height: 120px;
  background: #0a0a15;
  border-radius: var(--radius);
  padding: 12px;
}

.settings-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 20px 0;
  text-align: center;
}

.settings-group {
  margin-bottom: 14px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group-title {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.param-row {
  display: flex;
  align-items: center;
  padding: 3px 0 3px 8px;
  border-left: 2px solid transparent;
  transition: border-color 0.15s;
  max-width: 340px;
}

.param-row.dirty {
  border-left-color: var(--yellow);
}

.param-label {
  width: 160px;
  min-width: 160px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
}

.param-input {
  width: 120px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 3px 8px;
  text-align: right;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.param-input::-webkit-inner-spin-button,
.param-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.param-input:focus {
  border-color: var(--red);
}

/* Placeholder */

.placeholder {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 40px 0;
}

/* ─── Responsive ─── */

@media (max-width: 700px) {
  header {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  .header-left {
    align-items: center;
  }

  .header-right {
    justify-content: center;
  }

  .sidebar {
    width: 50px;
    min-width: 50px;
  }

  .sidebar .tab {
    font-size: 0;
    padding: 14px 0;
    text-align: center;
  }

  /* Show first letter only on narrow screens */
  .sidebar .tab::first-letter {
    font-size: 0.85rem;
  }

  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .sensor-axes {
    grid-template-columns: 1fr;
  }

  .ch-name {
    width: 50px;
    font-size: 0.75rem;
  }
}
