:root {
    --bg-primary: #0a0e27;
    --bg-secondary: #1a1f3a;
    --bg-card: #1e2433;
    --text-primary: #e1e8ed;
    --text-secondary: #9ca3af;
    --success: #10b981;
    --warning: #ffb800;
    --danger: #ff4757;
    --border: #2d3561;
}

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

html, body {
    width: 100%;
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 8px;
    margin: 0;
    min-height: 100vh;
    line-height: 1.6;
}

@media (min-width: 768px) {
    body { padding: 20px; }
}

@media (max-width: 480px) {
    body { 
        padding: 5px;
        width: 100%;
        max-width: 100vw;
    }
    .erp-container {
        padding: 5px;
        gap: 8px;
        width: 100%;
    }
    .erp-card {
        padding: 10px;
        margin-bottom: 8px;
        width: 100%;
    }
}

.header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding: 0 7.5px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    position: relative;
    height: 45px;
    min-height: 45px;
    max-height: 45px;
}

.header .logo {
    height: 60px;
    display: none;
}

@media (min-width: 768px) {
    .header .logo {
        display: block;
        margin-left: 10px;
    }
}

.balance-display {
    font-size: 14px;
    font-weight: bold;
    order: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

.balance-display .profit {
    color: var(--success);
    font-size: 14px;
}

.balance-display .loss {
    color: var(--danger);
    font-size: 14px;
}

@media (min-width: 768px) {
    .balance-display {
        font-size: 24px;
        order: 1;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        flex: none;
    }
    .balance-display .profit,
    .balance-display .loss {
        font-size: 16px;
    }
}

.header-top {
    display: none;
}

@media (min-width: 768px) {
    .header-top {
        display: flex;
        justify-content: flex-end;
        margin-left: auto;
    }
}

.status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    line-height: 1;
}

@media (min-width: 768px) {
    .status {
        font-size: 16px;
        margin-right: 30px;
    }
}

.refresh-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pulse {
    width: 10px;
    height: 10px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.status-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
}

.status-content pre {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.9rem;
    line-height: 1.8;
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
}

.loading {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--success);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.error {
    background: var(--danger);
    color: white;
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

/* Burger Menu */
.burger-menu {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.burger-menu svg {
    width: 24px;
    height: 24px;
}

.burger-menu .line {
    transition: all 0.2s ease;
    transform-origin: center;
}

.burger-menu.active .line1 {
    transform: translateY(6px) rotate(45deg);
}

.burger-menu.active .line2 {
    opacity: 0;
}

.burger-menu.active .line3 {
    transform: translateY(-6px) rotate(-45deg);
}

/* Header */
header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    height: 45px;
    min-height: 45px;
    max-height: 45px;
    padding: 0 15px;
    margin-bottom: 20px;
    gap: 15px;
}

.header-stats {
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    flex-wrap: nowrap;
}

.header-stats #balance,
.header-stats #winrate,
.header-stats #balance-change {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
}

.trades-display {
    justify-self: end;
    font-size: 18px;
    font-weight: 600;
    color: rgba(255, 255, 255, 1);
    white-space: nowrap;
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.trades-separator {
    color: rgba(255, 255, 255, 0.5);
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, rgba(26, 31, 58, 0.98) 0%, rgba(10, 14, 39, 0.98) 100%);
    backdrop-filter: blur(10px);
    box-shadow: 2px 0 20px rgba(0,0,0,0.5);
    transition: left 0.2s ease;
    z-index: 1000;
    padding-top: 80px;
}

.side-menu.active {
    left: 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 30px;
    margin: 8px 15px;
    color: #9ca3af;
    text-decoration: none;
    transition: all 0.3s;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
}

.menu-item:hover {
    background: rgba(102, 126, 234, 0.15);
    color: #fff;
    transform: translateX(5px);
}

.menu-item.active {
    background: rgba(102, 126, 234, 0.25);
    color: #fff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Analytics Content */
.analytics-content {
    max-width: 1400px;
    margin: 0 auto;
}

.overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border: 2px solid var(--border);
}

.stat-card.active {
    border-color: var(--success);
}

.stat-card.offline {
    border-color: var(--danger);
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.service-card {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid var(--success);
}

.service-card.offline {
    border-left-color: var(--danger);
}

.service-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.service-name {
    font-size: 16px;
    font-weight: 600;
}

.service-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.service-status.active {
    background: var(--success);
    color: white;
}

.service-status.offline {
    background: var(--danger);
    color: white;
}

.service-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.activity-section, .watchdog-section {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.activity-section h2, .watchdog-section h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: var(--success);
}

.activity-log {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.activity-timestamp {
    color: var(--text-secondary);
    margin-right: 10px;
}

.activity-service {
    color: var(--success);
    font-weight: 600;
    margin-right: 10px;
}

.watchdog-status {
    padding: 15px;
    border-radius: 6px;
    font-size: 14px;
}

.watchdog-status.healthy {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.watchdog-status.unhealthy {
    background: rgba(255, 71, 87, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.issue-list {
    margin-top: 10px;
    padding-left: 20px;
}


/* ERP Control Center Styles */
.erp-container {
    display: grid;
    grid-template-columns: 30% 45% 25%;
    gap: 20px;
    padding: 20px;
    max-width: 1800px;
    margin: 0 auto;
    overflow-x: hidden;
}

/* Tablet (landscape) */
@media (max-width: 1200px) {
    .erp-container {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        padding: 15px;
    }
    .erp-right {
        grid-column: 1 / -1;
    }
}

/* Tablet (portrait) and Mobile */
@media (max-width: 768px) {
    .erp-container {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 10px;
        width: 100%;
        max-width: 100%;
    }
    .erp-card {
        padding: 15px;
        margin-bottom: 12px;
        width: 100%;
        max-width: 100%;
    }
    .erp-card h3 {
        font-size: 15px;
    }
}

/* Smartphone */
@media (max-width: 480px) {
    .erp-container {
        padding: 8px;
        gap: 10px;
    }
    .erp-card {
        padding: 12px;
        margin-bottom: 10px;
    }
}

.erp-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.erp-card h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

/* Responsive Header */
@media (max-width: 768px) {
    header {
        grid-template-columns: auto 1fr;
        padding: 0 10px;
        gap: 10px;
    }
    .header-stats {
        justify-self: start;
        gap: 8px;
        font-size: 14px;
    }
    .header-stats #balance,
    .header-stats #winrate,
    .header-stats #balance-change {
        font-size: 14px;
    }
    .trades-display {
        display: none;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0 8px;
        gap: 8px;
    }
    .header-stats {
        gap: 6px;
        font-size: 12px;
    }
    .header-stats #balance,
    .header-stats #winrate,
    .header-stats #balance-change {
        font-size: 12px;
    }
}

/* Service List */
.service-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.service-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--bg-card);
    border-radius: 8px;
    transition: all 0.3s;
    cursor: pointer;
}

@media (max-width: 480px) {
    .service-item {
        padding: 8px;
        gap: 8px;
    }
    .service-name {
        font-size: 13px;
    }
    .service-stats {
        font-size: 11px;
    }
}

.service-item:hover {
    background: rgba(102, 126, 234, 0.1);
    transform: translateX(5px);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.status-dot.pulsing {
    animation: pulse 2s infinite;
}

.status-dot.active {
    background: var(--success);
}

.status-dot.idle {
    background: var(--warning);
}

.status-dot.error {
    background: var(--danger);
}

.service-name {
    flex: 1;
    font-weight: 500;
    word-break: break-word;
    overflow-wrap: break-word;
}

.service-stats {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* Metrics */
.metrics-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

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

.metric-bar {
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}

.metric-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--warning));
    transition: width 0.5s;
    width: 0%;
}

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

/* Positions Table */
.positions-table {
    display: flex;
    flex-direction: column;
}

.table-header, .table-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1.5fr 1.5fr 1fr;
    gap: 10px;
    padding: 10px;
    font-size: 13px;
}

@media (max-width: 768px) {
    .table-header, .table-row {
        grid-template-columns: 2fr 1fr 1.5fr;
        font-size: 12px;
        padding: 8px;
        gap: 8px;
    }
    .table-header :nth-child(4),
    .table-header :nth-child(5),
    .table-row :nth-child(4),
    .table-row :nth-child(5) {
        display: none;
    }
}

@media (max-width: 480px) {
    .table-header, .table-row {
        grid-template-columns: 2fr 1.5fr;
        font-size: 11px;
        padding: 6px;
        gap: 6px;
    }
    .table-header :nth-child(2),
    .table-row :nth-child(2) {
        display: none;
    }
}

.table-header {
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.table-row {
    border-bottom: 1px solid rgba(45, 53, 97, 0.3);
    transition: background 0.2s;
}

.table-row:hover {
    background: rgba(102, 126, 234, 0.05);
}

.table-row .long {
    color: var(--success);
}

.table-row .short {
    color: var(--danger);
}

.table-row .profit {
    color: var(--success);
}

.table-row .loss {
    color: var(--danger);
}

/* Signal Pipeline */
.pipeline {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 20px 0;
}

@media (max-width: 768px) {
    .pipeline {
        flex-direction: column;
        gap: 15px;
        padding: 15px 0;
    }
    .pipeline-arrow {
        transform: rotate(90deg);
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .pipeline {
        gap: 12px;
        padding: 12px 0;
    }
    .stage-count {
        font-size: 20px;
    }
    .stage-label {
        font-size: 11px;
    }
}

.pipeline-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.stage-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.stage-count {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.stage-breakdown {
    display: flex;
    gap: 8px;
}

.breakdown-item {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.breakdown-item.enter {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.breakdown-item.postpone {
    background: rgba(255, 184, 0, 0.2);
    color: var(--warning);
}

.breakdown-item.skip {
    background: rgba(255, 71, 87, 0.2);
    color: var(--danger);
}

.pipeline-arrow {
    font-size: 24px;
    color: var(--text-secondary);
}

/* Activity Log */
.activity-log {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

@media (max-width: 768px) {
    .activity-log {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .activity-log {
        max-height: 150px;
        gap: 6px;
    }
}

.activity-item {
    padding: 8px;
    background: var(--bg-card);
    border-radius: 6px;
    font-size: 12px;
    border-left: 3px solid var(--border);
}

@media (max-width: 480px) {
    .activity-item {
        padding: 6px;
        font-size: 11px;
    }
}

/* Performance Stats */
.performance-stats, .learning-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

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

.stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-value.best {
    color: var(--success);
}

.stat-value.worst {
    color: var(--danger);
}

.stat-divider {
    height: 1px;
    background: var(--border);
    margin: 5px 0;
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 480px) {
    .action-buttons {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

.action-btn {
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
}

@media (max-width: 480px) {
    .action-btn {
        padding: 10px;
        font-size: 12px;
    }
}

.action-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateY(-2px);
}

/* ERP Footer */
.erp-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    z-index: 100;
}

@media (max-width: 768px) {
    .erp-footer {
        padding: 8px 15px;
        font-size: 11px;
        flex-direction: column;
        gap: 5px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .erp-footer {
        padding: 6px 10px;
        font-size: 10px;
    }
}

.erp-footer a {
    color: var(--success);
    text-decoration: none;
}

.erp-footer a:hover {
    text-decoration: underline;
}

/* Menu Divider */
.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 15px;
}

.no-data {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}


/* Service Accordion */
.service-expand {
    margin-left: auto;
    font-size: 12px;
    transition: transform 0.3s;
    cursor: pointer;
    opacity: 0.4;
}

.service-item.expanded .service-expand {
    transform: rotate(180deg);
}

.service-description {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    padding: 0 10px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    background: rgba(102, 126, 234, 0.05);
    border-radius: 6px;
    margin: 0 10px 0 10px;
}

.service-description.expanded {
    max-height: 400px;
    overflow-y: auto;
    padding: 12px 10px;
    margin-bottom: 8px;
}

.service-description.expanded::-webkit-scrollbar {
    width: 6px;
}

.service-description.expanded::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.service-description.expanded::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 3px;
}

.service-description.expanded::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* Activity Log Scrollbar - Match Service Description */
#activityList::-webkit-scrollbar {
    width: 6px;
}

#activityList::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

#activityList::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 3px;
}

#activityList::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}
