/*
 * public/css/layout.css
 */

:root {
    --kamos-primary-color-rgb: 16, 185, 129;
    --kamos-box-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --kamos-box-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --kamos-box-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.06);
    --kamos-box-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --kamos-box-shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.12), 0 8px 10px rgba(0, 0, 0, 0.06);
    --kamos-box-shadow-focus: 0 0 0 3px rgba(var(--kamos-primary-color-rgb), 0.3);
}

/* 2カラムレイアウトのための新しいスタイル */
body {
    display: flex;
    flex-direction: row;
    /* 明示的にrow方向を設定 */
    height: 100vh;
    /* ビューポートの高さに固定 */
    overflow-y: auto;
    /* Allow scroll by default, specific layouts can restrict it */
}

/* For split-screen apps that need fixed body */
body.fixed-layout {
    overflow: hidden;
}

#left-panel {
    flex-grow: 1;
    flex-shrink: 1;
    /* チャットパネル表示時に適切に縮小できるように追加 */
    position: relative;
    /* 絶対配置のモーダルの基準点 */
    height: 100%;
    /* 親(body)の高さに追従 */
    overflow-y: auto;
    /* 左パネル全体をスクロール可能に */
    min-width: 0;
    /* Flexアイテムが内容によって縮小しすぎないようにする */
}

/* モーダル/ダイアログが開いているときは背景のスクロールを防ぐ */
body.modal-open #left-panel {
    overflow-y: hidden;
}

/* 1. 全体的なコンテナ/ページラッパー */
.kamos-app-container {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    /* 親のスクロール領域いっぱいに広がる */
    position: relative;
    min-width: 0;
}

.kamos-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    padding: var(--kamos-space-lg);
}

.kamos-main-content-wrapper {
    flex-grow: 1;
    /* overflow-y: auto; 左パネルがスクロールするので不要に */
    padding-top: 120px;
    /* ヘッダーの高さ */
    padding-bottom: 70px;
    /* フッターの高さ */
    position: relative;
    z-index: 1;
    /* フッターより低く */
}

/* 2. ヘッダー / 認証コンテナ */
#authContainer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 0.5rem 1.5rem;
    /* Matches bio-navbar */
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1001;
    box-shadow: none;
    /* Removed heavy shadow for flat look */
    gap: var(--kamos-space-md);
    background-color: rgba(255, 255, 255, 0.95);
    /* High opacity */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    /* Light border */
    border-radius: 0;
    /* Ensure flat corners */
    transition: right 0.3s ease-in-out, background-color 0.3s ease, border-color 0.3s ease;
}

html.dark #authContainer {
    background-color: rgba(17, 24, 39, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* Auto Mode Panel が開いている時のヘッダー調整 */
/* Auto Mode Panel moves the flow, so we don't need manual adjustment for absolute header inside relative container */
/* body.auto-mode-open #authContainer {
    right: 400px !important;
} */

#authContainer img {
    height: 48px;
}

#hamburger-menu-button {
    display: none;
}

#authContainer span#userStatus {
    display: none !important;
}

#authContainer button {
    background-color: transparent;
    color: var(--kamos-text-color-default);
    transition: all var(--kamos-transition-duration-short) ease-in-out;
    border: none;
    min-width: 48px;
    min-height: 48px;
    padding: var(--kamos-space-sm);
    border-radius: var(--kamos-border-radius-md);
}

#authContainer button:hover {
    background-color: rgba(var(--kamos-primary-color-rgb), 0.1);
    color: var(--kamos-primary-darker);
    transform: translateY(-1px);
    box-shadow: var(--kamos-box-shadow-sm);
}

#startNewAnalysisHeaderButton {
    background-color: var(--kamos-primary-color);
    color: var(--kamos-text-color-inverted);
    box-shadow: var(--kamos-box-shadow-md);
    font-weight: 600;
}

#startNewAnalysisHeaderButton:hover {
    background-color: var(--kamos-primary-darker);
    box-shadow: var(--kamos-box-shadow-lg);
    transform: translateY(-2px);
}

/* 3. メインコンテンツエリア */
.kamos-section-card {
    background-color: var(--kamos-bg-color-body);
    border: 1px solid var(--kamos-border-color-default);
    border-radius: var(--kamos-border-radius-lg);
    padding: var(--kamos-space-xl);
    margin-bottom: var(--kamos-space-2xl);
    box-shadow: var(--kamos-box-shadow-md);
}

/* 4. フッター */
#fixed-footer-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
    gap: var(--kamos-space-md);
    padding: var(--kamos-space-md) var(--kamos-space-lg);
    background-color: var(--kamos-bg-color-body);
    border-top: 1px solid var(--kamos-border-color-light);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    z-index: 1000;
    /* Auto Mode Panel の幅を考慮するためのクラス */
    transition: right 0.3s ease-in-out;
}

/* Auto Mode Panel が開いている時のフッター調整 */
body.auto-mode-open #fixed-footer-actions {
    right: 400px !important;
    /* Panel Width */
}

/* 5. 分析履歴サイドパネル */
/* Duplicate definition removed - see lines 145-157 for the main definition */

#toggleHistoryPanelButton,
#toggleCustomHistoryPanelButton {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    /* 1049 から 998 に変更 */
    background-color: var(--kamos-primary-color);
    color: var(--kamos-text-color-inverted);
    padding: var(--kamos-space-md);
    box-shadow: var(--kamos-box-shadow-md);
    cursor: pointer;
    border: none;
    min-width: 56px;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: right 0.3s ease-in-out;
}

#toggleHistoryPanelButton {
    right: 0;
    border-radius: var(--kamos-border-radius-lg) 0 0 var(--kamos-border-radius-lg);
}

#toggleCustomHistoryPanelButton {
    left: 0;
    border-radius: 0 var(--kamos-border-radius-lg) var(--kamos-border-radius-lg) 0;
}

/* 5. 分析履歴サイドパネル */
#analysisHistoryPanel,
#customFrameworkHistoryPanel {
    /* position is set by Tailwind class kamos-fixed */
    top: 0;
    /* height is set dynamically by JavaScript based on footer height */
    height: 100vh;
    /* fallback if JS hasn't run yet */
    width: 320px;
    z-index: 1050;
    background-color: var(--kamos-bg-color-container-light);
    box-shadow: var(--kamos-box-shadow-lg);
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

#analysisHistoryPanel {
    right: 0;
    transform: translateX(100%);
    border-left: 1px solid var(--kamos-border-color-default);
}

#customFrameworkHistoryPanel {
    left: 0;
    transform: translateX(-100%);
    border-right: 1px solid var(--kamos-border-color-default);
}

#analysisHistoryPanel.is-open,
#customFrameworkHistoryPanel.is-open {
    transform: translateX(0);
}

/* 7. 全幅モード */
html.full-width-active .kamos-container {
    max-width: 100%;
    padding-left: var(--kamos-space-xl);
    padding-right: var(--kamos-space-xl);
}

/* 8. チャットノートパネル表示時のレイアウト調整 */
body.chat-note-open #report-actions-container {
    padding-right: 384px;
    /* チャットパネルの幅分、右側にパディングを追加 */
    transition: padding-right 0.3s ease-in-out;
}

#chatNotePanel.is-closed {
    display: none;
    /* レイアウトフローから完全に削除して非表示にする */
}

#closeAnalysisHistoryPanel,
#closeCustomHistoryPanel {
    z-index: 1000;
    /* サイドパネルのz-index (999) より高く設定 */
    position: relative;
    /* z-indexを有効にするために追加 */
}

/* 9. レスポンシブ対応 */
@media (max-width: 768px) {
    #header-menu {
        display: none;
    }

    #hamburger-menu-button {
        display: block;
    }

    #authContainer {
        padding: var(--kamos-space-sm) var(--kamos-space-md);
    }

    .kamos-container {
        padding: var(--kamos-space-md);
    }

    .kamos-main-content-wrapper {
        padding-top: 60px;
        /* ヘッダーの高さ */
        padding-bottom: 80px;
        /* フッターの高さ */
        position: relative;
        z-index: 1;
        /* フッターより低く */
    }

    #fixed-footer-actions {
        padding: var(--kamos-space-sm) var(--kamos-space-md);
        right: 0 !important;
        /* Mobile overrides Auto Mode Panel logic */
    }

    #analysisHistoryPanel,
    #customFrameworkHistoryPanel {
        width: 100%;
    }

    #toggleHistoryPanelButton,
    #toggleCustomHistoryPanelButton {
        min-width: 48px;
        min-height: 48px;
    }
}

/* Shift Report Actions and Modals when Auto Mode panel is open */
#report-actions-container {
    transition: transform 0.3s ease-in-out, right 0.3s ease-in-out;
}

body.auto-mode-open #report-actions-container,
body.auto-mode-open .kamos-dialog-backdrop {
    right: 400px !important;
    width: auto !important;
}

@media (min-width: 769px) {
    body.auto-mode-open #toggleHistoryPanelButton {
        right: 400px !important;
    }
}

/* Custom Framework History Panel Open Adjustments (Left Panel) */
body.custom-history-open #authContainer {
    right: 0 !important;
    left: 320px !important;
    width: auto !important;
    transition: left 0.3s ease-in-out;
}

body.custom-history-open #fixed-footer-actions {
    right: 0 !important;
    left: 320px !important;
    width: auto !important;
    transition: left 0.3s ease-in-out;
}

body.custom-history-open #report-actions-container {
    padding-left: 320px !important;
    left: 0 !important;
    right: 0 !important;
    transition: padding-left 0.3s ease-in-out;
}

/* Config Kit Custom Layout Styles */
#configKitLayout.collapsed #settingsPanel {
    flex: 0 0 0 !important;
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border-width: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
}

#configKitLayout.collapsed #toggleSettingsPanelButton {
    left: 0 !important;
    transform: translateY(-50%) rotate(180deg);
}