/* Nyx AI Studio - Layout Fixes */

/* メインレイアウトの修正 */
body {
    overflow-x: hidden;
}

.d-flex {
    min-height: 100vh;
    position: relative;
}

/* サイドバーの固定 */
.nyx-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    z-index: 1040;
    overflow-y: auto;
    background: var(--nyx-sidebar-bg, #1F2937);
}

/* メインコンテンツの配置 */
.nyx-main {
    margin-left: 280px;
    width: calc(100% - 280px);
    min-height: 100vh;
    padding: 2rem;
    overflow-x: auto;
}

/* 中間サイズ画面用の調整 */
@media (min-width: 768px) and (max-width: 1024px) {
    .nyx-main {
        padding: 1.5rem;
    }
}

/* Prevent content from being cut off */
.glass-card {
    margin-bottom: 1.5rem;
    min-height: auto;
    overflow: visible;
}

/* Dashboard specific fixes */
.nyx-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

/* ダッシュボード生成履歴のレスポンシブ修正 */
@media (max-width: 1199px) {
    .col-xl-8 {
        flex: 0 0 auto;
        width: 100%;
    }
    
    .col-xl-4 {
        flex: 0 0 auto;
        width: 100%;
    }
}

/* テーブルのレスポンシブ対応強化 */
.table-responsive {
    min-height: 200px;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* スクロールインジケーター */
.table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.1));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.table-responsive:hover::after {
    opacity: 1;
}

@media (max-width: 768px) {
    .table-responsive table {
        font-size: 0.85rem;
    }
    
    .table-responsive .btn-sm {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* テーブルセルの最小幅を設定 */
    .table td, .table th {
        min-width: 100px;
        white-space: nowrap;
    }
}

/* Ensure proper spacing for all screen sizes */
.row {
    margin-bottom: 2rem;
}

.col-12,
.col-lg-8,
.col-lg-4 {
    margin-bottom: 1.5rem;
}

/* Fix for model usage section */
.progress {
    height: 8px;
    margin-bottom: 0.5rem;
}

/* Table responsiveness */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    min-width: 100%;
    margin-bottom: 0;
}

/* Sidebar fixed positioning */
.nyx-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--nyx-purple) var(--nyx-bg-secondary);
}

/* Main content scroll */
html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    overflow-y: auto;
}

/* レスポンシブデザインの修正 */
@media (max-width: 1200px) {
    .nyx-sidebar {
        width: 240px;
    }
    
    .nyx-main {
        margin-left: 240px;
        width: calc(100% - 240px);
        padding: 1.5rem;
    }
}

@media (max-width: 992px) {
    .nyx-sidebar {
        width: 220px;
    }
    
    .nyx-main {
        margin-left: 220px;
        width: calc(100% - 220px);
        padding: 1.25rem;
    }
}

@media (max-width: 768px) {
    .nyx-sidebar {
        position: fixed;
        left: -280px;
        width: 280px;
        transition: left 0.3s ease;
    }
    
    .nyx-sidebar.active {
        left: 0;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }
    
    .nyx-main {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 1rem;
        padding-top: 70px; /* モバイルメニューボタンのスペース */
    }
    
    /* モバイルメニューボタン */
    .mobile-menu-btn {
        display: block !important;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1050;
        background: var(--nyx-primary);
        color: white;
        border: none;
        border-radius: 50%;
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
        box-shadow: 0 2px 10px rgba(0,0,0,0.3);
        cursor: pointer;
    }
    
    /* モバイルオーバーレイ */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1045;
    }
    
    .mobile-overlay.active {
        display: block;
    }
    
    .nyx-stats-grid {
        grid-template-columns: 1fr;
    }
    
    .glass-card {
        padding: 1.5rem;
    }
    
    .nyx-page-title {
        font-size: 1.5rem;
    }
    
    .nyx-stat-value {
        font-size: 1.75rem;
    }
}

@media (min-width: 769px) {
    .mobile-menu-btn,
    .mobile-overlay {
        display: none !important;
    }
}

/* Ensure minimum height for content areas */
.glass-card {
    min-height: 200px;
}

.nyx-stat-card {
    min-height: 120px;
}

/* Fix for cut-off content */
.d-flex {
    min-height: 100vh;
    position: relative;
}

/* Padding bottom to ensure content is not cut off */
.nyx-main > *:last-child {
    margin-bottom: 3rem;
}

/* Fix specific dashboard elements */
#dashboard-content {
    padding-bottom: 3rem;
}

/* 極小画面対応 */
@media (max-width: 576px) {
    .nyx-main {
        padding: 0.75rem;
        padding-top: 70px;
    }
    
    .nyx-page-header {
        padding: 1rem 0;
    }
    
    .nyx-page-title {
        font-size: 1.5rem;
    }
    
    /* カードを縦に積む */
    .col-sm-6,
    .col-md-3,
    .col-md-4,
    .col-md-6,
    .col-lg-4,
    .col-lg-8 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* テーブルのレスポンシブ対応 */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table {
        font-size: 0.875rem;
    }
    
    .table td,
    .table th {
        padding: 0.5rem;
    }
}

/* モーダルのレスポンシブ対応 */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-xl {
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
}

/* モーダルの修正 */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

/* モーダルのz-index管理 */
.modal {
    z-index: 1050;
}

.modal-backdrop.show {
    opacity: 0.5;
}

/* 複数モーダル対応 */
.modal-backdrop:nth-of-type(2) {
    z-index: 1051;
}

.modal:nth-of-type(2) {
    z-index: 1052;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto;
}

.modal-dialog-centered {
    min-height: calc(100% - 1rem);
}

/* プリセットモーダルの修正 */
#presetModal .modal-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* モーダル内のフォーム要素の修正 */
.modal-body .form-control,
.modal-body .form-select {
    background-color: var(--nyx-bg-elevated, #fff);
    border: 1px solid var(--nyx-border, #dee2e6);
    color: var(--nyx-text-primary, #212529);
}

/* モーダルが開いている時のbodyのスクロール防止 */
body.modal-open {
    overflow: hidden;
    padding-right: 0 !important;
}

/* フォームのレスポンシブ対応 */
@media (max-width: 576px) {
    .form-label {
        font-size: 0.875rem;
    }
    
    .form-control,
    .form-select {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }
    
    .btn-lg {
        font-size: 1rem;
        padding: 0.75rem 1.25rem;
    }
}

/* System info table fix */
.table-sm td {
    padding: 0.5rem;
    white-space: nowrap;
}

/* Better scrollbar styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--nyx-bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--nyx-purple);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--nyx-light-purple);
}

/* DMM記事生成ページの修正 */
#productDetailCard {
    margin-bottom: 100px !important;
    overflow: visible !important;
}

#productDetailCard .card-body {
    overflow: visible !important;
    max-height: none !important;
}

/* ページ全体の下部余白 */
.nyx-main {
    padding-bottom: 100px !important;
    min-height: 100vh;
}

/* フォームコンテナの修正 */
#generateForm {
    overflow: visible !important;
}

/* カード内のオーバーフロー修正 */
.card {
    overflow: visible !important;
}

.card-body {
    overflow: visible !important;
}

/* Container width management */
@media (min-width: 1400px) {
    .container-xxl {
        max-width: 1320px;
    }
}

/* Ensure cards don't overflow */
.card-body {
    overflow-x: auto;
}

/* Fix Bootstrap grid gutters */
.row {
    --bs-gutter-x: 1.5rem;
    --bs-gutter-y: 1.5rem;
}

/* Prevent text overflow */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ensure proper z-index stacking */
.nyx-sidebar {
    z-index: 1040;
}

.mobile-menu-btn {
    z-index: 1050;
}

.mobile-overlay {
    z-index: 1030;
}

/* Fix for specific width ranges */
@media (min-width: 992px) and (max-width: 1199px) {
    .col-lg-4 {
        flex: 0 0 auto;
        width: 33.33333333%;
    }
    
    .col-lg-8 {
        flex: 0 0 auto;
        width: 66.66666667%;
    }
}