/*
 * Design tokens
 * 5 colors, 3 font sizes, 2 fonts, 2 border widths, 1 radius
 */
:root {
    --c-bg:      #f4f5f7;
    --c-surface: #ffffff;
    --c-border:  #dfe1e6;
    --c-text:    #2c3e50;
    --c-muted:   #7a8599;
    --c-accent:  #2563eb;
    --c-hover:   #eceef1;

    --f-sans: "Inter", "Segoe UI", system-ui, sans-serif;
    --f-mono: "JetBrains Mono", "Fira Code", monospace;

    --fs-s: 1.3rem;
    --fs-m: 1.5rem;
    --fs-l: 1.7rem;

    --bw: 1px;
    --bw2: 2px;
    --r: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: hidden; }
body { margin: 0; font-family: var(--f-sans); color: var(--c-text); background: var(--c-bg); font-size: var(--fs-m); overflow-x: hidden; width: 100vw; max-width: 100%; }

/* --- Reset Milligram overrides --- */
select { -webkit-appearance: none; -moz-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237a8599'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.4rem center; background-size: 10px 6px;
    padding-right: 1.4rem !important;
}
button { margin-bottom: 0; }

/* --- Navbar --- */
.navbar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; gap: 1.5rem;
    padding: 0.6rem 2rem;
    background: var(--c-text); color: var(--c-surface);
}
.navbar-brand { font-size: var(--fs-l); font-weight: 700; cursor: pointer; margin: 0; }
.navbar-links { margin-left: auto; display: flex; gap: 1.5rem; }
.navbar-links a { color: var(--c-muted); text-decoration: none; font-size: var(--fs-s); }
.navbar-links a:hover { color: var(--c-surface); }
.hamburger { display: none; background: none; border: none; color: var(--c-surface); font-size: 1.3rem; cursor: pointer; padding: 0; }

/* --- Layout --- */
.app-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    max-width: 960px;
    margin: 0 auto;
    min-height: calc(100vh - 44px - 32px);
}

/* --- Sidebar --- */
.sidebar { background: var(--c-surface); border-right: var(--bw) solid var(--c-border); padding: 0.8rem 0.6rem; font-size: var(--fs-s); }
.sidebar-section { margin-bottom: 0.8rem; }
.sidebar-section h3 { font-size: var(--fs-s); text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-muted); margin: 0 0 0.3rem 0.2rem; }
.sidebar-btn {
    display: block; width: 100%;
    background: var(--c-bg); border: var(--bw) solid var(--c-border);
    padding: 0.15rem 0.5rem; margin-bottom: 0.1rem; border-radius: var(--r);
    cursor: pointer; font-size: var(--fs-s); color: var(--c-text); text-align: left;
    font-family: var(--f-sans); line-height: 1.4;
}
.sidebar-btn:hover { background: var(--c-hover); }
.sidebar-btn.primary { background: var(--c-accent); color: var(--c-surface); border-color: var(--c-accent); }
.sidebar-btn.primary:hover { opacity: 0.85; }
.sidebar-btn.danger { background: #c0392b; color: #fff; border-color: #a93226; }
.sidebar-btn.danger:hover { background: #a93226; }
.sidebar-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.sidebar-list { list-style: none; padding: 0; margin: 0 0 0.1rem 0; }
.sidebar-list-item {
    padding: 0.15rem 0.5rem; border-radius: var(--r);
    cursor: pointer; font-size: var(--fs-s); margin-bottom: 0.1rem;
    line-height: 1.4;
}
.sidebar-list-item:hover { background: var(--c-hover); }
.sidebar-list-item.active { background: var(--c-accent); color: var(--c-surface); }

.main-content { padding: 1.2rem 1.5rem; }

/* --- Tabs + subtabs ---
   Horizontally scrollable when there are more tabs than fit. On narrow
   viewports (mesh tab can generate 8+ subtabs from the catalog) the
   user flicks/scrolls the bar; flex-shrink:0 on buttons keeps their
   natural width so they don't squeeze into unreadable slivers. */
.tabs, .subtabs {
    display: flex; flex-wrap: nowrap; gap: 0;
    border-bottom: var(--bw2) solid var(--c-border); margin-bottom: 1rem;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.tabs::-webkit-scrollbar,
.subtabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb,
.subtabs::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
.tab-btn, .subtab-btn {
    padding: 0.5rem 1rem; border: none; background: none;
    font-family: var(--f-sans); font-size: var(--fs-m); font-weight: 500;
    color: var(--c-muted); cursor: pointer;
    border-bottom: var(--bw2) solid transparent; margin-bottom: calc(-1 * var(--bw2));
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap; flex-shrink: 0;
}
.subtab-btn { font-size: var(--fs-s); padding: 0.35rem 0.8rem; }
.subtabs { border-bottom-width: var(--bw); margin-bottom: 0.8rem; }
.tab-btn:hover, .subtab-btn:hover { color: var(--c-text); background: var(--c-hover); }
.tab-btn.active, .subtab-btn.active { color: var(--c-accent); border-bottom-color: var(--c-accent); background: none; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

/* --- Cards --- */
.card {
    border: var(--bw) solid var(--c-border); border-radius: var(--r);
    background: var(--c-surface); margin-bottom: 0.8rem;
    cursor: pointer; transition: border-color 0.15s;
}
.card:hover { border-color: var(--c-muted); }
.card.selected { border: var(--bw2) solid var(--c-accent); }
.card.collapsed .card-body,
.card.collapsed .expandable { display: none; }
.card-header {
    padding: 0.5rem 0.8rem;
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-weight: 600; font-size: var(--fs-m); }
.card-header-actions { display: flex; gap: 0.3rem; align-items: center; visibility: hidden; }
.card.selected .card-header-actions { visibility: visible; }
.card[data-requires-tag] .card-header-actions { visibility: visible; }
.card-body { padding: 0 0.8rem 0.5rem; }
.card-description { color: var(--c-muted); font-size: var(--fs-s); line-height: 1.5; margin: 0 0 0.4rem 0; }
.card-description img { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: var(--r); margin: 0.3rem 0; display: block; }
.card-description .katex { font-size: var(--fs-m); }
.card-description p { margin: 0.3rem 0; }
.card-description h2, .card-description h3, .card-description h4 { margin: 0.5rem 0 0.2rem; color: var(--c-text); }
.card-description ul, .card-description ol { margin: 0.3rem 0 0.3rem 1.2rem; padding: 0; }
.card-description li { margin: 0.1rem 0; }
.card-description code { background: var(--c-hover); padding: 0 0.25rem; border-radius: var(--r); font-family: var(--f-mono); font-size: 0.9em; }
.card-description pre.md-code { background: var(--c-bg); border: var(--bw) solid var(--c-border); border-radius: var(--r); padding: 0.4rem 0.6rem; overflow: auto; font-size: 0.85em; }
.card-description hr { border: 0; border-top: var(--bw) solid var(--c-border); margin: 0.5rem 0; }

/* --- Unified card anatomy ---
   Code-bearing cards all share the same shape:
     header -> description? -> controls -> #params -> #editor-wrap -> output.
   The controls bar carries per-frame knobs (timeline / field selector)
   plus gear / edit / play / size. The play button is HIDDEN by
   default — CSS reveals it on vis cards and on any card whose edit
   panel is open (see .card.has-vis / .card.edit-open below). */
.card-controls { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0.3rem 0; }
.card-output { margin: 0.3rem 0; }
.card-output .output-cells { border: var(--bw) solid var(--c-border); border-radius: var(--r); background: var(--c-bg); max-height: 480px; overflow: auto; }
.card-output-preview { display: block; width: 100%; max-height: 280px; object-fit: contain; }
.card-code { /* .expandable handles collapse */ }
/* Play button — styled as an accent variant of .icon-btn. Selectors are
   doubled to outrank the generic .icon-btn rules that appear later in
   this file (CSS cascade: equal specificity → later wins; we bump
   specificity with .card .card-play-btn instead). */
.card .card-play-btn { display: none; background: var(--c-accent); color: var(--c-surface); border-color: var(--c-accent); }
.card.has-vis   .card-play-btn,
.card.edit-open .card-play-btn { display: inline-flex; }
.card .card-play-btn:hover { opacity: 0.85; }
.card .card-play-btn:disabled { opacity: 0.5; cursor: wait; }

/* Title is the ONLY collapse handle now (independent of selection). */
.card-title { cursor: pointer; user-select: none; }

.card-select {
    padding: 0.15rem 1.4rem 0.15rem 0.4rem; border: var(--bw) solid var(--c-border);
    border-radius: var(--r); font-size: var(--fs-s); font-family: var(--f-sans);
    background-color: var(--c-surface); color: var(--c-text); height: 28px;
}

/* --- Icon buttons --- */
.icon-btn {
    background: var(--c-bg); border: var(--bw) solid var(--c-border);
    cursor: pointer; border-radius: var(--r);
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.3rem; color: var(--c-muted); line-height: 1;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.icon-btn.sm { width: 28px; height: 28px; font-size: 1rem; }
/* Trash icon on user-authored cards. Red on hover so accidental clicks
   stand out before the confirm() prompt fires. */
.icon-btn.card-trash-btn:hover { background: #c0392b; color: #fff; border-color: #a93226; }
.icon-btn:hover { background: var(--c-hover); color: var(--c-text); }
.icon-btn.open { background: var(--c-accent); color: var(--c-surface); border-color: var(--c-accent); }
.icon-btn:disabled { opacity: 0.3; cursor: wait; }

/* --- Maximized card overlay ---
   Every code-bearing card maximizes to a side-by-side "code | output"
   layout. Controls bar + play button pin to the code pane so timeline
   scrubbing stays within reach while the output fills the right half. */
.card.maximized {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 200; border-radius: 0; margin: 0; overflow: hidden;
    display: grid; grid-template-rows: auto 1fr;
}
.card.maximized .card-body {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem;
    height: 100%; overflow: hidden;
    grid-template-areas:
        "code output"
        "code output";
}
.card.maximized .card-description,
.card.maximized .card-controls,
.card.maximized .card-code,
.card.maximized .card-play { grid-column: code; }
.card.maximized .card-output { grid-column: output; overflow: auto; }
.card.maximized .card-code { display: block; max-height: none; overflow: auto; }
.card.maximized .card-code .inline-editor { height: calc(100vh - 240px); min-height: 300px; }
.card.maximized .card-output .output-cells { max-height: none; height: 100%; }

/* --- Expandable panels --- */
.expandable { overflow: hidden; max-height: 0; transition: max-height 0.3s ease; }
.expandable.open { max-height: 3000px; border-top: var(--bw) solid var(--c-border); padding: 0.5rem 0.8rem; }

/* --- Param Widgets --- */
/* Param widgets — two (label | widget) pairs per row on wide viewports,
   one pair per row on narrow ones. Each .param-row uses display:contents
   so its children (label + widget) become direct grid children,
   aligning labels in one column and widgets in the next. No more label /
   selector overlap inside a flex row. */
.param-widgets { display: grid; grid-template-columns: auto 1fr auto 1fr; column-gap: 0.8rem; row-gap: 0.15rem; align-items: center; }
@media (max-width: 700px) { .param-widgets { grid-template-columns: auto 1fr; } }
.param-row { display: contents; }
.param-label { color: var(--c-muted); font-family: var(--f-mono); font-size: var(--fs-s); padding: 0.2rem 0; white-space: nowrap; }
.param-widgets input, .param-widgets select { font-size: var(--fs-s); font-family: var(--f-sans); min-width: 0; }
.param-widgets input[type="number"] { width: 100%; max-width: 120px; padding: 0.1rem 0.25rem; border: var(--bw) solid var(--c-border); border-radius: var(--r); }
.param-widgets input[type="text"]   { width: 100%; max-width: 180px; padding: 0.1rem 0.25rem; border: var(--bw) solid var(--c-border); border-radius: var(--r); }
.param-widgets input[type="checkbox"] { margin: 0; justify-self: start; }
.param-widgets select { padding: 0.1rem 1.4rem 0.1rem 0.25rem; border: var(--bw) solid var(--c-border); border-radius: var(--r); max-width: 100%; }
.param-slider-wrap { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.param-slider-wrap input[type="range"] { flex: 1; height: 4px; min-width: 0; }
.param-value { font-family: var(--f-mono); font-size: var(--fs-s); min-width: 48px; text-align: right; }
.param-dict { border: var(--bw) solid var(--c-border); border-radius: var(--r); padding: 0.3rem; margin: 0; grid-column: 1 / -1; }
.param-dict legend { font-size: var(--fs-s); font-weight: 600; padding: 0 0.2rem; }
.param-dict .param-widgets { gap: 0.1rem 0.6rem; }

/* --- Inline editor --- */
.inline-editor { height: 200px; width: 100%; }

/* --- Gear description editor --- */
.gear-desc-section { margin: 0.4rem 0; grid-column: 1 / -1; }
.gear-desc-toggle {
    cursor: pointer; font-size: var(--fs-s); color: var(--c-muted);
    padding: 0.2rem 0; user-select: none;
}
.gear-desc-toggle:hover { color: var(--c-text); }
.gear-desc-editor {
    border: var(--bw) solid var(--c-border); border-radius: var(--r); overflow: hidden;
}
.gear-desc-editor .ace_editor {
    font-family: var(--f-sans) !important;
    font-size: var(--fs-s) !important;
    line-height: 1.5 !important;
    background: var(--c-surface) !important;
    color: var(--c-text) !important;
}
.gear-desc-editor .ace_content { background: var(--c-surface) !important; }
.gear-desc-editor .ace_cursor { color: var(--c-text) !important; }
.gear-desc-editor .ace_active-line { background: var(--c-hover) !important; }
.gear-desc-editor .ace_gutter { display: none !important; }

/* --- Timeline in card actions --- */
.card-timeline { display: flex; align-items: center; gap: 0.3rem; flex: 1; }
.card-timeline input[type="range"] { flex: 1; }
.card-timeline span { font-size: var(--fs-s); font-family: var(--f-mono); min-width: 32px; text-align: right; }

/* --- Backend indicator (navbar) --- */
.backend-indicator {
    font-size: var(--fs-s); color: var(--c-muted);
    padding: 0.15rem 0.5rem; border-radius: 10px;
    border: var(--bw) solid var(--c-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px;
}
.backend-indicator.connected { color: #22c55e; border-color: #22c55e; }

/* --- Card connection status (solver cards) --- */
.card-connection-status {
    font-size: var(--fs-s); color: var(--c-muted); font-weight: 500;
    padding: 0.1rem 0.4rem; border-radius: 10px;
    border: var(--bw) solid var(--c-muted);
}
.card-connection-status.connected { color: #22c55e; border-color: #22c55e; }

/* --- Session connection tags --- */
.session-connections { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.session-conn-tag {
    font-size: var(--fs-s); color: var(--c-text);
    padding: 0.1rem 0.5rem; border-radius: 10px;
    background: var(--c-bg); border: var(--bw) solid var(--c-border);
    display: inline-flex; align-items: center; gap: 0.3rem;
}
.session-conn-x {
    background: none; border: none; cursor: pointer;
    color: var(--c-muted); font-size: var(--fs-m); line-height: 1; padding: 0;
}
.session-conn-x:hover { color: #dc2626; }

/* --- Sidebar input --- */
.sidebar-input {
    display: block; width: 100%; margin-bottom: 0.2rem;
    padding: 0.15rem 0.4rem; border: var(--bw) solid var(--c-border);
    border-radius: var(--r); font-size: var(--fs-s); font-family: var(--f-mono);
    color: var(--c-text); background: var(--c-surface);
}

/* --- Disabled cards (requires backend) --- */
/* Disabled = the card's backend tag isn't connected. The card stays
   clickable so the user can expand it and look at params/code; the
   Run button's handler refuses the run with a toast. */
.card.disabled { opacity: 0.5; }
.card.disabled .card-play-btn { opacity: 0.6; cursor: not-allowed; }

/* --- Progress bar --- */
.progress-bar { height: 4px; background: var(--c-border); border-radius: 2px; overflow: hidden; margin-top: 0.3rem; }
.progress-bar-fill { height: 100%; background: var(--c-accent); transition: width 0.3s; width: 0%; }

/* --- Debug panel --- */
.debug-panel {
    border: var(--bw) solid var(--c-border); border-radius: var(--r);
    background: var(--c-surface); overflow: hidden;
}
.debug-header {
    padding: 0.3rem 0.6rem; background: var(--c-bg);
    border-bottom: var(--bw) solid var(--c-border);
    display: flex; align-items: center; justify-content: space-between;
    font-size: var(--fs-s); font-weight: 600; color: var(--c-muted);
}
.debug-log {
    height: 150px; overflow-y: auto; padding: 0.4rem 0.6rem;
    font-family: var(--f-mono); font-size: var(--fs-s); line-height: 1.4;
    background: #1e1e2e; color: #a0a8b8;
}

/* --- Dashboard --- */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.dashboard-card { border: var(--bw) solid var(--c-border); border-radius: var(--r); background: var(--c-surface); padding: 0.8rem; }
.dashboard-card h3 { font-size: var(--fs-m); margin: 0 0 0.3rem 0; }
.dashboard-card p { font-size: var(--fs-s); color: var(--c-muted); margin: 0; }

/* --- Status indicators --- */
.status-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    margin-right: 0.3rem; vertical-align: middle;
}
.status-idle { background: var(--c-muted); }
.status-running { background: #22c55e; animation: status-pulse 1.5s ease-in-out infinite; }
.status-failed { background: #dc2626; }
@keyframes status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* --- Card grid layout (CardManager layout:"grid") --- */
.card-grid { display: grid; gap: 0.8rem; }
.card-grid > .card { cursor: pointer; }
.card-grid > .card:hover { border-color: var(--c-muted); }
.card-grid > .card .card-header { padding: 0.8rem 0.8rem 0.3rem; }
.card-grid > .card .card-title { font-weight: 300; }
.card-grid > .card .card-header-actions { display: none; }
.card-grid > .card .card-body { padding: 0 0.8rem 0.8rem; }
.card-grid > .card .card-description { margin: 0; }

/* --- Card variants --- */
.card--log { overflow: hidden; cursor: default; }
.card--log .card-header { padding: 0.3rem 0.6rem; background: var(--c-bg); border-bottom: var(--bw) solid var(--c-border); }
.card--log .card-title { font-weight: 600; font-size: var(--fs-s); color: var(--c-muted); }
.card--log .card-header-actions { visibility: visible; }

.card--backends { cursor: default; }
.card--backends .card-header { padding: 0.8rem 0.8rem 0; }
.card--backends .card-title { font-weight: 300; }
.card--backends .card-header-actions { display: none; }
.card--backends .card-body { padding: 0.5rem 0.8rem 0.8rem; }

.card[data-has-actions] .card-header-actions { visibility: visible; }

/* --- Card slot: log --- */
.card-slot-log {
    height: 300px; overflow-y: auto; padding: 0.4rem 0.6rem;
    font-family: var(--f-mono); font-size: var(--fs-s); line-height: 1.4;
    background: #1e1e2e; color: #a0a8b8;
    resize: vertical; min-height: 100px; max-height: 80vh;
}
.log-drag-handle {
    height: 6px; cursor: ns-resize; background: var(--c-border);
    border-radius: 3px; margin: 0 auto; width: 48px;
    opacity: 0.5; transition: opacity 0.15s;
}
.log-drag-handle:hover { opacity: 1; }

/* --- Footer --- */
.footer {
    padding: 0.5rem 2rem;
    background: var(--c-surface); border-top: var(--bw) solid var(--c-border);
    display: flex; justify-content: center; gap: 1.5rem;
    font-size: var(--fs-s); color: var(--c-muted);
}
.footer a { color: var(--c-muted); text-decoration: none; }
.footer a:hover { color: var(--c-text); }
.gui-version { font-family: var(--f-mono); font-size: var(--fs-s); color: var(--c-muted); opacity: 0.7; }

/* --- Toast stack ---
   Bottom-left, newest-on-top (flex-direction:column-reverse + appendChild).
   Each .toast is its own row with its own lifecycle; multiple can
   stack so unrelated notifications don't clobber each other. The
   stack is transparent to pointer events between toasts; each toast
   re-enables pointer-events so dismiss-on-click (future) still works. */
#toast-stack {
    position: fixed; bottom: 16px; left: 16px;
    display: flex; flex-direction: column-reverse; gap: 6px;
    z-index: 1000; pointer-events: none;
    max-width: calc(100vw - 32px);
}
.toast {
    background: var(--c-text); color: var(--c-surface);
    padding: 0.4rem 1rem; border-radius: 20px;
    font-size: var(--fs-s);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    pointer-events: auto;
    max-width: 400px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    animation: toast-in 0.18s ease-out;
    transition: opacity 0.18s ease-out, transform 0.18s ease-out;
}
.toast.toast-success { background: #2c8c4a; color: #fff; }
.toast.toast-error   { background: #c0392b; color: #fff; }
.toast.toast-leaving { opacity: 0; transform: translateX(-8px); }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* --- Output cells (notebook-style display) --- */
.output-cells {
    border-top: var(--bw) solid var(--c-border);
    background: var(--c-bg);
    max-height: 400px; overflow-y: auto;
}
.output-cell {
    padding: 0.4rem 0.6rem;
    border-bottom: var(--bw) solid var(--c-border);
    font-size: var(--fs-s);
}
.output-cell:last-child { border-bottom: none; }
.output-cell-text { font-family: var(--f-mono); white-space: pre-wrap; word-break: break-word; color: var(--c-text); line-height: 1.4; }
.output-cell-html { line-height: 1.4; }
.output-cell-html table { font-size: var(--fs-s); border-collapse: collapse; width: 100%; }
.output-cell-html table th, .output-cell-html table td { padding: 0.15rem 0.4rem; border: var(--bw) solid var(--c-border); text-align: left; }
.output-cell-html table th { background: var(--c-hover); font-weight: 600; }
.output-cell-svg { text-align: center; }
.output-cell-svg svg { max-width: 100%; height: auto; }
.output-cell-mermaid { text-align: center; padding: 0.6rem; }
.output-cell-latex { text-align: center; padding: 0.4rem; }
.output-cell-plotly { min-height: 400px; }
/* Plotly cells must grow past the shared output cap when a plot is present;
   remove the max-height constraint so the plot fills its natural size. */
.card-output .output-cells:has(.output-cell-plotly) { max-height: none; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .hamburger { display: block; }
    .navbar-links { display: none; }
    .app-layout { grid-template-columns: 1fr; max-width: 100vw; width: 100%; padding: 0; }
    .sidebar {
        display: none; position: fixed; top: 44px; left: 0;
        width: 200px; height: calc(100vh - 44px); z-index: 99;
        box-shadow: 4px 0 12px rgba(0,0,0,0.1);
    }
    .sidebar.open { display: block; }
    .navbar { padding: 0.6rem 1rem; }
    .main-content { padding: 0.6rem; max-width: 100vw; width: 100%; overflow-x: hidden; }
    .card-preview img { max-height: 180px; }
    .param-widgets { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .card-body { padding: 0 0.5rem 0.5rem; }
    .card-header { padding: 0.4rem 0.5rem; }
    .footer { padding: 0.5rem 1rem; }
    .card.maximized .editor-layout { flex-direction: column; }
}

/* Placeholder card that lives at the end of each card-bearing tab and
   hosts the + New card / Upload .msh action buttons. Sits in the same
   flow as real cards so CardManager's grid/stack spacing applies, but
   with a dashed outline signalling "this is an affordance, not data". */
.card.new-card-placeholder {
    border-style: dashed;
    background: transparent;
    padding: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    /* No hover highlight on the card itself — the buttons inside
       carry their own hover state. */
    cursor: default;
    box-shadow: none;
}
.card.new-card-placeholder:hover { border-color: var(--c-accent); }
.new-card-btn {
    flex: 1 1 200px;
    padding: 0.6rem 1rem;
    background: transparent;
    color: var(--c-muted);
    border: 1px dashed var(--c-border);
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.new-card-btn:hover {
    background: var(--c-hover);
    color: var(--c-text);
    border-color: var(--c-accent);
    border-style: solid;
}
