/* TradingView-inspired dark theme */
:root {
    --bg-primary: #131722;
    --bg-secondary: #1e222d;
    --bg-tertiary: #2a2e39;
    --bg-hover: #363a45;
    --text-primary: #d1d4dc;
    --text-secondary: #787b86;
    --text-muted: #5d606b;
    --accent-blue: #2962ff;
    --accent-blue-hover: #1e53e4;
    --accent-green: #26a69a;
    --accent-red: #ef5350;
    --accent-orange: #ff9800;
    --border-color: #363a45;
    --code-bg: #0d1117;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    color: var(--accent-blue);
    display: flex;
    align-items: center;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.badge {
    font-size: 11px;
    padding: 3px 8px;
    background: var(--accent-blue);
    color: white;
    border-radius: 4px;
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 4px;
    transition: all 0.15s;
}

.header-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.pip-badge {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
    color: var(--accent-green);
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 420px 1fr;
    height: calc(100vh - 52px);
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

/* Config Panel */
.config-panel {
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.panel-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    border-bottom: none;
}

/* Screener Grid */
.screener-section {
    padding: 12px 16px;
    background: var(--bg-secondary);
}

.screener-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.screener-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.screener-btn:hover {
    background: var(--bg-hover);
}

.screener-btn.active {
    border-color: var(--accent-blue);
    background: rgba(41, 98, 255, 0.1);
}

.screener-icon {
    font-size: 20px;
    line-height: 1;
}

.screener-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.screener-count {
    font-size: 10px;
    color: var(--text-muted);
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.section-header.collapsible {
    cursor: pointer;
    user-select: none;
}

.section-header .chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
}

.section-header.collapsed .chevron {
    transform: rotate(-90deg);
}

/* Buttons */
.btn-add {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-add:hover {
    background: var(--accent-blue-hover);
}

/* Filter Rows */
.filters-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.filter-field {
    flex: 1;
    min-width: 0;
}

.filter-operator {
    width: 70px;
}

.filter-value {
    width: 80px;
}

.filter-field,
.filter-operator,
.filter-value,
.filter-value2 {
    padding: 7px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.filter-field:focus,
.filter-operator:focus,
.filter-value:focus {
    border-color: var(--accent-blue);
}

.btn-remove {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-remove:hover {
    background: var(--accent-red);
    color: white;
}

.hint-text {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 16px;
}

#no-filters {
    display: block;
}

.filters-list:not(:empty) + #no-filters {
    display: none;
}

/* Field Counter */
.field-counter {
    font-size: 12px;
    color: var(--accent-blue);
    font-weight: 500;
}

/* Field Toolbar */
.field-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.btn-tool {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-tool svg {
    flex-shrink: 0;
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    min-width: 150px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
    display: none;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-primary);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: var(--bg-hover);
}

.dropdown-item:first-child {
    border-radius: 6px 6px 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 6px 6px;
}

/* Field Search */
.field-search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.search-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent-blue);
}

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

.category-select {
    width: 140px;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

/* Fields Grid */
.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 4px;
}

.field-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.field-item:hover {
    background: var(--bg-hover);
}

.field-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent-blue);
    cursor: pointer;
    flex-shrink: 0;
}

.field-item label {
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.field-item.hidden {
    display: none;
}

/* Options Section */
.options-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.options-section.collapsed .options-content {
    display: none;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.option-row label {
    font-size: 13px;
    color: var(--text-secondary);
}

.option-row select,
.option-row input {
    padding: 7px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.option-row select:focus,
.option-row input:focus {
    border-color: var(--accent-blue);
}

#index-select {
    width: 180px;
}

.sort-row {
    display: flex;
    gap: 6px;
}

.sort-row select:first-child {
    width: 120px;
}

.sort-order {
    width: 70px;
}

#limit-input {
    width: 80px;
    text-align: center;
}

#index-group.hidden {
    display: none;
}

/* Code Panel */
.code-panel {
    display: flex;
    flex-direction: column;
    background: var(--code-bg);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.code-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.code-title svg {
    color: var(--accent-blue);
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-copy:hover {
    background: var(--accent-blue-hover);
}

.btn-copy.copied {
    background: var(--accent-green);
}

.code-container {
    flex: 1;
    overflow: auto;
    padding: 16px 20px;
}

.code-container pre {
    margin: 0;
    font-family: 'SF Mono', Monaco, 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
}

.code-container code {
    background: transparent !important;
    padding: 0 !important;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

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

/* Field empty state */
.fields-empty {
    grid-column: 1 / -1;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
