/* ==========================================================================
   組織図の画面（js/org.js。見本は docs/org/preview-org.html、設計は docs/org/design.md）
   - クラスはすべて og- で始める（ほかの画面とぶつけない）。色は css/crm.css と同じ土台
   ========================================================================== */
.og {
  --brand: #56693a; --brand-50: #f4f5ee; --brand-100: #e8ebdc;
  --g50: #f7f5f0; --g100: #efece5; --g200: #e4e0d6; --g300: #d1cbbe; --g400: #a39c8e; --g500: #736c60; --g700: #3d3933; --g900: #1c1a17;
  --ok: #3a7254; --ok-bg: #ecf3ec; --warn: #94630f; --warn-bg: #fbf4e4; --ng: #a8392b; --ng-bg: #f9ece8;
  --ink: var(--g900); --muted: var(--g500); --line: var(--g200); --wire: #cbc4b6;
  font-size: 13px; line-height: 1.55; color: var(--ink);
}
.og *, .og *::before, .og *::after { box-sizing: border-box; }
.og button, .og input, .og select { font: inherit; color: inherit; }
.og button { cursor: pointer; }
.og button:disabled { opacity: .45; cursor: default; }
.og .og-muted { color: var(--muted); }
.og .og-small { font-size: 12px; }
.og .og-sp { flex: 1; }
.og input[type=text], .og input[type=date], .og input[type=search], .og select {
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; background: #fff; min-height: 32px; }

.og-btn { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 5px 12px; white-space: nowrap; }
.og-btn:hover:not(:disabled) { border-color: var(--g300); background: var(--g50); }
.og-btn.sm { padding: 3px 9px; font-size: 12.5px; }
.og-btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.og-btn.pri:hover:not(:disabled) { background: #485830; }
.og-btn.ng { color: var(--ng); }
.og-btn.ngfill { background: var(--ng); border-color: var(--ng); color: #fff; font-weight: 700; }
.og-tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 4px; background: var(--g100); color: var(--muted); white-space: nowrap; }
.og-tag.pri { background: var(--brand-50); color: var(--brand); } .og-tag.ok { background: var(--ok-bg); color: var(--ok); }
.og-tag.warn { background: var(--warn-bg); color: var(--warn); } .og-tag.bad { background: var(--ng-bg); color: var(--ng); }
.og-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.og-empty { padding: 40px; text-align: center; color: var(--muted); }

/* 上のタブ */
.og-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.og-tabs button { border: 0; background: none; padding: 7px 14px 8px; border-bottom: 3px solid transparent; color: var(--muted); }
.og-tabs button:hover { color: var(--ink); }
.og-tabs button.on { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }

/* 版の帯・道具 */
.og-vbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.og-vbar select.og-ver { font-weight: 700; min-width: 280px; }
.og-vinfo { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.og-vinfo b { color: var(--ink); font-variant-numeric: tabular-nums; }
.og-note { font-size: 12px; color: var(--muted); margin: 0 2px 8px; }
.og-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.og-tools input[type=search] { width: 220px; }
.og-zoom { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.og-zoom button { border: 0; background: none; padding: 4px 10px; font-size: 12.5px; }
.og-zoom button + button { border-left: 1px solid var(--line); }
.og-zoom button:hover { background: var(--g100); }
.og-chk { display: inline-flex; gap: 5px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; }

.og-chg { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.og-chg-h { display: flex; gap: 8px; align-items: center; }
.og-chg ul { list-style: none; margin: 6px 0 2px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.og-chg li { font-size: 12.5px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px 2px 3px; background: #fdfcfa; display: inline-flex; gap: 6px; align-items: center; }
.og-chg li[data-chg] { cursor: pointer; } .og-chg li[data-chg]:hover { border-color: var(--brand); }
.og-chg li .og-tag { border-radius: 999px; }
.og-scopebar { background: var(--brand-50); color: #576c37; border-radius: 10px; padding: 7px 12px; margin-bottom: 10px; }

/* 組織図の舞台 */
.og-work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.og-work.has-panel { grid-template-columns: minmax(0, 1fr) 340px; }
.og-stage { background-color: #f7f8f4; background-image: radial-gradient(#eae8e3 1px, transparent 1px); background-size: 18px 18px;
            border: 1px solid var(--line); border-radius: 14px; height: calc(100vh - 330px); min-height: 440px; overflow: auto; }
.og-canvas { width: max-content; min-width: 100%; padding: 28px 28px 60px; }

/* 木の線 */
.og-tree ul { display: flex; justify-content: center; padding: 30px 0 0; margin: 0; position: relative; }
.og-tree li { list-style: none; position: relative; padding: 30px 8px 0; display: flex; flex-direction: column; align-items: center; }
.og-tree li::before, .og-tree li::after { content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 30px; border-top: 2px solid var(--wire); }
.og-tree li::after { right: auto; left: 50%; border-left: 2px solid var(--wire); }
.og-tree li:only-child::before, .og-tree li:only-child::after { display: none; }
.og-tree li:only-child { padding-top: 0; }
.og-tree li:first-child::before, .og-tree li:last-child::after { border: 0 none; }
.og-tree li:last-child::before { border-right: 2px solid var(--wire); border-radius: 0 10px 0 0; }
.og-tree li:first-child::after { border-radius: 10px 0 0 0; }
.og-tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 30px; border-left: 2px solid var(--wire); }
.og-tree > ul { padding-top: 0; }
.og-tree > ul > li { padding-top: 0; }
.og-tree > ul > li::before, .og-tree > ul > li::after { display: none; }

/* 組織の箱 */
.og-node { position: relative; min-width: 200px; max-width: 320px; width: max-content; background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 12px;
           padding: 9px 12px 12px; text-align: left; cursor: pointer; transition: transform .12s, box-shadow .12s, opacity .15s;
           box-shadow: 0 1px 2px rgba(30, 34, 23, .06), 0 6px 16px rgba(30, 34, 23, .05); }
.og-node:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(30, 34, 23, .08), 0 10px 24px rgba(30, 34, 23, .09); }
.og-node:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.og-node.sel { box-shadow: 0 0 0 2px var(--c), 0 10px 24px rgba(30, 34, 23, .12); }
/* いちばん上（会社）の箱も、ほかと同じ白い箱にする。組織は上下の偉さではなく役割の分担なので、色や大きさで上を目立たせない（2026-11-21） */
.og-node.dim { opacity: .28; }
.og-node.hit { box-shadow: 0 0 0 3px #a46237, 0 10px 24px rgba(30, 34, 23, .12); }
/* 箱をドラッグして別の組織の下へ移す */
.og-node[draggable="true"] { cursor: grab; }
.og-node.dragging { opacity: .45; }
.og-node.drop-ok { box-shadow: 0 0 0 3px #85a555, 0 10px 24px rgba(133, 165, 85, .25); transform: scale(1.03); }
/* 箱の左・右の端に重ねたとき：そこへ並べる印の縦の線 */
.og-node.drop-before { box-shadow: -8px 0 0 -2px #85a555, 0 10px 24px rgba(30, 34, 23, .12); }
.og-node.drop-after { box-shadow: 8px 0 0 -2px #85a555, 0 10px 24px rgba(30, 34, 23, .12); }
.og-node.inscope { box-shadow: 0 0 0 3px var(--brand), 0 10px 24px rgba(126, 156, 80, .18); }
.og-node.new { border-style: dashed; border-top-style: solid; }
.og-nh { display: flex; align-items: baseline; gap: 6px; }
.og-nh b { font-size: 15px; letter-spacing: .02em; white-space: nowrap; }
.og-kind { font-size: 11px; color: var(--c); font-weight: 700; white-space: nowrap; }
.og-ld { display: flex; align-items: center; gap: 8px; margin: 6px 0 8px; min-height: 30px; }
.og-ld .og-nm { font-weight: 700; font-size: 13px; line-height: 1.2; }
.og-ld .og-lt { font-size: 11px; color: var(--g400); }
.og-ld .og-none { font-size: 12px; color: var(--warn); }
.og-cnt { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
/* 箱の中の人の名前（フルネーム。印刷しても読めるように1人1行） */
.og-ml { margin: 0; padding: 7px 0 0; border-top: 1px dashed var(--g200); display: grid; gap: 2px 10px; }
.og-ml.two { grid-template-columns: 1fr 1fr; }
.og-mr { display: flex; align-items: baseline; gap: 5px; font-size: 12.5px; line-height: 1.45; min-width: 0; }
.og-ml .og-mn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.og-ml .og-mt { font-size: 10.5px; color: var(--g500); white-space: nowrap; }
.og-mr.vac .og-mn { color: var(--warn); }
.og-badges { position: absolute; top: -11px; right: 8px; display: flex; gap: 4px; }
.og-badges .og-tag { border-radius: 999px; box-shadow: 0 0 0 2px #f7f8f4; font-weight: 700; font-size: 11px; }
.og-tog { position: absolute; left: 50%; bottom: -11px; transform: translateX(-50%); width: 22px; height: 22px; border-radius: 50%;
          border: 1px solid var(--line); background: #fff; font-size: 12px; line-height: 1; padding: 0; color: var(--muted); z-index: 1; }
.og-tog.closed { width: auto; padding: 0 8px; border-radius: 999px; font-size: 11px; }
.og-tog:hover { border-color: var(--c); color: var(--ink); }

/* 箱の右下の＋（この下に組織を足す）。いつも見えるが控えめに、箱にマウスを乗せると目立たせる */
.og-add { position: absolute; right: 10px; bottom: -11px; width: 22px; height: 22px; border-radius: 50%; padding: 0; line-height: 1;
          border: 1px dashed var(--g300); background: #fff; color: var(--g400); font-size: 14px; font-weight: 700; z-index: 1; }
.og-node:hover .og-add, .og-node.sel .og-add { border: 1px solid var(--brand); color: var(--brand); }
.og-add:hover { background: var(--brand); color: #fff !important; }
#og-print .og-add { display: none; }
/* 下書きの案内（何をどこで押せばよいか） */
.og-guide { background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 12.5px; color: #4d5d35; }
.og-guide ol { margin: 4px 0 0; padding-left: 20px; display: flex; flex-wrap: wrap; gap: 2px 22px; }
.og-warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 7px 10px; margin-bottom: 10px; }
.og-dlg .og-row select { width: 100%; }

/* 右の欄 */
.og-panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; max-height: calc(100vh - 330px); min-height: 440px; overflow: auto; position: sticky; top: 12px; }
.og-ph { padding: 12px 14px 10px; border-bottom: 1px solid var(--g100); border-top: 4px solid var(--c); border-radius: 14px 14px 0 0; }
.og-ph .og-path { font-size: 11.5px; color: var(--g400); }
.og-ph h2 { margin: 2px 0 0; font-size: 18px; display: flex; gap: 8px; align-items: baseline; }
.og-ph .og-x { float: right; border: 0; background: none; font-size: 18px; color: var(--g400); line-height: 1; }
.og-sec { padding: 10px 14px; border-bottom: 1px solid var(--g100); }
.og-sec h3 { font-size: 12px; color: var(--muted); margin: 0 0 6px; font-weight: 700; }
.og-mem { display: flex; gap: 9px; align-items: center; padding: 6px 0; flex-wrap: wrap; }
.og-mem + .og-mem { border-top: 1px dashed var(--g100); }
.og-mem .og-who { flex: 1; min-width: 0; }
.og-mem .og-who b { font-size: 13.5px; }
.og-mem .og-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
/* メンバーの並び（入社日の順・手で並べた順）と、名前をドラッグして並べ替える */
.og-memh { display: flex; align-items: center; gap: 6px; }
.og-ord { font-size: 11px; font-weight: 400; color: var(--g500); }
.og-mem.og-sortable { cursor: grab; position: relative; }
.og-grip { color: var(--g300); font-size: 12px; letter-spacing: -2px; width: 10px; flex: none; user-select: none; }
.og-mem.og-sortable:hover .og-grip { color: var(--g500); }
.og-mem.mdragging { opacity: .4; }
.og-mem.mdrop-before { box-shadow: inset 0 3px 0 #85a555; }
.og-mem.mdrop-after { box-shadow: inset 0 -3px 0 #85a555; }
.og-acts { display: flex; gap: 4px; width: 100%; flex-wrap: wrap; }
.og-acts select { font-size: 12px; padding: 2px 6px; min-height: 28px; }
.og-frm { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.og-frm + .og-frm { margin-top: 7px; }
.og-frm input[type=text] { flex: 1 1 120px; min-width: 0; }
.og-lock { font-size: 12.5px; color: var(--muted); background: var(--g100); border-radius: 8px; padding: 8px 10px; }

/* 表（人ごと・版の一覧） */
.og table { border-collapse: collapse; width: 100%; }
.og th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.og td { padding: 8px 9px; border-bottom: 1px solid var(--g100); vertical-align: middle; }
.og tr[data-open] { cursor: pointer; } .og tr[data-open]:hover td { background: #fcfaf7; }
.og .og-num { text-align: right; font-variant-numeric: tabular-nums; }
.og-flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.og-flow .og-arw { color: var(--g400); }

/* 確かめの画面 */
.og-veil { position: fixed; inset: 0; background: rgba(32, 35, 26, .38); display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 16px; }
.og-dlg { background: #fff; border-radius: 14px; width: 500px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 18px 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.og-dlg h2 { margin: 0 0 10px; font-size: 17px; }
.og-dlg .og-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.og-dlg .og-row input { width: 100%; }
.og-checks { list-style: none; margin: 6px 0 0; padding: 0; }
.og-checks li { padding: 4px 0 4px 24px; position: relative; }
.og-checks li::before { position: absolute; left: 2px; top: 4px; font-weight: 700; }
.og-checks li.e { color: var(--ng); } .og-checks li.e::before { content: '✕'; }
.og-checks li.w { color: var(--warn); } .og-checks li.w::before { content: '！'; }
.og-checks li.i { color: var(--muted); } .og-checks li.i::before { content: '・'; }
.og-checks li.o { color: var(--ok); } .og-checks li.o::before { content: '✓'; }
.og-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.og-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #25221e; color: #fff; padding: 9px 18px;
            border-radius: 999px; font-size: 13px; opacity: 0; transition: .2s; pointer-events: none; z-index: 2100; }
.og-toast.on { opacity: 1; transform: translateX(-50%); }
.og-toast.ng { background: var(--ng); }

/* 利用権限マスターの「所属」の欄（js/users.js） */
.og-user-cell { display: flex; flex-direction: column; gap: 4px; min-width: 190px; }
.og-user-cell select { font-size: 12.5px; padding: 3px 6px; border: 1px solid var(--g200, #e4e0d6); border-radius: 6px; background: #fff; }
.og-user-cell .og-user-sub { font-size: 11.5px; color: #736c60; }

/* 印刷（js/org.js の printChart。印刷するあいだだけ body の直下に #og-print を置く） */
#og-print { display: none; }
#og-print.measure { display: block; position: absolute; left: -99999px; top: 0; width: max-content; }
#og-print .og-pr-h { display: flex; gap: 14px; align-items: baseline; font-size: 12px; color: var(--g700); border-bottom: 2px solid var(--g900); padding: 0 2px 5px; margin-bottom: 12px; }
#og-print .og-pr-h b { font-size: 17px; color: var(--g900); letter-spacing: .04em; }
#og-print .og-pr-body { width: max-content; margin: 0 auto; }
#og-print .og-node { box-shadow: none; cursor: default; break-inside: avoid; }
@page orgchart { size: A4 landscape; margin: 8mm; }
@media print {
  body.og-printing > *:not(#og-print) { display: none !important; }
  body.og-printing { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body.og-printing #og-print { display: block; page: orgchart; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 900px) {
  .og-work.has-panel { grid-template-columns: minmax(0, 1fr); }
  .og-panel { position: static; max-height: none; min-height: 0; }
  .og-vbar select.og-ver { min-width: 0; width: 100%; }
  .og-stage { height: 60vh; }
}
