@media screen {
  .app-shell {
    --forge-ink: #263c59;
    --forge-muted: #526780;
    --forge-border: #cdd8e7;
    --forge-panel: #f0f4fa;
    --forge-chrome: linear-gradient(#fcfdff,#edf3fb);
    --forge-handle: 24px;
    --forge-project-width: clamp(244px,17vw,310px);
    --forge-instructions-width: clamp(210px,16vw,252px);
    height: 100dvh;
    min-height: 0;
    grid-template-columns: var(--forge-project-width) var(--forge-handle) minmax(0,1fr);
    grid-template-rows: auto minmax(0,1fr) auto;
    grid-template-areas: "top top top" "nav project-toggle work" "status status status";
    font: 14px "Segoe UI", Tahoma, sans-serif;
    color: var(--forge-ink);
    background: var(--forge-panel);
  }
  .app-shell.project-panel-closed { --forge-project-width: 0px; }
  .app-shell.instructions-panel-closed { --forge-instructions-width: 0px; }
  .app-shell :is(#projectNav,#instructionPanel)[hidden] { display: none !important; }
  .app-shell :focus-visible { outline: 2px solid #2877e0; outline-offset: -2px; }

  .app-shell .topbar {
    grid-template-rows: 36px auto auto;
    height: auto;
    min-height: 0;
    border-bottom: 1px solid #b9c7db;
    background: var(--forge-chrome);
  }
  .app-shell .window-title {
    align-self: stretch;
    gap: 10px;
    padding: 0 13px;
    background: linear-gradient(#2c374b,#172235);
    border-bottom: 1px solid #101a2a;
    color: #eef5ff;
    font: 13px "Segoe UI", Tahoma, sans-serif;
  }
  .window-title img { flex: none; }
  .window-title .title-separator { height: 14px; border-left: 1px solid #526b90; }
  #windowProjectName { overflow: hidden; text-overflow: ellipsis; color: #b9cbed; }
  .app-shell .top-menu {
    flex-wrap: wrap;
    gap: 2px;
    width: auto;
    margin: 0;
    padding: 3px 8px;
    background: #f8fafd;
    border-bottom: 1px solid #d6e0ee;
    overflow: visible;
  }
  .app-shell .top-menu .app-menu > button, .app-shell .layout-menu-link {
    height: 28px;
    border-radius: 5px;
    color: var(--forge-ink) !important;
    font: 600 12px "Segoe UI", Tahoma, sans-serif !important;
  }
  .app-shell .top-menu .menu-popover {
    top: 100%;
    border: 1px solid #bdcbe0;
    border-radius: 6px;
    box-shadow: 0 6px 20px #26384b25;
  }
  .app-shell .top-menu .menu-submenu > .menu-popover { top: -4px; }
  .app-shell .top-actions {
    min-width: 0;
    min-height: 0;
    padding: 3px 8px;
    border: 0;
    background: transparent;
    overflow-x: auto;
  }
  .app-shell .classic-toolbar { gap: 3px; flex-wrap: wrap; flex: 0 1 auto; min-width: 0; }
  #desktopProjectSelect {
    width: clamp(135px, 24vw, 220px);
    max-width: 100%;
    height: 27px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    padding-inline: 5px;
    background: #fff;
    color: var(--forge-ink);
    font: 12px "Segoe UI", Tahoma, sans-serif;
  }
  @media (pointer: coarse) {
    #desktopProjectSelect { height: 36px; font-size: 16px; }
  }
  .app-shell .classic-toolbar button {
    height: 27px;
    min-width: 27px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    background: #fff;
    text-shadow: none;
  }
  .app-shell .classic-toolbar button:hover:not(:disabled) { background: #eaf3ff; border-color: #789fd8; outline: 0; }
  .app-shell .classic-toolbar > i { height: 18px; border: 0; border-left: 1px solid #cdd8e7; margin: 0 3px; }
  .app-shell .classic-toolbar .tool-label { color: inherit; font: 600 12px "Segoe UI", Tahoma, sans-serif; }
  .app-shell .statusbar {
    gap: 10px;
    min-height: 30px;
    border-top: 1px solid #cdd8e7;
    background: #eaf0f8;
    color: var(--forge-muted);
    font-size: 11px;
  }
  .app-shell .statusbar a { color: #2358a6; }

  .app-shell #projectNav, .app-shell #instructionPanel {
    min-width: 0;
    min-height: 0;
    background: var(--forge-panel);
    color: var(--forge-ink);
    font: inherit;
  }
  .app-shell #projectNav { width: auto; border-right: 1px solid #c0cde0; overflow: hidden; }
  .app-shell .panel-heading {
    display: flex;
    flex: none;
    align-items: center;
    min-height: 46px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--forge-border);
    background: linear-gradient(#fbfdff,#edf4fc);
  }
  .panel-heading h2 { margin: 0; font-size: 14px; }
  .app-shell .tree-project-name {
    flex: none;
    height: auto;
    min-height: 32px;
    padding: 4px 10px;
    border: 0;
    border-bottom: 1px solid #d3dded;
    background: #e2edfd;
  }
  .app-shell .tree-project-name strong { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-shell .tree { min-height: 0; overscroll-behavior: contain; }
  .app-shell :is(.tree-row,.tree-static,.device-tree) {
    height: auto;
    min-height: 27px;
    border-bottom-color: #dfe7f3;
    background: transparent;
    color: var(--forge-ink);
    font: 12px "Segoe UI", Tahoma, sans-serif;
  }
  .app-shell .tree-row:hover, .app-shell .device-links button:hover { background: #e2edfd; }
  .app-shell .tree-row.active { background: #dceaff; color: #184581; }
  .app-shell .tree-branch { border-left-color: #adc1da; }
  .app-shell .count, .app-shell .device-tree #miniMode { background: #e0e9f7; color: #395575; border-radius: 4px; }
  .app-shell .device-links button { color: var(--forge-muted); font: inherit; }
  .app-shell .nav-footer {
    flex: none;
    min-height: 38px;
    background: #eaf0f8;
    border-top: 1px solid #cdd8e7;
    color: var(--forge-ink);
  }
  .app-shell .nav-footer small { color: var(--forge-muted); }
  .app-shell .mini-plc {
    margin: 6px 10px 9px;
    padding: 0;
    overflow: hidden;
    border: 1px solid #222e40;
    border-radius: 6px !important;
    background: #283644;
    box-shadow: 0 3px 6px #42597740;
  }
  .app-shell .mini-plc header {
    gap: 8px;
    margin: 0;
    padding: 7px 8px;
    border-block: 1px solid #708398;
    background: linear-gradient(145deg,#63798e,#3a4d60 55%,#506679);
    font: 700 12px "Segoe UI", Tahoma, sans-serif;
  }
  .app-shell .mini-plc header button {
    flex: none;
    width: 26px;
    min-height: 25px;
    border: 1px solid #7890aa;
    border-radius: 4px;
    background: #edf4fe;
  }
  .mini-vents { flex: 0 0 12px; height: 31px; background: repeating-linear-gradient(#182a3a 0 2px,#6d8093 2px 3px,transparent 3px 6px); }
  .app-shell .mini-status { padding-top: 4px; }
  .app-shell .mini-plc > label { margin: 0; padding: 5px 8px 3px; letter-spacing: .07em; font: 9px Consolas, monospace; }
  .app-shell .mini-io { padding: 0 7px 5px; gap: 3px; }
  .app-shell .mini-channel {
    min-height: 25px;
    place-content: center;
    border: 1px solid #4d5b6b;
    border-radius: 3px;
    background: linear-gradient(#465668,#303d4e);
    color: #e6edf5;
  }
  .app-shell .mini-channel:not(:disabled):hover { background: #4a617a; }
  .app-shell .mini-channel:not(.on) i { background: #738079; border: 0; box-shadow: inset 0 -1px 1px #152835; }
  .app-shell .mini-plc footer { margin: 0; padding: 6px 7px; border-top: 1px solid #53667c; }
  .app-shell .mini-plc footer button { border-radius: 4px; font: 600 10px "Segoe UI", Tahoma, sans-serif; }
  .app-shell .mini-plc footer [data-command="cpu-run"] { background: #e7f5ed; color: #136746; }
  .app-shell .mini-plc footer [data-command="cpu-stop"] { background: #fff0f1; color: #9c2d37; }

  .forge-panel-toggle {
    z-index: 4;
    align-self: center;
    width: 100%;
    min-height: 56px;
    padding: 0;
    border: 1px solid #bdcbe0;
    background: #eaf2fe;
    box-shadow: 0 1px 4px #33537825;
    color: #284f80;
    font: 600 21px/1 "Segoe UI", Tahoma, sans-serif;
    cursor: pointer;
    touch-action: manipulation;
  }
  .forge-panel-toggle:hover { background: #dceaff; }
  .forge-panel-toggle-left { grid-area: project-toggle; border-left: 0; border-radius: 0 7px 7px 0; }
  .forge-panel-toggle-right { grid-column: 2; grid-row: 1; border-right: 0; border-radius: 7px 0 0 7px; }

  .app-shell .workspace { min-width: 0; min-height: 0; background: #f8fafd; }
  .app-shell.ladder-workspace .workspace { overflow: hidden; }
  #ladderView.active {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 0;
  }
  #ladderView .compact-work-header {
    flex: none;
    min-height: 28px;
    margin: 0;
    padding: 4px 12px;
    background: #f8fafd;
  }
  #ladderView .breadcrumbs { color: var(--forge-muted); }
  #ladderView .block-editor-meta {
    flex: none;
    margin: 0;
    border: 0;
    border-block: 1px solid #c0cde0;
    background: #f8fafd;
  }
  #ladderView .block-meta-fields { padding: 4px 10px; }
  #ladderView .block-meta-fields input {
    min-width: 0;
    border: 1px solid #bdcbe0;
    border-radius: 4px;
    color: var(--forge-ink);
    background: #fff;
  }
  #ladderView .ladder-quickbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px 10px;
    border-top: 1px solid #d7e1ef;
    background: var(--forge-chrome);
  }
  #ladderView .ladder-quickbar > span { color: var(--forge-muted); }
  #ladderView .ladder-quickbar button,
  .instruction-group-actions button {
    min-height: 31px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    background: #fff;
    color: var(--forge-ink);
    touch-action: manipulation;
  }
  #ladderView .ladder-quickbar button:hover:not(:disabled),
  .instruction-group-actions button:hover:not(:disabled) { border-color: #789fd8; background: #eaf3ff; }
  #ladderView .workbench-actions { gap: 5px; }
  #ladderView .workbench-actions button {
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    font: 600 11px "Segoe UI", Tahoma, sans-serif;
  }
  #ladderView .ladder-layout {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(0,1fr) var(--forge-handle) var(--forge-instructions-width);
    grid-template-rows: minmax(0,1fr);
    gap: 0;
  }
  #ladderView .ladder-editor {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    min-height: 0;
    border: 0;
    background: #f8fafd;
  }
  #ladderView .editor-toolbar {
    flex: none;
    min-height: 33px;
    height: auto;
    border-bottom: 1px solid var(--forge-border);
    background: linear-gradient(#fbfdff,#edf4fc);
    color: var(--forge-ink);
    font: 600 12px "Segoe UI", Tahoma, sans-serif;
  }
  #ladderView .ladder-view-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 27px;
    padding: 2px 7px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    background: #fff;
    color: var(--forge-ink);
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
  }
  #ladderView .ladder-view-action:hover,
  #ladderView .ladder-view-action[aria-pressed="true"] { border-color: #789fd8; background: #eaf3ff; }
  #ladderView .ladder-view-action > [aria-hidden] { font-size: 15px; line-height: 1; }
  .app-shell.ladder-workspace:is(.ladder-focused,.ladder-detached) {
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: minmax(0,1fr);
    grid-template-areas: "work";
  }
  .app-shell.ladder-workspace:is(.ladder-focused,.ladder-detached) > :is(.topbar,#projectNav,#toggleProjectPanel,.statusbar),
  .app-shell.ladder-workspace:is(.ladder-focused,.ladder-detached) #ladderView .compact-work-header { display: none; }
  .app-shell.ladder-workspace:is(.ladder-focused,.ladder-detached) #ladderView .instruction-palette { display: none; }
  .app-shell.ladder-workspace:is(.ladder-focused,.ladder-detached) #ladderView .block-meta-fields { display: grid; }
  .app-shell:is(.ladder-focused,.ladder-detached) #ladderView .block-editor-meta { border-top: 0; }
  #ladderView #rungs {
    flex: 1;
    display: block;
    min-height: 0;
    overflow: auto;
    overflow-anchor: none;
    overscroll-behavior: contain;
    padding-bottom: 220px;
    background: #f0f4fa;
  }
  #rungs .section-rungs { overflow: visible; }
  #ladderView .ladder-section { margin: 0 0 9px; border-bottom-color: #c0cde0; background: #fff; }
  #ladderView .section-header { background: #e6edf8; color: var(--forge-ink); }
  #ladderView .section-header > div > span { color: var(--forge-muted); }
  #ladderView .section-header .section-name { color: var(--forge-ink); }
  #ladderView .section-comment { background: #f8fafd; }

  .app-shell #instructionPanel {
    grid-area: 1 / 3;
    display: flex;
    flex-direction: column;
    width: auto;
    height: 100%;
    max-height: none;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-left: 1px solid #c0cde0;
    border-radius: 0;
    box-shadow: none;
  }
  #instructionPanel .palette-search { flex: none; margin: 0; padding: 8px 10px 4px; border: 0; background: transparent; }
  #instructionPanel .palette-search input {
    width: 100%;
    min-height: 34px;
    min-width: 0;
    padding: 0 8px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    background: #fff;
  }
  .instruction-group-actions { display: flex; flex: none; gap: 4px; padding: 4px 10px; }
  #instructionPanel .instruction-group-actions button {
    flex: 1;
    margin: 0;
    padding: 4px;
    display: block;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
  }
  #instructionGroups { flex: 1; min-height: 0; padding: 0 10px 10px; overflow: auto; overscroll-behavior: contain; }
  #instructionGroups .instruction-group { padding-bottom: 4px; border-bottom: 1px solid var(--forge-border); }
  #instructionGroups summary {
    padding: 9px 4px 5px;
    background: transparent;
    color: #4d6383;
    font: 700 11px "Segoe UI", Tahoma, sans-serif;
  }
  #instructionGroups .instruction-group button {
    display: grid;
    grid-template-columns: minmax(54px,auto) minmax(0,1fr);
    gap: 6px;
    width: 100%;
    margin: 4px 0;
    padding: 4px 6px;
    border: 1px solid #bdcbe0;
    border-radius: 5px;
    background: #fdfdff;
    color: var(--forge-ink);
    touch-action: manipulation;
  }
  #instructionGroups .instruction-group button:hover { background: #eaf3ff; border-color: #789fd8; }
  #instructionGroups button b {
    min-width: 0;
    padding: 4px 3px;
    border-radius: 4px;
    text-align: center;
    background: #e2edfd;
    color: #2b61ad;
    font: 12px Consolas, monospace;
  }
  #instructionGroups button small { font: 11px/1.3 "Segoe UI", Tahoma, sans-serif; color: #526780; overflow-wrap: anywhere; }
  #instructionGroups > p { padding: 6px 0; color: var(--forge-muted); }
}

@media screen and (max-width: 980px) {
  .app-shell { --forge-project-width: 0px; --forge-instructions-width: 0px; }
  .app-shell #projectNav {
    grid-area: work;
    position: relative;
    z-index: 12 !important;
    inset: auto !important;
    transform: none !important;
    visibility: visible;
    width: min(292px,100% - 32px);
    justify-self: start;
    box-shadow: 8px 0 22px #26384b30;
  }
  .app-shell #instructionPanel {
    position: absolute;
    z-index: 3;
    grid-area: auto;
    inset: 0 var(--forge-handle) 0 auto;
    width: min(252px,calc(100% - var(--forge-handle) - 25px));
    box-shadow: -8px 0 22px #26384b30;
  }
  #ladderView .workbench-actions { justify-content: flex-start; }
}

@media screen and (max-width: 560px) {
  .app-shell .statusbar > div { gap: 7px; }
  .app-shell .statusbar .forge-brand { display: none; }
  #ladderView .block-meta-fields { grid-template-columns: 1fr; gap: 3px; }
  #ladderView .block-meta-fields label { grid-template-columns: 94px minmax(0,1fr); }
  #ladderView .ladder-quickbar > span { display: none; }
  #ladderView .workbench-actions { flex-basis: 100%; margin-left: 0; }
  #ladderView .ladder-view-action > :last-child { display: none; }
}

@media screen and (any-pointer: coarse) {
  .app-shell { --forge-handle: 36px; }
  .app-shell .top-menu .app-menu > button, .app-shell .layout-menu-link { height: 36px; }
  .app-shell .classic-toolbar button { min-width: 36px; height: 36px; }
  .app-shell .mini-channel, .app-shell :is(.tree-row,.tree-static) { min-height: 34px; }
  .forge-panel-toggle { min-height: 64px; }
  #ladderView .ladder-quickbar button, #instructionGroups .instruction-group button,
  #instructionPanel .instruction-group-actions button, #instructionGroups summary { min-height: 40px; }
  #instructionPanel .palette-search input { font-size: 16px; }
  #ladderView .ladder-view-action { min-width: 40px; min-height: 40px; }
}

@media print {
  .forge-panel-toggle { display: none !important; }
}
