/* ================================================================
   リセット・基本
   ================================================================ */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ================================================================
   ローディング
   ================================================================ */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 16px 32px;
    font-size: 0.95em;
    color: #555;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
}

/* ================================================================
   ツールバー（ヘッダー）
   ================================================================ */
#toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    z-index: 10;
}

.toolbar-title {
    font-size: 0.85em;
    font-weight: 600;
    color: #999;
    margin-right: 6px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-group label {
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
}

/* ボタン */
#toolbar button {
    padding: 6px 14px;
    font-size: 0.85em;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background: #fff;
    color: #333;
    transition: background 0.15s, border-color 0.15s;
}

#toolbar button:hover {
    background: #e8f4fd;
    border-color: #90caf9;
}

#toolbar button:active {
    background: #bbdefb;
}

/* セレクト */
#toolbar select {
    padding: 5px 8px;
    font-size: 0.85em;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    max-width: 280px;
}

/* 検索 */
.search-box {
    position: relative;
}

.search-box input {
    padding: 5px 10px;
    font-size: 0.85em;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    width: 220px;
}

.search-box input:focus {
    outline: none;
    border-color: #64b5f6;
    box-shadow: 0 0 0 2px rgba(100, 181, 246, 0.25);
}

.search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 300px;
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85em;
    border-bottom: 1px solid #f0f0f0;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: #e8f4fd;
}

/* ================================================================
   メインエリア（グラフ + サイドバー）
   ================================================================ */
main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* グラフ */
#network {
    flex: 1;
    min-width: 0;
    background: #fdfdfd;
}

/* サイドバー */
#sidebar {
    width: 320px;
    flex-shrink: 0;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

/* ================================================================
   講義情報テーブル
   ================================================================ */
.table-container {
    flex-shrink: 0;
}

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

.table-container th,
.table-container td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.85em;
}

.table-container th {
    background: #fafafa;
    color: #555;
    font-weight: 600;
    width: 35%;
    white-space: nowrap;
}

.table-container td {
    color: #333;
    word-break: break-all;
}

.table-container tr:last-child th,
.table-container tr:last-child td {
    border-bottom: none;
}

.table-container a {
    color: #1976d2;
    text-decoration: none;
}

.table-container a:hover {
    text-decoration: underline;
}

/* ================================================================
   凡例（折りたたみ）
   ================================================================ */
.legend {
    border-top: 1px solid #e0e0e0;
    padding: 10px 12px;
    flex-shrink: 0;
}

.legend-title {
    font-size: 0.8em;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    user-select: none;
}

.legend-content {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.legend-section {
    min-width: 0;
}

.legend-subtitle {
    font-weight: 600;
    font-size: 0.78em;
    color: #888;
    margin-bottom: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
    color: #666;
    margin-bottom: 2px;
}

/* エッジ凡例ライン */
.legend-edge {
    display: inline-block;
    width: 24px;
    height: 0;
    border-top: 2px solid;
    flex-shrink: 0;
}

.edge-required {
    border-color: #D32F2F;
    border-top-width: 3px;
}

.edge-prerequisite {
    border-color: #E53935;
}

.edge-recommended {
    border-color: #1976D2;
}

.edge-related {
    border-color: #757575;
    border-top-style: dashed;
}

.edge-exclusive {
    border-color: #AB47BC;
    border-top-width: 3px;
}

/* ノード凡例 */
.legend-node {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ================================================================
   フッター
   ================================================================ */
#footer {
    flex-shrink: 0;
    text-align: right;
    padding: 2px 12px;
    background: #fff;
    border-top: 1px solid #eee;
}

#footer a {
    font-size: 0.7em;
    color: #aaa;
    text-decoration: none;
}

#footer a:hover {
    color: #777;
    text-decoration: underline;
}

/* ================================================================
   レスポンシブ
   ================================================================ */
@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }

    main {
        flex-direction: column;
        overflow: hidden;
    }

    #network {
        flex: 1;
        min-height: 0;
    }

    #sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e0e0e0;
        max-height: 40vh;
        overflow-y: auto;
        flex-shrink: 0;
    }

    #toolbar {
        gap: 6px;
        padding: 6px 10px;
    }

    .toolbar-title {
        font-size: 0.8em;
    }

    .search-box input {
        width: 160px;
    }

    #toolbar select {
        max-width: 200px;
    }

    .search-results {
        width: calc(100vw - 20px);
        left: auto;
        right: 0;
    }
}

@media (max-width: 480px) {
    #toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 8px;
        padding: 6px 8px;
    }

    .toolbar-title {
        width: 100%;
        margin-bottom: 0;
        font-size: 0.75em;
    }

    .toolbar-group {
        flex-shrink: 0;
    }

    /* 検索ボックスは残りスペースを埋める */
    .toolbar-group.search-box {
        flex: 1;
        min-width: 0;
    }

    .search-box input {
        width: 100%;
        min-width: 0;
    }

    /* 講義セレクトは全幅 */
    .toolbar-class-select {
        flex-basis: 100%;
    }

    #toolbar select {
        max-width: none;
    }

    #classSelect {
        width: 100%;
    }

    #toolbar button {
        padding: 5px 10px;
        font-size: 0.8em;
    }

    #toolbar select {
        font-size: 0.8em;
        padding: 4px 6px;
    }

    .search-box input {
        font-size: 0.8em;
        padding: 4px 8px;
    }

    .search-results {
        left: 0;
        right: auto;
        width: calc(100vw - 16px);
    }

    /* サイドバーをよりコンパクトに */
    #sidebar {
        max-height: 35vh;
    }

    .table-container th,
    .table-container td {
        padding: 5px 8px;
        font-size: 0.8em;
    }

    .table-container th {
        width: 30%;
    }

    .legend {
        padding: 8px 10px;
    }

    .legend-title {
        font-size: 0.75em;
    }

    .legend-item {
        font-size: 0.72em;
    }

    /* vis-network ナビゲーションボタンを小さく */
    #network .vis-navigation .vis-button {
        width: 28px;
        height: 28px;
    }
}
