/* Theme styles are screen-only: generated diagrams keep their white paper. */
@media screen {
  #theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 20px;
    line-height: 1;
    touch-action: manipulation;
  }

  .device-photo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    background: transparent;
    border-radius: 3px;
    pointer-events: none;
    user-select: none;
  }

  .edge-toolbar {
    position: absolute;
    z-index: 8;
    top: 48px;
    left: 50%;
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    max-width: calc(100% - 24px);
    padding: 7px 9px 7px 12px;
    background: #fff;
    border: 1px solid #dfe5d7;
    border-radius: 9px;
    box-shadow: 0 4px 18px #26371c1a;
    color: #536347;
  }

  .edge-toolbar > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10px;
  }

  .edge-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; gap: 5px; }
  .edge-toolbar button, .edge-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 36px;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid #dfe5d7;
    border-radius: 6px;
    background: #f7f9f3;
    color: #536347;
    font-size: 11px;
    white-space: nowrap;
    touch-action: manipulation;
  }
  .edge-toolbar button:hover, .edge-actions button:hover { background: #edf3e3; }
  .edge-toolbar button.danger, .edge-actions button.danger {
    color: #a84139;
    border-color: #ead0ca;
    background: #fff6f3;
  }

  html[data-theme="dark"] {
    color-scheme: dark;
    color: #e2e7e1;
    background: #111613;
    --lime: #a8c879;
    --green: #b0ce8d;
    --border: #333c35;
    --muted: #a4afa0;
    --ink: #e2e7e1;
    --surface: #1b221d;
    --surface-raised: #242d26;
    --surface-input: #151c17;
    --text-secondary: #b4c0ae;
    --text-muted: #a0ad99;
  }

  html[data-theme="dark"] body { background: #111613; color: var(--ink); }
  html[data-theme="dark"] :is(.topbar,.projectbar,.editor-tabs,.editor-footer,.inspector-panel,.inspector-heading) {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--border);
  }
  html[data-theme="dark"] .library-panel,
  html[data-theme="dark"] .library-panel .panel-heading { background: #181f1a; border-color: var(--border); }
  html[data-theme="dark"] .editor-panel { background: #111613; }
  html[data-theme="dark"] .brand-symbol { color: #1f2b16; }
  html[data-theme="dark"] .beta { background: #283123; color: #bacbaa; border-color: #45513b; }
  html[data-theme="dark"] .avatar { background: #34402e; color: #c2d3af; border-color: #242e24; }
  html[data-theme="dark"] :is(.workspace-label,.top-right,.project-subtitle,.project-version,.eyebrow,.library-toolbar,.library-footer,.device-brand,.custom-device-btn small,.small-arrow,.inspector-bottom,.source-note,.no-results) {
    color: var(--text-muted);
  }
  html[data-theme="dark"] .project-icon { background: #283124 !important; color: #b6c5a7; }
  html[data-theme="dark"] .project-title { color: var(--ink); }
  html[data-theme="dark"] .status-dot { background: #91b66b; }
  html[data-theme="dark"] .tiny-square { background: #8c9d80; }
  html[data-theme="dark"] .top-right .icon-btn { border-color: #45513f; color: #bdcdb0; }
  html[data-theme="dark"] #theme-toggle { background: #2a3425; color: #d6e5b7; }
  html[data-theme="dark"] :is(.btn,.category-chip,.cable-choice) {
    background: #242e25;
    border-color: #414e3c;
    color: #d0dcc6;
  }
  html[data-theme="dark"] :is(.btn,.category-chip,.cable-choice):hover { background: #303d2a; border-color: #728b59; }
  html[data-theme="dark"] .btn.primary { background: var(--lime); border-color: #a0bf73; color: #1d2b13; }
  html[data-theme="dark"] .btn.primary:hover { background: #b6d28e; }
  html[data-theme="dark"] .btn.text-btn { border-color: transparent; background: transparent; color: #b4c4a5; }
  html[data-theme="dark"] .btn.danger {
    color: #f0a79f;
    border-color: #74504b;
    background: #382623;
  }
  html[data-theme="dark"] .btn.danger:hover { background: #4b2d28; border-color: #af756b; }
  html[data-theme="dark"] .dropdown { background: #242d26; box-shadow: 0 8px 40px #0007; }
  html[data-theme="dark"] .dropdown button { color: #dce5d6; }
  html[data-theme="dark"] .dropdown button:hover { background: #35442d; }
  html[data-theme="dark"] .count-badge { background: #303d29; color: #c0d3ac; }
  html[data-theme="dark"] .search-field { background: var(--surface-input); border-color: #43503d; }
  html[data-theme="dark"] .search-field svg { color: #a8ba99; }
  html[data-theme="dark"] .search-field input { color: #e2eadb; }
  html[data-theme="dark"] input::placeholder,
  html[data-theme="dark"] textarea::placeholder { color: #8d9c86; opacity: 1; }
  html[data-theme="dark"] .key { border-color: #46533e; color: #a5b597; }
  html[data-theme="dark"] .category-chip.active,
  html[data-theme="dark"] .cable-choice.active {
    color: #d5e7b5;
    border-color: #789757;
    background: #354728;
  }
  html[data-theme="dark"] .library-toolbar select { color: #bdcbb0; }
  html[data-theme="dark"] :is(select option,datalist option) { background: #222c24; color: #e2e8dd; }
  html[data-theme="dark"] :is(.device-list,.inspector-panel,.modal-body,.schedule-view) {
    scrollbar-color: #526149 #1b221d;
  }
  html[data-theme="dark"] .library-device { color: #e0e8d9; }
  html[data-theme="dark"] .library-device:hover { background: #263123; border-color: #4b5b40; box-shadow: 0 2px 6px #0002; }
  html[data-theme="dark"] .device-thumb { background: #30362f; border-color: #47503f; }
  html[data-theme="dark"] .device-meta span { color: #b4c4a6; border-color: #43523a; background: #25301f; }
  html[data-theme="dark"] .library-device .add-device { color: #afce8a; }
  html[data-theme="dark"] .library-device:hover .add-device { color: #d2e5b9; background: #415530; }
  html[data-theme="dark"] .custom-device-btn { color: #d5dfcb; background: #222d1f; border-color: #546847; }
  html[data-theme="dark"] .custom-device-btn > span:first-child { color: #b4cf92; }
  html[data-theme="dark"] .view-tab { color: #9fab95; }
  html[data-theme="dark"] .view-tab.active { color: #d0e0b9; }
  html[data-theme="dark"] .view-tab.active::after { background: #9dbe77; }
  html[data-theme="dark"] .validation-btn { color: #b5c7a6; }
  html[data-theme="dark"] .validation-btn.has-issues { color: #e9bc7c; }
  html[data-theme="dark"] .canvas-wrap {
    background-color: #111714;
    background-image: radial-gradient(#354338 .7px,transparent .7px);
  }
  html[data-theme="dark"] :is(.canvas-tag,.paper-tag,.canvas-help) { color: #9eae96; }
  html[data-theme="dark"] .diagram-node {
    background: #232c25;
    color: #e5ecdf;
    border-color: #4a5744;
    box-shadow: 0 3px 9px #0003;
  }
  html[data-theme="dark"] .diagram-node.selected {
    border-color: #a8ca7b;
    box-shadow: 0 0 0 2px #95ba652a,0 5px 18px #0004;
  }
  html[data-theme="dark"] .diagram-node.dragging { box-shadow: 0 10px 25px #0007; }
  html[data-theme="dark"] .node-top { border-color: #394334; }
  html[data-theme="dark"] :is(.node-category,.node-number,.node-sub) { color: #b2c1a5; }
  html[data-theme="dark"] .node-port { border-color: #232c25; box-shadow: 0 0 0 1px #809273; }
  html[data-theme="dark"] .node-port:hover { box-shadow: 0 0 0 3px #8db35866; }
  html[data-theme="dark"] .node-port.compatible { box-shadow: 0 0 0 3px #a7c77b,0 0 8px #90b75180; }
  html[data-theme="dark"] .node-port.snap-target { box-shadow: 0 0 0 7px #a5c877,0 0 16px #8ebd4b; border-color: #e6f4d6; }
  html[data-theme="dark"] .node-port.pending { box-shadow: 0 0 0 5px #9fbd645e; outline-color: #b4d183; }
  html[data-theme="dark"] .node-port::after { background: #d3dfc7; color: #1f2d17; }
  html[data-theme="dark"] .canvas .edge-label rect { fill: #222e26; stroke: #4a5a43; }
  html[data-theme="dark"] .canvas .edge-label text { fill: #d2dfc7; }
  html[data-theme="dark"] .canvas .edge-line.selected { filter: drop-shadow(0 0 4px #b7d08050); }
  html[data-theme="dark"] .canvas-legend {
    background: #202a22f2;
    border-color: #43523c;
    box-shadow: 0 2px 10px #0004;
  }
  html[data-theme="dark"] :is(.legend-title,.legend-item) { color: #c0cfb4; }
  html[data-theme="dark"] .canvas-controls { background: #232e25; border-color: #495a40; box-shadow: 0 2px 8px #0003; }
  html[data-theme="dark"] .canvas-controls button,
  html[data-theme="dark"] .canvas-controls #zoom-value { color: #c9dab9; }
  html[data-theme="dark"] .canvas-controls button:hover { background: #3b4b30; }
  html[data-theme="dark"] :is(.control-separator,.top-divider) { background: #43513b; }
  html[data-theme="dark"] .editor-footer { color: #adba9f; }
  html[data-theme="dark"] .editor-footer b { color: #d0ddc4; }
  html[data-theme="dark"] .footer-separator { color: #65755a; }
  html[data-theme="dark"] .inspector-heading span { color: #a6b69a; }
  html[data-theme="dark"] .inspector-preview {
    background: radial-gradient(ellipse at 50% 45%,#3c4538,#242d25);
    border-color: #46513e;
  }
  html[data-theme="dark"] .inspector-preview .preview-badge { color: #c2d2b1; border-color: #596b4a; background: #263220e6; }
  html[data-theme="dark"] .inspector-title p { color: #b2c0a6; }
  html[data-theme="dark"] .inspector-section { border-color: var(--border); }
  html[data-theme="dark"] :is(.section-label,.field > span,.spec-row > span:first-child,.port-spec) { color: #bac9ae; }
  html[data-theme="dark"] :is(.section-label span,.port-spec small) { color: #9eaf90; }
  html[data-theme="dark"] .field :is(input,select,textarea) {
    background: var(--surface-input);
    border-color: #4d5c42;
    color: #e0ead6;
  }
  html[data-theme="dark"] :is(input,select,textarea):focus { outline-color: #9fbd79; }
  html[data-theme="dark"] :is(button,a):focus-visible { outline-color: #b7d492; }
  html[data-theme="dark"] .spec-row strong { color: #dce7d2; }
  html[data-theme="dark"] .source-link { color: #c7ddae; background: #293822; border-color: #4b613d; }
  html[data-theme="dark"] .source-link:hover { background: #35472b; }
  html[data-theme="dark"] .shortcut { color: #b8d299; background: #334428; }
  html[data-theme="dark"] .inspector-empty { color: #b0c09f; }
  html[data-theme="dark"] .inspector-empty h3 { color: #d0e0bc; }
  html[data-theme="dark"] .inspector-empty svg { color: #819a6a; }
  html[data-theme="dark"] .cable-preview { background: #232e23; }
  html[data-theme="dark"] .cable-preview span { background: #172018; border-color: #4b5d40; }
  html[data-theme="dark"] :is(.connection-notice,.connection-status) { background: #2c3c23; color: #d0e3b7; border-color: #607b45; }
  html[data-theme="dark"] .connection-status { box-shadow: 0 3px 14px #0004; }
  html[data-theme="dark"] .connection-status button { color: #d5e4c4; background: #1e2b1b; border-color: #687e52; }
  html[data-theme="dark"] .connect-route-arrow { color: #bbd59b; }
  html[data-theme="dark"] .toast { background: #3d542d; color: #e9f3dc; box-shadow: 0 5px 25px #0006; }
  html[data-theme="dark"] .toast.error { background: #77462c; color: #fff0df; }
  html[data-theme="dark"] dialog { background: #1c251d; color: #e4ecdb; border-color: #4a5c3c; box-shadow: 0 20px 90px #0008; }
  html[data-theme="dark"] dialog::backdrop { background: #020904a6; }
  html[data-theme="dark"] :is(.modal-header,.modal-footer) { border-color: #3e4d34; }
  html[data-theme="dark"] .modal-header p { color: #b4c4a4; }
  html[data-theme="dark"] .modal-footer { background: #222e20; }
  html[data-theme="dark"] .icon-btn:hover { background: #3a4a2f; }
  html[data-theme="dark"] .help-step { color: #bacbae; }
  html[data-theme="dark"] .help-step b { color: #d7e7c5; }
  html[data-theme="dark"] .help-step > span { background: #3b502d; color: #cee5ad; }
  html[data-theme="dark"] .empty-state { color: #aebfa0; }
  html[data-theme="dark"] .empty-state > span { color: #9dbd75; }
  html[data-theme="dark"] .empty-state h2 { color: #d2e3bc; }
  html[data-theme="dark"] .schedule-view { background: #151e16; }
  html[data-theme="dark"] .schedule-header p { color: #b1c39e; }
  html[data-theme="dark"] .cable-table { background: #1e291f; border-color: #43543a; }
  html[data-theme="dark"] .cable-table th { background: #2f3f27; color: #c3d8ad; }
  html[data-theme="dark"] .cable-table td { border-color: #3b4b32; color: #d1dfc4; }
  html[data-theme="dark"] .cable-table tbody tr:hover { background: #2c3c25; }
  html[data-theme="dark"] .cable-table small { color: #acbf99; }
  html[data-theme="dark"] .issue-item { background: #3a3020; border-color: #79623f; color: #e8c88e; }
  html[data-theme="dark"] .issue-item button { color: #d3e4a6; }
  html[data-theme="dark"] .brand-group { border-color: #45573b; }
  html[data-theme="dark"] .brand-group h3 { color: #dfebd3; }
  html[data-theme="dark"] .brand-guide-btn,
  html[data-theme="dark"] .brand-guide-item a { color: #bedb9b; }
  html[data-theme="dark"] .brand-guide-item a:hover { color: #e0f0cc; text-decoration: underline; }
  html[data-theme="dark"] .brand-guide-item small { color: #b4c5a2; }
  html[data-theme="dark"] .brand-guide-filter { color: #d5e7bf; background: #324529; border-color: #647e4d; }
  html[data-theme="dark"] .brand-guide-filter:hover { background: #435b33; }
  html[data-theme="dark"] .edge-toolbar {
    background: #253027;
    border-color: #566a48;
    color: #deead4;
    box-shadow: 0 4px 18px #0006;
  }
  html[data-theme="dark"] :is(.edge-toolbar button,.edge-actions button) { background: #33432b; color: #d3e5be; border-color: #607b49; }
  html[data-theme="dark"] :is(.edge-toolbar button,.edge-actions button):hover { background: #455d34; }
  html[data-theme="dark"] :is(.edge-toolbar button.danger,.edge-actions button.danger) { background: #472e29; color: #f6b7a9; border-color: #996a5d; }
}

@media screen and (max-width:850px) {
  #theme-toggle { min-width: 40px; min-height: 40px; margin: 0; }
  .edge-toolbar { top: 43px; gap: 6px; padding: 6px; }
  .edge-toolbar > span { padding-left: 4px; }
  .edge-toolbar button,.edge-actions button { min-height: 44px; min-width: 44px; }
  html[data-theme="dark"] #mobile-tools { background: #1c251d; border-color: var(--border); }
  html[data-theme="dark"] #mobile-tools button { background: #2a3824; color: #d2e3bf; border-color: #506442; }
  html[data-theme="dark"] #mobile-tools button:is(.active,[aria-pressed="true"],[aria-expanded="true"]) { background: #415a2e; border-color: #9cbe6c; color: #e4f2d1; }
  html[data-theme="dark"] .library-panel { border-color: #566848; box-shadow: 0 -12px 50px #0007; }
  html[data-theme="dark"] #library-backdrop { background: #0008; }
  html[data-theme="dark"] .library-panel .library-close { color: #d1e0bd; background: #34462a; }
  html[data-theme="dark"] .library-panel .library-device { background: #232e24; border-color: #45583b; }
  html[data-theme="dark"] .library-panel .add-device { background: #3a512b; color: #d1e8b5; }
  html[data-theme="dark"] .inspector-panel.mobile-open { border-color: #536448; box-shadow: 0 -12px 60px #0008; }
  html[data-theme="dark"] .inspector-panel.mobile-open .inspector-heading { background: #1c251d; }
  html[data-theme="dark"] .inspector-heading [data-action="close-inspector"] { color: #d7e7c5; background: #34442a; }
}
