:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-panel: #f1f5f9;
    --accent-primary: #0f172a;
    /* Deep Slate / Black */
    --accent-hover: #000000;
    /* Pure Black */
    --accent-secondary: #334155;
    --accent-gradient: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    --accent-glow: 0 4px 15px rgba(15, 23, 42, 0.15);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --up-color: #e11d48;
    --down-color: #2563eb;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Pretendard', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 10px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Premium Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.container {
    max-width: 1700px;
    /* 3단 레이아웃을 위해 너비 확장 */
    margin: 0 auto;
}

.grid-container {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 1.3fr;
    gap: 1.25rem;
    margin-top: 1rem;
    align-items: start;
}

@media (max-width: 900px) {
    .grid-container {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.panel-controls {
    display: flex;
    gap: 0.5rem;
}

/* Header */
header {
    margin-bottom: 0.5rem;
}

.header-single-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.status-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 4px;
    margin-bottom: 8px;
    position: relative;
}

.status-separator {
    color: var(--text-muted);
    opacity: 0.5;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.header-icon {
    font-size: 1.2rem;
    padding: 6px;
    opacity: 0.6;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-secondary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-icon:hover {
    opacity: 1;
    color: var(--accent-primary);
    background: #f1f5f9;
    transform: translateY(-1px);
}

/* Refresh Control */
.interval-select {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.interval-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.toggle-switch {
    width: 40px;
    height: 20px;
}

.slider:before {
    height: 14px;
    width: 14px;
}

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


/* Table */
.table-wrapper {
    border-radius: 8px;
}

/* Table Alignment */
.align-right {
    text-align: right;
}

.align-center {
    text-align: center;
}

.table-wrapper table thead th {
    padding: 0.6rem 0.5rem;
    font-size: 0.8rem;
    background: var(--bg-secondary);
    font-weight: 400;
    /* Header not bold */
}

.table-wrapper table tbody tr:nth-child(even) {
    background-color: #f8fafc;
    /* Subtle zebra striping */
}

.table-wrapper table tbody tr:hover {
    background-color: rgba(15, 23, 42, 0.03);
    /* Subtle hover effect */
}

/* Specific Column Widths for Rank Tables */
.table-wrapper table thead th:nth-child(1),
.table-wrapper table tbody td:nth-child(1) {
    width: 45px;
    /* 순위 */
}

.table-wrapper table thead th:nth-child(2),
.table-wrapper table tbody td:nth-child(2) {
    width: 45px;
    /* 시장 */
}

.table-wrapper table thead th:nth-child(3),
.table-wrapper table tbody td:nth-child(3) {
    width: 140px;
    /* 종목명 (Fixed to reduce gap) */
}

.table-wrapper table thead th:nth-child(4),
.table-wrapper table tbody td:nth-child(4) {
    width: 80px;
    /* 등락률 */
}

.table-wrapper table thead th:nth-child(5),
.table-wrapper table tbody td:nth-child(5) {
    width: 100px;
    /* 거래대금 */
}

/* eFriend Table Specific Widths */
#efriendStockTable thead th:nth-child(1),
#efriendStockTable tbody td:nth-child(1) {
    width: 60px;
    /* 순위 */
}

#efriendStockTable thead th:nth-child(2),
#efriendStockTable tbody td:nth-child(2) {
    width: 50px;
    /* 시장 (K/Q) */
}

#efriendStockTable thead th:nth-child(3),
#efriendStockTable tbody td:nth-child(3) {
    width: 150px;
    /* 종목명 */
}

#efriendStockTable thead th:nth-child(4),
#efriendStockTable tbody td:nth-child(4) {
    width: 80px;
    /* 등락률 */
}

#efriendStockTable thead th:nth-child(5),
#efriendStockTable tbody td:nth-child(5) {
    width: 90px;
    /* 매매가능수량 */
}

#efriendStockTable thead th:nth-child(6),
#efriendStockTable tbody td:nth-child(6) {
    width: 120px;
    /* 매매가능금액(원) */
}

/* Colspan fix for empty messages */
table tbody td[colspan] {
    width: 100% !important;
}

/* Table Body Scrolling */
/* Table Body Scrolling - Scoped */
.table-wrapper tbody {
    display: block;
    max-height: 560px;
    /* Approx 20 items * 29px */
    overflow-y: auto;
    width: 100%;
}

/* Table Body Scrolling - Scoped to specific tables to avoid breaking FullCalendar */
#transactionTable thead,
#stockTable thead,
#efriendStockTable thead,
#transactionTable tbody tr,
#stockTable tbody tr,
#efriendStockTable tbody tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.table-wrapper thead {
    width: calc(100% - 10px);
    /* 17px에서 10px로 조정 (표준 스크롤바 너비 대응) */
    position: sticky;
    top: 0;
    z-index: 10;
}

.table-wrapper tbody td {
    padding: 0.15rem 0.5rem;
    font-size: 0.85rem;
}

footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    font-size: 0.8rem;
}

.price-up {
    color: var(--up-color);
}

.price-down {
    color: var(--down-color);
}

.price-neutral {
    color: var(--text-muted);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.market-type {
    text-align: center;
    color: var(--text-muted);
}

.num-cell {
    font-size: 0.85rem;
    font-weight: 300 !important;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

/* ==========================================================
   Tabbed Interface Styles
   ========================================================== */

.tab-container {
    display: flex;
    background: var(--bg-secondary);
    padding: 0 10px;
    border-bottom: 2px solid var(--border-color);
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.tabs-wrapper {
    flex: 1;
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Styled scrollbar for Chrome/Safari/Edge */
.tabs-wrapper::-webkit-scrollbar {
    height: 4px;
}

.tabs-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.tabs-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.tabs-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.tab-btn {
    padding: 0 15px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.tab-btn:hover {
    color: var(--accent-primary);
    background: rgba(15, 23, 42, 0.04);
}

.tab-btn.active {
    color: var(--accent-primary);
    font-weight: 700;
    border-bottom-color: var(--accent-primary);
    background: transparent;
}

.add-tab-btn {
    padding: 0 15px;
    height: 32px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    border-radius: 6px;
    margin-left: 5px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.add-tab-btn:hover {
    background: #ffffff;
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.right-controls {
    margin-left: auto;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    padding-left: 10px;
    box-shadow: -10px 0 10px -5px rgba(0, 0, 0, 0.03);
}

.capture-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.capture-btn:hover {
    color: var(--accent-primary);
    background: #f1f5f9;
    transform: translateY(-1px);
}

.tab-contents {
    padding: 15px;
    min-height: calc(100vh - 45px);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-content.full-tab {
    padding: 0 !important;
}

.embedded-iframe {
    width: 100%;
    height: calc(100vh - 47px);
    border: none;
    display: block;
}

/* --- Context Menu --- */
.context-menu {
    position: absolute;
    background: #ffffff;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    z-index: 2000;
    border-radius: 8px;
    padding: 5px 0;
    min-width: 150px;
}

.context-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.context-menu li {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: background 0.2s;
}

.context-menu li:hover {
    background: var(--accent-primary);
}

#deleteTab {
    color: #ff6b6b;
    /* Red for delete */
    border-top: 1px solid var(--border-color);
    margin-top: 5px;
    padding-top: 12px;
}

#deleteTab:hover {
    background: #c92a2a;
    color: white;
}

/* ==========================================================
   Chart Grid & Box Styles
   ========================================================== */

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
}

.chart-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 480px;
}

.chart-header {
    padding: 8px 12px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.chart-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.chart-input {
    flex: 1;
    background: #0a0e27;
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 4px 8px;
    font-size: 0.8rem;
    border-radius: 4px;
    min-width: 60px;
}

.chart-go-btn {
    background: var(--accent-primary);
    border: none;
    color: #fff;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.chart-control-icon {
    width: 20px;
    height: 20px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.chart-control-icon:hover {
    opacity: 1;
}

.chart-title-input {
    background: transparent;
    border: none;
    color: var(--accent-primary);
    font-weight: bold;
    font-size: 0.85rem;
    width: 80px;
    cursor: default;
}

.chart-title-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.1);
}

iframe {
    width: 100%;
    flex: 1;
    border: none;
}

/* --- ADR Specific --- */
.adr-chart-container {
    display: flex;
    flex-direction: row;
    gap: 30px;
    padding: 20px;
    width: 100%;
}

.adr-chart-wrapper {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex: 1;
    /* Equal proportional width */
    min-width: 0;
    /* Prevent overflow in flex items */
}

.adr-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 12px 20px;
    background: var(--bg-panel);
    color: var(--text-primary);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid var(--border-color);
}

.adr-chart-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}


.adr-period-selector {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    padding: 0 10px;
}

.period-btn {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.period-btn:hover {
    background: #f8fafc;
    border-color: var(--text-muted);
}

.period-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.adr-canvas-new {
    display: block;
    width: 100% !important;
    height: auto !important;
    background: white;
    border-radius: 4px;
}

.adr-canvas {
    background: #fff;
    border-radius: 4px;
    margin: 10px;
    cursor: crosshair;
}

.adr-last {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-left: auto;
}

.tab-rename-input {
    background: #fff;
    color: #000;
    border: none;
    padding: 2px 5px;
    width: 100px;
    font-size: 0.85rem;
}

@media (max-width: 1200px) {
    .chart-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 800px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}



/* ==========================================================
   Finviz Chart Grid Styles (2-Column Layout)
   ========================================================== */

/* --- Finviz Grid (Overseas) --- */
.finviz-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px 40px;
    /* Space for protruding titles */
    max-width: 1400px;
    margin: 0 auto;
}

.finviz-col {
    display: contents;
    /* Let items be direct children of grid */
}

/* Divider Header (Sector Group) */
.finviz-divider {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    position: relative;
    margin: 25px 0 10px 0;
    /* Reduced margins to save space */
    height: 30px;
}

.divider-title {
    position: absolute;
    left: -30px;
    /* Protrude to the left */
    background: var(--bg-body);
    padding: 0 15px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.divider-line {
    flex: 1;
    height: 1px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
    margin: 0 10px;
    margin-left: 100px;
    /* Offset to start after the protruding title */
}

.divider-controls {
    position: relative;
    padding-left: 10px;
    background: var(--bg-body);
    /* Overlap the divider border */
}

.btn-section-edit {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-section-edit:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Quick Edit Popup */
.section-edit-popup {
    position: absolute;
    top: 100%;
    right: 0;
    /* Align to the right of the container, opens left */
    background: #1c1f3b;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    width: 250px;
    display: none;
    flex-direction: column;
    gap: 10px;
}

.section-edit-popup.active {
    display: flex;
}

.edit-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.edit-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.edit-group input[type="text"] {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 8px;
    border-radius: 4px;
}

.color-presets {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
}

.color-swatch {
    width: 25px;
    height: 25px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.color-swatch:hover {
    transform: scale(1.1);
}

/* Chart Title Coloring */
.finviz-chart-title.colorful {
    background: var(--section-color, var(--accent-color));
    color: white;
    /* Ensure text is readable on colored background */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.finviz-chart-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.finviz-chart-title {
    padding: 8px 12px;
    background: var(--bg-secondary);
    font-weight: bold;
    font-size: 0.85rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.finviz-chart-img {
    width: 100%;
    display: block;
    background: #ffffff;
}

/* Sizing for different chart types */
.finviz-img-wrapper {
    position: relative;
    /* Position reference for cursor line */
    width: 100%;
    aspect-ratio: 900 / 340;
    /* Container determines the height based on the 900:340 ratio */
    background: #ffffff;
    display: flex;
    justify-content: center;
    /* Default for stocks */
}

/* Stock charts: fill the container's width and height */
.finviz-chart-img.stock {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

/* Futures charts: 0.4x width, same height as stock chart, right aligned */
.finviz-img-wrapper.is-future {
    justify-content: flex-end;
    /* Right align hook for parent */
}

.finviz-chart-img.future {
    width: 38%;
    /* 👈 이 수치만 마음껏 조정하세요! (세로는 고정됩니다) */
    height: 100%;
    object-fit: fill;
    object-position: right;
    cursor: crosshair;
}

/* Vertical Cursor Line for Finviz Charts */
.finviz-cursor-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    border-left: 2px dotted rgba(0, 0, 255, 1);
    /* Use dark dotted line on white chart bg */
    pointer-events: none;
    visibility: hidden;
    z-index: 5;
}

/* Responsive adjustment: 2 columns if width > 1000px, otherwise 1 column */
/* ==========================================================
   Modal Styles
   ========================================================== */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 95%;
    max-width: 850px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
}

.btn-icon:hover {
    color: var(--accent-primary);
    background: rgba(15, 23, 42, 0.04);
}


.close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.modal-hint code {
    background: var(--bg-secondary);
    padding: 2px 4px;
    border-radius: 4px;
    color: var(--accent-color);
}

.highlight-editor-container {
    position: relative;
    width: 100%;
    height: 450px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.highlight-backdrop,
#customChartInput {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 12px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
}

#customChartInput {
    color: transparent;
    caret-color: var(--text-primary);
    outline: none;
    resize: none;
    z-index: 2;
}

.highlight-backdrop {
    color: var(--text-primary);
    pointer-events: none;
    z-index: 1;
    overflow: auto;
}

.syntax-comment {
    color: #40c057;
    /* Green for comments */
    font-style: italic;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Global Buttons already defined above */

.chart-search-input {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    min-width: 250px;
    transition: all 0.2s;
}

.chart-search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
    background: #ffffff;
}

.chart-go-btn {
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    background: var(--accent-primary);
    color: #ffffff;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.chart-go-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Override for custom tab header controls */
.header-controls .btn-config {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

.header-controls .btn-config:hover {
    background: var(--border-color);
}

/* Status bar config button style - Centered */
.status-info .btn-config.status-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 10px;
    height: 24px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    vertical-align: middle;
    line-height: normal;
    white-space: nowrap;
    z-index: 5;
}

.status-info .btn-config.status-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

@media (max-width: 1000px) {
    .finviz-container {
        flex-direction: column;
    }
}

/* ==========================================================
   TradingEconomics Chart Styles
   ========================================================== */
.te-container {
    padding-bottom: 40px;
}

.te-chart-box,
.multi-chart-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 380px;
    /* Uniform height for all TradingEconomics/FRED charts */
    overflow: hidden;
}

.te-chart-wrapper {
    position: relative;
    flex: 1;
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    margin-top: 5px;
}

.te-chart-canvas,
.multi-chart-canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.te-chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 39, 0.7);
    color: var(--text-muted);
    font-size: 0.8rem;
    z-index: 5;
}

/* Overseas & Earnings Tab Layout Fixes */
.overseas-container {
    height: calc(100vh - 47px);
    display: flex;
    flex-direction: column;
    max-width: 100% !important;
    padding: 0 !important;
}

.overseas-content-scroll {
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.overseas-content-scroll iframe {
    height: 100% !important;
    width: 100% !important;
}

/* ===== QUILL MEMO EDITOR STYLES ===== */
#quillEditor {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.ql-container {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
}

.ql-editor {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 20px;
    min-height: 500px;
}

.ql-editor.ql-blank::before {
    color: var(--text-muted);
}

.ql-toolbar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color) !important;
    border-bottom: 1px solid var(--border-color);
}

.ql-toolbar.ql-snow .ql-formats button,
.ql-toolbar.ql-snow .ql-formats button:hover,
.ql-toolbar.ql-snow .ql-formats button.ql-active,
.ql-toolbar.ql-snow .ql-formats select,
.ql-toolbar.ql-snow .ql-formats select:hover,
.ql-toolbar.ql-snow .ql-formats select.ql-active {
    color: var(--text-secondary);
}

.ql-toolbar.ql-snow .ql-picker-label {
    color: var(--text-secondary);
}

.ql-toolbar.ql-snow .ql-stroke {
    stroke: var(--text-secondary);
}

.ql-toolbar.ql-snow .ql-fill,
.ql-toolbar.ql-snow .ql-stroke.ql-fill {
    fill: var(--text-secondary);
}

.ql-toolbar.ql-snow button:hover,
.ql-toolbar.ql-snow button.ql-active,
.ql-toolbar.ql-snow select:hover,
.ql-toolbar.ql-snow select.ql-active {
    color: var(--accent-primary);
}

.ql-toolbar.ql-snow button:hover .ql-stroke,
.ql-toolbar.ql-snow button.ql-active .ql-stroke {
    stroke: var(--accent-primary);
}

.memo-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.memo-toolbar button {
    padding: 8px 16px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.memo-toolbar button:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.btn-primary {
    background: var(--accent-primary) !important;
    color: white !important;
    border: none !important;
    padding: 0.6rem 1.25rem !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.btn-primary:hover {
    background: var(--accent-hover) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: #ffffff !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-color) !important;
    padding: 0.6rem 1.25rem !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
}

.btn-secondary:hover {
    background: #f8fafc !important;
    border-color: var(--text-muted) !important;
    color: var(--text-primary) !important;
}

.btn-danger {
    background: #fff !important;
    color: var(--danger-color) !important;
    border: 1px solid #fee2e2 !important;
    padding: 0.6rem 1.25rem !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
}

.btn-danger:hover {
    background: #fef2f2 !important;
    border-color: var(--danger-color) !important;
    transform: translateY(-1px);
}

#memoStatus {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 15px;
}

/* --- Memo Grid Layout --- */
.memo-grid {
    display: grid;
    grid-template-columns: 7fr 3fr;
    gap: 15px;
    width: 100%;
    margin-top: 5px;
}

.calendar-section,
.memo-section {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.calendar-section iframe {
    flex: 1;
    border-radius: 4px;
    background: white;
    /* Optional: good for keeping calendar clean */
}

@media (max-width: 1000px) {
    .memo-grid {
        grid-template-columns: 1fr;
    }

    .calendar-section,
    .memo-section {
        height: auto;
    }
}

/* ==========================================================
   Login Overlay & Card
   ========================================================== */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #151933 0%, #0a0e27 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.login-card {
    background: var(--bg-card);
    padding: 3rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 450px;
    width: 90%;
    backdrop-filter: blur(10px);
    animation: fadeIn 0.6s ease-out;
}

.login-logo {
    font-size: 3rem;
    margin-bottom: 1.5rem;
}

.login-card h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #fff;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.g_id_signin {
    display: flex;
    justify-content: center;
}

#g_id_signin_button {
    display: flex;
    justify-content: center;
}

/* ==========================================================
   Memo Tab & Calendar Layout
   ========================================================== */
.memo-grid {
    display: grid;
    grid-template-columns: 7fr 3fr;
    gap: 20px;
    height: calc(100vh - 120px);
    /* Slightly taller */
    overflow: visible;
    /* Allow content to dictate height */
    padding: 15px;
}

@media (max-width: 1200px) {
    .memo-grid {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
}

#calendar {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 15px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    min-height: 650px !important;
}

.fc {
    min-height: 600px;
}

/* Ensure Week view and all FC tables fill width correctly */
.fc .fc-scrollgrid,
.fc .fc-scrollgrid-table,
.fc .fc-timegrid-body table,
.fc .fc-col-header {
    width: 100% !important;
    min-width: 100% !important;
}

/* Specific fix for Month View tables */
.fc-daygrid-body {
    width: 100% !important;
}

.fc-daygrid-body table {
    width: 100% !important;
    table-layout: fixed !important;
}

/* Time Axis Fix - Hard left alignment */
.fc .fc-timegrid-axis,
.fc .fc-timegrid-axis-frame,
.fc .fc-timegrid-axis-cushion,
.fc .fc-timegrid-slot-label,
.fc .fc-timegrid-slot-label-frame,
.fc .fc-timegrid-slot-label-cushion {
    width: 70px !important;
    min-width: 70px !important;
    max-width: 70px !important;
    left: 0 !important;
    position: sticky !important;
    z-index: 5 !important;
}

/* Ensure the grid columns fill the remaining width correctly */
.fc .fc-timegrid-cols table {
    width: 100% !important;
}

/* Fix for Modal Scrolling - Ensure the body scrolls while header/footer stay fixed */
.modal-content {
    max-height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.modal-body {
    overflow-y: auto !important;
    flex: 1 !important;
    padding: 20px !important;
    min-height: 200px;
}

/* Fix for Quill Editor Toolbar visibility */
.ql-toolbar.ql-snow {
    background: #fcfcfc !important;
    border-color: #ccc !important;
    border-radius: 4px 4px 0 0 !important;
}

.ql-snow .ql-stroke {
    stroke: #444 !important;
}

.ql-snow .ql-fill {
    fill: #444 !important;
}

.ql-snow .ql-picker {
    color: #444 !important;
}

.ql-container.ql-snow {
    border-color: var(--border-color) !important;
    border-radius: 0 0 4px 4px !important;
    background: #ffffff !important;
    color: var(--text-primary) !important;
}

.ql-snow .ql-picker.ql-font .ql-picker-label::before,
.ql-snow .ql-picker.ql-size .ql-picker-label::before {
    color: #333 !important;
}

.ql-snow .ql-picker-label {
    color: #333 !important;
    font-weight: 500 !important;
}

.ql-snow .ql-picker-options {
    background-color: #fff !important;
}

.ql-editor {
    color: #333333 !important;
    background: #ffffff !important;
}

/* Modal Open State - Prevent background scroll */
body.modal-open {
    overflow: hidden !important;
    padding-right: 0px;
    /* Prevent jitter if needed */
}

.fc {
    --fc-border-color: var(--border-color);
    --fc-daygrid-event-dot-width: 6px;
    --fc-page-bg-color: transparent;
}

.fc .fc-toolbar-title {
    font-size: 1.2rem !important;
    color: var(--text-primary);
}

/* FullCalendar Weekends & Holidays Styling */
.fc-day-sun .fc-col-header-cell-cushion,
.fc-day-sun .fc-daygrid-day-number {
    color: #ef4444 !important;
    /* Red for Sundays */
}

.fc-day-sat .fc-col-header-cell-cushion,
.fc-day-sat .fc-daygrid-day-number {
    color: #f97316 !important;
    /* Orange-red for Saturdays */
}

.fc-day-holiday .fc-daygrid-day-number {
    color: #ef4444 !important;
    /* Red for Holidays */
    font-weight: 700 !important;
}

.fc .fc-button-primary {
    background-color: #ffffff !important;
    border-color: var(--border-color) !important;
    color: var(--text-secondary) !important;
    text-transform: capitalize;
    box-shadow: var(--shadow-sm);
}

.fc .fc-button-primary:hover {
    background-color: #f1f5f9 !important;
    color: var(--accent-primary) !important;
}

.fc .fc-button-active {
    background-color: var(--accent-primary) !important;
    border-color: var(--accent-primary) !important;
    color: #fff !important;
}

.fc-theme-standard td,
.fc-theme-standard th {
    border: 1px solid var(--border-color) !important;
}

.fc .fc-day-today {
    background-color: rgba(15, 23, 42, 0.05) !important;
}

.fc-event {
    cursor: pointer;
    border: none !important;
    padding: 2px 4px;
    font-size: 0.8rem;
}

.fc-daygrid-day-number {
    color: var(--text-secondary);
    padding: 8px !important;
    text-decoration: none !important;
}

.fc-col-header-cell-cushion {
    color: var(--text-primary);
    padding: 10px 0 !important;
    text-decoration: none !important;
}

/* Modal Form Groups - Extended */
.modal-input {
    width: 100%;
    background: #ffffff !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 10px !important;
    border-radius: 6px !important;
    font-family: inherit !important;
    font-size: 0.9rem !important;
}

.modal-input:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#eventDescription {
    min-height: 150px !important;
    font-size: 1rem !important;
    line-height: 1.5 !important;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Per-tab capture button */
.capture-btn-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 5px;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 14px;
    height: 32px;
    line-height: 1;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    margin-right: 4px;
}

.capture-btn-small:hover {
    background: var(--bg-panel, #f1f5f9);
    color: var(--text-primary, #0f172a);
    border-color: var(--accent-secondary, #334155);
}

.capture-btn-small:active {
    background: var(--accent-primary, #0f172a);
    color: #ffffff;
}

/* ==========================================================
   Mobile Header Optimization
   ========================================================== */
@media (max-width: 600px) {
    .tab-container {
        padding: 0 5px;
    }

    .right-controls {
        gap: 4px;
        padding-left: 5px;
    }

    /* Hide non-essential buttons by default on mobile */
    #bulkUpload, 
    #bulkDownload, 
    #captureAllBtn {
        display: none !important;
    }

    /* Show them when 'show-all' class is toggled */
    .right-controls.show-all {
        position: absolute;
        top: 45px;
        right: 10px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 5px 10px;
        box-shadow: var(--shadow-lg);
        z-index: 1001;
        flex-direction: row;
        box-shadow: var(--shadow-lg);
    }

    .right-controls.show-all #bulkUpload, 
    .right-controls.show-all #bulkDownload, 
    .right-controls.show-all #captureAllBtn {
        display: flex !important;
    }

    #moreControlsBtn {
        display: flex !important;
    }

    /* Hide text labels on mobile to save space */
    #globalRefreshBtn span, 
    #logoutBtn span {
        display: none;
    }

    #globalRefreshBtn, 
    #logoutBtn {
        padding: 0 12px !important;
        min-width: 44px;
        justify-content: center;
        display: flex;
        align-items: center;
    }
    
    #logoutBtn {
        margin-left: 5px !important;
    }
}