* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f4f5f7;
    color: #333;
    font-family:
        "Meiryo",
        "Yu Gothic UI",
        sans-serif;
}


/* ヘッダー */

.header {
    background: #263445;
    color: white;
    padding: 16px 32px;
}

.header h1 {
    margin: 0;
    font-size: 22px;
}


/* メイン領域 */

main {
    max-width: 1200px;
    margin: 30px auto;
    padding: 0 24px;
}

h2 {
    margin-bottom: 24px;
}

h3 {
    margin-top: 28px;
    margin-bottom: 14px;
    font-size: 16px;
}


/* メインタブ */

.main-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid #d5d9df;
    margin-bottom: 24px;
}

.main-tab {
    padding: 12px 28px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 15px;
    cursor: pointer;
}

.main-tab.active {
    color: #2878c8;
    font-weight: bold;
    border-bottom: 3px solid #2878c8;
}

.help-cards {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.help-card {
    min-width: 0;
    margin: 0;
    padding: 14px 18px 18px;
    border: 1px solid #d5d9df;
    border-radius: 5px;
    background: white;
    line-height: 1.6;
}

.help-card ol,
.help-card ul {
    margin: 0;
    padding-left: 22px;
}

.help-card li + li {
    margin-top: 6px;
}

.help-backup-group {
    margin-top: 18px;
    padding: 14px 18px 18px;
    border: 1px solid #d5d9df;
    border-radius: 5px;
    background: white;
}

.help-backup-group p {
    margin: 0 0 14px;
    line-height: 1.6;
}

.help-backup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}


/* ================================= */
/* ノウハウ本管理 */
/* ================================= */


/* 操作エリア */

.book-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.book-toolbar-groups {
    display: flex;
    align-items: stretch;
    flex: none;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 10px;
}

.book-toolbar-group {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    margin: 0;
    padding: 6px 8px 8px;
    border: 1px solid #d5d9df;
    border-radius: 5px;
    background: #fff;
}

.book-toolbar-group:last-child {
    flex: none;
}

.book-toolbar-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.book-toolbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
}


/* 本管理画面のボタン高さを統一 */

.book-toolbar .button {
    height: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#book-delete-button {
    background: #f6d6d8;
    color: #842029;
}

.book-search-clear-button {
    align-self: flex-end;
    flex: none;
    margin-left: auto;
}

.book-title-search,
.book-category-search {
    height: 36px;
    min-width: 150px;
    padding: 0 8px;
    border: 1px solid #c8cdd3;
    border-radius: 4px;
    background: white;
    color: #333;
}

.book-title-search {
    width: 190px;
}


/* 本管理画面専用メッセージ */

.book-message {
    margin: 0;
    padding: 8px 12px;
    border-radius: 4px;
    background: #fce8e8;
    color: #a12626;
    font-size: 13px;
    text-align: left;
    white-space: normal;
}

.message-slot {
    height: 64px;
    margin-bottom: 12px;
    overflow: auto;
}

.message-slot .message {
    margin: 0;
    min-height: 40px;
    padding: 8px 12px;
}


#book-grid .book-edit-status-cell {
    text-align: center;
    color: #666;
    font-size: 13px;
    font-weight: bold;
}


/* グリッド */

.book-grid-container {
    width: 100%;
    max-height: 700px;
    overflow: auto;
    border: 1px solid #c8cdd3;
    border-radius: 5px;
    background: white;
}

#book-grid {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

#book-grid th,
#book-grid td {
    padding: 6px;
    border-right: 1px solid #e0e3e7;
    border-bottom: 1px solid #e0e3e7;
    text-align: center;
    white-space: nowrap;
}

#book-grid th {
    background: #edf1f5;
    font-weight: bold;
}

#book-grid td {
    background: white;
}


/* 基本情報列 */

.book-basic-column {
    min-width: 110px;
}

/* 本のタイトル */
.book-name-column {
    width: 154px;
    min-width: 154px;
    max-width: 154px;
}

/* カテゴリー */
.book-category-column {
    width: 154px;
    min-width: 154px;
    max-width: 154px;
}

/* Vo / Da / Vi / Me */
.book-stat-column {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
}


/* アビリティ列 */

.book-ability-column {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
}


/* アビリティ名ヘッダー */

.book-ability-header {
    height: 150px;
    vertical-align: bottom;
    padding: 8px 2px !important;
}

.book-ability-header.book-ability-mix-exempt {
    background: #d9efdd !important;
    color: #2f6335;
}

.book-ability-header span {
    display: inline-block;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
    line-height: 1.4;
}


/* ================================= */
/* 横スクロール時の固定列 */
/* ================================= */

/* 編集列 */
#book-grid th:nth-child(1),
#book-grid td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 2;
}

/* 削除列 */
#book-grid th:nth-child(2),
#book-grid td:nth-child(2) {
    position: sticky;
    left: 48px;
    z-index: 2;
}

/* 本のタイトル列 */
#book-grid th:nth-child(3),
#book-grid td:nth-child(3) {
    position: sticky;
    left: 96px;
    z-index: 2;
}

/* カテゴリー列 */
#book-grid th:nth-child(4),
#book-grid td:nth-child(4) {
    position: sticky;
    left: 250px;
    z-index: 2;
}

/* ヘッダーの固定列は最前面 */
#book-grid thead th:nth-child(-n+4) {
    z-index: 4;
}


/* 検索条件行 */

.book-search-row td {
    background: #fff9e8 !important;
    position: sticky;
    top: 150px;
    z-index: 3;
}

#book-grid .book-search-row td:nth-child(-n+4) {
    z-index: 4;
}

.book-search-row input {
    width: 18px;
    padding: 5px 0;
    text-align: center;
}

.book-search-row input[type="number"]::-webkit-inner-spin-button,
.book-search-row input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.book-search-row input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}


/* 入力行 */

.book-input-row td {
    background: #f8fbff !important;
}

.book-input-row input,
.book-input-row select {
    width: 100%;
    min-width: 0;
    padding: 6px 2px;
    border: 1px solid #cbd2da;
    border-radius: 3px;
    background: white;
    font-size: 13px;
}

.book-input-row input:focus,
.book-input-row select:focus {
    outline: none;
    border-color: #2878c8;
}

.book-input-row input[type="number"] {
    text-align: center;
}

/* 数値入力欄の上下ボタンを非表示 */
.book-input-row input[type="number"]::-webkit-inner-spin-button,
.book-input-row input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.book-input-row input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* アビリティ入力欄 */
.book-input-row .book-ability-input {
    width: 18px;
    padding: 6px 0;
}


/* 入力行の表示状態 */

.book-input-row.editing {
    background: #edf7ff;
}

.book-input-row.hidden-input {
    display: none;
}


/* 一覧行 */

.book-data-row {
    cursor: default;
}

.book-data-row:hover td {
    background: #f5f9fd;
}

#book-grid .book-data-row.search-result td {
    background: #fff3bf;
}

.book-data-row.edit-target td {
    background: #fff1d6;
}

.book-data-row.search-result.edit-target td {
    background: #e9e5f8;
}


/* 一覧操作列 */

.book-operation-column,
.book-operation-cell {
    min-width: 48px;
    width: 48px;
    max-width: 48px;
}

.book-operation-cell input {
    width: 16px;
    height: 16px;
}


/* ソート可能なヘッダー */

.book-sortable {
    cursor: pointer;
    user-select: none;
}

.book-sortable:hover {
    background: #dce8f4;
}


/* ================================= */
/* マスタ管理レイアウト */
/* ================================= */

.tabs {
    display: flex;
    border-bottom: 2px solid #d5d9df;
    margin-bottom: 24px;
}

.tab {
    padding: 12px 28px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 15px;
    cursor: pointer;
}

.tab.active {
    color: #2878c8;
    font-weight: bold;
    border-bottom: 3px solid #2878c8;
}


/* マスタ管理レイアウト */

.master-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
}


/* グループボックス共通 */

.master-group,
.display-order-group {
    min-width: 0;
    margin: 0;
    padding: 16px;
    border: 1px solid #c8cdd3;
    border-radius: 6px;
    background: white;
}

.help-backup-group legend,
.help-card legend,
.book-toolbar-group-title,
.master-group legend,
.display-order-group legend {
    padding: 0 10px;
    font-size: 16px;
    font-weight: bold;
    color: #333;
}


/* 新規登録 */

.add-area {
    display: flex;
    align-items: end;
    gap: 16px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 14px;
}

.add-name {
    flex: 1;
    min-width: 0;
}

.add-name label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

.add-name input {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 15px;
}

.add-name input:focus {
    outline: none;
    border-color: #2878c8;
}

.add-flag {
    white-space: nowrap;
    padding-bottom: 10px;
}

.add-flag label {
    cursor: pointer;
}


/* マスタ一覧 */

.table-container {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    max-height: 600px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 9px 8px;
    border-bottom: 1px solid #e5e5e5;
    text-align: left;
}

th {
    position: sticky;
    top: 0;
    background: #edf1f5;
    font-weight: bold;
    z-index: 1;
}

.delete-column {
    width: 55px;
    text-align: center;
}

.flag-column {
    width: 95px;
    text-align: center;
}

td.delete-cell,
td.flag-cell {
    text-align: center;
}

td input[type="text"] {
    width: 100%;
    min-width: 0;
    padding: 7px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 14px;
}

td input[type="text"]:hover {
    border-color: #ccc;
}

td input[type="text"]:focus {
    outline: none;
    border-color: #2878c8;
    background: white;
}

td input[type="checkbox"] {
    width: 17px;
    height: 17px;
    cursor: pointer;
}


/* 変更状態 */

tr.new-row,
tr.changed-row {
    background: #edf7ff;
}

tr.deleted-row {
    background: #fce8e8;
}

tr.deleted-row td:not(.delete-cell) {
    opacity: 0.5;
}


/* マスタ編集操作 */

.action-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

#change-status {
    color: #666;
    font-size: 13px;
}

#change-status.modified {
    color: #c07800;
    font-weight: bold;
}

.action-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}


/* ボタン */

.button {
    padding: 9px 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.primary {
    background: #2878c8;
    color: white;
}

.secondary {
    background: #e5e8ec;
    color: #333;
}

.danger {
    background: #f6d6d8;
    color: #842029;
}


/* アビリティ表示順 */

.display-order-group {
    display: flex;
    flex-direction: column;
}

.display-order-description {
    margin: 8px 0 16px;
    color: #666;
    font-size: 13px;
    line-height: 1.6;
}

.display-order-buttons {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

#display-order-status {
    margin-top: 14px;
    color: #666;
    font-size: 13px;
}

#display-order-status.modified {
    color: #c07800;
    font-weight: bold;
}

.display-order-container {
    margin-top: 12px;
    max-height: 600px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

#display-order-list {
    margin: 0;
    padding: 8px 8px 8px 36px;
}

#display-order-list li {
    padding: 10px 8px;
    margin: 3px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f8f9fa;
    cursor: grab;
    user-select: none;
    overflow-wrap: anywhere;
}

#display-order-list li:hover {
    background: #edf7ff;
    border-color: #9bc8ef;
}

#display-order-list li.dragging {
    opacity: 0.4;
}

#display-order-list li.drag-over {
    border-top: 3px solid #2878c8;
}


/* カテゴリー管理時は表示順設定を隠す */

.master-layout:has(#category-section:not(.hidden)) {
    grid-template-columns: minmax(0, 1fr);
}

.master-layout:has(#category-section:not(.hidden)) .display-order-group {
    display: none;
}


/* メッセージ */

.message {
    margin: 12px 0;
    padding: 12px 16px;
    border-radius: 4px;
    background: #e5f3e8;
    color: #286338;
}

.message.error {
    background: #fce8e8;
    color: #a12626;
}

.hidden {
    display: none !important;
}


/* 画面幅が狭い場合 */

@media (max-width: 700px) {

    main {
        padding: 0 12px;
    }

    .master-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .master-group,
    .display-order-group {
        padding: 14px;
    }

    .add-area {
        flex-direction: column;
        align-items: stretch;
    }

    .add-flag {
        padding-bottom: 0;
    }

    .action-buttons {
        justify-content: flex-end;
    }

    .display-order-buttons {
        justify-content: flex-end;
    }

}

@media (max-width: 1000px) {

    .book-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .book-toolbar-groups {
        display: grid;
        grid-column: 1;
        grid-row: 1 / 3;
        grid-template-columns: minmax(0, 1fr);
        grid-auto-rows: 1fr;
        width: 100%;
    }

    .book-toolbar-group,
    .book-toolbar-group:last-child {
        min-width: 0;
        width: max-content;
        max-width: 100%;
        justify-self: start;
    }

    .book-toolbar-actions {
        flex-wrap: wrap;
    }

    .book-search-clear-button {
        grid-column: 2;
        grid-row: 2;
        justify-self: end;
    }

}