/*
 * RuangIoT IoTwinLab 3.0 — shared design system (light + dark).
 * Scoped to .iw-* classes and to the Virtual Lab only when wrapped by .iw-app,
 * so the existing editor keeps its look when IOTWIN_ENABLED=false.
 */
:root {
    --iw-font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --iw-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --iw-top-h: 60px;
    --iw-bar-h: 64px;
    --iw-side-w: 236px;
    --iw-right-w: 384px;
    --iw-radius: 10px;
    --iw-radius-sm: 7px;

    --iw-nav-bg: #0c1f3f;
    --iw-nav-bg-2: #12305f;
    --iw-nav-text: #dbe6f7;
    --iw-nav-muted: #93a8c8;
    --iw-nav-active: #1658cc;

    --iw-bg: #f2f5fa;
    --iw-surface: #ffffff;
    --iw-surface-2: #f7f9fc;
    --iw-surface-3: #eef3fa;
    --iw-border: #dde5f0;
    --iw-border-strong: #c8d4e4;
    --iw-text: #0f1c30;
    --iw-text-2: #33435c;
    --iw-muted: #536177;
    --iw-primary: #1658cc;
    --iw-primary-hover: #1249ad;
    --iw-primary-bg: #1658cc;
    --iw-primary-soft: #e8f0ff;
    --iw-success: #166534;
    --iw-success-soft: #e3f6ea;
    --iw-warning: #92400e;
    --iw-warning-soft: #fdf1df;
    --iw-danger: #c81e1e;
    --iw-danger-soft: #fde8e8;
    --iw-info: #1658cc;
    --iw-info-soft: #e8f0ff;
    --iw-shadow: 0 1px 2px rgba(15, 28, 48, .05), 0 4px 14px rgba(15, 28, 48, .05);
    --iw-focus: 0 0 0 3px rgba(29, 107, 243, .35);
    --iw-code-bg: #ffffff;
    --iw-code-text: #1e2b40;
    --iw-canvas-bg: #eef4fb;
    --iw-canvas-dot: #c3d1e3;
    --iw-console-bg: #0f172a;
    --iw-console-text: #d7e3f4;
}

[data-theme="dark"] {
    --iw-nav-bg: #0a1426;
    --iw-nav-bg-2: #102043;
    --iw-bg: #0a1120;
    --iw-surface: #111a2c;
    --iw-surface-2: #0e1627;
    --iw-surface-3: #16223a;
    --iw-border: #233350;
    --iw-border-strong: #2f4366;
    --iw-text: #e6eefb;
    --iw-text-2: #c3d0e6;
    --iw-muted: #94a6c2;
    --iw-primary: #7cb0ff;
    --iw-primary-hover: #1e40af;
    --iw-primary-bg: #1d4ed8;
    --iw-primary-soft: #16294d;
    --iw-success: #34d399;
    --iw-success-soft: #0f3326;
    --iw-warning: #fbbf24;
    --iw-warning-soft: #3a2a0b;
    --iw-danger: #f87171;
    --iw-danger-soft: #3d1414;
    --iw-info: #7cb0ff;
    --iw-info-soft: #16294d;
    --iw-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    --iw-code-bg: #0c1424;
    --iw-code-text: #dbe5f5;
    --iw-canvas-bg: #0d1628;
    --iw-canvas-dot: #23324d;
    --iw-console-bg: #070d18;
    --iw-console-text: #cfe0f5;
    color-scheme: dark;
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
.iw-body {
    margin: 0;
    background: var(--iw-bg);
    color: var(--iw-text);
    font-family: var(--iw-font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
.iw-body *, .iw-body *::before, .iw-body *::after { box-sizing: border-box; }
.iw-body svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.iw-body a { color: var(--iw-primary); }
.iw-body :focus-visible { outline: none; box-shadow: var(--iw-focus); border-radius: 6px; }
/* top/left eksplisit: label tersembunyi di dalam panel yang di-scroll tidak boleh memanjangkan halaman
   (sebelumnya halaman editor Virtual Lab setinggi 2700 px dengan area kosong di bawah workspace). */
.iw-visually-hidden { position: absolute !important; top: 0; left: 0; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.iw-skip { position: absolute; left: 8px; top: -60px; z-index: 1000; background: var(--iw-primary-bg); color: #fff !important; padding: 8px 12px; border-radius: 8px; }
.iw-skip:focus { top: 8px; }
.iw-muted { color: var(--iw-muted); }
.iw-small { font-size: 12px; }
.iw-error { color: var(--iw-danger); }
.iw-block { display: flex; width: 100%; justify-content: center; }

/* Buttons & badges */
.iw-button {
    display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 14px;
    border-radius: 8px; border: 1px solid transparent; font: 600 13px/1 var(--iw-font);
    cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.iw-button svg { width: 16px; height: 16px; }
.iw-button-primary { background: var(--iw-primary-bg); color: #fff !important; }
.iw-button-primary:hover { background: var(--iw-primary-hover); }
.iw-button-danger { background: #dc2626; color: #fff !important; }
.iw-button-danger:hover { background: #b91c1c; }
.iw-button-success { background: #16a34a; color: #fff !important; }
.iw-button-ghost { background: var(--iw-surface); color: var(--iw-text) !important; border-color: var(--iw-border-strong); }
.iw-button-ghost:hover { border-color: var(--iw-primary); color: var(--iw-primary) !important; }
.iw-button-light { background: rgba(255, 255, 255, .1); color: #fff !important; border-color: rgba(255, 255, 255, .25); }
.iw-button[disabled], .iw-button[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.iw-icon-button {
    display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
    border: 1px solid var(--iw-border-strong); background: var(--iw-surface); color: var(--iw-text); cursor: pointer;
}
.iw-icon-primary { background: var(--iw-primary-bg); color: #fff; border-color: var(--iw-primary-bg); }
.iw-badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
    font: 600 11.5px/1.3 var(--iw-font); white-space: nowrap; background: var(--iw-surface-3); color: var(--iw-muted);
}
.iw-badge[data-tone="success"] { background: var(--iw-success-soft); color: var(--iw-success); }
.iw-badge[data-tone="warning"] { background: var(--iw-warning-soft); color: var(--iw-warning); }
.iw-badge[data-tone="danger"] { background: var(--iw-danger-soft); color: var(--iw-danger); }
.iw-badge[data-tone="info"] { background: var(--iw-info-soft); color: var(--iw-info); }
.iw-badge[hidden] { display: none; }
.iw-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: 0 0 8px; }
.iw-dot[data-state="online"], .iw-dot[data-state="fresh"] { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.iw-dot[data-state="offline"] { background: #ef4444; }
.iw-dot[data-state="stale"] { background: #f59e0b; }
.iw-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ------------------------------------------------------------------ */
/* Top navigation                                                      */
/* ------------------------------------------------------------------ */
.iw-topnav {
    position: sticky; top: 0; z-index: 60; height: var(--iw-top-h); display: flex; align-items: center; gap: 14px;
    padding: 0 18px; background: linear-gradient(90deg, var(--iw-nav-bg), var(--iw-nav-bg-2)); color: var(--iw-nav-text);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.iw-brand { display: flex; align-items: center; gap: 10px; color: #fff !important; text-decoration: none; min-width: 0; }
.iw-brand img { width: 36px; height: 36px; }
.iw-brand strong { display: block; font-size: 19px; letter-spacing: -.01em; line-height: 1.05; }
.iw-brand em { font-style: normal; color: #5ea2ff; }
.iw-brand small { display: block; font-size: 10.5px; color: var(--iw-nav-muted); letter-spacing: .02em; white-space: nowrap; }
.iw-primary-nav { display: flex; align-items: center; gap: 2px; margin-left: 18px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.iw-primary-nav::-webkit-scrollbar { display: none; }
.iw-primary-nav a {
    display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 12px; border-radius: 9px;
    color: var(--iw-nav-text); text-decoration: none; font-weight: 500; font-size: 13.5px; white-space: nowrap;
}
.iw-primary-nav a:hover { background: rgba(255, 255, 255, .08); }
.iw-primary-nav a.is-active { background: var(--iw-nav-active); color: #fff; box-shadow: 0 6px 16px rgba(29, 107, 243, .35); }
.iw-topnav-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.iw-topnav .iw-icon-button { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .16); color: #e5eefc; }
.iw-when-dark { display: none; }
[data-theme="dark"] .iw-when-dark { display: block; }
[data-theme="dark"] .iw-when-light { display: none; }
.iw-agent-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--iw-nav-text); white-space: nowrap; }
.iw-account { position: relative; }
.iw-account summary { display: flex; align-items: center; gap: 9px; cursor: pointer; list-style: none; }
.iw-account summary::-webkit-details-marker { display: none; }
.iw-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; font-weight: 700; }
.iw-account-text strong { display: block; font-size: 13px; color: #fff; line-height: 1.15; }
.iw-account-text small { display: block; font-size: 11px; color: var(--iw-nav-muted); }
.iw-account-menu {
    position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; padding: 6px; background: var(--iw-surface);
    border: 1px solid var(--iw-border); border-radius: 10px; box-shadow: var(--iw-shadow); z-index: 80;
}
.iw-account-menu a, .iw-account-menu button {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 7px;
    color: var(--iw-text); font: 500 13px var(--iw-font); text-decoration: none; cursor: pointer;
}
.iw-account-menu a:hover, .iw-account-menu button:hover { background: var(--iw-surface-3); }
.iw-account-menu form { margin: 0; }
.iw-nav-toggle { display: none; width: 38px; height: 38px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, .08); cursor: pointer; padding: 10px 9px; flex-direction: column; justify-content: space-between; }
.iw-nav-toggle span { display: block; height: 2px; background: #fff; border-radius: 2px; }

/* ------------------------------------------------------------------ */
/* Workspace frame (JPG 01 / 05)                                        */
/* ------------------------------------------------------------------ */
.iw-frame { display: grid; grid-template-columns: var(--iw-side-w) minmax(0, 1fr); min-height: calc(100vh - var(--iw-top-h)); }
.iw-sidebar {
    position: sticky; top: var(--iw-top-h); height: calc(100vh - var(--iw-top-h)); overflow-y: auto; display: flex; flex-direction: column;
    gap: 14px; padding: 16px 14px; background: var(--iw-surface); border-right: 1px solid var(--iw-border);
}
.iw-side-title { margin: 0 0 8px 4px; font-size: 13px; font-weight: 700; color: var(--iw-text); }
.iw-mode-list { display: grid; gap: 7px; }
.iw-mode {
    display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 11px; border-radius: 10px; border: 1px solid var(--iw-border);
    background: var(--iw-surface-2); color: var(--iw-text); text-align: left; cursor: pointer; font-family: var(--iw-font);
}
.iw-mode svg { width: 22px; height: 22px; color: var(--iw-muted); }
.iw-mode strong { display: block; font-size: 13.5px; }
.iw-mode small { display: block; font-size: 11.5px; color: var(--iw-muted); }
.iw-mode:hover { border-color: var(--iw-primary); }
.iw-mode[aria-checked="true"] { background: var(--iw-primary-bg); border-color: var(--iw-primary-bg); color: #fff; box-shadow: 0 8px 18px rgba(29, 107, 243, .28); }
.iw-mode[aria-checked="true"] svg, .iw-mode[aria-checked="true"] small { color: rgba(255, 255, 255, .85); }
.iw-panel-list { display: grid; gap: 2px; }
.iw-panel-link {
    display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border: 0; border-left: 3px solid transparent; border-radius: 8px;
    background: none; color: var(--iw-text-2); font: 500 13.5px var(--iw-font); text-align: left; cursor: pointer;
}
.iw-panel-link:hover { background: var(--iw-surface-3); }
.iw-panel-link[aria-pressed="true"] { background: var(--iw-primary-soft); color: var(--iw-primary); border-left-color: var(--iw-primary); font-weight: 600; }
.iw-device-card {
    margin-top: auto; display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; padding: 12px; border: 1px solid var(--iw-border);
    border-radius: 12px; background: var(--iw-surface-2);
}
.iw-device-card img { width: 44px; height: 78px; object-fit: contain; }
.iw-device-card strong { display: block; font-size: 13px; }
.iw-device-card .iw-button { grid-column: 1 / -1; }
.iw-device-card dl { margin: 6px 0 0; font-size: 11.5px; color: var(--iw-muted); }
.iw-device-card dl div { display: flex; gap: 4px; }
.iw-device-card dt::after { content: ":"; }
.iw-device-card dd { margin: 0; color: var(--iw-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iw-status { display: inline-flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; font-weight: 600; color: var(--iw-muted); }
.iw-status[data-state="online"] { color: var(--iw-success); }
.iw-status[data-state="offline"] { color: var(--iw-warning); }
.iw-status[data-state="online"] .iw-dot { background: #22c55e; }
.iw-status[data-state="offline"] .iw-dot { background: #f59e0b; }

/* Existing Virtual Lab inside the shell */
.iw-app .iw-page { margin: 0 !important; min-height: 0; background: var(--iw-bg) !important; color: var(--iw-text); --vl-dashboard-rail: 0px; }
.iw-app .vl-studio-header {
    position: static !important; height: var(--iw-bar-h); min-height: var(--iw-bar-h); padding: 0 16px; gap: 12px;
    background: var(--iw-surface) !important; color: var(--iw-text) !important; border-bottom: 1px solid var(--iw-border) !important; box-shadow: none !important;
}
.iw-app .vl-studio-header .vl-brand,
.iw-app .vl-studio-header .vl-navigation-toggle,
.iw-app .vl-studio-header .vl-header-divider,
.iw-app .vl-studio-header .vl-header-link,
.iw-app .vl-studio-header #vlThemeToggle,
.iw-app .vl-studio-header .is-account { display: none !important; }
.iw-app .vl-header-primary { gap: 12px; min-width: 0; }
.iw-app .vl-project-heading { order: -1; min-width: 0; max-width: 520px; }
.iw-app .vl-project-heading h1 { color: var(--iw-text) !important; font-size: 19px !important; font-weight: 700 !important; letter-spacing: -.01em; }
.iw-app .vl-project-heading #vlSaveStatus { color: var(--iw-muted) !important; }
.iw-app .iw-project-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.iw-breadcrumb { display: flex; gap: 6px; font-size: 12px; color: var(--iw-muted); white-space: nowrap; overflow: hidden; }
.iw-breadcrumb a { color: var(--iw-primary); text-decoration: none; }
.iw-app .vl-save-split .vl-header-button, .iw-app .vl-header-button.is-share {
    background: var(--iw-surface) !important; color: var(--iw-primary) !important; border: 1px solid var(--iw-border-strong) !important; box-shadow: none !important;
}
.iw-app .vl-save-split .vl-header-button.is-save { background: var(--iw-primary) !important; color: #fff !important; border-color: var(--iw-primary) !important; }
.iw-app .vl-project-menu summary { background: var(--iw-primary) !important; color: #fff !important; }
.iw-app .vl-header-secondary { gap: 10px; }

.iw-mobile-tabs { display: none; }
.iw-stage {
    display: grid; grid-template-columns: minmax(0, 1fr) var(--iw-right-w); gap: 0;
    height: calc(100vh - var(--iw-top-h) - var(--iw-bar-h)); min-height: 600px;
}
.iw-app .iw-stage .vl-studio {
    height: 100% !important; min-height: 0 !important; border-right: 1px solid var(--iw-border);
    grid-template-columns: minmax(300px, var(--vl-code-width, 44%)) 6px minmax(340px, 1fr) !important;
}
.iw-app .vl-code-workspace { background: var(--iw-surface); }
.iw-app .vl-sim-workspace { position: relative; background: var(--iw-surface); }
.iw-app .vl-canvas { background-color: var(--iw-canvas-bg) !important; background-image: radial-gradient(var(--iw-canvas-dot) 1.2px, transparent 1.2px) !important; }
.iw-app .vl-studio .vl-empty-canvas:not([hidden]) {
    inset: auto 14px 64px auto !important; left: auto !important; top: auto !important; width: 280px !important; height: auto !important;
    transform: none !important; padding: 12px 14px !important; border: 1px solid var(--iw-border) !important; border-radius: 12px !important;
    background: var(--iw-surface) !important; box-shadow: var(--iw-shadow); text-align: left; z-index: 4;
}
.iw-app .vl-empty-canvas strong { font-size: 13.5px; }
.iw-app .vl-empty-canvas span { font-size: 12px; }
.vl-zoom-label { font: 600 12px var(--iw-font, inherit); color: inherit; min-width: 42px; text-align: center; }
.vl-sim-tabs .vl-zoom-label { display: none; }
.iw-zoom-bar {
    position: absolute; left: 14px; bottom: calc(var(--vl-serial-height, 190px) + 58px); z-index: 5; display: flex; align-items: center; gap: 2px; padding: 4px;
    background: var(--iw-surface); border: 1px solid var(--iw-border); border-radius: 10px; box-shadow: var(--iw-shadow);
}
.iw-zoom-bar button { width: 30px; height: 30px; border: 0; border-radius: 7px; background: none; color: var(--iw-text); font: 600 15px var(--iw-font); cursor: pointer; }
.iw-zoom-bar button:hover { background: var(--iw-surface-3); }
.iw-zoom-bar .vl-zoom-label { display: inline-block !important; color: var(--iw-text); }

/* Right column */
.iw-right { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow-y: auto; background: var(--iw-bg); min-height: 0; }
.iw-card { background: var(--iw-surface); border: 1px solid var(--iw-border); border-radius: 12px; box-shadow: var(--iw-shadow); min-width: 0; }
.iw-card-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--iw-border); }
.iw-card-head h2 { margin: 0 auto 0 0; font-size: 14.5px; font-weight: 700; color: var(--iw-text); }
.iw-card-body { padding: 12px 14px; }
.iw-card h3 { margin: 4px 0 8px; font-size: 12.5px; font-weight: 700; color: var(--iw-primary); text-transform: none; }
.iw-card p { margin: 0 0 6px; }
.iw-flash { animation: iw-flash 1.1s ease; }
@keyframes iw-flash { 0% { box-shadow: 0 0 0 0 rgba(29, 107, 243, .55); } 100% { box-shadow: 0 0 0 10px rgba(29, 107, 243, 0); } }
.iw-twin-empty { padding: 4px 0 10px; }
.iw-sim-pins { margin-top: 8px; padding-top: 10px; border-top: 1px dashed var(--iw-border); }
.iw-sim-pins h3 { display: flex; align-items: center; gap: 6px; color: var(--iw-text) !important; }
.iw-pin-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.iw-pin-list li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 8px; font-size: 12.5px; padding: 5px 8px; border-radius: 7px; background: var(--iw-surface-2); }
.iw-pin { font-family: var(--iw-mono); font-weight: 600; }
.iw-pin-target { color: var(--iw-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iw-findings { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.iw-findings li { display: flex; gap: 8px; align-items: flex-start; font-size: 12.8px; color: var(--iw-text-2); }
.iw-findings li svg { width: 16px; height: 16px; margin-top: 1px; }
.iw-findings li[data-level="ok"] svg { color: var(--iw-success); }
.iw-findings li[data-level="info"] svg { color: var(--iw-info); }
.iw-findings li[data-level="warn"] svg { color: var(--iw-warning); }
.iw-findings li[data-level="error"] svg { color: var(--iw-danger); }
.iw-ref { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; background: var(--iw-surface-3); font-family: var(--iw-mono); font-size: 11px; color: var(--iw-muted); }
.iw-ai-block { padding: 10px 12px; border-radius: 10px; background: var(--iw-surface-2); border: 1px solid var(--iw-border); margin-top: 8px; }
.iw-steps { margin: 0; padding: 0; list-style: none; counter-reset: iw-step; display: grid; gap: 8px; }
.iw-steps li { counter-increment: iw-step; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 8px; font-size: 12.8px; }
.iw-steps li::before { content: counter(iw-step); grid-row: span 2; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--iw-primary-soft); color: var(--iw-primary); font-weight: 700; font-size: 11.5px; }
.iw-steps li small { color: var(--iw-muted); font-size: 11.5px; }
.iw-ai-chat { display: flex; gap: 8px; margin-top: 10px; }
.iw-ai-chat[hidden], .iw-ai-thread[hidden] { display: none; } /* rc1 fix: form had no handler but was visible */
.iw-ai-chat input { flex: 1; min-width: 0; height: 38px; padding: 0 12px; border: 1px solid var(--iw-border-strong); border-radius: 9px; background: var(--iw-surface); color: var(--iw-text); font: 13px var(--iw-font); }
.iw-ai-thread { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; max-height: 260px; overflow-y: auto; }
.iw-ai-thread li { padding: 8px 10px; border-radius: 10px; font-size: 12.8px; background: var(--iw-surface-2); border: 1px solid var(--iw-border); }
.iw-ai-thread li[data-role="user"] { background: var(--iw-primary-soft); border-color: transparent; margin-left: 24px; }
.iw-status-list { list-style: none; margin: 0; padding: 6px 14px 12px; display: grid; }
.iw-status-list li { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--iw-border); }
.iw-status-list li:last-child { border-bottom: 0; }
.iw-status-list strong { display: block; font-size: 12.8px; }
.iw-status-list small { display: block; font-size: 11.5px; color: var(--iw-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iw-status-list svg { color: var(--iw-muted); }

/* Toasts */
.iw-toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.iw-toast { padding: 11px 14px; border-radius: 10px; background: var(--iw-text); color: var(--iw-surface); font-size: 13px; box-shadow: var(--iw-shadow); animation: iw-in .2s ease; }
.iw-toast[data-tone="danger"] { background: #b91c1c; color: #fff; }
.iw-toast[data-tone="success"] { background: #15803d; color: #fff; }
.iw-toast.is-leaving { opacity: 0; transition: opacity .35s; }
@keyframes iw-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------------ */
/* Dark theme for the existing editor surfaces                          */
/* ------------------------------------------------------------------ */
[data-theme="dark"] .iw-app .vl-code-workspace,
[data-theme="dark"] .iw-app .vl-sim-workspace,
[data-theme="dark"] .iw-app .vl-file-tabs,
[data-theme="dark"] .iw-app .vl-sim-tabs,
[data-theme="dark"] .iw-app .vl-stagebar,
[data-theme="dark"] .iw-app .vl-editor-status,
[data-theme="dark"] .iw-app .vl-build-panel,
[data-theme="dark"] .iw-app .vl-serial-panel,
[data-theme="dark"] .iw-app .vl-console-tabs,
[data-theme="dark"] .iw-app .vl-instrument-tabs,
[data-theme="dark"] .iw-app .vl-instrument-panel,
[data-theme="dark"] .iw-app .vl-instrument-panel header,
[data-theme="dark"] .iw-app .vl-information-panel,
[data-theme="dark"] .iw-app .ri-fw-bottom-panel,
[data-theme="dark"] .iw-app .vl-drawer { background: var(--iw-surface) !important; color: var(--iw-text) !important; border-color: var(--iw-border) !important; }
[data-theme="dark"] .iw-app .vl-editor-frame,
[data-theme="dark"] .iw-app .vl-code-layer,
[data-theme="dark"] .iw-app #vlSource,
[data-theme="dark"] .iw-app #vlSyntaxHighlight,
[data-theme="dark"] .iw-app .vl-line-numbers { background: var(--iw-code-bg) !important; color: var(--iw-code-text) !important; border-color: var(--iw-border) !important; }
[data-theme="dark"] .iw-app #vlSource { caret-color: #fff; }
[data-theme="dark"] .iw-app .vl-line-numbers { color: #5f739a !important; }
[data-theme="dark"] .iw-app .vl-token-keyword { color: #0ca1a6 !important; }
[data-theme="dark"] .iw-app .vl-token-function { color: #f39c12 !important; }
[data-theme="dark"] .iw-app .vl-token-constant { color: #0ca1a6 !important; }
[data-theme="dark"] .iw-app .vl-token-string { color: #7fcbcd !important; }
[data-theme="dark"] .iw-app .vl-token-comment { color: #7f8c8d !important; }
[data-theme="dark"] .iw-app .vl-token-preprocessor { color: #c1de6f !important; }
[data-theme="dark"] .iw-app .vl-token-number { color: #e2c08d !important; }
[data-theme="dark"] .iw-app .vl-file-tabs button,
[data-theme="dark"] .iw-app .vl-file-tabs [role="tab"],
[data-theme="dark"] .iw-app .vl-console-tabs button,
[data-theme="dark"] .iw-app .vl-instrument-tabs button,
[data-theme="dark"] .iw-app .vl-sim-tabs button { background: transparent !important; color: var(--iw-muted) !important; border-color: var(--iw-border) !important; }
[data-theme="dark"] .iw-app .vl-file-tabs .is-active,
[data-theme="dark"] .iw-app .vl-file-tabs [aria-selected="true"],
[data-theme="dark"] .iw-app .vl-console-tabs .is-active,
[data-theme="dark"] .iw-app .vl-instrument-tabs .is-active,
[data-theme="dark"] .iw-app .vl-sim-tabs .active { background: var(--iw-surface-3) !important; color: #fff !important; }
[data-theme="dark"] .iw-app #vlSerialOutput,
[data-theme="dark"] .iw-app #ri-fw-unified-console,
[data-theme="dark"] .iw-app #vlBusOutput { background: var(--iw-console-bg) !important; color: var(--iw-console-text) !important; }
[data-theme="dark"] .iw-app input, [data-theme="dark"] .iw-app select, [data-theme="dark"] .iw-app textarea:not(#vlSource) {
    background: var(--iw-surface-2) !important; color: var(--iw-text) !important; border-color: var(--iw-border-strong) !important;
}
[data-theme="dark"] .iw-app .vl-node .vl-node-label, [data-theme="dark"] .iw-app .vl-node-title { color: var(--iw-text) !important; }
[data-theme="dark"] .iw-app .vl-information-panel dt, [data-theme="dark"] .iw-app .vl-instrument-note { color: var(--iw-muted) !important; }
[data-theme="dark"] .iw-app .ri-agent-toolbar__device,
[data-theme="dark"] .iw-app .ri-agent-toolbar__board-manager,
[data-theme="dark"] .iw-app .ri-agent-toolbar__flavours { background: var(--iw-surface-2) !important; color: var(--iw-text) !important; border-color: var(--iw-border-strong) !important; }
[data-theme="dark"] .iw-app .vl-studio-header { background: var(--iw-surface) !important; }
[data-theme="dark"] .iw-app .vl-save-split .vl-header-button, [data-theme="dark"] .iw-app .vl-header-button.is-share { background: var(--iw-surface-2) !important; color: #9cc2ff !important; }

/* ------------------------------------------------------------------ */
/* Responsive                                                           */
/* ------------------------------------------------------------------ */
@media (max-width: 1599px) {
    :root { --iw-side-w: 212px; --iw-right-w: 344px; }
    .iw-primary-nav a { padding: 0 10px; }
    .iw-agent-chip span { display: none; }
}
@media (max-width: 1439px) {
    .iw-primary-nav a span { display: none; }
    .iw-primary-nav a.is-active span { display: inline; }
}
@media (max-width: 1365px) {
    :root { --iw-side-w: 68px; --iw-right-w: 320px; }
    .iw-sidebar { padding: 12px 8px; align-items: center; }
    .iw-side-title, .iw-mode small, .iw-mode strong, .iw-panel-link span, .iw-device-card div, .iw-device-card .iw-button { display: none; }
    .iw-mode, .iw-panel-link { justify-content: center; padding: 10px; width: 48px; }
    .iw-device-card { grid-template-columns: 1fr; padding: 6px; }
    .iw-device-card img { width: 34px; height: 60px; margin: 0 auto; }
    .iw-primary-nav a span { display: none; }
    .iw-primary-nav a.is-active span { display: inline; }
    .iw-account-text { display: none; }
}
@media (max-width: 1100px) {
    .iw-stage { grid-template-columns: minmax(0, 1fr); height: auto; }
    .iw-app .iw-stage .vl-studio { height: calc(100vh - var(--iw-top-h) - var(--iw-bar-h)) !important; min-height: 620px !important; border-right: 0; }
    .iw-right { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
    .iw-status-card { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
    :root { --iw-top-h: 56px; --iw-bar-h: auto; }
    .iw-frame { grid-template-columns: minmax(0, 1fr); }
    .iw-sidebar { display: none; }
    .iw-nav-toggle { display: flex; }
    .iw-brand small { display: none; }
    .iw-primary-nav {
        display: none; position: absolute; top: var(--iw-top-h); left: 0; right: 0; flex-direction: column; align-items: stretch; margin: 0;
        padding: 10px; background: var(--iw-nav-bg); box-shadow: 0 16px 30px rgba(0, 0, 0, .3);
    }
    .iw-nav-open .iw-primary-nav { display: flex; }
    .iw-primary-nav a span { display: inline !important; }
    .iw-agent-chip, .iw-hide-sm { display: none; }
    .iw-app .vl-studio-header { height: auto; min-height: 0; flex-wrap: wrap; padding: 10px 12px; }
    .iw-app .vl-project-heading { max-width: 100%; }
    .iw-app .vl-project-heading h1 { font-size: 16px !important; }
    .iw-app .vl-header-primary, .iw-app .vl-header-secondary { flex-wrap: wrap; width: 100%; }
    .iw-mobile-tabs {
        display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px; background: var(--iw-surface); border-bottom: 1px solid var(--iw-border);
        position: sticky; top: var(--iw-top-h); z-index: 30;
    }
    .iw-mobile-tabs button {
        flex: 1 0 auto; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--iw-border-strong); background: var(--iw-surface-2);
        color: var(--iw-text); font: 600 13px var(--iw-font);
    }
    .iw-mobile-tabs button[aria-pressed="true"] { background: var(--iw-primary-bg); border-color: var(--iw-primary-bg); color: #fff; }
    .iw-mobile-tabs select { flex: 0 0 auto; min-height: 36px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--iw-primary); background: var(--iw-primary-soft); color: var(--iw-primary); font: 600 13px var(--iw-font); }
    .iw-app .vl-studio-header .vl-header-primary { display: flex !important; }
    .iw-app .vl-studio-header .vl-project-heading { display: block !important; }
    .iw-app .iw-project-meta { display: none; }
    .iw-stage { display: block; height: auto; min-height: 0; }
    .iw-app .iw-stage .vl-studio { display: block !important; height: auto !important; min-height: 0 !important; }
    .iw-app .vl-workspace-divider { display: none !important; }
    .iw-right { display: block; padding: 10px; }
    .iw-right > .iw-card { margin-bottom: 10px; }
    /* one panel at a time */
    .iw-app .vl-code-workspace, .iw-app .vl-sim-workspace, .iw-app .iw-twin-card, .iw-app .iw-ai-card, .iw-app .iw-status-card { display: none !important; }
    .iw-app[data-iw-panel="code"] .vl-code-workspace { display: flex !important; flex-direction: column; height: calc(100vh - 210px); min-height: 460px; }
    .iw-app[data-iw-panel="circuit"] .vl-sim-workspace, .iw-app[data-iw-panel="serial"] .vl-sim-workspace { display: flex !important; flex-direction: column; height: calc(100vh - 210px); min-height: 520px; }
    .iw-app[data-iw-panel="serial"] .vl-sim-workspace .vl-canvas, .iw-app[data-iw-panel="serial"] .vl-stagebar, .iw-app[data-iw-panel="serial"] .iw-zoom-bar { display: none !important; }
    .iw-app[data-iw-panel="serial"] .vl-serial-panel { flex: 1; height: auto !important; }
    .iw-app[data-iw-panel="twin"] .iw-twin-card, .iw-app[data-iw-panel="twin"] .iw-status-card { display: block !important; }
    .iw-app[data-iw-panel="ai"] .iw-ai-card { display: block !important; }
    .iw-app:not([data-iw-panel="twin"]):not([data-iw-panel="ai"]) .iw-right { display: none; }
    .iw-zoom-bar { bottom: calc(var(--vl-serial-height, 190px) + 16px); }
}
@media (prefers-reduced-motion: reduce) {
    .iw-flash, .iw-toast { animation: none !important; }
}

/* Accessibility (WCAG AA contrast) for existing editor parts inside the IoTwin shell only */
.iw-app #vlLineNumbers span { color: #5b6878; }
[data-theme="dark"] .iw-app #vlLineNumbers span { color: #a3b3c9; }
.iw-app [data-console], .iw-app .vl-console-tabs button { color: #4b5768; }
[data-theme="dark"] .iw-app [data-console], [data-theme="dark"] .iw-app .vl-console-tabs button { color: #c3d0e6; }
.iw-app .vl-node-code { color: #4b5768; }

/* Dark theme: existing editor parts keep light cards on the canvas — keep their text dark; lift muted labels. */
[data-theme="dark"] .iw-app .vl-node:not(.is-hardware) { color: #0f1c30; }
[data-theme="dark"] .iw-app .vl-node:not(.is-hardware) .vl-pin:not(.is-anchor) { color: #0f1c30; }
[data-theme="dark"] .iw-app .iw-breadcrumb, [data-theme="dark"] .iw-app [data-device-button-label],
[data-theme="dark"] .iw-app .vl-serial-source, [data-theme="dark"] .iw-app #vlBaudLabel, [data-theme="dark"] .iw-app #vlSerialStatus { color: var(--iw-muted) !important; }
[data-theme="dark"] .iw-app .iw-breadcrumb span { color: var(--iw-muted) !important; }

/* G4 (2026-10-20): the closed project menu must not widen the page on phones; open it right-aligned. */
.vl-project-menu:not([open]) > :not(summary) { display: none !important; }
.vl-project-menu > div { right: 0; left: auto; }

/* ------------------------------------------------------------------ */
/* Audit UX 2026-10-23: editor Virtual Lab tanpa menu kiri             */
/* Mode Lab menjadi tombol segmen di header; kembali ke daftar lewat    */
/* tautan "‹ Virtual Lab" di bawah judul.                               */
/* ------------------------------------------------------------------ */
.iw-frame-wide { grid-template-columns: minmax(0, 1fr); }
.iw-heading-sub { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; color: var(--iw-muted); white-space: nowrap; overflow: hidden; }
.iw-heading-sub #vlSaveStatus { overflow: hidden; text-overflow: ellipsis; }
.iw-back-link { color: var(--iw-primary) !important; text-decoration: none; font-weight: 600; }
.iw-back-link:hover { text-decoration: underline; }
.iw-mode-switch { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--iw-border); border-radius: 11px; background: var(--iw-surface-2); flex: 0 0 auto; }
.iw-mode-switch button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px; border: 0; border-radius: 8px; background: none; color: var(--iw-text-2); font: 600 12.5px var(--iw-font); cursor: pointer; white-space: nowrap; }
.iw-mode-switch button svg { width: 16px; height: 16px; color: var(--iw-muted); }
.iw-mode-switch button:hover { background: var(--iw-surface-3); color: var(--iw-text); }
.iw-mode-switch button[aria-checked="true"] { background: var(--iw-primary-bg); color: #fff; box-shadow: 0 4px 12px rgba(29, 107, 243, .28); }
.iw-mode-switch button[aria-checked="true"] svg { color: rgba(255, 255, 255, .92); }
.iw-mode-short { display: none; }
.iw-session-pill { flex: 0 0 auto; }
@media (max-width: 1599px) {
    .iw-mode-long { display: none; }
    .iw-mode-short { display: inline; }
    .iw-app .vl-project-heading { max-width: 300px; }
}
@media (max-width: 1279px) {
    .iw-mode-switch button { padding: 0 9px; }
    .iw-mode-switch button:not([aria-checked="true"]) .iw-mode-short { display: none; }
    .iw-app .vl-project-heading { max-width: 220px; }
}
@media (max-width: 900px) {
    .iw-mode-switch { display: none; }
}

/* Petunjuk kanvas kosong: kanan bawah area kanvas, di atas panel instrumen (tidak ikut tergulir). */
.iw-app .vl-sim-workspace > .vl-empty-canvas:not([hidden]) { inset: auto 14px calc(var(--vl-serial-height, 190px) + 58px) auto !important; }
@media (max-width: 900px) { .iw-app .vl-sim-workspace > .vl-empty-canvas:not([hidden]) { inset: auto 10px calc(var(--vl-serial-height, 190px) + 16px) auto !important; width: min(280px, calc(100% - 20px)) !important; } }
/* Tombol segmen mode: kontras teks tetap terbaca di atas gaya tombol header lama. */
.iw-app .vl-studio-header .iw-mode-switch button { color: var(--iw-text-2) !important; background: none !important; border: 0 !important; box-shadow: none !important; }
.iw-app .vl-studio-header .iw-mode-switch button:hover { background: var(--iw-surface-3) !important; color: var(--iw-text) !important; }
.iw-app .vl-studio-header .iw-mode-switch button[aria-checked="true"] { background: var(--iw-primary-bg) !important; color: #fff !important; box-shadow: 0 4px 12px rgba(29, 107, 243, .28) !important; }
.iw-app .vl-studio-header .iw-mode-switch button span { color: inherit !important; font: inherit !important; }
[data-theme="dark"] .iw-app .vl-empty-canvas strong { color: var(--iw-text) !important; }
[data-theme="dark"] .iw-app .vl-empty-canvas span { color: var(--iw-muted) !important; }
/* Tema gelap: tombol Simpan ▾ tetap biru tua (bukan biru muda) dan menu tab berkas tidak putih. */
[data-theme="dark"] .iw-app .vl-save-split .vl-header-button.is-save,
[data-theme="dark"] .iw-app .vl-project-menu summary { background: var(--iw-primary-bg) !important; color: #fff !important; border-color: var(--iw-primary-bg) !important; }
[data-theme="dark"] .iw-app .vl-file-tabs .vl-tab-menu summary,
[data-theme="dark"] .iw-app .vl-file-tabs details > summary { background: transparent !important; color: var(--iw-text) !important; }

/* Audit tema 2026-10-24: latar studio & dock bawah ikut gelap (tidak ada celah putih di antara panel). */
[data-theme="dark"] .vl-studio { background: var(--iw-bg); }
[data-theme="dark"] #ri-fw-bottom-dock.vl-build-panel { background: var(--iw-surface) !important; border-color: var(--iw-border) !important; }

/* Opsi A: tombol bahasa ID/EN di bilah atas editor (warna mengikuti navbar navy). */
.iw-topnav .iw-locale-switch { height: 36px; border-color: rgba(255, 255, 255, .22); color: var(--iw-nav-text); background: transparent; }
.iw-topnav .iw-locale-switch:hover { border-color: #9cc0ff; color: #fff; }

/* Opsi A (2026-10-24): pasangkan perangkat langsung dari panel Digital Twin editor. */
.iw-twin-pairing { margin-top: 12px; padding: 12px; border: 1px solid var(--iw-border); border-radius: 12px; background: var(--iw-surface-2); }
.iw-twin-pairing[hidden] { display: none; }
.iw-twin-pairing:focus { outline: none; }
.iw-pair-title { margin: 0 0 4px; font-size: 13.5px; font-weight: 800; color: var(--iw-text); }
.iw-pair-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.iw-pair-list li { display: grid; gap: 5px; padding: 9px 10px; border: 1px solid var(--iw-border); border-radius: 10px; background: var(--iw-surface); }
.iw-pair-sig { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0; }
.iw-pair-sig b { font-size: 12.5px; color: var(--iw-text); }
.iw-pair-sig small { font-size: 11px; color: var(--iw-muted); white-space: nowrap; }
.iw-pair-list select { width: 100%; min-height: 34px; padding: 6px 8px; border: 1px solid var(--iw-border-strong); border-radius: 8px; background: var(--iw-surface); color: var(--iw-text); font: inherit; font-size: 12.5px; }
.iw-pair-list select:focus { outline: none; border-color: var(--iw-primary); box-shadow: var(--iw-focus); }
.iw-pair-list select:disabled { opacity: .6; cursor: not-allowed; }
.iw-pair-desired { font-size: 11px; font-weight: 700; color: var(--iw-muted); margin-top: 2px; }
.iw-pair-warn { font-size: 11px; color: var(--iw-danger); }
.iw-twin-pairing .iw-empty { display: grid; gap: 4px; padding: 12px; margin: 10px 0 0; border: 1px dashed var(--iw-border-strong); border-radius: 10px; background: var(--iw-surface); font-size: 12.5px; color: var(--iw-text-2); }
.iw-twin-pairing .iw-empty strong { color: var(--iw-text); }
.iw-twin-pairing .iw-actions { margin-top: 10px; }
.iw-twin-empty [data-iw-twin-actions] { display: flex; flex-wrap: wrap; gap: 6px; }
.iw-twin-empty [data-iw-twin-actions] .iw-button { height: 32px; padding: 0 10px; font-size: 12.5px; flex: 1 1 auto; justify-content: center; }
.iw-twin-empty [data-iw-twin-actions] .iw-button svg { width: 15px; height: 15px; }
