﻿:root {
      --bg: #0f1419;
      --surface: #1a2332;
      --surface2: #243044;
      --border: #2d3a4f;
      --text: #e6edf3;
      --muted: #8b949e;
      --accent: #58a6ff;
      --accent-dim: #388bfd66;
      --green: #3fb950;
      --red: #f85149;
      --yellow: #d29922;
      --branch: #a371f7;
      --leaf: #3fb950;
      --font: "Segoe UI", system-ui, sans-serif;
      --mono: "Cascadia Code", "Consolas", monospace;
      --dock-height: 200px;
      --header-h: 52px;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }

    html, body {
      height: 100%;
      overflow: hidden;
    }

    body {
      font-family: var(--font);
      background: var(--bg);
      color: var(--text);
      display: flex;
      flex-direction: column;
    }

    header {
      flex: 0 0 auto;
      padding: 0.65rem 1.25rem;
      border-bottom: 1px solid var(--border);
      background: var(--surface);
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.75rem;
    }

    header h1 {
      font-size: 1.1rem;
      font-weight: 600;
      margin-right: auto;
    }

    header h1 span { color: var(--muted); font-weight: 400; }

    .btn {
      font: inherit;
      font-size: 0.85rem;
      padding: 0.45rem 0.9rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface2);
      color: var(--text);
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s;
    }

    .btn:hover:not(:disabled) { background: var(--border); }
    .btn:disabled { opacity: 0.45; cursor: not-allowed; }
    .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
    .btn-primary:hover:not(:disabled) { background: #4393e6; }
    .btn-danger { border-color: var(--red); color: var(--red); }
    .btn-sm { font-size: 0.72rem; padding: 0.2rem 0.5rem; }
    .btn-toggle.active {
      background: #23863655;
      border-color: var(--green);
      color: var(--green);
    }

    label.inline {
      display: flex;
      align-items: center;
      gap: 0.4rem;
      font-size: 0.85rem;
      color: var(--muted);
    }

    select, input[type="number"] {
      font: inherit;
      font-size: 0.85rem;
      padding: 0.4rem 0.5rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface2);
      color: var(--text);
    }

    .status {
      font-size: 0.8rem;
      padding: 0.25rem 0.6rem;
      border-radius: 999px;
      background: var(--surface2);
    }
    .status.connected { background: #23863633; color: var(--green); }
    .status.disconnected { color: var(--muted); }
    .status.simulator { background: #8957e533; color: var(--branch); }

    .device-banner {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      gap: 0.75rem;
      padding: 0.55rem 1.25rem;
      border-bottom: 1px solid var(--border);
      font-size: 0.85rem;
    }

    .device-banner.serial {
      background: #23863618;
      border-bottom-color: #23863644;
    }

    .device-banner.simulator {
      background: #8957e518;
      border-bottom-color: #8957e544;
    }

    .device-kind {
      flex-shrink: 0;
      font-size: 0.68rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      padding: 0.25rem 0.55rem;
      border-radius: 5px;
    }

    .device-banner.serial .device-kind {
      background: #23863644;
      color: var(--green);
    }

    .device-banner.simulator .device-kind {
      background: #8957e544;
      color: var(--branch);
    }

    .device-name {
      font-weight: 600;
      font-family: var(--mono);
      font-size: 0.88rem;
    }

    .device-detail {
      color: var(--muted);
      font-size: 0.8rem;
      margin-left: auto;
    }

    .connection-select {
      font: inherit;
      font-size: 0.85rem;
      padding: 0.4rem 0.5rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface2);
      color: var(--text);
      max-width: 11rem;
    }

    #serialOptions { display: contents; }
    #serialOptions[hidden] { display: none; }

    .header-meta {
      font-size: 0.75rem;
      color: var(--muted);
    }

    header h1 a {
      color: inherit;
      text-decoration: none;
    }
    header h1 a:hover { color: var(--accent); }

    .warn-banner {
      flex: 0 0 auto;
      background: #9e6a0333;
      border-bottom: 1px solid #9e6a0355;
      color: var(--yellow);
      padding: 0.5rem 1.25rem;
      font-size: 0.82rem;
    }

    /* ---- Main layout: workspace + bottom dock ---- */

    .app-layout {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0;
    }

    .workspace {
      flex: 1;
      display: grid;
      grid-template-columns: minmax(220px, 1fr) minmax(280px, 380px);
      min-height: 0;
    }

    @media (max-width: 720px) {
      .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
    }

    .panel {
      display: flex;
      flex-direction: column;
      min-height: 0;
      border-right: 1px solid var(--border);
      background: var(--bg);
    }

    .panel:last-child { border-right: none; }

    .panel-header {
      flex: 0 0 auto;
      padding: 0.6rem 1rem;
      border-bottom: 1px solid var(--border);
      font-size: 0.8rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--muted);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.5rem;
      background: var(--surface);
    }

    .panel-header .meta {
      font-weight: 400;
      text-transform: none;
      letter-spacing: 0;
    }

    #tree {
      flex: 1;
      overflow: auto;
      padding: 0.5rem 0;
      min-height: 0;
    }

    .inspector-body {
      flex: 1;
      overflow: auto;
      min-height: 0;
      padding: 1rem;
    }

    .inspector-empty {
      color: var(--muted);
      font-size: 0.88rem;
      line-height: 1.6;
      text-align: center;
      padding: 2rem 1rem;
    }

    /* ---- Tree ---- */

    .tree-row {
      display: flex;
      align-items: center;
      gap: 0.35rem;
      padding: 0.2rem 0.75rem;
      cursor: default;
      border-radius: 4px;
      min-height: 1.75rem;
    }

    .tree-row:hover { background: var(--surface2); }
    .tree-row.selected { background: var(--accent-dim); outline: 1px solid var(--accent); }
    .tree-row.loading { opacity: 0.55; }

    .twisty {
      width: 1rem;
      text-align: center;
      color: var(--muted);
      cursor: pointer;
      flex-shrink: 0;
      font-size: 0.7rem;
    }
    .twisty.empty { visibility: hidden; }

    .node-icon { font-size: 0.75rem; flex-shrink: 0; }
    .node-icon.branch { color: var(--branch); }
    .node-icon.leaf { color: var(--leaf); }

    .node-name {
      font-family: var(--mono);
      font-size: 0.82rem;
    }
    .node-name.has-brief { color: var(--text); }

    .node-value {
      margin-left: auto;
      font-family: var(--mono);
      font-size: 0.78rem;
      color: var(--muted);
      max-width: 38%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .node-value.live { color: var(--green); }

    .node-acc {
      font-size: 0.65rem;
      padding: 0.1rem 0.35rem;
      border-radius: 3px;
      background: var(--surface2);
      color: var(--muted);
      flex-shrink: 0;
    }

    .node-brief {
      font-size: 0.72rem;
      color: var(--muted);
      margin-left: 0.25rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 7rem;
    }

    /* ---- Inspector / detail ---- */

    #detail .path-display {
      font-family: var(--mono);
      font-size: 0.82rem;
      word-break: break-all;
      margin-bottom: 0.75rem;
      color: var(--accent);
    }

    #detail h3 {
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--muted);
      margin-bottom: 0.5rem;
    }

    .detail-grid {
      display: grid;
      grid-template-columns: auto 1fr;
      gap: 0.3rem 0.75rem;
      font-size: 0.82rem;
      margin-bottom: 0.75rem;
    }

    .detail-grid dt { color: var(--muted); }
    .detail-grid dd { font-family: var(--mono); }
    .detail-grid dd.pre { white-space: pre-wrap; }

    .edit-controls {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      margin-top: 0.75rem;
      padding-top: 0.75rem;
      border-top: 1px solid var(--border);
    }

    .edit-controls label {
      font-size: 0.75rem;
      color: var(--muted);
    }

    .edit-controls textarea,
    .edit-controls input[type="number"],
    .edit-controls select,
    .edit-controls input[type="text"] {
      width: 100%;
      font-family: var(--mono);
      font-size: 0.82rem;
      padding: 0.4rem 0.6rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface2);
      color: var(--text);
    }

    .edit-controls textarea {
      min-height: 4.5rem;
      resize: vertical;
    }

    .edit-actions {
      display: flex;
      gap: 0.5rem;
      align-items: center;
      flex-wrap: wrap;
    }

    .edit-hint {
      font-size: 0.72rem;
      color: var(--muted);
    }

    .empty-state {
      padding: 2rem 1.25rem;
      color: var(--muted);
      text-align: center;
      font-size: 0.9rem;
      line-height: 1.6;
    }

    /* ---- Bottom dock ---- */

    .dock-resizer {
      flex: 0 0 5px;
      background: var(--border);
      cursor: ns-resize;
      transition: background 0.15s;
    }
    .dock-resizer:hover,
    .dock-resizer.dragging { background: var(--accent); }

    .bottom-dock {
      flex: 0 0 var(--dock-height);
      display: flex;
      flex-direction: column;
      min-height: 100px;
      max-height: 60vh;
      border-top: 1px solid var(--border);
      background: var(--surface);
    }

    .bottom-dock.collapsed {
      flex: 0 0 auto;
      max-height: none;
    }

    .bottom-dock.collapsed .dock-body { display: none; }

    .dock-header {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.35rem 0.75rem;
      border-bottom: 1px solid var(--border);
      background: var(--surface2);
    }

    .dock-tabs {
      display: flex;
      gap: 0.25rem;
    }

    .dock-tab {
      font: inherit;
      font-size: 0.78rem;
      padding: 0.3rem 0.65rem;
      border: 1px solid transparent;
      border-radius: 5px;
      background: transparent;
      color: var(--muted);
      cursor: pointer;
    }

    .dock-tab:hover { color: var(--text); background: var(--border); }
    .dock-tab.active {
      color: var(--text);
      background: var(--bg);
      border-color: var(--border);
    }

    .dock-actions {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    .dock-actions label {
      font-size: 0.72rem;
      color: var(--muted);
      display: flex;
      align-items: center;
      gap: 0.3rem;
    }

    .dock-body {
      flex: 1;
      min-height: 0;
      position: relative;
    }

    .dock-panel {
      display: none;
      flex-direction: column;
      height: 100%;
      min-height: 0;
    }

    .dock-panel.active {
      display: flex;
    }

    #log {
      flex: 1;
      overflow: auto;
      padding: 0.5rem;
      font-family: var(--mono);
      font-size: 0.72rem;
      line-height: 1.5;
      background: #0d1117;
      min-height: 0;
    }

    .log-line { white-space: pre-wrap; word-break: break-all; }
    .log-line.tx { color: var(--accent); }
    .log-line.rx { color: var(--green); }
    .log-line.err { color: var(--red); }
    .log-line.info { color: var(--muted); }
    .log-line.comment { color: #8b949e; font-style: italic; }

    /* ---- Console ---- */

    #consoleOutput {
      flex: 1;
      overflow: auto;
      padding: 0.5rem;
      font-family: var(--mono);
      font-size: 0.72rem;
      line-height: 1.5;
      background: #0d1117;
      min-height: 0;
    }

    .console-line { white-space: pre-wrap; word-break: break-all; margin-bottom: 0.35rem; }
    .console-line.cmd { color: var(--accent); }
    .console-line.ok { color: var(--green); }
    .console-line.err { color: var(--red); }
    .console-line.hint { color: var(--muted); font-style: italic; }

    .console-form {
      flex: 0 0 auto;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.45rem 0.75rem;
      border-top: 1px solid var(--border);
      background: var(--surface2);
    }

    .console-prompt {
      font-family: var(--mono);
      color: var(--green);
      font-size: 0.9rem;
      flex-shrink: 0;
    }

    .console-form input {
      flex: 1;
      font-family: var(--mono);
      font-size: 0.82rem;
      padding: 0.4rem 0.6rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--bg);
      color: var(--text);
      min-width: 0;
    }

    .console-form input:focus {
      outline: none;
      border-color: var(--accent);
    }

    .console-hint {
      flex: 0 0 auto;
      padding: 0.25rem 0.75rem 0.4rem;
      font-size: 0.68rem;
      color: var(--muted);
      font-family: var(--mono);
      border-top: 1px solid var(--border);
      background: var(--surface);
    }


.back-home {
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  padding-right: 0.7rem;
  margin-right: 0.15rem;
  border-right: 1px solid var(--border);
}
.back-home:hover {
  color: var(--text);
  text-decoration: underline;
}
