/* 2. Sidebar Drawer (127-211) */
.sidebar-drawer {
    position: absolute;
    left: 64px;
    top: 0;
    width: 310px;
    height: 100%; /* app-main-rowの高さに制限される */
    background: var(--drawer-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 15px 0 45px rgba(0, 0, 0, 0.4);
}

.sidebar-drawer.closed {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.drawer-header {
    padding: 24px 24px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.drawer-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--text);
}

.drawer-close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.drawer-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px calc(60px + env(safe-area-inset-bottom, 20px));
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.drawer-content::-webkit-scrollbar {
    width: 4px;
}

.drawer-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.drawer-section {
    display: none;
}

.drawer-section.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

/* Cards & Settings (231-271) */
.drawer-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    transition: all 0.2s ease;
}

.drawer-card:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.settings-row:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.settings-info {
    display: flex;
    flex-direction: column;
}

.settings-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.settings-desc {
    font-size: 10px;
    color: var(--text-dim);
}

/* Footer (314-321) */
.drawer-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.1);
    font-size: 11px;
    color: var(--text-dim);
}

/* Layout Icons (1089-1372) */
.layout-grid-v2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 8px;
}

.layout-btn-v2 {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 4px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
}

.layout-btn-v2.active {
    border-color: var(--accent) !important;
    background: rgba(52, 120, 255, 0.15) !important;
    color: white !important;
    box-shadow: 0 0 12px rgba(52, 120, 255, 0.2);
}

[data-theme="light"] .layout-btn-v2.active {
    color: var(--accent) !important;
}

.layout-btn-v2 span {
    font-size: 10px;
    font-weight: 600;
}

.layout-icon {
    width: 24px;
    height: 18px;
    border: 1px solid currentColor;
    position: relative;
    opacity: 0.6;
}

.layout-btn-v2.active .layout-icon {
    opacity: 1;
    color: var(--accent);
}

/* --- Layout Icons (Improved Accuracy) --- */
.icon-2-3 span,
.icon-2v-3 span,
.icon-3x2 span,
.icon-2x3 span {
    position: absolute;
    background: currentColor;
    pointer-events: none;
}

.icon-2-3 .v-split {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
}

.icon-2-3 .h-left {
    left: 0;
    width: 50%;
    top: 50%;
    height: 1px;
}

.icon-2-3 .h-right1 {
    right: 0;
    width: 50%;
    top: 33.3%;
    height: 1px;
}

.icon-2-3 .h-right2 {
    right: 0;
    width: 50%;
    top: 66.6%;
    height: 1px;
}

.icon-2v-3 .h-split {
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
}

.icon-2v-3 .v-top {
    top: 0;
    height: 50%;
    left: 50%;
    width: 1px;
}

.icon-2v-3 .v-bottom1 {
    bottom: 0;
    height: 50%;
    left: 33.3%;
    width: 1px;
}

.icon-2v-3 .v-bottom2 {
    bottom: 0;
    height: 50%;
    left: 66.6%;
    width: 1px;
}

.icon-3x2 .h-mid {
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
}

.icon-3x2 .v1 {
    left: 33.3%;
    top: 0;
    bottom: 0;
    width: 1px;
}

.icon-3x2 .v2 {
    left: 66.6%;
    top: 0;
    bottom: 0;
    width: 1px;
}

.icon-2x3 .v-mid {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
}

.icon-2x3 .h1 {
    top: 33.3%;
    left: 0;
    right: 0;
    height: 1px;
}

.icon-2x3 .h2 {
    top: 66.6%;
    left: 0;
    right: 0;
    height: 1px;
}

.icon-1x1::before {
    content: "";
    position: absolute;
    inset: 0;
}

.icon-2x1::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    border-left: 1px solid currentColor;
}

.icon-1x2::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px solid currentColor;
}

.icon-2x2::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 1px solid currentColor;
}

.icon-2x2::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 1px solid currentColor;
}

.icon-1-2::before {
    content: "";
    position: absolute;
    left: 60%;
    top: 0;
    bottom: 0;
    border-left: 1px solid currentColor;
}

.icon-1-2::after {
    content: "";
    position: absolute;
    left: 60%;
    right: 0;
    top: 50%;
    height: 0;
    border-top: 1px solid currentColor;
}

.icon-1v-2::before {
    content: "";
    position: absolute;
    top: 60%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 1px solid currentColor;
}

.icon-1v-2::after {
    content: "";
    position: absolute;
    top: 60%;
    bottom: 0;
    left: 50%;
    width: 0;
    border-left: 1px solid currentColor;
}

.icon-3x1::before {
    content: "";
    position: absolute;
    left: 33%;
    top: 0;
    bottom: 0;
    border-left: 1px solid currentColor;
}

.icon-3x1::after {
    content: "";
    position: absolute;
    left: 66%;
    top: 0;
    bottom: 0;
    border-left: 1px solid currentColor;
}

.icon-1-3::before {
    content: "";
    position: absolute;
    left: 65%;
    top: 0;
    bottom: 0;
    border-left: 1px solid currentColor;
}

.icon-1-3::after {
    content: "";
    position: absolute;
    left: 65%;
    right: 0;
    top: 33.3%;
    height: 33.3%;
    border-top: 1px solid currentColor;
    border-bottom: 1px solid currentColor;
}

.icon-1v-3::before {
    content: "";
    position: absolute;
    top: 60%;
    left: 0;
    right: 0;
    border-top: 1px solid currentColor;
}

.icon-1v-3::after {
    content: "";
    position: absolute;
    top: 60%;
    bottom: 0;
    left: 33.3%;
    right: 33.3%;
    border-left: 1px solid currentColor;
    border-right: 1px solid currentColor;
}



/* Sub-headers (1350-1372) */
.drawer-sub-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10px;
    font-weight: 800;
    color: var(--text-dim);
    letter-spacing: 0.12em;
    margin-bottom: 12px;
    text-transform: uppercase;
    font-family: 'Outfit', sans-serif;
}

.drawer-sub-header .material-symbols-rounded {
    font-size: 14px;
    color: var(--accent);
}

.drawer-divider {
    height: 1px;
    background: linear-gradient(to right, var(--border), transparent);
    margin: 16px 0;
}

/* Priority Badge (1454-1474) */
.priority-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    background: var(--accent) !important;
    border-radius: 50%;
    color: white !important;
    font-size: 9px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 9999;
}

/* Layout Favorites (v3.7.1 - text-dim base, Light/Dark auto) */
.layout-btn-v2 {
    position: relative;
    overflow: visible !important;
}

/* 未選択の星: text-dim を使うことでライト/ダーク自動対応 (インジケーター星と同じ仕組み) */
.layout-fav-star {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 16px !important;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    opacity: 0.4;
}

.layout-btn-v2:hover .layout-fav-star {
    opacity: 0.85;
}

/* ライトモード: アクティブボタンの青文字化 */
[data-theme="light"] .layout-btn-v2.active {
    background: rgba(9, 105, 218, 0.1) !important;
    color: var(--accent) !important;
    border-color: var(--accent) !important;
}

[data-theme="light"] .layout-btn-v2.active span {
    color: var(--accent) !important;
    font-weight: 800;
}

[data-theme="light"] .layout-btn-v2.active .layout-icon {
    color: var(--accent) !important;
    opacity: 1;
}

/* ライトモード active 時でも is-fav の星は黄色を維持 */
[data-theme="light"] .layout-btn-v2.active.is-fav .layout-fav-star {
    color: #ffca28 !important;
}

/* お気に入り登録済み状態 */
.layout-btn-v2.is-fav .layout-fav-star {
    color: #ffca28 !important;
    text-shadow: 0 0 8px rgba(255, 202, 40, 0.5);
    opacity: 1;
}

.layout-btn-v2.is-fav::after {
    content: attr(data-fav-idx);
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 17px;
    height: 17px;
    background: #ffbe0b;
    color: #000;
    font-size: 10px;
    font-weight: 900;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* ============================================================
   履歴テーブル デザイン改善 (v3.11.1)
   ============================================================ */

/* テーブル山山ヘッダ */
.th-fixed,
.th-hist {
    padding: 8px 5px;
    color: var(--text-dim);
    font-size: 9px;
    font-weight: 700;
    text-align: left;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.04em;
    white-space: nowrap;
    user-select: none;
}
.th-hist[data-col="pnl"],
.th-hist[data-col="pct"] { text-align: right; }

/* 列表示トグルボタン */
.hist-col-toggle {
    padding: 2px 7px;
    font-size: 9px;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(255,255,255,0.03);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 0.02em;
}
.hist-col-toggle.active {
    background: rgba(52,120,255,0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* 履歴スロットバー */
.history-slot-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hist-slot-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.03);
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    transition: all 0.18s;
    user-select: none;
}
.hist-slot-chip:hover {
    border-color: rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.06);
    color: var(--text);
}
.hist-slot-chip.active {
    border-color: var(--accent);
    background: rgba(52,120,255,0.15);
    color: var(--accent);
}
.hist-slot-chip .slot-cnt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: rgba(255,255,255,0.08);
    font-size: 9px;
    font-weight: 700;
    color: var(--text-dim);
}
.hist-slot-chip.active .slot-cnt {
    background: rgba(52,120,255,0.25);
    color: var(--accent);
}
.hist-slot-chip .slot-del {
    font-size: 11px;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity 0.15s;
    line-height: 1;
    padding: 0 2px;
}
.hist-slot-chip:hover .slot-del {
    opacity: 0.7;
}
.hist-slot-chip:hover .slot-del:hover {
    opacity: 1;
    color: var(--accent-red, #ef5350);
}

/* ライトモード対応 */
[data-theme="light"] .hist-slot-chip.active {
    background: rgba(9,105,218,0.1);
    border-color: var(--accent);
    color: var(--accent);
}
[data-theme="light"] .hist-col-toggle.active {
    background: rgba(9,105,218,0.1);
    border-color: var(--accent);
    color: var(--accent);
}

/* --- Mobile Optimization (v3.9.1) --- */
@media screen and (max-width: 768px) {
    .sidebar-drawer {
        left: 60px; /* Sidebar width */
        width: calc(100% - 60px);
    }

    .drawer-content {
        /* メニューバーおよび下部ボタンの削除に合わせてパディングを見直し */
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 10px));
    }

    .close-btn-v2 {
        padding: 18px;
        font-size: 14px;
        margin-top: 24px;
    }
}

/* ============================================================
   分析レポート パネル (analytics.js)
   ============================================================ */

.anlys-section {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.anlys-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 9px;
    font-weight: 800;
    color: var(--text-dim);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-family: 'Outfit', sans-serif;
    margin-bottom: 8px;
}
.anlys-header .material-symbols-rounded {
    font-size: 13px;
    color: var(--accent);
}

/* KPI グリッド（2列） */
.anlys-kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.anlys-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 7px 4px;
    background: var(--drawer-bg);
    gap: 2px;
}
.anlys-kpi-lbl {
    font-size: 9px;
    color: var(--text-dim);
    font-weight: 600;
    letter-spacing: 0.04em;
}
.anlys-kpi-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    letter-spacing: -0.02em;
}

/* 詳細行リスト */
.anlys-rows {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.anlys-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 11px;
}
.anlys-row:last-child { border-bottom: none; }
.anlys-rl {
    color: var(--text-dim);
    font-size: 10px;
}
.anlys-rv {
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    color: var(--text);
}

/* ロング / ショート */
.anlys-ls-wrap {
    display: flex;
    align-items: stretch;
}
.anlys-ls-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 0;
}
.anlys-ls-div {
    width: 1px;
    background: var(--border);
    margin: 4px 0;
}
.anlys-ls-dir {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
}
.anlys-ls-cnt {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    font-family: 'Outfit', sans-serif;
}
.anlys-ls-wr {
    font-size: 12px;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
}
.anlys-ls-sub {
    font-size: 9px;
    color: var(--text-dim);
}

/* PnL 分布 */
.anlys-dist-wrap {
    display: flex;
    align-items: center;
    gap: 1px;
    height: 28px;
}
.anlys-dist-bar {
    height: 100%;
    min-width: 2px;
    border-radius: 1px;
    cursor: default;
    transition: opacity 0.1s;
}
.anlys-dist-bar:hover { opacity: 1 !important; }

/* ライトモード対応 */
[data-theme="light"] .anlys-section {
    background: rgba(0,0,0,0.02);
}
[data-theme="light"] .anlys-kpi {
    background: var(--drawer-bg);
}