:root {
  --primary: #7b1a2e;
  --primary-dark: #5a0f1f;
  --primary-light: #a83250;
  --secondary: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  font-size: 14px;
}

.min-h-screen { min-height: 100vh; }

/* ---------- ログイン ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #3d0b17 0%, #7b1a2e 45%, #5a0f1f 100%);
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  border-top: 4px solid var(--primary);
}
.login-header { text-align: center; margin-bottom: 22px; }
.login-header .logo { font-size: 36px; color: var(--primary); margin-bottom: 8px; }
.login-header h1 { font-size: 18px; font-weight: 900; letter-spacing: 0.08em; color: var(--primary); margin: 0 0 4px; }
.login-header p { font-size: 12px; color: var(--text-muted); margin: 0; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.form-control {
  width: 100%;
  padding: 11px 13px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  background: #f8fafc;
  transition: border-color .2s, background .2s;
}
.form-control:focus { border-color: var(--primary); background: #fff; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
textarea.form-control { resize: vertical; min-height: 70px; }
.error-text { color: var(--danger); font-size: 12px; margin-top: 6px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer; min-height: 38px;
  transition: transform .1s, background .15s; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; min-height: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- ヘッダー ---------- */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  padding: 14px 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-md);
}
.app-header .title { font-weight: 900; font-size: 16px; letter-spacing: .04em; }
.app-header .subtitle { font-size: 11px; opacity: .85; }
.app-header nav { display: flex; gap: 6px; margin-left: 12px; flex-wrap: wrap; }
.app-header nav button {
  background: rgba(255,255,255,.12); color: #fff; border: none; border-radius: 8px;
  padding: 7px 12px; font-size: 12.5px; cursor: pointer; font-weight: 600;
}
.app-header nav button.active { background: #fff; color: var(--primary); }
.app-header .spacer { flex: 1; }
.app-header .userbox { font-size: 12px; text-align: right; line-height: 1.4; }
.app-header .userbox .role { opacity: .8; font-size: 10.5px; }

main.container { max-width: 1200px; margin: 0 auto; padding: 22px 18px 60px; }
main.container.container-wide { max-width: none; padding: 22px 20px 40px; }

.breadcrumb { font-size: 12.5px; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--primary); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---------- カード ---------- */
.card {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.grid-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px;
}
.category-card {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px; cursor: pointer; transition: box-shadow .15s, transform .1s;
  display: flex; flex-direction: column; gap: 8px; border-top: 3px solid var(--primary-light);
  min-height: 132px;
}
.category-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.category-card .icon { font-size: 22px; color: var(--primary); }
.category-card .name {
  font-weight: 700; font-size: 14px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.category-card .meta { font-size: 11.5px; color: var(--text-muted); min-height: 1.4em; }
/* カテゴリの性質別カラー（経営レベル系=紫／設備・現場系=青／監査・審査系=橙／品質記録・不具合系=赤／教育系=緑） */
.category-card.cat-group-mgmt { border-top-color: #7c3aed; }
.category-card.cat-group-equip { border-top-color: #2563eb; }
.category-card.cat-group-audit { border-top-color: var(--warning); }
.category-card.cat-group-issue { border-top-color: var(--danger); }
.category-card.cat-group-edu { border-top-color: var(--success); }
.category-card.locked { border-top-color: var(--warning); }

/* ---------- ドラッグ&ドロップ並び替え（共通） ---------- */
.drag-handle { cursor: grab; text-align: center; color: var(--text-muted); width: 28px; }
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { color: var(--primary); }
tr.is-dragging { opacity: .4; }
tr.drag-over-row td { box-shadow: inset 0 2px 0 var(--primary); }

/* ---------- テーブル ---------- */
/* 全社共通ルール：表は固定幅+折り返しでなくnowrap+可変幅を基本形にする。
   はみ出す場合は各テーブルを包む overflow-x:auto ラッパー側で横スクロールさせる。 */
table.data-table { width: auto; min-width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left; font-size: 11.5px; color: var(--text-muted); font-weight: 600;
  padding: 6px 10px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
table.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.data-table td.cell-wrap { white-space: normal; }
table.data-table tr:hover td { background: #f8fafc; }
table.data-table td.is-editable { cursor: pointer; }
table.data-table td.is-editable:hover { background: #fff4e6 !important; }
.cell-truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 700;
}
.badge-admin { background: #fee2e2; color: #991b1b; }
.badge-editor { background: #dbeafe; color: #1e40af; }
.badge-locked { background: #fef3c7; color: #92400e; }
.badge-expired { background: #fee2e2; color: #991b1b; }
.badge-ok { background: #dcfce7; color: #166534; }

/* ---------- スキルマップ（元Excelの色分けマトリクスに合わせた表示） ---------- */
.skillmap-legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.skillmap-legend .legend-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; margin-right: 4px; }
.skillmap-legend .legend-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 6px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; border: 1px solid rgba(0,0,0,.06);
}
.skillmap-legend .legend-chip .dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

.skillmap-wrap { overflow: auto; max-height: calc(100vh - 250px); min-height: 320px; border: 1px solid var(--border); border-radius: var(--radius-sm); display: inline-block; max-width: 100%; }
table.skillmap-table { border-collapse: separate; border-spacing: 0; font-size: 12.5px; width: max-content; }
table.skillmap-table th, table.skillmap-table td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }

table.skillmap-table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700; padding: 6px 4px; text-align: center; white-space: nowrap;
  border-right-color: rgba(255,255,255,.2); border-bottom-color: var(--primary-dark);
}
table.skillmap-table thead th:first-child, table.skillmap-table thead th:nth-child(2) { z-index: 4; }
table.skillmap-table thead th.emp-th { min-width: 38px; width: 38px; }
table.skillmap-table thead th.emp-th .emp-th-name { writing-mode: vertical-rl; text-orientation: mixed; letter-spacing: 1px; padding: 3px 0; }

table.skillmap-table th.col-major, table.skillmap-table th.col-minor { text-align: left; }
table.skillmap-table td.col-major, table.skillmap-table td.col-minor {
  position: sticky; background: var(--card-bg); z-index: 1; white-space: nowrap; padding: 6px 8px;
  overflow: hidden; text-overflow: ellipsis;
}
table.skillmap-table td.col-major { left: 0; z-index: 2; font-weight: 700; color: var(--primary-dark); background: #faf3f4; }
table.skillmap-table th.col-major { position: sticky; left: 0; z-index: 5; }
table.skillmap-table td.col-minor { left: 80px; }
table.skillmap-table th.col-minor { position: sticky; left: 80px; z-index: 5; }
table.skillmap-table td.col-major, table.skillmap-table th.col-major { min-width: 80px; max-width: 80px; width: 80px; }
table.skillmap-table td.col-drag, table.skillmap-table th.col-drag {
  position: sticky; left: 0; z-index: 5; text-align: center; padding: 0;
  width: 26px; min-width: 26px; max-width: 26px; background: var(--card-bg);
}
table.skillmap-table th.col-drag { background: var(--primary); }
table.skillmap-table.has-drag-col td.col-major, table.skillmap-table.has-drag-col th.col-major { left: 26px; }
table.skillmap-table.has-drag-col td.col-minor, table.skillmap-table.has-drag-col th.col-minor { left: 106px; }
table.skillmap-table td.col-minor, table.skillmap-table th.col-minor { min-width: 84px; max-width: 320px; box-shadow: 2px 0 3px -2px rgba(0,0,0,.15); }
table.skillmap-table th.col-minor { background: var(--primary); box-shadow: 2px 0 3px -2px rgba(0,0,0,.3); }

table.skillmap-table td.cell-level { padding: 0; text-align: center; min-width: 38px; }

table.skillmap-table td.col-major.is-editable, table.skillmap-table td.col-minor.is-editable { cursor: pointer; }
table.skillmap-table td.col-major.is-editable:hover, table.skillmap-table td.col-minor.is-editable:hover { background: #fff4e6; }
.skillmap-inline-edit {
  width: 100%; height: 22px; font-size: 12.5px; font-family: inherit; padding: 0 4px;
  border: 1px solid var(--primary); border-radius: 4px; box-sizing: border-box;
}
table.skillmap-table tbody tr:nth-child(odd) td.col-minor { background: #fff; }
table.skillmap-table tbody tr:nth-child(even) td.col-minor { background: #fafafa; }
table.skillmap-table tbody tr:nth-child(even) td.col-major { background: #f5eaec; }

.skillmap-badge {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 26px;
  font-weight: 800; font-size: 12px;
}
.skillmap-cell-btn {
  border: none; cursor: pointer; font-family: inherit; padding: 0; margin: 0; box-sizing: border-box;
}
.skillmap-cell-btn:hover { filter: brightness(0.94); }
.skillmap-cell-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.skillmap-picker-backdrop { position: fixed; inset: 0; z-index: 60; background: transparent; }
.skillmap-tagpicker {
  position: fixed; z-index: 61; background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  border: 1px solid var(--border); padding: 6px; display: flex; flex-direction: column; gap: 4px; width: 132px;
}
.skillmap-tag {
  border: none; border-radius: 6px; padding: 6px 8px; font-size: 12px; font-weight: 700; text-align: left;
  cursor: pointer; font-family: inherit;
}
.skillmap-tag:hover { filter: brightness(0.94); }
.skillmap-tag.is-current { box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); }

.lvl-0 { background: #e2e8f0; color: #64748b; }
.lvl-1 { background: #fde3cf; color: #9a4a12; }
.lvl-2 { background: #fed7a1; color: #9a5b00; }
.lvl-3 { background: #fef08a; color: #7a5c00; }
.lvl-4 { background: #bfdbfe; color: #1e40af; }
.lvl-5 { background: #bbf7d0; color: #14532d; }

/* ---------- モーダル ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 40;
}
.modal-card { background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 800; }
.modal-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted); }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 13px; }
.section-title { font-weight: 800; font-size: 14px; margin-bottom: 10px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
