/* Indicator Builder — 画面。色は fx-tools-common.css の --sft-* トークンだけを使う
   (ここで生の 16 進を足すとテーマ切替で片方だけ壊れる)。 */

:root {
    --indb-cat-source: #0ea5e9;
    --indb-cat-builtin: #8b5cf6;
    --indb-cat-math: #f97316;
    --indb-cat-signal: #ec4899;
    --indb-cat-plot: #10b981;
    --indb-header-h: 52px;
    --indb-pal-w: 232px;
    --indb-side-w: 288px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--sft-bg);
    color: var(--sft-text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

.indb-home-link {
    position: fixed; top: 8px; right: 12px; z-index: 101;
    font: 600 12px/1 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--sft-text-secondary); text-decoration: none;
    background: color-mix(in srgb, var(--sft-bg-card) 75%, transparent);
    border: 1px solid var(--sft-border); padding: 6px 10px; border-radius: 8px;
    backdrop-filter: blur(6px);
    display: inline-flex; align-items: center; gap: 6px;
}
.indb-home-link svg { flex: none; }
.indb-home-link:hover { color: var(--sft-text); }
.indb-home-link b { color: var(--sft-primary-text); }

.indb-wrapper { display: flex; flex-direction: column; height: 100vh; }
.indb-hidden { display: none !important; }

/* ── ヘッダ ── */
.indb-header {
    height: var(--indb-header-h); flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 0 12px;
    background: var(--sft-bg-card); border-bottom: 1px solid var(--sft-border);
    z-index: 100;
}
.indb-header-left, .indb-header-right { display: flex; align-items: center; gap: 8px; }
.indb-header-right { padding-right: 92px; }   /* 右上の home-link を避ける */
.indb-logo { font-weight: 700; letter-spacing: -0.01em; }
.indb-badge {
    font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
    background: var(--sft-primary-bg); color: var(--sft-primary-text);
    border: 1px solid color-mix(in srgb, var(--sft-primary) 30%, transparent);
}
/* EA / Indicator の切替 (EA Builder 側の .eab-mode と同じ形) */
.indb-mode {
    display: inline-flex; align-items: center; gap: 2px; padding: 2px; flex: none;
    border: 1px solid var(--sft-border); border-radius: 999px;
}
.indb-mode-item {
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; line-height: 1.2; padding: 4px 12px; border-radius: 999px;
    color: var(--sft-text-secondary); text-decoration: none; white-space: nowrap;
}
.indb-mode-item:hover { color: var(--sft-text); }
.indb-mode-item.is-active { background: var(--sft-primary); color: var(--sft-on-primary); }
.indb-mode-item:focus-visible { outline: 2px solid var(--sft-primary); outline-offset: 2px; }
.indb-status { font-size: 12px; color: var(--sft-text-muted); min-width: 0; }
.indb-status.is-error { color: var(--sft-error); }
.indb-status.is-ok { color: var(--sft-success); }

/* ── ボタン ── */
.indb-btn {
    font: 600 13px/1 inherit; padding: 8px 12px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--sft-border); background: var(--sft-bg-card); color: var(--sft-text);
    white-space: nowrap;
}
.indb-btn:hover { background: var(--sft-bg-hover); }
.indb-btn-primary {
    background: var(--sft-primary); border-color: var(--sft-primary); color: var(--sft-on-primary);
}
.indb-btn-primary:hover { background: var(--sft-primary-dark); }
.indb-btn-danger { color: var(--sft-error); border-color: color-mix(in srgb, var(--sft-error) 40%, transparent); }
.indb-btn-danger:hover { background: var(--sft-error-bg); }
.indb-btn-block { width: 100%; margin-top: 10px; }
.indb-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.indb-icon-btn {
    width: 32px; height: 32px; border-radius: 8px; cursor: pointer; line-height: 1;
    border: 1px solid var(--sft-border); background: var(--sft-bg-card); color: var(--sft-text);
    font-size: 15px;
}
.indb-icon-btn:hover { background: var(--sft-bg-hover); }

.indb-more-wrap { position: relative; }
.indb-more-menu {
    position: absolute; right: 0; top: 38px; min-width: 178px; z-index: 200;
    background: var(--sft-bg-card); border: 1px solid var(--sft-border);
    border-radius: 10px; box-shadow: var(--sft-card-shadow); padding: 5px;
}
.indb-more-item {
    display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0;
    background: none; color: var(--sft-text); font: 500 13px/1.3 inherit;
    border-radius: 7px; cursor: pointer;
}
.indb-more-item:hover { background: var(--sft-bg-hover); }
.indb-more-danger { color: var(--sft-error); }

/* ── 本体 3 ペイン ── */
.indb-body { flex: 1 1 auto; display: flex; min-height: 0; }

.indb-palette {
    width: var(--indb-pal-w); flex: 0 0 auto; display: flex; flex-direction: column;
    background: var(--sft-bg-alt); border-right: 1px solid var(--sft-border);
}
.indb-palette.is-collapsed { display: none; }
.indb-palette-search-wrap { padding: 10px; border-bottom: 1px solid var(--sft-border); }
.indb-palette-search {
    width: 100%; padding: 7px 10px; border-radius: 8px;
    border: 1px solid var(--sft-border); background: var(--sft-input-bg); color: var(--sft-text);
    font: 13px/1.3 inherit;
}
.indb-palette-body { flex: 1 1 auto; overflow-y: auto; padding: 8px; }
.indb-cat { margin-bottom: 12px; }
.indb-cat-head {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--sft-text-muted); padding: 4px 6px;
}
.indb-pal-item {
    display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
    padding: 7px 8px; margin: 2px 0; border-radius: 8px; cursor: pointer;
    border: 1px solid transparent; background: none; color: var(--sft-text);
    font: 500 13px/1.3 inherit;
}
.indb-pal-item:hover { background: var(--sft-bg-hover); border-color: var(--sft-border); }
.indb-pal-item .indb-pal-icon { font-size: 15px; width: 20px; text-align: center; }
.indb-pal-item .indb-pal-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── キャンバス ── */
.indb-canvas-wrap { flex: 1 1 auto; position: relative; min-width: 0; background: var(--sft-bg); }
#indb-drawflow { width: 100%; height: 100%; }
.indb-canvas-hint {
    position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
    text-align: center; color: var(--sft-text-muted); pointer-events: none;
    display: flex; flex-direction: column; gap: 6px; font-size: 13px;
}
.indb-canvas-hint strong { color: var(--sft-text-secondary); font-size: 15px; }

.indb-zoom {
    position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px;
    background: var(--sft-bg-card); border: 1px solid var(--sft-border);
    border-radius: 10px; padding: 4px; box-shadow: var(--sft-card-shadow);
}
.indb-zoom-btn {
    width: 28px; height: 28px; border: 0; border-radius: 7px; cursor: pointer;
    background: none; color: var(--sft-text); font-size: 14px; line-height: 1;
}
.indb-zoom-btn:hover { background: var(--sft-bg-hover); }
.indb-zoom-level { font-size: 11px; color: var(--sft-text-muted); min-width: 38px; text-align: center; }

/* ── ノードカード ── */
.drawflow .drawflow-node {
    background: var(--sft-bg-card); border: 1px solid var(--sft-border);
    border-radius: 12px; padding: 0; width: auto; min-width: 148px;
    box-shadow: var(--sft-card-shadow); color: var(--sft-text);
}
.drawflow .drawflow-node.selected {
    border-color: var(--sft-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--sft-primary) 35%, transparent);
}
.indb-node-card { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.indb-node-icon { font-size: 17px; }
.indb-node-label { font-weight: 600; font-size: 13px; }
.indb-node-param {
    margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
    background: var(--sft-bg-hover); color: var(--sft-text-secondary); white-space: nowrap;
}
.drawflow .drawflow-node.cat-source { border-left: 3px solid var(--indb-cat-source); }
.drawflow .drawflow-node.cat-builtin { border-left: 3px solid var(--indb-cat-builtin); }
.drawflow .drawflow-node.cat-math { border-left: 3px solid var(--indb-cat-math); }
.drawflow .drawflow-node.cat-signal { border-left: 3px solid var(--indb-cat-signal); }
.drawflow .drawflow-node.cat-plot { border-left: 3px solid var(--indb-cat-plot); }
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output {
    background: var(--sft-bg-card); border: 2px solid var(--sft-text-muted);
    width: 12px; height: 12px;
}
.drawflow .drawflow-node .output { border-color: var(--sft-primary); }
.drawflow .connection .main-path { stroke: var(--sft-text-muted); stroke-width: 2px; }
.drawflow .connection .main-path:hover { stroke: var(--sft-primary); }

/* ── 右ペイン ── */
.indb-side {
    width: var(--indb-side-w); flex: 0 0 auto; overflow-y: auto;
    background: var(--sft-bg-alt); border-left: 1px solid var(--sft-border); padding: 12px;
}
.indb-side-section { margin-bottom: 18px; }
.indb-side-title {
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--sft-text-muted); margin: 0 0 8px;
}
.indb-side-sub { text-transform: none; letter-spacing: 0; color: var(--sft-text-secondary); font-weight: 500; }
.indb-field { display: block; margin-bottom: 9px; }
.indb-field > span { display: block; font-size: 12px; color: var(--sft-text-secondary); margin-bottom: 3px; }
.indb-field input, .indb-field select {
    width: 100%; padding: 7px 9px; border-radius: 8px; font: 13px/1.3 inherit;
    border: 1px solid var(--sft-border); background: var(--sft-input-bg); color: var(--sft-text);
}
.indb-field input:focus, .indb-field select:focus {
    outline: none; border-color: var(--sft-primary); background: var(--sft-input-focus-bg);
}
.indb-field-hint { font-size: 11px; color: var(--sft-text-muted); margin-top: 3px; }
.indb-empty { font-size: 13px; color: var(--sft-text-muted); margin: 0; }

.indb-checks { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.indb-checks li { display: flex; gap: 6px; padding: 4px 0; align-items: flex-start; }
.indb-checks li.is-error { color: var(--sft-error); }
.indb-checks li.is-warn { color: var(--sft-warning); }
.indb-checks li.is-ok { color: var(--sft-success); }

/* ── 下ドロワー (プレビュー / コード) ── */
.indb-drawer {
    flex: 0 0 auto; height: 43vh; min-height: 260px; display: flex; flex-direction: column;
    background: var(--sft-bg-card); border-top: 1px solid var(--sft-border);
}
.indb-drawer[hidden] { display: none; }
.indb-drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; border-bottom: 1px solid var(--sft-border);
}
.indb-tabs { display: flex; gap: 4px; }
.indb-tab {
    border: 0; background: none; color: var(--sft-text-muted); cursor: pointer;
    font: 600 13px/1 inherit; padding: 8px 12px; border-radius: 8px;
}
.indb-tab:hover { background: var(--sft-bg-hover); }
.indb-tab.is-active { background: var(--sft-bg-hover); color: var(--sft-text); }
.indb-drawer-body { flex: 1 1 auto; overflow: auto; padding: 10px 12px; }
.indb-tabpane { display: none; }
.indb-tabpane.is-active { display: block; }
.indb-preview-note { font-size: 12px; color: var(--sft-text-muted); margin-bottom: 8px; }
.indb-preview-canvas { width: 100%; display: block; margin-bottom: 8px; border-radius: 8px; background: var(--sft-bg); }
.indb-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--sft-text-secondary); }
.indb-legend span { display: inline-flex; align-items: center; gap: 5px; }
.indb-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.indb-code {
    margin: 0; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre; color: var(--sft-text);
}
.indb-code code { display: block; }

/* ── EA から使うための案内 ── */
.indb-use-lead { margin: 0 0 8px; font-size: 13px; color: var(--sft-text-secondary); }
.indb-use-steps { margin: 0 0 14px; padding-left: 20px; font-size: 13px; color: var(--sft-text-secondary); }
.indb-use-steps li { margin: 3px 0; }
.indb-use-grid { display: flex; flex-wrap: wrap; gap: 22px; margin-bottom: 10px; }
.indb-use-k {
    display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--sft-text-muted); margin-bottom: 2px;
}
.indb-use-note { font-size: 12px; color: var(--sft-text-muted); margin: 8px 0; }
.indb-use-table { border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.indb-use-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--sft-text-muted); font-weight: 600; padding: 4px 14px 4px 0;
    border-bottom: 1px solid var(--sft-border);
}
.indb-use-table td { padding: 7px 14px 7px 0; border-bottom: 1px solid var(--sft-border-light); }
.indb-use-open { padding: 5px 10px; font-size: 12px; text-decoration: none; display: inline-block; }
#indb-use code {
    font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--sft-bg-hover); padding: 2px 6px; border-radius: 5px;
}

/* ── Pro 案内 (EA Builder の .eab-pro-card と同じ形) ──
   Code / Use in an EA タブの中と、Download の前に出る。色は --sft-* だけ。 */
.indb-pro-pill {
    font-size: 10px; font-weight: 700; letter-spacing: .4px; margin-left: 6px;
    padding: 1px 6px; border-radius: 999px; vertical-align: middle;
    border: 1px solid color-mix(in srgb, var(--sft-primary) 55%, transparent);
    color: var(--sft-primary-text); background: transparent;
}
.indb-btn-primary .indb-pro-pill { border-color: color-mix(in srgb, var(--sft-on-primary) 70%, transparent); color: var(--sft-on-primary); }
.indb-pro-card {
    max-width: 420px; width: 100%;
    background: var(--sft-bg-card); color: var(--sft-text);
    border: 1px solid var(--sft-border); border-radius: 14px; padding: 24px 22px;
    box-shadow: var(--sft-card-shadow); font-family: inherit;
}
.indb-pro-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; line-height: 1.35; }
.indb-pro-body { font-size: 13px; line-height: 1.6; color: var(--sft-text-secondary); margin: 0 0 18px; }
.indb-pro-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.indb-pro-secondary {
    cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--sft-border); background: transparent; color: var(--sft-text-secondary);
    border-radius: 9px; padding: 9px 14px; font: 500 13px/1.2 inherit; min-height: 40px;
}
.indb-pro-secondary:hover { color: var(--sft-text); border-color: var(--sft-text-muted); }
.indb-pro-cta {
    text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
    background: var(--sft-primary); color: var(--sft-on-primary);
    border-radius: 9px; padding: 9px 16px; font: 600 13px/1.2 inherit; min-height: 40px;
}
.indb-pro-cta:hover { background: var(--sft-primary-dark); }
.indb-pro-cta:focus-visible, .indb-pro-secondary:focus-visible { outline: 2px solid var(--sft-primary); outline-offset: 2px; }
#indb-pro-overlay {
    position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, #000 62%, transparent); padding: 20px;
}
#indb-code-gate { padding: 4px 0; }

/* ── 狭い画面 ── */
@media (max-width: 1100px) {
    .indb-side { width: 244px; }
    .indb-header-right .indb-btn { padding: 8px 9px; }
}
@media (max-width: 860px) {
    .indb-palette { position: absolute; z-index: 90; height: calc(100% - var(--indb-header-h)); }
    .indb-side { display: none; }
    .indb-header-right { padding-right: 8px; }
    .indb-home-link { display: none; }
}

/* ── スマホ / タブレット縦 (≤768px) ──
   ヘッダ 3 段 (1: ☰ ロゴ ⋯ / 2: 主操作 3 つ / 3: 状態文)、パレットはキャンバスに重なる
   ドロワー、タップ領域は 44px 以上。横スクロールはページでなくコード枠の中だけ。
   JS 側の閉じる判定 (ind-builder.js SMALL) と幅を揃えること。 */
@media (max-width: 768px) {
    html, body { overflow-x: hidden; max-width: 100%; }
    .indb-wrapper { height: 100vh; height: 100dvh; width: 100%; max-width: 100vw; }
    .indb-header {
        height: auto; flex-wrap: wrap; gap: 6px 8px; padding: 6px 8px;
    }
    .indb-header-left { flex: 1 1 calc(100% - 56px); min-width: 0; }
    .indb-header-right { display: contents; padding-right: 0; }
    .indb-more-wrap { order: 1; }
    .indb-header-right > .indb-btn { order: 2; flex: 1 1 28%; min-height: 44px; }
    .indb-status { order: 3; flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .indb-status:empty { display: none; }
    .indb-badge, .indb-hide-sm { display: none; }
    .indb-logo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .indb-btn, .indb-tab, .indb-more-item, .indb-pal-item { min-height: 44px; }
    .indb-icon-btn { width: 44px; height: 44px; }
    .indb-zoom-btn { width: 44px; height: 44px; }
    .indb-more-menu { top: 48px; }
    .indb-use-open { min-height: 44px; display: inline-flex; align-items: center; }
    .indb-pro-secondary, .indb-pro-cta { min-height: 44px; }
    .indb-mode-item { min-height: 44px; min-width: 44px; padding: 0 14px; font-size: 13px; }
    .indb-pro-pill { margin-left: 4px; padding: 0 4px; }

    .indb-body { position: relative; }
    .indb-palette {
        position: absolute; z-index: 90; top: 0; left: 0; bottom: 0; height: auto;
        width: min(var(--indb-pal-w), 85vw); box-shadow: var(--sft-card-shadow);
    }
    .indb-palette-search { min-height: 44px; font-size: 16px; }
    .indb-canvas-hint { width: 90%; }

    .indb-drawer { height: 50vh; height: 50dvh; min-height: 0; min-width: 0; }
    .indb-drawer-head { padding: 4px 8px; gap: 8px; }
    .indb-tabs { overflow-x: auto; min-width: 0; }
    .indb-tab { white-space: nowrap; }
    .indb-drawer-body { min-width: 0; }
    .indb-use-table { display: block; overflow-x: auto; max-width: 100%; }
}

/* ══ テンプレートギャラリー ══
   カードの中身は ind-templates.js が描く。ここは器と並びだけ。 */
.indb-gallery {
    position: fixed; inset: 0; z-index: 200;
    background: color-mix(in srgb, #000 60%, transparent);
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.indb-gallery[hidden] { display: none; }
.indb-gallery-panel {
    background: var(--sft-bg-card); border: 1px solid var(--sft-border); border-radius: 12px;
    width: min(920px, 100%); max-height: 86vh; overflow: auto; padding: 20px 22px 24px;
}
.indb-gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.indb-gallery-head h2 { font-size: 18px; font-weight: 700; margin: 0; color: var(--sft-text); }
.indb-gallery-note { margin: 6px 0 16px; font-size: 12px; color: var(--sft-text-dim); }
.indb-gallery-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.indb-tpl-card {
    display: flex; flex-direction: column; gap: 6px; text-align: left; cursor: pointer;
    background: var(--sft-bg); border: 1px solid var(--sft-border); border-radius: 10px;
    padding: 14px 16px; color: inherit; font: inherit;
}
.indb-tpl-card:hover { background: var(--sft-bg-hover); border-color: var(--sft-primary); }
.indb-tpl-name { font-size: 14px; font-weight: 700; color: var(--sft-text); }
.indb-tpl-desc { font-size: 12px; line-height: 1.55; color: var(--sft-text-dim); }
.indb-tpl-tags { font-size: 11px; color: var(--sft-primary-text); }

@media (max-width: 600px) {
    .indb-gallery { padding: 12px; }
    .indb-gallery-body { grid-template-columns: 1fr; }
}
