/*
========================================
0. ベーススタイル・リセット / ユーティリティ
========================================
*/

/* ボックスサイズのグローバルリセット */
*, *::before, *::after {
    box-sizing: border-box;
}

/* 基本フォント */
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: #212529;
}

/* 見出し */
h5 {
    font-size: 1.25rem;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

h6 {
    font-size: 1rem;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

small {
    font-size: 0.875em;
}

/* フォーム要素のフォント継承（ブラウザデフォルト上書き） */
button,
input,
select,
textarea {
    margin: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* グリッドシステム */
.row {
    display: flex;
    flex-wrap: nowrap;
}

.col-2 {
    flex: 0 0 auto;
    width: 16.66666667%;
}

.col-5 {
    flex: 0 0 auto;
    width: 41.66666667%;
}

/* 高さユーティリティ */
.h-100 { height: 100% !important; }

/* スペーシングユーティリティ */
.mb-0 { margin-bottom: 0 !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-5 { margin-top: 3rem !important; }
.pt-3 { padding-top: 1rem !important; }
.me-1 { margin-right: 0.25rem !important; }
.me-2 { margin-right: 0.5rem !important; }

/* Flexboxユーティリティ */
.d-flex { display: flex !important; }
.d-block { display: block !important; }
.justify-content-between { justify-content: space-between !important; }
.align-items-center { align-items: center !important; }
.text-end { text-align: right !important; }

/* テキストユーティリティ */
.text-primary { color: #0d6efd !important; }
.text-muted { color: #6c757d !important; }
.text-decoration-none { text-decoration: none !important; }

/* ボーダーユーティリティ */
.border-top { border-top: 1px solid #dee2e6 !important; }

/* ボタン基本スタイル */
.btn {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    background-color: transparent;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.375rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.25rem;
}

.btn-primary {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-primary:hover {
    color: #fff;
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn-outline-primary {
    color: #0d6efd;
    border-color: #0d6efd;
}

.btn-outline-primary:hover {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-success {
    color: #fff;
    background-color: #198754;
    border-color: #198754;
}

.btn-success:hover {
    color: #fff;
    background-color: #157347;
    border-color: #146c43;
}

.btn-outline-success {
    color: #198754;
    border-color: #198754;
}

.btn-outline-success:hover {
    color: #fff;
    background-color: #198754;
    border-color: #198754;
}

/*
========================================
1. 基本設定・リセット
========================================
*/

/* ブラウザデフォルトリセット */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    min-width: 768px; /* iPad mini横向き未満で横スクロール */
}

/* 画面全体の最小幅をiPad mini横向き(768px)に固定 */
.container-fluid {
    width: 100%;
    min-width: 768px;
}

/* 全画面高さユーティリティ */
.full-height {
    height: 100vh;
}

/*
========================================
2. レイアウトシステム（3カラム構成）
========================================
*/

/* カラム背景・境界線 */
.left-column,
.right-column {
    background-color: #f8f9fa;
}

.left-column {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 左カラム タブバー */
.left-tab-bar {
    display: flex;
    flex-shrink: 0;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.left-tab-btn {
    flex: 1;
    padding: 8px 4px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #6c757d;
    font-weight: 500;
}

.left-tab-btn:hover {
    color: #212529;
    background-color: #e9ecef;
}

.left-tab-btn.active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
}

/* 左カラム内の column-content はタブバーの残り高さを占有 */
.left-column .column-content {
    flex: 1;
    height: 0;
    min-height: 0;
}

/* 柱書リスト */
.scene-list-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #333;
    overflow: hidden;
}

.scene-list-item:hover {
    background-color: #e8f0fe;
    color: #0d6efd;
}

.scene-number {
    flex-shrink: 0;
    color: #6c757d;
    font-size: 0.75rem;
    min-width: 2.5em;
    text-align: right;
}

.scene-list-item:hover .scene-number {
    color: #0d6efd;
}

.scene-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scene-list-empty {
    color: #6c757d;
    font-size: 0.85rem;
    padding: 16px 8px;
    text-align: center;
}

.center-column {
    background-color: #fff;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.right-column {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* カラム仕切り（ドラッグリサイズ） */
.col-divider {
    flex: 0 0 5px;
    width: 5px;
    background-color: #dee2e6;
    cursor: col-resize;
    flex-shrink: 0;
    transition: background-color 0.15s ease;
    z-index: 10;
}

.col-divider:hover,
.col-divider.dragging {
    background-color: #adb5bd;
}

/* カラム内コンテンツ共通 */
.column-content {
    padding: 20px;
    overflow-y: auto;
}

.right-column .column-content {
    flex: 1;
    min-height: 0;
}

/*
========================================
2.1. テキストエディターコンポーネント
========================================
*/

/* エディター構造 */
.editor-menu-bar {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 15px 20px;
    flex-shrink: 0;
}

.editor-container {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* エディターミラー（行オフセット計算用・不可視） */
.code-editor-mirror {
    /* テキストエリアと同じ位置・サイズ */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    margin: 0;
    box-sizing: border-box;

    /* テキストエリアと同じフォント・レイアウト設定 */
    font-family: 'Courier New', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;

    /* 不可視・操作無効 */
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
}

/* エディター入力エリア */
.code-editor {
    /* サイズ・配置 */
    width: 100%;
    height: 100%;
    padding: 20px;
    margin: 0;

    /* 表示・動作 */
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;

    /* 外観 */
    background-color: #fff;
    color: #333;
    font-family: 'Courier New', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.code-editor::placeholder {
    color: #888;
    font-style: italic;
}

.code-editor:focus {
    background-color: #fff;
}

/*
========================================
3. 縦書き表示システム
========================================
*/

/* B5用紙コンテナ */
.b5-paper {
    width: 400px;
    height: 560px;
    margin: 0 auto 20px auto;
    background-color: #ffffff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
}

/* 縦書きテキストコンテナ */
.vertical-text-container {
    height: 100%;
    width: 100%;
    background-color: #ffffff;
    border: 1px solid #ccc;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
}

/* 縦書きテキスト本体 */
.vertical-text {
    /* 縦書き設定 */
    writing-mode: vertical-rl;
    text-orientation: upright;

    /* 配置・サイズ */
    position: absolute;
    right: 15px;
    top: calc(15px + 151px - 5em);
    width: calc(100% - 30px);
    height: calc(100% - 30px - 151px + 5em);
    padding-top: 5em;

    /* 表示設定 */
    overflow: visible;
    white-space: pre-wrap;
    border: none;
    outline: none;
    resize: none;
    box-sizing: border-box;

    /* フォント・文字 */
    font-family: 'MS Mincho', 'Yu Mincho', 'Hiragino Mincho ProN', serif;
    font-size: 12px;
    line-height: 1.8;
    color: #333;
}

/* プレビュークリック：対応行へジャンプ可能なことを示すカーソル */
.vertical-text [data-line-index] {
    cursor: pointer;
}

/* プレビューホバー：柱書リストと同じ色でハイライト */
.vertical-text [data-line-index]:hover {
    background-color: #e8f0fe;
}

/* セリフ行の発言者プレフィックス用：空白だけ固定幅にする */
.fixed-space {
    display: inline-block;
    inline-size: 1em;
    block-size: 1em;
    line-height: 1;
    white-space: pre;
}

/* ページ番号 */
.page-number {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #666;
}

/*
========================================
4. 台本専用要素
========================================
*/

/* 柱書スタイル */
.scene-line {
    color: #000;
    display: block;
    margin-bottom: 0;
    position: relative;
    top: -5em;
    border: #000 1px solid;
    border-bottom: none;
    margin-left: 0.5em;
    margin-right: 0.5em;
    height: calc(29em + 5em);
}

/*
========================================
5. 通知システム
========================================
*/

/* 通知ベース */
.notification {
    /* 配置 */
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;

    /* サイズ・外観 */
    padding: 15px 20px;
    max-width: 300px;
    border-radius: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);

    /* 文字 */
    color: white;
    font-weight: bold;
    font-size: 14px;

    /* アニメーション */
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease-in-out;
}

/* 通知状態 */
.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification.fade-out {
    opacity: 0;
    transform: translateX(100%);
}

/* 通知種類別カラー */
.notification-success {
    background-color: #28a745;
}

.notification-warning {
    background-color: #ffc107;
    color: #333;
}

.notification-error {
    background-color: #dc3545;
}

/*
========================================
6. 印刷専用スタイル
========================================
*/

@media print {
    /* B5縦書き印刷設定 */
    @page {
        size: B5 portrait; /* B5縦書き */
        margin: 25mm 9mm 0mm 9mm; /* ページマージン */
    }

    /* 印刷対象以外を非表示 */
    * {
        visibility: hidden;
    }

    #pages-container,
    #pages-container * {
        visibility: visible;
    }

    /* 印刷レイアウト調整 */
    #pages-container {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        /* B5 印刷スケール算出根拠：
           プレビュー紙 400×560px をブラウザの印刷エンジンで B5 (182×257mm) に
           合わせるための実測値。ブラウザ／OS のデフォルト DPI 設定によっては
           ズレが生じる場合があり、その際はこの値を調整する。 */
        transform: scale(2.28);
        transform-origin: top left;
    }

    .b5-paper {
        page-break-after: always;
        margin: 0 0 20px 0;
        max-width: none;
        width: 400px;
        height: 560px;
        box-shadow: none;
    }

    .vertical-text-container {
        border: none;
    }

    .page-number {
        display: block;
        visibility: visible;
    }
}
