/* ===================================
   OWON Power Supply Web App - Styles
   =================================== */

/* ----- CSS Variables ----- */
:root {
  --bg: #0a0a12;
  --device-bg: #0d1117;
  --display-bg: #0a1628;
  --voltage-color: #f4d03f;
  --current-color: #5dade2;
  --on-color: #2ecc71;
  --off-color: #666;
  --cc-color: #e67e22;
  --cv-color: #27ae60;
  --text: #ffffff;
  --text-muted: #8899aa;
  --border: #1a2332;
}

/* ----- Base Reset ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ----- Device Frame ----- */
.device-frame {
  max-width: 800px;
  margin: 20px auto;
  background: linear-gradient(180deg, rgba(14, 17, 26, 0.98) 0%, rgba(16, 22, 36, 0.98) 100%),
    var(--device-bg);
  border-radius: 16px;
  border: 5px solid #1a1a2e;
  overflow: hidden;
}

/* ----- Header ----- */
.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, #1a1a2e, #12121e);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
}

.owon-logo {
  font-family: 'Orbitron', monospace;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 2px;
}

.reg {
  font-size: 12px;
  color: #888;
  margin-left: 2px;
}

.model-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.model-name {
  font-family: 'Orbitron', monospace;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  align-self: center;
  text-align: center;
}

.model-specs {
  font-size: 13px;
  color: var(--text-muted);
  align-self: center;
  text-align: center;
}

/* ----- Connect Buttons ----- */
.connection-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.connect-btn {
  padding: 10px;
  border-radius: 18px;
  border: 2px solid var(--border, #444);
  background: var(--device-bg, #181c20);
  color: #f4d03f;
  font-family: 'Orbitron', 'Inter', Arial, sans-serif;
  font-weight: 700;
  font-size: 1em;
  box-shadow: 0 2px 8px 0 rgba(44, 62, 80, 0.1), 0 1.5px 0 0 #fff1 inset;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, color 0.2s, border 0.2s;
}

.connect-btn:hover {
  background: #23282e;
  color: #ffe259;
  border-color: #f4d03f;
  box-shadow: 0 4px 16px 0 rgba(44, 62, 80, 0.18), 0 1.5px 0 0 #fff2 inset;
}

.connect-btn.ws-btn {
  color: #5dade2;
}

.connect-btn.ws-btn:hover {
  background: #23282e;
  color: #ffe259;
  border-color: #f4d03f;
  box-shadow: 0 4px 16px 0 rgba(44, 62, 80, 0.18), 0 1.5px 0 0 #fff2 inset;
}

.connect-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ----- Status Bar ----- */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ----- Indicator Badges ----- */
.indicator {
  padding: 4px 12px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  min-width: 4em;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s, background 0.15s;
  outline: none;
}

.indicator:focus {
  box-shadow: 0 0 0 2px #fff2, 0 0 0 4px #27ae60aa;
}

.indicator:hover {
  box-shadow: 0 2px 8px #0004;
  filter: brightness(1.1);
}

.indicator-disabled {
  pointer-events: none;
  opacity: 0.6;
  filter: grayscale(0.5);
}

.indicator-on {
  background: var(--on-color);
  color: #000;
  box-shadow: 0 0 12px var(--on-color);
}

.indicator-off {
  background: #c0392b;
  color: #fff;
  box-shadow: 0 0 8px #c0392b88;
}

.mode-badge {
  display: inline-block;
  font-family: 'Share Tech Mono', monospace;
  color: var(--voltage-color);
  font-weight: 600;
  font-size: 18px;
  background: none;
  border-radius: 4px;
  text-align: center;
  padding: 0 6px;
  min-width: 3em;
  width: 3em;
}

.mode-badge.cc {
  background: var(--cc-color);
  color: #000;
}

.mode-badge.cv {
  background: var(--cv-color);
  color: #000;
}

.timer {
  font-family: 'Share Tech Mono', monospace;
  font-size: 24px;
  color: #5dade2;
}

.power-display {
  font-family: 'Share Tech Mono', monospace;
  font-size: 18px;
  color: var(--on-color);
}

.power-display .unit {
  font-size: 14px;
  font-weight: bold;
  color: var(--text-muted);
  margin-left: 2px;
}

.prot-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 13px;
  background: #e74c3c;
  color: #fff;
}

.prot-badge.hidden {
  display: none;
}

/* ----- Display Area ----- */
.display-area {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
}

/* ----- Chart Panel ----- */
.chart-panel {
  display: flex;
  align-items: stretch;
  background: transparent;
  border-radius: 8px;
  padding: 8px;
}

.chart-y-labels,
.chart-y-labels-right {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 11px;
}

.chart-y-labels-right {
  text-align: right;
}

.y-label {
  font-weight: 600;
}

.voltage-label {
  color: var(--voltage-color);
}

.current-label {
  color: var(--current-color);
}

.chart-container {
  flex: 1;
  position: relative;
  height: 200px;
  background: transparent;
  border-radius: 4px;
}

#chartVC {
  width: 100%;
  height: 100%;
  position: relative;
}

#chartVC canvas {
  width: 100% !important;
  height: 100% !important;
  background: transparent !important;
}

.chart-x-label {
  align-self: flex-end;
  font-size: 11px;
  color: var(--text-muted);
  padding-left: 8px;
}

/* ----- Readings Panel ----- */
.readings-panel {
  display: flex;
  justify-content: space-around;
  padding: 4px 0;
  gap: 10px;
  flex-wrap: wrap;
}

.reading {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: fit-content;
}

.reading-value {
  font-family: 'Share Tech Mono', monospace;
  font-size: 56px;
  font-weight: 400;
  letter-spacing: 2px;
}

.reading-unit {
  font-family: 'Share Tech Mono', monospace;
  font-size: 28px;
  font-weight: 400;
}

.voltage-reading .reading-value,
.voltage-reading .reading-unit {
  color: var(--voltage-color);
}

.current-reading .reading-value,
.current-reading .reading-unit {
  color: var(--current-color);
}

.multimeter-reading .reading-value,
.multimeter-reading .reading-unit {
  color: #ffdc00;
  margin: 6px 0 0 0;
  /* font-size: 15px; */
  text-align: center;
  font-family: 'Share Tech Mono', monospace;
  min-height: 1.5em;
}

/* ----- Multimeter Section ----- */
.multimeter-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.multimeter-section label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.multimeter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mm-func-btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  background: #2a3a4a;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}

.mm-func-btn:hover {
  background: #3a4a5a;
}

/* ----- Multimeter Slider Icons ----- */
.mm-slider-icons {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 0 0 2px 0;
  padding: 0;
  flex-wrap: wrap;
}

.mm-slider-icons span {
  flex: 1 1 0;
  min-width: 32px;
  max-width: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
  opacity: 0.5;
  color: #665c1a;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s, color 0.2s, transform 0.2s;
}

.mm-slider-icons span svg {
  width: 100%;
  height: auto;
  max-width: 80px;
  min-width: 20px;
  aspect-ratio: 1.5 / 1;
  display: block;
  margin: 0 auto;
  transition: width 0.2s, height 0.2s;
}

.mm-slider-icons span.disabled {
  opacity: 0.2;
  cursor: not-allowed;
  pointer-events: none;
}

.mm-slider-icons span.active {
  opacity: 1;
  transform: scale(1.2);
  color: var(--on-color);
  background: none;
  border-radius: 0;
  box-shadow: none;
}

.mm-slider-icons span.active svg {
  filter: drop-shadow(0 0 8px #ffdc00) drop-shadow(0 0 16px #ffdc00);
}

/* ----- Multimeter Slider Row ----- */
.mm-slider-row {
  display: none;
}

#mm-func-slider {
  width: 180px;
  accent-color: #27ae60;
  height: 4px;
  border-radius: 4px;
}

#mm-func-label {
  min-width: 80px;
  font-weight: 600;
  font-size: 14px;
  color: var(--on-color);
  text-align: center;
  letter-spacing: 1px;
}

#mm-func-send {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  background: #2a3a4a;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}

#mm-func-send:hover {
  background: #3a4a5a;
}

/* ----- Visually Hidden (Accessibility) ----- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ----- Settings Panel ----- */
.settings-panel {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
}

.settings-table th {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 12px;
  text-align: center;
}

.settings-table td {
  padding: 8px;
  vertical-align: middle;
}

.col-voltage {
  color: var(--voltage-color);
}

.col-current {
  color: var(--current-color);
}

.row-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  padding-right: 16px;
  white-space: nowrap;
}

.set-input,
.limit-input {
  width: 120px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #2a3a4a;
  background: #0d1825;
  font-family: 'Share Tech Mono', monospace;
  font-size: 20px;
  text-align: right;
}

.voltage-input {
  color: var(--voltage-color);
}

.current-input {
  color: var(--current-color);
}

.param-unit {
  font-family: 'Share Tech Mono', monospace;
  font-size: 20px;
  color: var(--text-muted);
  display: inline-block;
  width: 18px;
  text-align: left;
  margin-left: 6px;
}

.value-cell {
  white-space: nowrap;
  text-align: center;
  min-width: 160px;
}

.value-cell input,
.value-cell span,
.value-cell button {
  display: inline-block;
  vertical-align: middle;
}

.send-btn {
  padding: 6px 10px;
  border-radius: 4px;
  border: none;
  background: #2a3a4a;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  margin-left: 4px;
}

.send-btn:hover {
  background: #3a4a5a;
}

/* ----- Mode Row ----- */
.mode-row {
  border-top: 1px solid var(--border);
  font-size: 18px;
  color: var(--text-muted);
}

.mode-cell {
  text-align: center;
  padding: 8px 18px;
}

/* ----- Multimeter Info Display ----- */
.mm-info {
  display: inline-block;
  font-family: 'Share Tech Mono', monospace;
  color: var(--voltage-color);
  font-weight: 600;
  min-width: auto;
  font-size: 18px;
}

.mode-separator {
  color: var(--border);
  font-size: 18px;
}

.status-separator {
  color: var(--border);
}

.mm-range {
  display: inline-block;
  font-family: 'Share Tech Mono', monospace;
  color: var(--text-muted);
  font-size: 18px;
}

/* ----- Output Control ----- */
.output-control {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.output-btn {
  width: 100%;
  max-width: 300px;
  padding: 14px 24px;
  border-radius: 8px;
  border: 2px solid;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.output-btn.off {
  background: linear-gradient(180deg, #c0392b, #922b21);
  border-color: #922b21;
  color: #fff;
  box-shadow: 0 0 10px rgba(192, 57, 43, 0.3);
}

.output-btn.on {
  background: linear-gradient(180deg, #27ae60, #1e8449);
  border-color: var(--on-color);
  color: #fff;
  box-shadow: 0 0 20px rgba(46, 204, 113, 0.4);
}

.output-btn:hover {
  transform: scale(1.02);
}

.output-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

/* ----- Control Drawer ----- */
.control-drawer {
  max-width: 800px;
  margin: 0 auto 20px;
  background: linear-gradient(180deg, rgba(14, 17, 26, 0.98) 0%, rgba(16, 22, 36, 0.98) 100%),
    var(--device-bg);
  border-radius: 16px;
  border: 5px solid #1a1a2e;
  overflow: hidden;
}

.control-drawer summary {
  padding: 12px 20px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
}

.control-drawer summary::-webkit-details-marker {
  display: none;
}

.control-drawer summary::before {
  content: '▶ ';
  font-size: 10px;
}

.control-drawer[open] summary::before {
  content: '▼ ';
}

.drawer-content {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ----- Info Grid ----- */
.info-grid {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-item label {
  font-size: 12px;
  color: var(--text-muted);
}

.info-item span {
  font-size: 14px;
  color: var(--text);
}

/* ----- Poll/Chart/Raw Sections ----- */
.poll-section,
.chart-controls,
.raw-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.poll-section label,
.chart-controls label,
.raw-section label {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 100px;
}

.poll-section input,
.chart-controls input,
.raw-section input {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #2a3a4a;
  background: #0d1825;
  color: var(--text);
  font-size: 14px;
}

.poll-section input[type='number'],
.chart-controls input[type='number'] {
  width: 80px;
}

.raw-section input {
  flex: 1;
  min-width: 200px;
}

.poll-section button,
.chart-controls button,
.raw-section button {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  background: #2a3a4a;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
}

.poll-section button:hover,
.chart-controls button:hover,
.raw-section button:hover {
  background: #3a4a5a;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ----- Log Section ----- */
.log-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-section label {
  font-size: 13px;
  color: var(--text-muted);
}

#logOutput {
  height: 150px;
  overflow: auto;
  background: #050d18;
  border: 1px solid #1a2838;
  border-radius: 6px;
  padding: 10px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 12px;
  color: #6a8a9a;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ----- Responsive Design ----- */
@media (max-width: 600px) {
  .device-frame {
    margin: 10px;
    border-radius: 12px;
  }

  .device-header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .owon-logo {
    font-size: 22px;
  }

  .model-name {
    font-size: 18px;
  }

  .reading-value {
    font-size: 36px;
  }

  .reading-unit {
    font-size: 20px;
  }

  .chart-container {
    height: 150px;
  }

  .settings-table {
    font-size: 12px;
  }

  .set-input,
  .limit-input {
    width: 80px;
    font-size: 20px;
    padding: 6px;
  }
}

/* ----- Form Element Styles ----- */
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

input[type='number'] {
  -moz-appearance: textfield;
}

/* ----- Scrollbar Styling ----- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #0a1420;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb {
  background: #2a3a4a;
  border-radius: 5px;
  border: 2px solid #0a1420;
}

::-webkit-scrollbar-thumb:hover {
  background: #3a4a5a;
}

::-webkit-scrollbar-corner {
  background: #0a1420;
}

