/* QUEENS Appliance Studio — たたき台
   トーン: 歯科技工×金属造形の精密機器。ダークビューポート、チタン系のニュートラル、
   アクセントはメタルの焼き色を思わせる青緑（#3fb0a6）。 */

:root {
  --bg:        #14171b;
  --panel:     #1e2329;
  --panel-2:   #232a31;
  --line:      #313a42;
  --text:      #dde4ea;
  --muted:     #8b97a1;
  --accent:    #3fb0a6;
  --accent-2:  #2c7f78;
  --warn:      #d9a441;
  --danger:    #d95c50;
  --stock:     #5b8dbf;
  --user:      #3fb0a6;
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 13px; overflow: hidden;
}
button { font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--accent-2); }
button.primary { background: var(--accent-2); border-color: var(--accent); }
button.primary:hover { background: var(--accent); color: #0d1214; }
button.ghost { background: transparent; }
button.small { font-size: 11px; padding: 3px 8px; }
button.wide { width: 100%; }
input[type=text], input[type=number], select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 4px 7px; font: inherit;
}
input[type=number] { width: 72px; text-align: right; font-family: var(--mono); }
.mono { font-family: var(--mono); }
.small { font-size: 11px; }
.muted { color: var(--muted); }

/* ---- 上部バー ---- */
#topbar {
  height: 46px; display: flex; align-items: center; gap: 16px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-q { font-weight: 800; letter-spacing: 0.14em; font-size: 15px; }
.brand-sub { color: var(--muted); letter-spacing: 0.06em; }
.brand-tag { font-size: 10px; color: var(--warn); border: 1px solid var(--warn);
  border-radius: 3px; padding: 1px 5px; }
.proj { display: flex; align-items: center; gap: 8px; flex: 1; }
#projName { width: 220px; }
.proj-right { display: flex; gap: 8px; align-items: center; }
.save-state { font-size: 11px; color: var(--muted); }

/* ---- レイアウト ---- */
#layout { display: flex; height: calc(100vh - 46px); }

/* ---- 工程レール（署名要素: 工程票のようなステップ進行） ---- */
#steps {
  width: 168px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 10px 8px; gap: 6px;
}
.steps-title { font-size: 10px; color: var(--muted); letter-spacing: 0.2em; padding: 2px 6px 6px; }
.step {
  display: grid; grid-template-columns: 22px 1fr; grid-template-rows: auto auto;
  text-align: left; padding: 7px 8px; background: transparent; border: 1px solid transparent;
}
.step:hover { background: var(--panel-2); }
.step.active { background: var(--panel-2); border-color: var(--accent-2); }
.step-no {
  grid-row: 1 / span 2; align-self: center;
  font-family: var(--mono); color: var(--muted); font-size: 14px;
}
.step.active .step-no { color: var(--accent); }
.step-name { font-weight: 600; }
.step-desc { grid-column: 2; font-size: 10px; color: var(--muted); }
.steps-foot { margin-top: auto; font-size: 10px; color: var(--muted); padding: 8px 6px; line-height: 1.8; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 4px; }
.dot.off { background: var(--danger); }
.dot.on  { background: var(--accent); }

/* ---- ビューポート ---- */
#viewport-wrap { flex: 1; position: relative; min-width: 0; }
#viewport { position: absolute; inset: 0; }
#vp-toolbar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; background: rgba(30,35,41,0.92); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px;
}
.tool { border-color: transparent; background: transparent; }
.tool.active { background: var(--accent-2); border-color: var(--accent); }
.vp-sep { width: 1px; background: var(--line); margin: 2px 3px; }
#vp-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(20,23,27,0.85); border: 1px solid var(--line); border-radius: 5px;
  padding: 5px 12px; font-size: 12px; color: var(--warn); display: none;
}
#vp-hint.show { display: block; }

/* ---- 右パネル ---- */
#rightpanel {
  width: 292px; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: none; border-radius: 0; background: transparent; padding: 9px 0; color: var(--muted); }
.tab.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tabpage { display: none; flex: 1; overflow-y: auto; padding: 10px; }
.tabpage.active { display: block; }
.panel-actions { margin-bottom: 10px; display: flex; gap: 6px; }
.filebtn {
  display: inline-block; background: var(--accent-2); border: 1px solid var(--accent);
  border-radius: 4px; padding: 5px 10px; cursor: pointer;
}
.filebtn:hover { background: var(--accent); color: #0d1214; }
.filebtn input { display: none; }
.empty-note { color: var(--muted); font-size: 12px; line-height: 1.9; padding: 16px 4px; }

/* コンポーネントリスト */
.complist { list-style: none; }
.complist li {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 7px; border: 1px solid transparent; border-radius: 4px; cursor: pointer;
}
.complist li:hover { background: var(--panel-2); }
.complist li.selected { background: var(--panel-2); border-color: var(--accent-2); }
.ctype {
  font-size: 9px; padding: 1px 5px; border-radius: 3px; letter-spacing: 0.05em;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.ctype.band { color: var(--accent); border-color: var(--accent-2); }
.ctype.stl  { color: var(--stock); border-color: var(--stock); }
.cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cvis, .cdel, .clock { background: transparent; border: none; color: var(--muted); padding: 2px 4px; }
.cvis:hover { color: var(--text); }
.cdel:hover { color: var(--danger); }
.complist li.hidden-comp .cname { opacity: 0.4; }

/* ライブラリ */
.lib-section { margin-bottom: 14px; }
.lib-head {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  padding: 5px 8px; border-left: 3px solid; margin-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center;
}
.lib-head.stock { border-color: var(--stock); }
.lib-head.user  { border-color: var(--user); }
.lib-note { font-size: 9px; color: var(--muted); font-weight: 400; }
.liblist { list-style: none; }
.liblist li {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 4px;
}
.liblist li:hover { background: var(--panel-2); }
.libname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#libCtxMenu { position: fixed; z-index: 4000; background: #232a33; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px; min-width: 150px; box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  display: flex; flex-direction: column; }
#libCtxMenu button { background: none; border: none; color: var(--text); text-align: left;
  padding: 7px 12px; border-radius: 5px; cursor: pointer; font-size: 12.5px; }
#libCtxMenu button:hover { background: rgba(63,176,166,0.16); }
#libCtxMenu button.danger { color: #e07a6a; }
#libCtxMenu button.danger:hover { background: rgba(224,122,106,0.14); }
.liblist li[draggable="true"] { cursor: grab; }
.liblist li[draggable="true"]:active { cursor: grabbing; }
.libthumb { width: 38px; height: 38px; border-radius: 5px; background: #1d232a;
  border: 1px solid var(--line); object-fit: contain; flex: none; }
.libcat { font-size: 9px; color: var(--muted); }

/* 設定 */
.prop-section { margin-bottom: 16px; }
.prop-head { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: var(--muted);
  padding-bottom: 5px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.prop-body .row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-body .row > span:first-child { flex: 1; }
.build-result { margin-top: 8px; font-size: 11px; line-height: 1.8; color: var(--muted);
  white-space: pre-wrap; }
.build-result .ok { color: var(--accent); }

/* ---- フローティングパネル ---- */
.floatpanel {
  position: fixed; top: 70px; left: 190px; width: 330px; z-index: 30;
  background: var(--panel); border: 1px solid var(--accent-2); border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5); padding: 12px;
}
.floatpanel.wide { width: 560px; left: 50%; transform: translateX(-50%); }
.floatpanel.hidden { display: none; }
.fp-title { font-weight: 700; margin-bottom: 10px; display: flex; justify-content: space-between; }
.fp-close { background: transparent; border: none; color: var(--muted); font-size: 15px; }
.fp-steps { margin: 0 0 10px 18px; font-size: 12px; line-height: 2; color: var(--muted); }
.fp-steps li.on { color: var(--text); }
.fp-steps li.done { color: var(--accent); }
.fp-params { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.fp-params label { display: flex; justify-content: space-between; align-items: center; }
.fp-actions { display: flex; gap: 6px; margin-bottom: 8px; }
.fp-note { font-size: 10px; color: var(--muted); line-height: 1.7; }
.fp-body { display: flex; flex-direction: column; gap: 10px; }

.preset-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset { display: flex; flex-direction: column; padding: 8px; }
.preset span { font-size: 10px; color: var(--muted); }
.preset:hover span { color: inherit; }

/* 履歴 */
.hist-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hist-head { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.histlist { list-style: none; max-height: 320px; overflow-y: auto; }
.histlist li { padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 12px;
  display: flex; align-items: center; gap: 8px; }
.histlist .grow { flex: 1; }
.histlist .when { font-family: var(--mono); font-size: 10px; color: var(--muted); }

/* ---- ビューキューブ ---- */
#viewcube {
  position: absolute; top: 56px; right: 14px; width: 84px; height: 84px;
  perspective: 340px; z-index: 5; user-select: none;
}
#vc-inner {
  position: absolute; transform-style: preserve-3d;
  margin: 21px; width: 42px; height: 42px;
}
.vc-face {
  position: absolute; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(35, 42, 49, 0.92); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer;
  backface-visibility: hidden;
}
.vc-face:hover { background: var(--accent-2); color: #fff; border-color: var(--accent); }
.vc-front  { transform: translateZ(21px); }
.vc-back   { transform: rotateY(180deg) translateZ(21px); }
.vc-right  { transform: rotateY(90deg) translateZ(21px); }
.vc-left   { transform: rotateY(-90deg) translateZ(21px); }
.vc-top    { transform: rotateX(90deg) translateZ(21px); }
.vc-bottom { transform: rotateX(-90deg) translateZ(21px); }

/* 設定行の折返し対策（長いラベル・セレクト） */
.prop-body .row { flex-wrap: wrap; }
.prop-body .row select { max-width: 168px; }

/* トースト */
#toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 99;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.toastmsg {
  background: var(--panel-2); border: 1px solid var(--accent-2); border-radius: 6px;
  padding: 8px 14px; font-size: 12px; animation: tin 0.18s ease-out;
}
.toastmsg.warn { border-color: var(--warn); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) { .toastmsg { animation: none; } }

/* リタッチブラシ */
.fp-retouch { border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 10px; }
.fp-retouch.hidden { display: none; }
.fp-retouch-head { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.08em; margin-bottom: 7px; }
.brushbtn.active { background: var(--accent-2); border-color: var(--accent); }
.fp-brushsize { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.fp-brushsize input { flex: 1; }


/* パネルのドラッグと縮小 */
.fp-title.vp-drag { cursor: move; user-select: none; }
.fp-btns { display: flex; gap: 4px; }
.fp-min { background: transparent; border: none; color: var(--muted); font-size: 14px; padding: 0 5px; }
.fp-min:hover, .fp-close:hover { color: var(--text); }
.floatpanel.mini .fp-steps, .floatpanel.mini .fp-note, .floatpanel.mini .fp-retouch { display: none; }
.floatpanel.mini { width: 250px; }

/* 右パネル縮小 */
.side-collapse { border: none; background: transparent; color: var(--muted); padding: 0 8px; font-size: 14px; }
#rightpanel.collapsed { width: 30px; }
#rightpanel.collapsed .tab, #rightpanel.collapsed .tabpage { display: none; }
#rightpanel.collapsed .side-collapse { transform: rotate(180deg); }

.preset.qsel { background: var(--accent-2); border-color: var(--accent); }

.barlifts { display: flex; flex-direction: column; gap: 4px; max-height: 130px; overflow-y: auto; }
.barlifts .row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.barlifts .row .no { width: 44px; color: var(--muted); font-family: var(--mono); }

/* ポイント別浮かせ量リスト */
.barlifts { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; max-height: 150px; overflow-y: auto; }
.barlifts label { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); gap: 6px; }
.barlifts input { width: 64px; }

/* グループバッジ */
.gbadge { display: inline-block; background: var(--accent-2); color: #fff; font-size: 9px; font-weight: 700;
  padding: 0 4px; border-radius: 3px; margin-right: 4px; cursor: pointer; }
.gbadge:hover { background: #b8542f; }


/* ツールバーの小型化 */
#vp-toolbar .tool { padding: 3px 8px; font-size: 11px; }
#vp-toolbar { gap: 3px; padding: 4px 6px; }

/* ライブラリフォルダツリー */
.libfolder { cursor: pointer; font-weight: 700; color: var(--muted); padding: 4px 2px; user-select: none; }
.libfolder:hover { color: var(--text); }
.libfolder.collapsed { opacity: 0.75; }
.liblist li[data-incat] { padding-left: 16px; }

.cren { background: transparent; border: none; color: var(--muted); padding: 2px 3px; font-size: 11px; }
.cren:hover { color: var(--text); }


/* ツールバー: 縦書き崩れの解消（横長許容） */
#vp-toolbar { flex-wrap: nowrap; max-width: none; }
#vp-toolbar .tool { white-space: nowrap; padding: 3px 7px; font-size: 11px; line-height: 1.3; }
#vp-toolbar .vp-sep { margin: 0 2px; }

/* 選択部品直下のクイック外観バー */
/* v21.94: グループヘッダ行と折り畳み */
#componentList li.cgroup { display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  background: rgba(102,126,234,0.10); border-left: 3px solid #6a7fd8; font-weight: 600; cursor: pointer; }
#componentList li.cgroup .gcaret { width: 14px; text-align: center; color: #9fb0d8; cursor: pointer; }
#componentList li.cgroup .gname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#componentList li.cgroup .gcount { color: #8fa0ad; }
#componentList li.cgroup .gop { width: 64px; }
#componentList li.in-group { padding-left: 24px; box-shadow: inset 3px 0 0 rgba(106,127,216,0.35); }
.cquick { display: flex; align-items: center; gap: 8px; padding: 4px 8px 6px 26px; background: rgba(63,176,166,0.06); }
.cquick .qcolor { width: 30px; height: 22px; padding: 0; border: 1px solid var(--line); }
.cquick .qop { flex: 1; }

/* 認証・患者リスト */
.fullscreen-overlay { position: fixed; inset: 0; background: #14171b; z-index: 200;
  display: flex; align-items: center; justify-content: center; }
.fullscreen-overlay.hidden { display: none; }
.auth-card { width: 320px; background: #1c2026; border: 1px solid var(--line); border-radius: 10px;
  padding: 26px 26px 22px; display: flex; flex-direction: column; gap: 10px; }
.auth-brand { color: #3fb0a6; font-weight: 700; letter-spacing: 0.12em; font-size: 17px; text-align: center; }
.auth-sub { color: #9aa3ad; text-align: center; font-size: 12px; margin-top: -6px; }
.auth-title { font-weight: 600; margin: 10px 0 2px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #9aa3ad; }
.auth-card input { background: #14171b; border: 1px solid var(--line); border-radius: 6px;
  color: #e6e9ec; padding: 8px 10px; font-size: 14px; }
.auth-err { color: #e08585; font-size: 12px; min-height: 16px; }
.auth-card .primary { margin-top: 4px; }
.patient-card { width: 640px; max-height: 80vh; background: #1c2026; border: 1px solid var(--line);
  border-radius: 10px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.patient-head { display: flex; align-items: center; gap: 14px; }
.patient-new { display: flex; gap: 8px; }
.patient-new input { flex: 1; background: #14171b; border: 1px solid var(--line); border-radius: 6px;
  color: #e6e9ec; padding: 8px 10px; }
.patient-list { overflow: auto; border-top: 1px solid var(--line); }
.patient-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px;
  border-bottom: 1px solid var(--line); cursor: pointer; }
.patient-row:hover { background: rgba(63,176,166,0.08); }
.patient-row .pname { font-weight: 600; flex: 1; }
.patient-row .pmeta { color: #9aa3ad; font-size: 12px; }

/* ネームプレートの折り畳み */
.np-fold { border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; padding: 0 6px 4px; }
.np-fold summary { cursor: pointer; padding: 6px 2px; font-size: 12px; color: #9aa3ad; user-select: none; }
.np-fold summary:hover { color: #e6e9ec; }
.np-fold[open] summary { color: #3fb0a6; }

/* 説明文の省スペース化: 本文は隠し、ⓘ ホバーで表示 */
.fp-steps, .fp-note { display: none !important; }
.info-dot { display: inline-block; margin: 4px 2px; padding: 1px 8px; border: 1px solid var(--line);
  border-radius: 10px; color: #9aa3ad; font-size: 11px; cursor: help; user-select: none; }
.info-dot:hover { color: #3fb0a6; border-color: #3fb0a6; }
.preset span:nth-child(2) { display: none; }

.complist li.multi-sel { outline: 1px solid #d9a441; outline-offset: -1px; }

/* ---- コンパクト操作ボタン（v21.37: Tag / D-A Bool / Parts / Align / Clear）---- */
#npFold:not([open]) { display: none; }   /* 開閉は Tag ボタンが担当（閉時は枠ごと非表示） */
.act-row { display: flex; gap: 4px; margin-bottom: 8px; }
.act-btn {
  flex: none; min-width: 0; padding: 6px 4px; font-size: 11px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: 5px; letter-spacing: .02em; background: var(--panel-2);
}
.act-row .act-btn { flex: 1 1 0; }   /* 均等割りは横一列の行内のみ（縦 flex 内では潰れるため） */
.act-btn.accent { border-color: var(--accent-2); color: var(--accent); }
.act-btn.accent:hover { background: rgba(63,176,166,0.12); }
.act-btn.on { background: var(--accent-2); color: #e6f4f2; }

/* ---- ホバー説明ツールチップ（data-tip 属性 / i18n は data-i18n-tip で登録）---- */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 240px; white-space: normal;
  background: #10161a; color: var(--text); border: 1px solid var(--accent-2);
  border-radius: 6px; padding: 6px 9px; font-size: 11px; line-height: 1.6; text-align: left;
  z-index: 80; pointer-events: none; box-shadow: 0 6px 22px rgba(0,0,0,0.55);
}
[data-tip]:hover::before {
  content: ''; position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--accent-2);
  z-index: 80; pointer-events: none;
}
/* 行の左右端ボタンは画面外クリップを避けて端寄せ */
.act-row .act-btn:first-child[data-tip]:hover::after { left: 0; transform: none; }
.act-row .act-btn:last-child[data-tip]:hover::after { left: auto; right: 0; transform: none; }

/* v21.62: ツールバードロップダウン */
.tb-dd { position: relative; display: inline-block; }
.tb-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 60;
  background: var(--panel, #17242b); border: 1px solid var(--line, #2a3b44);
  border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); min-width: 220px; }
.tb-menu.hidden { display: none; }
#clipFlipBtn.hidden { display: none; }   /* v22.06: 断面中のみ表示 */
.tb-menu > button { text-align: left; background: transparent; color: var(--text, #dfe8ec);
  border: none; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.tb-menu > button:hover { background: var(--accent-2, #1d4d46); }
.tb-menu label { font-size: 11.5px; color: var(--muted, #9fb2ba); }
