/* 従業員名簿 */
:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --text: #1f2933;
  --muted: #6b7480;
  --line: #dfe3e8;
  --accent: #2f5bea;
  --danger: #d6336c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.6 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
.error { color: var(--danger); }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.count { color: var(--muted); margin: 0 0 8px; font-size: 13px; }
.container { max-width: 1440px; margin: 0 auto; padding: 16px 24px 64px; }

/* ヘッダー */
.site-header { background: #1e293b; color: #fff; position: sticky; top: 0; z-index: 20; }
.header-inner { max-width: 1440px; margin: 0 auto; padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #fff; color: #1e293b; display: grid; place-items: center; font-size: 12px; letter-spacing: .5px; }
.nav { display: flex; gap: 4px; height: 100%; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 0 14px; display: flex; align-items: center; border-bottom: 3px solid transparent; font-weight: 600; }
.nav a:hover { color: #fff; }
.nav a.is-active { color: #fff; border-bottom-color: #fff; }
.me-warn { color: #fbbf24 !important; display: inline !important; }
.me { margin-left: auto; color: #94a3b8; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }

/* ツールバー */
.toolbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 56px; z-index: 10; }
.toolbar-inner { max-width: 1440px; margin: 0 auto; padding: 12px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.page-title { font-size: 18px; margin: 0 8px 0 0; }
.search { flex: 1 1 280px; max-width: 420px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; background: var(--bg); }
.search svg { color: var(--muted); }
.search input { border: 0; background: none; outline: none; height: 38px; width: 100%; font-size: 16px; }
.search:focus-within { border-color: var(--accent); background: #fff; }
select, input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), textarea {
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 10px; min-height: 38px; font-size: 15px; max-width: 100%;
}
.search input { border: 0 !important; padding: 0 !important; min-height: 0 !important; background: transparent !important; outline: none !important; }
textarea { width: 100%; resize: vertical; }
select:focus, input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 14px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.is-on { background: #1e293b; color: #fff; }
.chips-row { max-width: 1440px; margin: 0 auto; padding: 0 24px 12px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips-row::-webkit-scrollbar { display: none; }
.chip-btn { --c: #64748b; flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 14px; cursor: pointer; white-space: nowrap; }
.chip-btn:hover { border-color: var(--c); }
.chip-btn.is-on { background: var(--c); border-color: var(--c); color: #fff; }
.chip-btn.is-on .dot { background: #fff; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* 共通パーツ */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c, #94a3b8); margin-right: 6px; vertical-align: middle; flex: none; }
.chip { display: inline-block; background: #eef1f5; color: #344054; border-radius: 6px; padding: 1px 8px; font-size: 12px; margin: 0 4px 4px 0; }
.chip-outline { background: none; border: 1px solid var(--line); }
.badge { display: inline-block; background: #1e293b; color: #fff; border-radius: 4px; padding: 0 6px; font-size: 11px; font-weight: 600; line-height: 18px; margin-left: 4px; vertical-align: middle; }
.badge-outline { background: none; color: var(--muted); border: 1px solid var(--line); }
.badge-muted { background: #e5e7eb; color: #4b5563; }
.badge-ok { background: #e6f4ea; color: #1e7b34; }
.avatar { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; background: #e5e7eb; }
.avatar-initial { display: grid; place-items: center; background: color-mix(in srgb, var(--c, #94a3b8) 18%, #fff); color: var(--c, #94a3b8); font-weight: 700; font-size: 40px; }
.avatar-xl { width: 112px; height: 112px; font-size: 44px; border-radius: 14px; }
.avatar-sm { width: 40px; height: 40px; font-size: 16px; border-radius: 50%; }
.avatar-xs { width: 28px; height: 28px; font-size: 12px; border-radius: 50%; }

/* 名簿 */
.dept-section { --c: #94a3b8; margin: 20px 0 28px; }
.dept-heading { display: flex; align-items: center; gap: 10px; font-size: 17px; margin: 0 0 12px; }
.dept-bar { width: 5px; height: 22px; border-radius: 3px; background: var(--c); }
.dept-parent { font-size: 12px; font-weight: 400; color: var(--muted); }
.dept-count { font-size: 12px; font-weight: 400; color: var(--muted); background: #e9ecf1; border-radius: 999px; padding: 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 14px; }
.card { --c: #94a3b8; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 0; cursor: pointer; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; border-top: 4px solid var(--c); }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(15, 23, 42, .1); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card-photo { padding: 14px 14px 0; position: relative; }
.card-photo .avatar { border-radius: 10px; }
.card-body { padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-badges { min-height: 0; margin-left: -4px; }
.card-badges:empty { display: none; }
.card-name { font-size: 17px; font-weight: 700; line-height: 1.35; }
.card-title { font-size: 12px; color: var(--c); font-weight: 700; }
.card-roles { margin-top: 2px; }
.card-meta { margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); }
.card-meta > span { display: inline-flex; align-items: center; }
.card-meta .dot { background: var(--c); }
.card-meta .loc svg { width: 13px; height: 13px; margin-right: 3px; }
.tag { color: var(--muted); }
.tag::before { content: "#"; }

/* 詳細ダイアログ */
.dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-shadow: 0 24px 64px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog form { padding: 24px; position: relative; }
.dialog-close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 6px; }
.detail-head { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.detail-head h2 { margin: 0; font-size: 22px; }
.detail-title { color: var(--muted); font-size: 13px; font-weight: 600; }
.kana { color: var(--muted); font-size: 12px; }
.detail-list { display: grid; grid-template-columns: 72px 1fr; gap: 8px 12px; margin: 0; }
.detail-list dt { color: var(--muted); font-size: 13px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.bio { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 12px; margin: 16px 0 0; }
.member-list { list-style: none; padding: 0; margin: 12px 0 0; }
.member-list button { width: 100%; display: flex; gap: 12px; align-items: center; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; text-align: left; }
.member-list button:hover { background: var(--bg); }
.member-list small { display: block; color: var(--muted); font-size: 12px; }

/* 組織図 */
.org-wrap { padding: 16px 0 64px; }
.org-scroll { overflow-x: auto; padding: 8px 24px 24px; }
.tree { display: inline-block; min-width: 100%; --line: #6b7280; }
.tree ul { position: relative; display: flex; justify-content: center; margin: 0; padding: 22px 0 0; }
.tree > ul { padding-top: 0; }
.tree li { list-style: none; position: relative; padding: 22px 8px 0; display: flex; flex-direction: column; align-items: center; }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 22px; border-top: 1.5px solid var(--line); }
.tree li::after { right: auto; left: 50%; border-left: 1.5px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0; }
.tree li:last-child::before { border-right: 1.5px solid var(--line); }
.tree ul ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 22px; border-left: 1.5px solid var(--line); }
.org-title, .org-meeting { width: 210px; background: #fff; border: 1px solid #333; padding: 4px 8px; text-align: center; font-weight: 700; font-size: 12px; line-height: 1.4; position: relative; z-index: 1; }
.org-meeting { color: #1d4ed8; }
.org-unit-wrap { display: flex; flex-direction: column; align-items: center; }
.org-unit { --c: #64748b; width: 210px; background: #fff; border: 1px solid #333; border-top: 3px solid var(--c); font-size: 12px; position: relative; z-index: 1; }
.org-unit-name { display: block; width: 100%; border: 0; border-bottom: 1px solid #333; background: color-mix(in srgb, var(--c) 8%, #fff); padding: 5px 8px; font-weight: 700; font-size: 12.5px; cursor: pointer; text-align: center; line-height: 1.35; }
.org-unit-name:hover { text-decoration: underline; }
.org-unit-name:last-child { border-bottom: 0; }
.org-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.org-table th, .org-table td { border-top: 1px solid #333; padding: 4px 6px; text-align: center; vertical-align: middle; line-height: 1.35; font-size: 11.5px; }
.org-table tr:first-child th, .org-table tr:first-child td { border-top: 0; }
.org-table th, .org-table td, .org-meeting, .org-title, .org-unit-name { word-break: keep-all; overflow-wrap: anywhere; }
.org-table th { font-weight: 400; color: #374151; border-right: 1px solid #333; width: 50%; }
.org-table td { font-weight: 600; }
.org-emp { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; text-align: left; }
.org-emp:hover span { text-decoration: underline; }
.org-emp .avatar-xs { width: 22px; height: 22px; font-size: 10px; flex: none; }
.red { color: #dc2626; margin-left: 2px; }
.org-link { width: 0; height: 14px; border-left: 1.5px solid var(--line); }
.org-more { font-size: 11px; color: var(--muted); margin-top: 4px; }
.zoom { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-left: auto; }
.zoom button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; min-width: 40px; }
.zoom button + button { border-left: 1px solid var(--line); }
.zoom button:hover { background: var(--bg); }

/* 管理画面 */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button.is-on { background: #1e293b; color: #fff; }
.admin-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; }
.admin-bar .hint { margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 16px; min-height: 40px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #b8c0cc; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); }
.btn-danger { border-color: transparent; background: none; color: var(--danger); }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.admin-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.admin-table .tr { display: grid; align-items: center; gap: 12px; padding: 10px 16px; border: 0; border-top: 1px solid var(--line); background: none; width: 100%; text-align: left; }
.admin-table button.tr { cursor: pointer; }
.admin-table button.tr:hover { background: #f8fafc; }
.admin-table .th { border-top: 0; background: #f8fafc; color: var(--muted); font-size: 12px; font-weight: 600; }
.admin-table small { display: block; color: var(--muted); font-size: 12px; }
.emp-table .tr { grid-template-columns: 44px 1.2fr 1fr 1.6fr .6fr 70px; }
.dep-table .tr { --c: #94a3b8; grid-template-columns: 2fr 140px 70px 110px; padding-top: 6px; padding-bottom: 6px; }
.dep-name { border: 0; background: none; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.dep-name:hover strong { text-decoration: underline; }
.kind { flex: none; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 0 5px; line-height: 18px; background: color-mix(in srgb, var(--c) 15%, #fff); color: var(--c); }
.kind-meeting { background: #dbeafe; color: #1d4ed8; }
.kind-title { background: #e5e7eb; color: #111827; }
.dialog-wide { width: min(980px, calc(100vw - 32px)); }
.pos-editor { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.pos-editor h3 { font-size: 15px; margin: 0 0 4px; }
#pos-list { display: grid; gap: 6px; margin-bottom: 10px; }
.pos-row { display: grid; grid-template-columns: 62px 1.2fr 104px 1.5fr 0.9fr 72px auto; gap: 6px; align-items: center; padding: 6px; border-radius: 8px; background: #f8fafc; }
.pos-row.is-lead { background: #fff7ed; }
.pos-row input:not([type=checkbox]), .pos-row select { min-height: 34px; padding: 4px 8px; font-size: 13px; width: 100%; }
.pos-row input:disabled, .pos-row select:disabled { opacity: .45; }
.pos-btns { display: flex; gap: 2px; }
.pos-btns .btn { padding: 2px 8px; min-height: 30px; }
[hidden] { display: none !important; }
.audit-table .tr { grid-template-columns: 170px 1fr 130px 2fr; }
.loc-list { display: grid; gap: 8px; max-width: 560px; }
.loc-row { display: grid; grid-template-columns: 1fr 80px auto auto; gap: 8px; align-items: center; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel #csv-preview { margin-top: 12px; }
.dialog-form { width: min(720px, calc(100vw - 32px)); }
.dialog-form h2 { margin: 0 0 16px; font-size: 19px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid > label:not(.check), .form-grid fieldset { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; min-width: 0; }
.form-grid > label:not(.check) input, .form-grid > label select { width: 100%; color: var(--text); font-weight: 400; }
.form-grid > label.check { align-self: end; min-height: 38px; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
.form-grid legend { padding: 0 4px; }
.form-grid input[type=color] { width: 64px !important; height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
.span2 { grid-column: 1 / -1; }
.req { background: var(--danger); color: #fff; font-size: 10px; border-radius: 3px; padding: 0 4px; margin-left: 4px; font-weight: 600; }
.check-list { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text); font-weight: 400; }
.photo-edit { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.photo-buttons { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.photo-buttons small { color: var(--muted); }
.form-actions { display: flex; gap: 8px; margin-top: 20px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1e293b; color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 100; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px); }
.toast-error { background: var(--danger); }

/* スマホ */
@media (max-width: 720px) {
  .header-inner, .toolbar-inner, .container { padding-left: 16px; padding-right: 16px; }
  .header-inner { gap: 12px; height: 52px; }
  .toolbar { top: 52px; }
  .brand span:last-child { font-size: 15px; }
  .me { display: none; }
  .nav a { padding: 0 10px; }
  .toolbar-inner { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .search { flex-basis: 100%; max-width: none; }
  .toolbar-inner select { flex: 1; }
  .chips-row { padding: 0 16px 10px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .card { flex-direction: row; border-top-width: 1px; border-left: 4px solid var(--c); }
  .card-photo { padding: 12px 0 12px 12px; width: 96px; flex: none; }
  .card-body { padding: 12px; }
  .card-name { font-size: 16px; }
  .detail-head { gap: 14px; }
  .avatar-xl { width: 88px; height: 88px; }
  .dialog form { padding: 20px 16px; }

  /* 組織図は縦の階層表示 */
  .zoom { display: none; }
  .tree { zoom: 1 !important; }
  .org-scroll { overflow: visible; padding: 4px 16px 24px; }
  .tree { display: block; }
  .tree ul { display: block; padding: 0 0 0 14px; }
  .tree > ul { padding-left: 0; }
  .tree li { display: block; padding: 10px 0 0 14px; }
  .tree > ul > li { padding-left: 0; }
  .tree li::before, .tree li::after { border: 0 !important; border-radius: 0; width: auto; height: auto; right: auto; display: block; }
  .tree li::before { left: 0; top: 0; bottom: 0; border-left: 1.5px solid var(--line) !important; }
  .tree li::after { left: 0; top: 24px; width: 12px; border-top: 1.5px solid var(--line) !important; }
  .tree li:last-child::before { bottom: auto; height: 25px; }
  .tree > ul > li::before, .tree > ul > li::after { display: none !important; }
  .tree ul ul::before { display: none; }
  .org-unit-wrap { align-items: stretch; }
  .org-title, .org-meeting, .org-unit { width: 100%; }
  .org-link { margin-left: 50%; }
  .org-table th, .org-table td { font-size: 13px; padding: 6px 8px; }
  .org-emp .avatar-xs { width: 26px; height: 26px; }
  /* 1本道のつながり（子が1つだけ）は字下げせず、真下に積む */
  .tree ul:has(> li:only-child) { padding-left: 0; }
  .tree li:only-child { padding-left: 0; }
  .tree li:only-child::after { display: none !important; }
  .tree li:only-child::before { left: 50%; bottom: auto; height: 10px; }
  .me-warn { display: none !important; }

  .admin-table .th { display: none; }
  .emp-table .tr { grid-template-columns: 40px 1fr auto; gap: 4px 12px; }
  .emp-table .tr > span:nth-child(1) { grid-row: span 3; }
  .emp-table .tr > span:nth-child(5) { display: none; }
  .emp-table .tr > span:nth-child(6) { grid-column: 3; grid-row: 1; }
  .emp-table .tr > span:nth-child(3), .emp-table .tr > span:nth-child(4) { grid-column: 2 / 4; }
  .dep-table .tr { grid-template-columns: 1fr auto; }
  .dep-table .tr > span:nth-child(2), .dep-table .tr > span:nth-child(3) { display: none; }
  .pos-row { grid-template-columns: 1fr 1fr; }
  .pos-row .check { grid-column: 1 / -1; }
  .pos-btns { grid-column: 1 / -1; justify-content: flex-end; }
  .audit-table .tr { grid-template-columns: 1fr; gap: 2px; }
  .loc-row { grid-template-columns: 1fr 64px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
}
