:root {
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent-primary: #28a745;
    --accent-secondary: #20c997;
    --border-color: #e1e5e9;
    --shadow: rgba(0, 0, 0, 0.1);
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #343434;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-muted: #cccccc;
    --accent-primary: #28a745;
    --accent-secondary: #20c997;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Apply dark theme by default */
html {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #343434;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-muted: #cccccc;
    --accent-primary: #28a745;
    --accent-secondary: #20c997;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
}

.sidebar {
    width: 250px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 1000;
    border-right: 2px solid var(--border-color);
}

.sidebar-header {
    padding: 30px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    position: relative;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    color: var(--text-primary);
}

.sidebar-header h2 i {
    color: var(--text-primary);
}

/* Make OzPvP text green - use a specific class since :contains() isn't widely supported */
.sidebar-header h2 {
    color: var(--text-primary);
}

.theme-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    width: 50px;
    height: 50px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 8px var(--shadow);
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--shadow);
}

/* Dark mode theme toggle styling */
[data-theme="dark"] .theme-toggle {
    color: #ffffff;
}

/* Light mode theme toggle styling */
[data-theme="light"] .theme-toggle,
:root .theme-toggle {
    color: #333333;
}

.stock-row.clickable {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.stock-row.clickable:hover {
    background-color: var(--bg-tertiary);
}

.stock-chart-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 10px 30px var(--shadow);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--text-primary);
    margin: 0;
    font-size: 1.4rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.close-modal:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    min-height: 500px;
    height: auto;
}

.sidebar-nav {
    padding: 20px 0;
}

.nav-btn {
    width: 100%;
    padding: 15px 25px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    text-align: left;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-right: 3px solid var(--accent-primary);
}

.nav-btn i {
    font-size: 1.1rem;
    width: 20px;
}

.main-content {
    margin-left: 250px;
    flex: 1;
    padding: 20px;
    max-width: calc(100vw - 250px);
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 20px var(--shadow);
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    color: var(--accent-primary);
}

header p {
    font-size: 1.1rem;
    opacity: 0.7;
    color: var(--text-secondary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.controls, .stocks-controls {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.stocks-overview {
    margin-bottom: 30px;
}

.stock-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
    transition: transform 0.3s;
}

.summary-card:hover {
    transform: translateY(-5px);
}

.summary-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.big-number {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-primary);
}

.big-number.crashed {
    color: var(--danger);
}

.stock-view-toggle {
    display: flex;
    gap: 5px;
}

.stock-view {
    display: none;
}

.stock-view.active {
    display: block;
}

.stocks-content {
    background: var(--bg-secondary);
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    padding: 30px;
    margin-bottom: 30px;
}

.search-container {
    position: relative;
    flex: 2;
    min-width: 350px;
}

.search-container i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

#searchInput, #stockSearchInput {
    width: 100%;
    padding: 12px 12px 12px 45px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] #searchInput,
[data-theme="dark"] #stockSearchInput {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

#searchInput::placeholder, #stockSearchInput::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

#searchInput:focus, #stockSearchInput:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.filter-container {
    display: flex;
    gap: 10px;
}

.filter-container select {
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    font-size: 14px;
    cursor: pointer;
}

[data-theme="dark"] .filter-container select {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .filter-container select option {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.data-type-toggle {
    display: flex;
    gap: 5px;
    margin-right: 15px;
}

.data-type-toggle button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.data-type-toggle button.active {
    background: var(--success);
    color: white;
}

.view-toggle {
    display: flex;
    gap: 5px;
}

.view-toggle button, .stock-view-toggle button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.view-toggle button.active, .stock-view-toggle button.active {
    background: var(--accent-primary);
    color: white;
}

.content {
    position: relative;
}

.view {
    display: none;
    background: var(--bg-secondary);
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    padding: 30px;
}

.view.active {
    display: block;
}

.chart-container {
    height: 500px;
    margin-bottom: 20px;
}

.chart-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.chart-btn {
    padding: 10px 20px;
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--accent-primary);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.chart-btn.active {
    background: var(--accent-primary);
    color: white;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    table-layout: fixed;
}

th, td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary) !important;
}

th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary) !important;
    position: sticky;
    top: 0;
    z-index: 10;
}

[data-theme="dark"] th,
[data-theme="dark"] td {
    color: var(--text-primary) !important;
    background: transparent !important;
}

[data-theme="dark"] th {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

.rank-cell {
    font-weight: bold;
    color: var(--accent-primary);
}

.profit-cell {
    font-weight: bold;
    color: var(--success);
}

.efficiency-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 5px;
}

.efficiency-fill {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    transition: width 0.3s;
}

.item-details {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    background: var(--bg-secondary);
    box-shadow: -5px 0 20px rgba(0,0,0,0.3);
    transition: right 0.3s;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.item-details.active {
    right: 0;
}

.details-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
}

.details-header h3 {
    color: var(--accent-primary);
    font-size: 1.3rem;
}

#closeDetails {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
}

.details-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.automation-list {
    margin-top: 20px;
}

.automation-item {
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s;
}

.automation-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.automation-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 10px;
}

.automation-type {
    font-weight: 600;
    color: var(--text-primary);
}

.automation-profit {
    font-weight: bold;
    color: var(--success);
}

.automation-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-secondary);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.status i {
    color: var(--success);
    animation: spin 2s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.currency {
    color: var(--success);
    font-weight: 600;
}

.item-icon {
    width: 32px;
    height: 32px;
    display: inline-block;
    background: var(--bg-tertiary);
    border-radius: 4px;
    margin-right: 10px;
    vertical-align: middle;
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }
    
    .sidebar-nav {
        display: flex;
        padding: 10px;
        overflow-x: auto;
    }
    
    .nav-btn {
        min-width: 150px;
        justify-content: center;
    }
    
    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding: 10px;
    }
    
    .controls, .stocks-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-container {
        justify-content: center;
    }
    
    .item-details {
        width: 100%;
        right: -100%;
    }
    
    .chart-container {
        height: 300px;
    }
    
    table {
        font-size: 0.9rem;
    }
    
    th, td {
        padding: 10px 8px;
    }
    
    .stock-summary-cards {
        grid-template-columns: 1fr;
    }
}

/* Stock-specific styles */
.positive {
    color: #28a745 !important;
}

.negative {
    color: #dc3545 !important;
}

.status.active {
    color: var(--success);
    font-weight: bold;
}

.status.crashed {
    color: var(--danger);
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

#stocksTable tbody tr:hover {
    background: var(--bg-tertiary);
    transform: scale(1.01);
    transition: all 0.2s;
}

.stock-summary-cards .summary-card {
    border-left: 4px solid var(--accent-primary);
}

.summary-card.crashed-card {
    border-left-color: var(--danger);
}

.last-update-cell {
    text-align: center;
    font-size: 0.9rem;
}


/* Make ozpvp text green */
*:contains("ozpvp"), *:contains("OZPVP") {
    color: #28a745 !important;
}

.ozpvp-text {
    color: #28a745 !important;
}

/* Comprehensive Dark Mode Fixes */

/* Fix option elements in selects */
.filter-container select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Fix chart canvas text rendering */
[data-theme="dark"] canvas {
    filter: invert(0);
}

/* Force white text on dark charts */
[data-theme="dark"] .chart-container {
    color: var(--text-primary) !important;
}

/* Force chart text colors to be white in dark mode */
[data-theme="dark"] .chart-container * {
    color: white !important;
}

/* Fix any remaining hardcoded colors */
[data-theme="dark"] * {
    border-color: var(--border-color) !important;
}

/* Fix input fields specifically */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] select {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] input[type="text"]::placeholder {
    color: var(--text-muted) !important;
}

/* Fix any table text */
[data-theme="dark"] table,
[data-theme="dark"] th,
[data-theme="dark"] td {
    color: var(--text-primary) !important;
    background: var(--bg-secondary) !important;
}

[data-theme="dark"] th {
    background: var(--bg-tertiary) !important;
}

/* Fix button text */
[data-theme="dark"] button {
    color: var(--text-primary) !important;
}

[data-theme="dark"] button.active {
    color: white !important;
}

/* Items Tab Styling */
.items-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.items-search-container {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    max-width: 400px;
}

.items-search-container i {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    z-index: 1;
}

.items-search-container input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
}

.items-search-container input::placeholder {
    color: var(--text-muted);
}

.items-info {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.items-table-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

#itemsTable {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

#itemsTable th,
#itemsTable td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#itemsTable th {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

#itemsTable th:first-child {
    width: 60px;
    text-align: center;
}

#itemsTable th:nth-child(2) {
    width: 350px;
    text-align: left;
}

#itemsTable th:last-child {
    width: 90px;
    text-align: right;
}

#itemsTable td {
    color: var(--text-primary);
    font-size: 0.95rem;
}

#itemsTable td:first-child {
    text-align: center;
    color: var(--text-muted);
    font-weight: 500;
}

#itemsTable td:last-child {
    text-align: right;
    font-weight: 600;
    color: var(--accent-primary);
}

#itemsTable tbody tr {
    transition: all 0.2s ease;
}

#itemsTable tbody tr:hover {
    background: var(--bg-tertiary);
    transform: scale(1.005);
}

#itemsTable tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

#itemsTable tbody tr:nth-child(even):hover {
    background: var(--bg-tertiary);
}

.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.pagination-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-1px);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-tertiary);
}

#itemsPageInfo {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0 1rem;
}

/* Dark mode specific overrides for items */
[data-theme="dark"] .items-controls,
[data-theme="dark"] .items-table-container,
[data-theme="dark"] .pagination-container {
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] #itemsTable th {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] #itemsTable td {
    color: var(--text-primary) !important;
}

[data-theme="dark"] #itemsTable tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02) !important;
}

[data-theme="dark"] #itemsTable tbody tr:hover {
    background: var(--bg-tertiary) !important;
}