/* 
 * WBS & Gantt Chart - Modern Tech Styling
 * Google Fonts Inter
 */
:root {
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --text-muted: #8b949e;
    
    --primary-color: #58a6ff;
    --primary-hover: #3182ce;
    --danger-color: #f85149;
    --warning-color: #d29922;
    
    --glass-bg: rgba(22, 27, 34, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* Background Animation */
.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.4;
    animation: float 20s infinite ease-in-out alternate;
}

.shape-1 {
    width: 400px;
    height: 400px;
    background: #58a6ff;
    top: -100px;
    left: -100px;
}

.shape-2 {
    width: 300px;
    height: 300px;
    background: #8957e5;
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.shape-3 {
    width: 250px;
    height: 250px;
    background: #238636;
    top: 40%;
    left: 30%;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, 50px) scale(1.1); }
}

/* Base Layout */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: hidden;
}

/* Glassmorphism Utilities */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--glass-shadow);
}

.glass-heavy {
    background: rgba(22, 27, 34, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.6);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap; /* allow wrapping on smaller screens */
    gap: 15px;
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-name {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.user-name strong {
    color: var(--text-color);
}

.project-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 20px;
    padding-right: 20px;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.project-select {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-color);
    padding: 6px 30px 6px 15px;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 15px;
    transition: all 0.3s ease;
}

.project-select:hover {
    border-color: var(--primary-color);
}

.project-select option {
    background: #1a1a2e;
    color: white;
}

.logo-circle {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #58a6ff, #8957e5);
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(88, 166, 255, 0.5);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #c9d1d9, #58a6ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    outline: none;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-primary {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 14px rgba(88, 166, 255, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(88, 166, 255, 0.4);
}

.btn-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(88, 166, 255, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(88, 166, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(88, 166, 255, 0); }
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-color);
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-outline.active {
    background: rgba(88, 166, 255, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Main Content Area */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

/* Panels */
.pane {
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

.pane-wbs {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* ガントチャートビュー */
.gantt-view {
    display: flex;
    flex: 1;
    min-height: 0;
}

.pane-gantt {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.pane-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--glass-border);
}

.pane-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.gantt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-mode-controls {
    display: flex;
    gap: 8px;
}

/* Priority Tasks */
.priority-tasks-container {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
}

.priority-title {
    font-size: 1.05rem;
    color: var(--danger-color);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.priority-tasks-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.priority-card {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    transition: var(--transition);
}

.priority-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.priority-card.overdue {
    border-left: 4px solid var(--danger-color);
}

.priority-card.warning {
    border-left: 4px solid var(--warning-color);
}

.priority-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.priority-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.priority-card-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.75rem;
}

.badge-overdue {
    background: rgba(248, 81, 73, 0.2);
    color: var(--danger-color);
}

.badge-warning {
    background: rgba(210, 153, 34, 0.2);
    color: var(--warning-color);
}

/* WBS Table */
.table-container {
    flex: 1 1 auto;
    min-height: 0; /* Crucial for scrolling inside flex container */
    overflow-x: auto;
    overflow-y: auto;
    max-height: 50vh;
    padding-right: 10px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4);
}

.wbs-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.wbs-table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 10px;
    position: sticky;
    top: 0;
    background: var(--bg-color);
    z-index: 10;
}

.wbs-table td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.9rem;
}

.wbs-table tr {
    transition: var(--transition);
}

.wbs-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.task-item-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.toggle-icon {
    cursor: pointer;
    user-select: none;
    padding: 2px 4px;
    border-radius: 4px;
    transition: var(--transition);
    display: inline-block;
    min-width: 24px;
    text-align: center;
}

.toggle-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.indent-level-1 { padding-left: 20px; }
.indent-level-2 { padding-left: 40px; }
.indent-level-3 { padding-left: 60px; }

/* Progress Bar mini */
.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 5px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 3px;
}

/* Action buttons in table */
.action-btns {
    display: flex;
    gap: 8px;
}
.btn-icon-only {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    padding: 4px;
}
.btn-icon-only:hover {
    color: var(--primary-color);
    transform: scale(1.1);
}
.btn-icon-only.delete:hover {
    color: #f85149;
}

/* Gantt Container */
.gantt-container {
    flex: 1;
    overflow-x: auto;
    overflow-y: visible;
    border-radius: 8px;
    background: #fff; /* Frappe gantt default needs light bg */
}

/* Override Frappe Gantt styles for better look */
.gantt .grid-header { fill: #f8f9fa; }
.gantt .grid-row { fill: #fff; }
.gantt .grid-row:nth-child(even) { fill: #f8f9fa; }
.gantt .bar-wrapper { cursor: pointer; }
.gantt .bar-progress { fill: rgba(0,0,0,0.2) !important; }

/* Gantt Color Classes based on Owner */
.gantt .bar-wrapper.gantt-item-color-1 .bar { fill: #58a6ff; }
.gantt .bar-wrapper.gantt-item-color-2 .bar { fill: #3fb950; }
.gantt .bar-wrapper.gantt-item-color-3 .bar { fill: #d29922; }
.gantt .bar-wrapper.gantt-item-color-4 .bar { fill: #f85149; }
.gantt .bar-wrapper.gantt-item-color-5 .bar { fill: #8957e5; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    transform: translateY(20px);
    transition: var(--transition);
}

.modal-overlay:not(.hidden) .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}

.modal-header h3 {
    font-size: 1.2rem;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding: 20px;
    border-top: 1px solid var(--glass-border);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    gap: 20px;
}
.half { flex: 1; }

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.required { color: #f85149; }

.form-control {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

/* Range input styling */
.range-container {
    display: flex;
    align-items: center;
    gap: 15px;
}
.form-control-range {
    flex: 1;
    accent-color: var(--primary-color);
}
.range-value {
    font-weight: 600;
    width: 40px;
    text-align: right;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* =========================================
   Responsive Design Breakpoints
   ========================================= */

/* Tablet & Smaller Laptops */
@media (max-width: 1024px) {
    .app-container {
        padding: 15px;
    }
    
    .main-content {
        flex-direction: column;
        overflow-y: auto;
    }

    .pane-wbs {
        flex: none;
        width: 100%;
    }

    .pane-gantt {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-x: auto;
    }
}

/* Mobile Devices */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
        /* 固定高さ・overflow:hidden を解除してページ全体をスクロール可能にする */
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 15px;
    }

    .header-logo {
        width: 100%;
        justify-content: flex-start;
    }

    .header-right {
        width: 100%;
        flex-direction: column;
        align-items: stretch; /* stretch buttons full width */
        gap: 15px;
    }

    .project-controls {
        margin-right: 0;
        padding-right: 0;
        border-right: none;
        padding-bottom: 15px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        width: 100%;
        justify-content: space-between;
    }

    .project-select {
        flex: 1; /* take remaining space */
        margin-right: 10px;
    }

    .user-controls {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap; /* allow wrapping if too tight */
    }

    /* Make modals fit screen */
    .form-row {
        flex-direction: column;
        gap: 10px;
    }

    .modal-content {
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* タブ：アイコンのみ表示 */
    .tab-label {
        display: none;
    }

    .view-tab {
        padding: 8px 14px;
        font-size: 1.15rem;
    }

    /* ナレッジ：縦並びレイアウト */
    .knowledge-view {
        flex-direction: column;
        overflow-y: auto;
        gap: 12px;
        /* flex: 1 + min-height: 0 をリセットして自然な高さにする */
        flex: none;
        width: 100%;
        height: auto;
        min-height: 0;
        box-sizing: border-box;
    }

    .knowledge-sidebar {
        width: 100%;
        max-height: 40vh;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .knowledge-content {
        width: 100%;
        /* flex 依存をやめてブロック要素として自然に高さを持たせる */
        flex: none;
        display: block;
        overflow: visible;
        box-sizing: border-box;
    }

    .knowledge-empty {
        min-height: 200px;
    }

    /* height: 100% を解除（親が auto のため 0 になる問題を防ぐ） */
    .knowledge-page {
        display: block;
        height: auto;
        overflow: visible;
    }

    .knowledge-page-header {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    /* flex: 1 をやめて内容量で高さを決める */
    .knowledge-rendered {
        flex: none;
        display: block;
        overflow-y: visible;
        max-height: none;
        min-height: 200px;
    }

    .knowledge-edit-area {
        display: block;
        overflow: visible;
        flex: none;
    }

    .knowledge-textarea {
        display: block;
        width: 100%;
        box-sizing: border-box;
        flex: none;
        min-height: 40vh;
        overflow-y: auto;
    }
}

/* =========================================
   Chat Modal Styles
   ========================================= */
   
#chat-modal {
    z-index: 2000; /* Ensure it's above everything including gantt */
}

.chat-modal-content {
    max-width: 500px;
    height: 80vh;
    display: flex;
    flex-direction: column;
}

.chat-history-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 0;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-message.self {
    align-self: flex-end;
}

.chat-message.other {
    align-self: flex-start;
}

.chat-message-sender {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-left: 2px;
}

.chat-message.self .chat-message-sender {
    text-align: right;
    margin-right: 2px;
}

.chat-message-bubble {
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-all;
}

.chat-message.other .chat-message-bubble {
    background-color: var(--card-bg);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-message.self .chat-message-bubble {
    background-color: var(--primary-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    text-align: right;
}

.chat-input-area {
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 5px;
}

/* ===== カレンダービュー ===== */
.calendar-view {
    display: flex;
    flex: 1;
    min-height: 0;
}

.calendar-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.calendar-nav h2 {
    font-size: 1.2rem;
    font-weight: 700;
    min-width: 110px;
    text-align: center;
    background: linear-gradient(to right, #c9d1d9, #58a6ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.calendar-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 8px;
    flex-wrap: wrap;
}

.legend-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-left: 8px;
}

.calendar-grid-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.calendar-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.calendar-table thead th {
    padding: 10px 0;
    text-align: center;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    background: rgba(22, 27, 34, 0.9);
    backdrop-filter: blur(8px);
    z-index: 1;
}

.calendar-table thead th.sun { color: #ff7b72; }
.calendar-table thead th.sat { color: #79c0ff; }

.cal-day {
    vertical-align: top;
    padding: 6px;
    border: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    height: 110px;
    transition: background 0.15s;
}

.cal-day:hover {
    background: rgba(255,255,255,0.04);
}

.cal-day--other {
    cursor: default;
    background: rgba(0,0,0,0.15);
}

.cal-day--today {
    background: rgba(88, 166, 255, 0.05);
}

.cal-day--sun .cal-day-num { color: #ff7b72; }
.cal-day--sat .cal-day-num { color: #79c0ff; }

.cal-day-num {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-bottom: 4px;
}

.cal-day-num--today {
    background: var(--primary-color);
    color: #fff !important;
    font-weight: 700;
}

.cal-event-chip {
    font-size: 0.75rem;
    color: #fff;
    border-radius: 4px;
    padding: 2px 6px;
    margin-bottom: 3px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
    transition: opacity 0.15s, transform 0.15s;
}

.cal-event-chip:hover {
    opacity: 1;
    transform: translateX(2px);
}

/* ===== ビュー切り替えタブ ===== */
.view-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    border-radius: var(--border-radius);
}

.view-tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.view-tab:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
}

.view-tab.active {
    background: rgba(88, 166, 255, 0.15);
    color: var(--primary-color);
    font-weight: 600;
}

/* ===== ナレッジビュー ===== */
.knowledge-view {
    display: flex;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

/* サイドバー */
.knowledge-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.knowledge-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--glass-border);
    gap: 8px;
}

.knowledge-sidebar-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.knowledge-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.knowledge-tree-empty {
    padding: 20px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.knowledge-tree-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 7px 12px;
    cursor: pointer;
    border-radius: 6px;
    margin: 1px 6px;
    transition: background 0.15s ease;
}

.knowledge-tree-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.knowledge-tree-item.active {
    background: rgba(88, 166, 255, 0.15);
}

.knowledge-tree-item.active .knowledge-tree-title {
    color: var(--primary-color);
    font-weight: 500;
}

.knowledge-tree-title {
    flex: 1;
    font-size: 0.88rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.knowledge-tree-toggle {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.65rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    padding: 0;
}

.knowledge-tree-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.knowledge-tree-toggle-spacer {
    flex-shrink: 0;
    width: 18px;
}

.knowledge-tree-add {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.knowledge-parent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.knowledge-parent-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.knowledge-parent-select {
    flex: 1;
    font-size: 0.85rem;
    padding: 4px 8px;
    height: auto;
}

.knowledge-tree-item:hover .knowledge-tree-add {
    opacity: 1;
}

.knowledge-tree-add:hover {
    background: rgba(88, 166, 255, 0.2);
    color: var(--primary-color);
}

.knowledge-tree-item[draggable] {
    cursor: grab;
}

.knowledge-tree-item.dragging {
    opacity: 0.4;
}

.knowledge-tree-item.drag-over-top {
    border-top: 2px solid var(--primary-color);
}

.knowledge-tree-item.drag-over-bottom {
    border-bottom: 2px solid var(--primary-color);
}

/* コンテンツエリア */
.knowledge-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.knowledge-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    font-size: 0.95rem;
    gap: 8px;
    height: 100%;
}

.knowledge-empty-icon {
    font-size: 3rem;
    margin-bottom: 8px;
    opacity: 0.5;
}

.knowledge-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.knowledge-page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.knowledge-title-display {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-color);
    font-family: inherit;
    cursor: default;
}

.knowledge-page-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.knowledge-delete-btn {
    color: var(--danger-color) !important;
    border-color: var(--danger-color) !important;
    opacity: 0.7;
}

.knowledge-delete-btn:hover {
    opacity: 1;
    background: rgba(248, 81, 73, 0.1) !important;
}

/* 閲覧モード: Markdownレンダリング */
.knowledge-rendered {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
}

/* 編集モード */
.knowledge-edit-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    gap: 0;
}

.knowledge-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.03);
    flex-shrink: 0;
}

.knowledge-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.knowledge-toolbar-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: rgba(88, 166, 255, 0.1);
}

.knowledge-toolbar-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: 4px;
}

.knowledge-title-input {
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: 1px solid var(--glass-border) !important;
    font-size: 1.3rem !important;
    font-weight: 700 !important;
    padding: 16px 24px !important;
    background: transparent !important;
}

.knowledge-textarea {
    flex: 1;
    resize: none;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    padding: 20px 32px;
    overflow-y: auto;
}

.knowledge-meta {
    padding: 10px 24px;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

/* ===== Markdownスタイル (markdown-body) ===== */
.markdown-body {
    color: var(--text-color);
    line-height: 1.8;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    color: #e6edf3;
    margin: 1.5em 0 0.5em;
    line-height: 1.3;
}

.markdown-body h1 { font-size: 1.8rem; border-bottom: 1px solid var(--glass-border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.4rem; border-bottom: 1px solid var(--glass-border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.1rem; }

.markdown-body p { margin: 0.8em 0; }

.markdown-body a { color: var(--primary-color); text-decoration: underline; }

.markdown-body strong { color: #e6edf3; font-weight: 600; }
.markdown-body em { color: #c9d1d9; }

.markdown-body ul, .markdown-body ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.markdown-body li { margin: 0.3em 0; }

.markdown-body blockquote {
    border-left: 3px solid var(--primary-color);
    padding: 4px 16px;
    margin: 0.8em 0;
    color: var(--text-muted);
    background: rgba(88, 166, 255, 0.05);
    border-radius: 0 6px 6px 0;
}

.markdown-body code {
    background: rgba(88, 166, 255, 0.1);
    color: #79c0ff;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
    font-size: 0.85em;
}

.markdown-body pre {
    background: #0d1117;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 1em 0;
}

.markdown-body pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.88em;
}

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--glass-border);
    padding: 8px 12px;
    text-align: left;
}

.markdown-body th {
    background: rgba(255,255,255,0.05);
    font-weight: 600;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 1.5em 0;
}

.markdown-body img {
    max-width: 320px;
    max-height: 240px;
    object-fit: cover;
    border-radius: 8px;
    cursor: zoom-in;
    border: 1px solid var(--glass-border);
    transition: opacity 0.2s, transform 0.2s;
    display: block;
    margin: 8px 0;
}

.markdown-body img:hover {
    opacity: 0.85;
    transform: scale(1.02);
}

/* ライトボックス */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    cursor: zoom-out;
    backdrop-filter: blur(4px);
    animation: lightbox-in 0.15s ease;
}

@keyframes lightbox-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    cursor: default;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.lightbox-close:hover {
    opacity: 1;
}

/* =============================================
   ナレッジ モバイル上書き
   ※ デスクトップの固定幅ルールより後に書くことで正しく上書きされる
   ============================================= */
@media (max-width: 768px) {
    .knowledge-view {
        flex-direction: column !important;
        width: 100% !important;
        flex: none !important;
        height: auto !important;
        min-height: 0 !important;
        gap: 12px !important;
    }

    .knowledge-sidebar {
        width: 100% !important;
        max-height: 40vh !important;
        flex-shrink: 0 !important;
        box-sizing: border-box !important;
    }

    .knowledge-content {
        width: 100% !important;
        flex: none !important;
        display: block !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    .knowledge-page {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
    }

    .knowledge-rendered {
        flex: none !important;
        display: block !important;
        overflow-y: visible !important;
        max-height: none !important;
        min-height: 100px !important;
    }

    .knowledge-edit-area {
        display: block !important;
        overflow: visible !important;
        flex: none !important;
    }

    .knowledge-textarea {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
        flex: none !important;
        min-height: 40vh !important;
    }
}
