/* Serial Debug Dashboard — MKLink Unified Design System */
:root {
  --bg:      #f5f4ed;
  --surface: #faf9f5;
  --fg:      #141413;
  --muted:   #5e5d59;
  --dim:     #87867f;
  --border:  #e8e6dc;
  --border-subtle: #f0eee6;
  --accent:  #c96442;
  --accent-light: #d97757;
  --info:    #3898ec;
  --danger:  #b53333;
  --warn:    #b58a1b;
  --success: #2d6a4f;
  --ring:    #d1cfc5;
  --font-display: Georgia, 'Iowan Old Style', 'Charter', serif;
  --font-body:    -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'Consolas', 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 8px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Header ─── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
header h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--fg);
}
.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 100px;
  letter-spacing: 0.02em;
}
.badge-ok    { background: #e6f2ea; color: var(--success); }
.badge-warn  { background: #f5f0e1; color: var(--warn); }
.badge-info  { background: #e6eef5; color: var(--info); }
.badge-mode  { background: #f3ece6; color: var(--accent); font-weight: 600; }
.badge-off   { background: var(--border); color: var(--dim); }
.badge-danger { background: #fdf0ef; color: var(--danger); }
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ─── Port indicators ─── */
.port-indicators {
  display: flex;
  gap: 12px;
}
.port-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.port-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ring);
}
.port-dot.open { background: var(--success); }
.port-dot.error { background: var(--danger); }
.port-dot.closed { background: var(--ring); }

/* ─── Profile info bar ─── */
#profile-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 20px;
  background: var(--border-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
  flex-shrink: 0;
}
#profile-bar .profile-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
#profile-bar .profile-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#profile-bar .profile-value {
  font-family: var(--font-mono);
  color: var(--muted);
}

/* ─── Toolbar ─── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.mode-btn {
  padding: 4px 14px;
  border: none;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.mode-btn:hover { color: var(--fg); }
.mode-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.panel-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: all 0.15s;
}
.panel-btn:hover { border-color: var(--accent); color: var(--accent); }
.panel-btn.active { border-color: var(--accent); color: var(--accent); background: #f5ece6; }
.stats-bar {
  margin-left: auto;
  font-size: 12px;
  color: var(--dim);
  display: flex;
  gap: 16px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ─── Main layout ─── */
.main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Data log (virtual scroll) ─── */
.data-log {
  flex: 7;
  overflow-y: auto;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  background: var(--bg);
  position: relative;
}
.log-viewport {
  position: relative;
  width: 100%;
}
.log-line {
  padding: 2px 12px;
  border-left: 3px solid transparent;
  white-space: pre-wrap;
  word-break: break-all;
  height: 22px;
  overflow: hidden;
}
.log-line:hover { background: var(--border-subtle); }
.log-line.rx { border-left-color: var(--success); }
.log-line.tx { border-left-color: var(--info); }
.log-line.crc-error { background: #fdf0ef; border-left-color: var(--danger); }
.log-line .ts { color: var(--dim); margin-right: 8px; }
.log-line .port-tag { color: var(--accent); margin-right: 8px; font-weight: 500; }
.log-line .direction { margin-right: 8px; font-weight: 600; }
.log-line .direction.rx { color: var(--success); }
.log-line .direction.tx { color: var(--info); }
.log-line .decoded {
  color: var(--accent);
  margin-left: 12px;
  font-size: 11px;
  opacity: 0.85;
}
.log-line .unit { color: var(--dim); font-size: 10px; }
.log-line .crc-badge {
  margin-left: 8px;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
}
.log-line .crc-badge.ok { background: #e6f2ea; color: var(--success); }
.log-line .crc-badge.fail { background: #fdf0ef; color: var(--danger); }

/* Log highlight classes */
.log-line.hl-error { background: #fdf0ef; }
.log-line.hl-warn { background: #fdf8e8; }
.log-line.hl-ok { background: #edf7f0; }

/* ─── Right panel ─── */
.right-panel {
  flex: 3;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
  min-width: 280px;
}
.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.panel-section:last-child { border-bottom: none; }
.panel-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 10px;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.panel-section.collapsed .panel-body { display: none; }
.panel-section h3 { cursor: pointer; user-select: none; }

/* ─── Form controls ─── */
.send-row {
  display: flex;
  gap: 6px;
}
.send-input, .filter-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.15s;
}
.send-input:focus, .filter-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(201,100,66,0.1);
}
.btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}
.btn:hover { background: var(--accent-light); }
.btn.secondary {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #d04040; }
.btn.success { background: var(--success); color: #fff; }
.btn.success:hover { background: #358a5f; }
.hex-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.port-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.cmd-list {
  max-height: 180px;
  overflow-y: auto;
}
.cmd-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
}
.cmd-item .cmd-text {
  flex: 1;
  font-family: var(--font-mono);
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cmd-item .btn { padding: 2px 8px; font-size: 11px; }
.auto-send-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.interval-input {
  width: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  text-align: center;
}
.filter-row {
  display: flex;
  gap: 6px;
}

/* ─── Auto-reply rules ─── */
.auto-reply-list {
  font-size: 12px;
  color: var(--muted);
  max-height: 160px;
  overflow-y: auto;
}
.auto-reply-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
}
.auto-reply-item .rule-desc {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auto-reply-item .rule-match {
  color: var(--info);
}
.auto-reply-item .rule-reply {
  color: var(--success);
}
.auto-reply-add {
  margin-top: 8px;
}
.auto-reply-add .send-row { margin-bottom: 4px; }

/* ─── Logger panel ─── */
.logger-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.logger-controls select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.logger-status {
  font-size: 11px;
  color: var(--dim);
  margin-top: 6px;
  font-family: var(--font-mono);
}
.logger-status.active { color: var(--success); }

/* ─── Send file ─── */
.send-file-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
