/* ============================================================
   AI Trading RAG Memory Viewer - Responsive Stylesheet
   Mobile-First + Breakpoints: 480px / 768px / 1024px / 1920px
   ============================================================ */

/* ---------- 1. CSS Variables ---------- */
:root {
    --bg-deep: #05070d;
    --bg-base: #0a0e17;
    --bg-elevated: #101624;
    --panel-bg: rgba(18, 24, 40, 0.82);
    --panel-border: rgba(148, 163, 184, 0.14);
    --panel-hover: rgba(30, 41, 66, 0.9);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-cyan: #22d3ee;
    --accent-violet: #a78bfa;
    --accent-green: #4ade80;
    --accent-rose: #fb7185;
    --accent-amber: #fbbf24;
    --shadow-positive: #00ff88;
    --shadow-negative: #ff3366;
    --danger: #ef4444;
    --border-soft: rgba(148, 163, 184, 0.18);

    /* Spacing scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
    --glow-cyan: 0 0 20px rgba(34, 211, 238, 0.18);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;

    /* Layout */
    --header-width: 1480px;
    --grid-gap: var(--space-md);
}

/* ---------- 2. Reset & Base ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.55;
    min-height: 100vh;
    overflow-x: hidden;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, select {
    font-family: inherit;
    font-size: 1rem;
    color: inherit;
}

h1, h2, h3 {
    font-weight: 600;
    line-height: 1.3;
}

/* ---------- 3. Background Effects ---------- */
.background-effects {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.5;
}

.orb-1 {
    width: 420px;
    height: 420px;
    top: -140px;
    right: -100px;
    background: radial-gradient(circle, rgba(34, 211, 238, 0.35), transparent 70%);
}

.orb-2 {
    width: 480px;
    height: 480px;
    bottom: -180px;
    left: -120px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.3), transparent 70%);
}

/* ---------- 4. Layout Shell ---------- */
.app-container {
    max-width: var(--header-width);
    margin: 0 auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

main {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    box-shadow: var(--shadow-md);
}

/* ---------- 5. Header / Controls ---------- */
.main-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
}

.logo i {
    font-size: 1.6rem;
    color: var(--accent-cyan);
    filter: drop-shadow(0 0 8px rgba(34, 211, 238, 0.5));
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.logo h1 span {
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.controls-container {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.controls-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.model-selector {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid var(--border-soft);
    transition: border-color var(--transition-fast), background var(--transition-fast);
    flex: 1 1 100%;
    min-width: 0;
    min-height: 64px;
}

.model-selector:hover {
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.08);
}

.model-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.2), rgba(167, 139, 250, 0.2));
    color: var(--accent-cyan);
    font-size: 1.1rem;
}

.model-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    text-align: left;
}

.model-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}

.model-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.3;
}

.model-caret {
    margin-left: auto;
    color: var(--text-muted);
    flex: 0 0 auto;
}

.controls-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    flex: 1 1 auto;
    width: 100%;
}

.model-selector-compact {
    flex: 1 1 320px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
    font-size: 1.05rem;
    flex: 0 0 auto;
}

.btn-icon:hover {
    color: var(--text-primary);
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
}

.search-input-wrapper .btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    font-size: 1rem;
}

.search-input-wrapper .btn-icon:hover {
    color: var(--text-primary);
    background: rgba(148, 163, 184, 0.08);
}

.btn-icon-premium {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.3);
    transition: all var(--transition-fast);
    font-size: 1.05rem;
    flex: 0 0 auto;
}

.btn-icon-premium:hover {
    background: rgba(34, 211, 238, 0.18);
    box-shadow: var(--glow-cyan);
    transform: translateY(-1px);
}

.btn-icon-premium.danger {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-icon-premium.danger:hover {
    background: rgba(239, 68, 68, 0.18);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.2);
}

.divider {
    width: 1px;
    height: 24px;
    background: var(--border-soft);
}

.btn-premium-action {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: 38px;
    padding: 8px var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    color: #05070d;
    background: linear-gradient(90deg, var(--accent-cyan), #67e8f9);
    box-shadow: 0 2px 12px rgba(34, 211, 238, 0.35);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-premium-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(34, 211, 238, 0.5);
}




.controls-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.control-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-md);
}

.control-group.control-group--four {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-sm) var(--space-md);
}

.control-group.control-group--four .control-item {
    flex: none;
    min-width: 0;
    width: 100%;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    flex: 1 1 200px;
    min-width: 0;
}

.bottom-controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-soft);
    width: 100%;
}

.bottom-controls-row .controls-actions {
    margin-left: auto;
}

.toggles-group {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: var(--space-md);
    flex: 1;
    width: 100%;
}

.control-item.leverage-trigger {
    background: none;
    border: none;
    padding: 0;
    text-align: left;
    cursor: pointer;
}

.control-label {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    text-transform: uppercase;
    white-space: nowrap;
}

.control-label i {
    font-size: 0.85rem;
}

.premium-select,
.premium-value-box,
.premium-input-wrapper {
    width: 100%;
    height: 42px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-sm);
    background: rgba(5, 7, 13, 0.6);
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.premium-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    font-size: 0.9rem;
}

.premium-select:focus,
.premium-input:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

.premium-value-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
}

.premium-value-box i {
    color: var(--text-muted);
}

.premium-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 0 10px;
}

.premium-input {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    font-size: 0.9rem;
    color: var(--text-primary);
    -moz-appearance: textfield;
}

.premium-input::-webkit-outer-spin-button,
.premium-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-suffix {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    flex: 0 0 auto;
}


.control-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    flex: 1 1 auto;
    min-width: 0;
}

.daily-loss-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.daily-loss-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.daily-loss-stepper {
    display: flex;
    align-items: center;
    gap: 3px;
}

.stepper-btn-sm {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-soft);
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.stepper-btn-sm:hover {
    background: var(--accent-cyan);
    color: #000;
    border-color: var(--accent-cyan);
}

.daily-loss-input {
    width: 38px;
    text-align: center;
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--text-primary);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    font-size: 11px;
    padding: 1px 2px;
    height: 20px;
}
.daily-loss-input::-webkit-inner-spin-button,
.daily-loss-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.control-toggle .control-label {
    height: 24px;
    min-width: 95px;
    display: flex;
    align-items: center;
}

/* Premium Toggle Switch */
.premium-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex: 0 0 auto;
}

.premium-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(148, 163, 184, 0.25);
    transition: background var(--transition-base);
    border-radius: 24px;
}

.slider:before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    transition: transform var(--transition-base);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.premium-switch input:checked + .slider {
    background: var(--accent-cyan);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
}

.premium-switch input:checked + .slider:before {
    transform: translateX(20px);
}

.premium-switch.rose input:checked + .slider {
    background: var(--accent-rose);
    box-shadow: 0 0 12px rgba(251, 113, 133, 0.4);
}

.premium-switch.cyan input:checked + .slider {
    background: var(--accent-cyan);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
}

.premium-switch.amber input:checked + .slider {
    background: var(--accent-amber);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

/* ---------- 6. Search ---------- */
.search-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}



.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    height: 46px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-md);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    flex: 1;
}

.search-input-wrapper:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12), var(--glow-cyan);
}

.search-icon {
    color: var(--text-muted);
    font-size: 1.1rem;
    flex: 0 0 auto;
}

.search-input-wrapper input {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.92rem;
}

.search-input-wrapper input::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    color: #05070d;
    background: linear-gradient(90deg, var(--accent-cyan), #67e8f9);
    box-shadow: 0 2px 12px rgba(34, 211, 238, 0.3);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(34, 211, 238, 0.45);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 9px var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
}

/* ---------- 7. AI Insight Panel ---------- */
.ai-insight-panel {
    padding: var(--space-md);
    border-left: 3px solid var(--accent-violet);
}

.panel-header h2 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1rem;
    color: var(--text-primary);
}

.panel-header h2 i {
    color: var(--accent-violet);
}

.markdown-content {
    margin-top: var(--space-sm);
    color: var(--text-secondary);
    font-size: 0.92rem;
    line-height: 1.65;
    overflow-wrap: break-word;
    word-break: break-word;
}

.markdown-content p { margin-bottom: 0.6em; }
.markdown-content strong { color: var(--text-primary); }
.markdown-content ul, .markdown-content ol { padding-left: 1.3em; margin-bottom: 0.6em; }
.markdown-content li { margin-bottom: 0.25em; }
.markdown-content code {
    background: rgba(148, 163, 184, 0.1);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.85em;
    color: var(--accent-cyan);
}
.markdown-content pre {
    background: rgba(5, 7, 13, 0.7);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    overflow-x: auto;
    margin-bottom: 0.8em;
}

/* ---------- 8. Stats Panel ---------- */
.stats-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-md);
    padding: var(--space-md);
    align-items: start;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-sm);
    min-width: 0;
    overflow: hidden;
}

.stat-card i {
    font-size: 1.4rem;
    color: var(--accent-cyan);
    flex: 0 0 auto;
}

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.stat-label {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-info h2 {
    font-size: clamp(0.85rem, 2.8vw, 1.25rem);
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Status text keeps single line, no split like "FILTER" / "OFF" */
#prefilterStatus,
#dailyLossStatus,
#btcPrice,
#upbitBtcPrice,
#bitgetBtcPrice,
#kimchiPremium,
#totalCount {
    white-space: nowrap;
}

.status-active {
    color: var(--accent-green);
    font-size: clamp(0.85rem, 2.8vw, 1.05rem);
}

/* AUTO-TRADE TARGET spans full row */
.stat-card.stat-card--full {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid rgba(34, 211, 238, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    margin-top: 4px;
}

.stat-card.stat-card--full .stat-info {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: auto;
    flex: 0 1 auto;
    flex-wrap: wrap;
}

.stat-card.stat-card--full .stat-label {
    margin-bottom: 0;
    color: var(--accent-cyan);
    font-weight: 700;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.stat-card.stat-card--full #activeTargetDisplay,
.stat-card.stat-card--full #activeTargetEmpty {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

#shadowBoard {
    padding: var(--space-md);
    border-left: 3px solid var(--accent-cyan);
}

#shadowBoard:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

#shadowBoard .board-header h2 {
    flex-wrap: wrap;
}

.shadow-board-capital {
    color: var(--accent-cyan);
    white-space: nowrap;
}

.shadow-stats {
    padding: 0;
}

.shadow-stat-detail {
    color: var(--text-muted);
    font-family: 'SF Mono', ui-monospace, monospace;
}

.shadow-tabs {
    display: flex;
    gap: var(--space-xs);
    width: fit-content;
    max-width: 100%;
    padding: var(--space-xs);
    overflow-x: auto;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    background: var(--bg-base);
    -webkit-overflow-scrolling: touch;
}

.shadow-tab {
    flex: 0 0 auto;
    min-height: 38px;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
    transition: color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.shadow-tab:hover {
    color: var(--text-primary);
    background: rgba(148, 163, 184, 0.08);
}

.shadow-tab.active {
    color: var(--bg-deep);
    background: linear-gradient(90deg, var(--accent-cyan), #67e8f9);
    box-shadow: var(--glow-cyan);
}

.shadow-table-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-width: 0;
}

.shadow-table-section[hidden] {
    display: none;
}

.shadow-table-section h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-primary);
}

.shadow-table-section h3 i {
    color: var(--accent-cyan);
}

.shadow-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    background: var(--bg-base);
    -webkit-overflow-scrolling: touch;
}

.shadow-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    white-space: nowrap;
}

.shadow-table th,
.shadow-table td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
}

.shadow-table th {
    color: var(--text-muted);
    background: var(--bg-elevated);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.shadow-table td {
    color: var(--text-secondary);
    font-family: 'SF Mono', ui-monospace, monospace;
}

.shadow-table tbody tr:last-child td {
    border-bottom: none;
}

.shadow-table tbody tr:hover td {
    background: var(--panel-hover);
}

#shadowBoard .positive {
    color: var(--shadow-positive);
}

#shadowBoard .negative {
    color: var(--shadow-negative);
}

.shadow-side {
    font-weight: 700;
}

.shadow-table .shadow-table-empty {
    padding: var(--space-lg);
    color: var(--text-muted);
    text-align: center;
}

/* ---------- 9. Memory Board & Chips ---------- */
.memory-board {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.board-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.board-header h2 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1.05rem;
}

.board-header h2 i {
    color: var(--accent-cyan);
}

.filter-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--space-sm);
    overflow-x: auto;
    padding-bottom: var(--space-xs);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.execution-query-toggle {
    flex-shrink: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9rem;
    cursor: pointer;
}

.execution-query-toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-cyan);
}



.filter-chips::-webkit-scrollbar {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
    white-space: nowrap;
    flex: 0 0 auto;
}

.chip:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.chip.active {
    color: #05070d;
    background: linear-gradient(90deg, var(--accent-cyan), #67e8f9);
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(34, 211, 238, 0.3);
}

.chip-long { border-color: rgba(74, 222, 128, 0.35); color: var(--accent-green); }
.chip-long.active { background: linear-gradient(90deg, var(--accent-green), #86efac); color: #052e16; }
.chip-short { border-color: rgba(239, 68, 68, 0.35); color: var(--danger); }
.chip-short.active { background: linear-gradient(90deg, var(--danger), #fca5a5); color: #450a0a; }
.chip-hold { border-color: rgba(234, 179, 8, 0.35); color: #eab308; }
.chip-hold.active { background: linear-gradient(90deg, #eab308, #fde047); color: #422006; }
.chip-outcome { border-color: rgba(167, 139, 250, 0.35); color: var(--accent-violet); }
.chip-outcome.active { background: linear-gradient(90deg, var(--accent-violet), #c4b5fd); color: #2e1065; }
.chip-correct { border-color: rgba(74, 222, 128, 0.35); color: var(--accent-green); }
.chip-correct.active { background: linear-gradient(90deg, var(--accent-green), #86efac); color: #052e16; }
.chip-incorrect { border-color: rgba(251, 113, 133, 0.35); color: var(--accent-rose); }
.chip-incorrect.active { background: linear-gradient(90deg, var(--accent-rose), #fda4af); color: #4c0519; }
.chip-close { border-color: rgba(148, 163, 184, 0.35); color: var(--text-secondary); }
.chip-close.active { background: linear-gradient(90deg, var(--text-secondary), #cbd5e1); color: #0f172a; }

/* ---------- Macro Calendar ---------- */
#macroCalendarBoard {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}
.calendar-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-sm);
}
.calendar-item {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.05);
    border: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    transition: transform var(--transition-fast), background var(--transition-fast);
}
.calendar-item:hover {
    background: rgba(148, 163, 184, 0.1);
    transform: translateY(-2px);
}
.calendar-item.is-today {
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.05);
}
.calendar-item.is-today::before {
    content: 'TODAY';
    position: absolute;
    top: -8px;
    right: 12px;
    background: var(--accent-cyan);
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}
.calendar-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.calendar-item-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.3;
    padding-right: 8px;
}
.calendar-impact {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-secondary);
}
.impact-high { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.impact-medium { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); border: 1px solid rgba(245, 158, 11, 0.3); }
.impact-low { background: rgba(74, 222, 128, 0.15); color: var(--accent-green); border: 1px solid rgba(74, 222, 128, 0.3); }
.calendar-date-time {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'SF Mono', ui-monospace, monospace;
    display: flex;
    gap: var(--space-sm);
    margin-top: auto;
    padding-top: var(--space-sm);
}

/* ---------- 10. Memory Grid ---------- */
.memory-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--grid-gap);
    min-height: 120px;
}

.memory-card {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.memory-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--text-muted);
    opacity: 0.4;
    transition: opacity var(--transition-fast);
}

.memory-card:hover {
    transform: translateY(-2px);
    background: var(--panel-hover);
    box-shadow: var(--shadow-lg);
}

.card-LONG::before { background: var(--accent-green); }
.card-SHORT::before { background: var(--danger); }
.card-HOLD::before { background: #eab308; }
.card-OUTCOME::before { background: var(--accent-violet); }
.card-CORRECT::before { background: var(--accent-green); }
.card-INCORRECT::before { background: var(--accent-rose); }
.card-CLOSE::before { background: var(--text-secondary); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
    text-transform: uppercase;
    flex: 0 0 auto;
}

.badge-LONG { background: rgba(74, 222, 128, 0.15); color: var(--accent-green); }
.badge-SHORT { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-HOLD { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.badge-OUTCOME { background: rgba(167, 139, 250, 0.15); color: var(--accent-violet); }
.badge-CORRECT { background: rgba(74, 222, 128, 0.15); color: var(--accent-green); }
.badge-INCORRECT { background: rgba(251, 113, 133, 0.15); color: var(--accent-rose); }
.badge-CLOSE { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }

.card-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: 'SF Mono', ui-monospace, monospace;
}

.card-price {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.card-price strong {
    color: var(--text-primary);
    font-weight: 600;
}

.card-distance {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.08);
    border: 1px solid rgba(34, 211, 238, 0.25);
    border-radius: 999px;
    padding: 3px 12px;
    align-self: flex-start;
}

.card-preview {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.55;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ---------- 11. Loading / Empty / Load More ---------- */
.loading-state,
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--text-muted);
}

.loading-state p,
.empty-state p {
    margin-top: var(--space-md);
    font-size: 0.9rem;
}

.empty-state i {
    font-size: 2.5rem;
    color: var(--text-muted);
    opacity: 0.6;
}

.empty-state h3 {
    margin-top: var(--space-sm);
    font-size: 1rem;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid rgba(148, 163, 184, 0.2);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.load-more-container {
    text-align: center;
    padding: var(--space-sm) 0 var(--space-xs);
}

/* ---------- 12. Modal ---------- */
.modal-overlay,
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 4, 10, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
    padding: var(--space-md);
}

.modal-overlay.active,
.lightbox-overlay.active {
    opacity: 1;
    pointer-events: all;
    visibility: visible;
}

.modal-content {
    width: 100%;
    max-width: 820px;
    max-height: 88vh;
    overflow-y: auto;
    padding: var(--space-lg);
    position: relative;
    transform: translateY(14px) scale(0.98);
    transition: transform var(--transition-base);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-sm {
    max-width: 480px;
}

#detailModal .modal-content {
    max-width: 1200px;
    width: 92vw;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: var(--space-md);
}

.modal-header h2 {
    font-size: 1.05rem;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.btn-danger {
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: var(--danger);
    color: var(--danger);
}

.modal-body {
    width: 100%;
    color: var(--text-secondary);
    font-size: 0.92rem;
    line-height: 1.65;
    overflow-wrap: break-word;
    word-break: break-word;
}

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.analysis-content h3 {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin: var(--space-md) 0 var(--space-sm);
}

.analysis-content p { margin-bottom: 0.6em; }
.analysis-content ul, .analysis-content ol { padding-left: 1.3em; margin-bottom: 0.6em; }
.analysis-content li { margin-bottom: 0.25em; }

.modal-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

/* Dynamic Model Slot System */
.model-slot-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}
.model-rank {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: 0;
    animation: slotIn 0.18s ease;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    border-radius: var(--radius-sm);
    padding: 2px 0;
}
.model-rank.dragging {
    opacity: 0.4;
    transform: scale(0.98);
}
.model-rank.drag-over-top {
    border-top: 2px solid var(--accent-cyan);
    padding-top: 4px;
    margin-top: -2px;
}
.model-rank.drag-over-bottom {
    border-bottom: 2px solid var(--accent-cyan);
    padding-bottom: 4px;
    margin-bottom: -2px;
}
.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.2rem;
    width: 24px;
    height: 36px;
    transition: color var(--transition-fast);
}
.drag-handle:hover {
    color: var(--text-primary);
}
.drag-handle:active {
    cursor: grabbing;
}
@keyframes slotIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.btn-slot-delete {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: rgba(148,163,184,0.06);
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
    font-size: 0.95rem;
}
.btn-slot-delete:hover {
    color: var(--danger);
    border-color: rgba(239,68,68,0.35);
    background: rgba(239,68,68,0.10);
}
.btn-slot-delete:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.btn-slot-delete:disabled:hover {
    color: var(--text-muted);
    border-color: var(--border-soft);
    background: rgba(148,163,184,0.06);
}
.btn-slot-add {
    width: 100%;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(34,211,238,0.35);
    color: var(--accent-cyan);
    background: rgba(34,211,238,0.06);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition-fast);
}
.btn-slot-add:hover {
    background: rgba(34,211,238,0.12);
    border-color: var(--accent-cyan);
    box-shadow: var(--glow-cyan);
}
.btn-slot-add:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.slot-count-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: -6px;
    margin-bottom: 8px;
}

.rank-label {
    flex: 0 0 92px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.rank-1 { color: var(--accent-amber); }
.rank-2 { color: var(--text-secondary); }
.rank-3 { color: var(--text-muted); }

.model-rank select {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-sm);
    background: rgba(5, 7, 13, 0.6);
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    font-size: 0.88rem;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color var(--transition-fast);
}

.model-rank select:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

/* Leverage Control */
.leverage-control {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.leverage-control label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.leverage-input-group {
    display: flex;
    align-items: center;
    height: 46px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-sm);
    background: rgba(5, 7, 13, 0.6);
    border: 1px solid var(--border-soft);
}

.leverage-input-group input {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    -moz-appearance: textfield;
}

.leverage-control input[type="range"] {
    width: 100%;
    accent-color: var(--accent-cyan);
    cursor: pointer;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* ---------- 13. Lightbox ---------- */
.lightbox-overlay {
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
}

.lightbox-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    z-index: 2;
    background: rgba(5, 7, 13, 0.7);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: rgba(5, 7, 13, 0.7);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
}

.lightbox-nav:hover {
    color: var(--text-primary);
    border-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
}

.lightbox-nav.prev {
    left: var(--space-lg);
}

.lightbox-nav.next {
    right: var(--space-lg);
}

.lightbox-overlay img {
    max-width: 100%;
    max-height: 86vh;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    object-fit: contain;
}

/* ---------- 14. Markdown Table / Image Gallery (in modal) ---------- */
.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-sm) 0 var(--space-md);
    font-size: 0.8rem;
    overflow: hidden;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.preview-table table {
    width: 100%;
    border-collapse: collapse;
}

.preview-table th,
.preview-table td {
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    text-align: left;
    color: var(--text-secondary);
}

.preview-table th {
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-table tr:hover td {
    background: rgba(34, 211, 238, 0.04);
}

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-sm);
    margin: var(--space-md) 0;
}

.gallery-item {
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-soft);
    background: rgba(5, 7, 13, 0.5);
    cursor: pointer;
    transition: all var(--transition-fast);
    aspect-ratio: 4 / 3;
}

.gallery-item:hover {
    border-color: var(--accent-cyan);
    box-shadow: var(--glow-cyan);
    transform: translateY(-1px);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS (Mobile-First)
   ============================================================ */

/* ---------- Base (mobile): already defined above ---------- */

/* ---------- ≥ 480px: compact phones landscape / large phones ---------- */
@media (min-width: 480px) {
    .app-container {
        padding: var(--space-md) var(--space-lg);
    }

    .search-container {
        flex-direction: row;
        align-items: center; /* Changed from stretch to center for better button alignment */
    }



    .search-input-wrapper {
        height: auto;
    }

    .btn-primary {
        flex: 0 0 auto;
    }

    .memory-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .controls-header {
        flex-wrap: nowrap;
        align-items: stretch;
    }

    .toggles-group {
        grid-template-columns: repeat(2, 1fr);
    }

    .control-group.control-group--four {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------- ≥ 768px: tablets ---------- */
@media (min-width: 768px) {
    .toggles-group {
        grid-template-columns: repeat(3, 1fr);
    }

    .control-group.control-group--four {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .app-container {
        padding: var(--space-lg) var(--space-xl);
        gap: var(--space-lg);
    }

    main {
        gap: var(--space-lg);
    }

    .main-header {
        gap: var(--space-lg);
    }

    .logo h1 {
        font-size: 1.3rem;
    }

    .stats-panel {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: var(--space-md) var(--space-lg);
        padding: var(--space-lg);
    }

    #shadowBoard {
        padding: var(--space-lg);
    }

    .shadow-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 0;
    }

    .stat-card i {
        font-size: 1.5rem;
    }

    .memory-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .board-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-md);
    }

    .filter-chips {
        flex-wrap: wrap;
        overflow-x: visible;
        justify-content: flex-end;
        max-width: 60%;
    }

    .ai-insight-panel {
        padding: var(--space-lg);
    }

    .modal-content {
        padding: var(--space-xl);
    }
}

/* ---------- ≥ 1024px: desktop ---------- */
@media (min-width: 1024px) {
    .toggles-group {
        grid-template-columns: repeat(4, 1fr);
    }

    .control-group.control-group--four {
        grid-template-columns: repeat(4, 1fr);
    }

    .memory-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .stats-panel {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        padding: var(--space-md) var(--space-lg);
    }

    .shadow-stats {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        padding: 0;
    }

    .stat-card {
        padding: var(--space-sm) var(--space-md);
    }

    .controls-container {
        padding: var(--space-lg);
    }

    .image-gallery {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

/* ---------- ≥ 1920px: large desktop ---------- */
@media (min-width: 1920px) {
    :root {
        --header-width: 1760px;
        --grid-gap: var(--space-lg);
    }

    .app-container {
        padding: var(--space-xl);
        gap: var(--space-lg);
    }

    .memory-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .logo h1 {
        font-size: 1.5rem;
    }
}

/* ---------- 15. Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 16. Scrollbar Styling ---------- */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.25);
    border-radius: 8px;
    border: 2px solid var(--bg-base);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.45);
}

/* ---------- 17. Focus Accessibility ---------- */
:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

/* Leverage Stepper Buttons */
.btn-stepper {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-base), color var(--transition-base);
}
.btn-stepper:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}
.btn-stepper:active {
    background: rgba(255, 255, 255, 0.15);
}
.leverage-input-group {
    padding: 0 var(--space-xs); /* Reduced padding to fit buttons */
}
.leverage-input-group input {
    text-align: center;
}
.leverage-input-group .input-suffix {
    margin-right: 8px;
}

/* ── Execution Policy ── */
.premium-value-box-policy {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    width: 100%;
    height: auto;
    min-height: 42px;
    padding: 4px var(--space-md);
}
.policy-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}
.policy-status-valid {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.3);
}
.policy-status-missing {
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.3);
}
.policy-status-expired {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}
.policy-status-error {
    background: rgba(255, 51, 102, 0.15);
    color: #ff3366;
    border: 1px solid rgba(255, 51, 102, 0.3);
}
.policy-status-unknown {
    background: rgba(100, 116, 139, 0.15);
    color: #64748b;
    border: 1px solid rgba(100, 116, 139, 0.3);
}
.policy-status-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
}
.policy-status-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.policy-save-status {
    margin-top: 1rem;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}
.policy-save-saved {
    background: rgba(74, 222, 128, 0.12);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.25);
}
.policy-save-conflict {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.25);
}
.policy-save-error {
    background: rgba(255, 51, 102, 0.12);
    color: #ff3366;
    border: 1px solid rgba(255, 51, 102, 0.25);
}

.segmented-control {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-sm);
    padding: 2px;
    border: 1px solid var(--border-soft);
    height: 42px;
    position: relative;
    width: 100%;
}
.segmented-control input[type="radio"] {
    display: none;
}
.segmented-control label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: calc(var(--radius-sm) - 2px);
    transition: all 0.2s ease;
    white-space: nowrap;
}
.segmented-control label:hover {
    color: var(--text-primary);
}
.segmented-control input[type="radio"]:checked + label {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.segmented-control input[type="radio"]#modeDisabled:checked + label {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-rose);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.segmented-control input[type="radio"]#modeShadow:checked + label {
    background: rgba(34, 211, 238, 0.15);
    color: var(--accent-cyan);
    border: 1px solid rgba(34, 211, 238, 0.3);
}
.segmented-control input[type="radio"]#modeLive:checked + label {
    background: rgba(74, 222, 128, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

/* ---------- Policy Details Row (Left / Right Layout) ---------- */
.policy-details-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin-top: var(--space-sm);
    padding: var(--space-xs) 0;
}

.policy-details-left {
    display: flex;
    gap: var(--space-md);
    font-size: 0.75rem;
    color: var(--text-muted);
    align-items: center;
    flex-wrap: wrap;
}

.policy-details-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-left: auto;
}

/* Primary-only controls and adjacent search actions. */
.controls-header.model-chain-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: var(--space-sm);
}
.model-chain-row .model-selector {
    width: 100%;
    height: 100%;
}
.search-container {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}
.search-container .search-input-wrapper {
    flex: 1 1 320px;
    min-width: 0;
}
.search-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.search-actions > button {
    flex-shrink: 0;
}
@media (max-width: 640px) {
    .controls-header.model-chain-row {
        grid-template-columns: minmax(0, 1fr);
    }
    .search-container .search-input-wrapper {
        flex-basis: 100%;
    }
    .search-actions {
        width: 100%;
    }
    .search-actions #forceAnalyzeBtn {
        flex: 1 1 auto;
        justify-content: center;
    }
}

/* Keep the query checkbox beside the existing action chips. */
.memory-query-filters {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.memory-board .filter-chips {
    max-width: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    align-items: center;
}

.memory-board .board-header {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
}
.memory-board .board-header h2,
.memory-query-filters,
.memory-board .filter-chips {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Keep the model summary visible while supplementary card content is folded. */
.card-expanded-content[hidden] {
    display: none;
}

.card-expand-toggle {
    padding: 6px 12px;
    color: var(--text-primary);
    background: rgba(96, 165, 250, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.4);
    border-radius: 6px;
    cursor: pointer;
}

.card-expand-toggle:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 3px;
}

.card-expanded-content {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Text-heavy analysis columns retain space; narrow cards scroll within the table. */
.analysis-table-scroll {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    margin: var(--space-sm) 0 var(--space-md);
    -webkit-overflow-scrolling: touch;
}

.analysis-table-scroll:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.analysis-table-scroll .analysis-readable-table {
    display: table;
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin: 0;
    overflow: visible;
    white-space: normal;
}

.analysis-readable-table th,
.analysis-readable-table td {
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: top;
    line-height: 1.55;
    white-space: normal;
    word-break: keep-all !important;
    overflow-wrap: break-word !important;
}

.analysis-readable-table th {
    color: var(--text-primary);
    background: rgba(148, 163, 184, 0.08);
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
}
