/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
    min-height: 100vh;
    padding-bottom: 48px; /* Height of footer (24px * 2) */
}

/* Sidebar layout */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 48px; /* leave space for fixed footer */
    width: 72px;
    background: #ffffff;
    border-right: 1px solid #e6e9ee;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    gap: 10px;
    z-index: 900;
}
.brand {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: #0f296a;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    letter-spacing: 0.03em;
}
.side-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
}
.side-link {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1f2d3d;
    text-decoration: none;
    border: 1px solid transparent;
}
.side-link .icon {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.side-link:hover { background: #f5f6f8; border-color: #e6e9ee; }
.side-link.active { background: #eef1f6; color: #0f296a; border-color: #d7dbe4; }

.main-content.with-sidebar { margin-left: 72px; }

@media (max-width: 768px) {
    .sidebar { bottom: 44px; width: 60px; }
    .side-link { width: 38px; height: 38px; }
    .side-link .icon { width: 20px; height: 20px; }
    .main-content.with-sidebar { margin-left: 60px; }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.logo a {
    color: white;
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: bold;
}

.logo a:hover {
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

/* Navigation */
.nav-list {
    display: flex;
    list-style: none;
    gap: 2rem;
    flex-wrap: wrap;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-link:hover {
    background-color: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.nav-link.active {
    background-color: rgba(255,255,255,0.3);
    font-weight: bold;
}

/* Main content */
.main-content {
    padding: 2rem 0;
}

/* Cards */
.card {
    background: white;
    border-radius: 10px;
    padding: 1rem; /* compact */
    margin-bottom: 1rem; /* compact */
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
}

.card-header {
    border-bottom: 2px solid #f1f3f4;
    padding-bottom: .5rem; /* compact */
    margin-bottom: .75rem; /* compact */
}

.card-title {
    color: #2c3e50;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.card-subtitle {
    color: #7f8c8d;
    font-size: 1rem;
}

/* Status indicators */
.status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 500;
    font-size: 0.9rem;
}

.status.connected {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status.disconnected {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status.error {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.metric-card {
    background: white;
    border-radius: 10px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.metric-card:hover {
    transform: translateY(-3px);
}

.metric-value {
    font-size: 2rem;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.metric-label {
    color: #7f8c8d;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: .5rem .9rem; /* compact & consistent */
    border: 1px solid transparent; /* 1px borders */
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary { background-color: #eef2f5; color: #334155; border-color: #6b7280; }
.btn-secondary:hover { background-color: #e5eaee; }

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(44, 62, 80, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 0.75rem;
    z-index: 1000;
    border-top: 1px solid rgba(52, 152, 219, 0.3);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.footer-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 1rem;
    height: 24px;
}

.footer-top {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-bottom {
    opacity: 0.8;
}

.copyright, .system-info {
    font-weight: 500;
    opacity: 0.9;
}

.mt5-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    font-weight: bold;
}

.status-indicator.connected {
    color: #2ecc71;
}

.status-indicator.disconnected {
    color: #e74c3c;
}

.status-indicator.error {
    color: #f39c12;
}

.account-data {
    font-family: 'Courier New', monospace;
    opacity: 0.9;
}

.account-data .value {
    color: #3498db;
    font-weight: bold;
}

.datetime .time {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #3498db;
    font-size: 0.8rem;
}

.date-info .date {
    font-size: 0.7rem;
    opacity: 0.8;
}

/* Responsive footer */
@media (max-width: 768px) {
    .footer {
        font-size: 0.7rem;
    }
    
    .footer-line {
        padding: 0.2rem 0.5rem;
        height: 22px;
    }
    
    .mt5-status {
        gap: 0.3rem;
    }
    
    .account-data {
        display: none; /* Hide account data on mobile */
    }
    
    body {
        padding-bottom: 44px; /* Adjust for smaller footer on mobile */
    }
}

@media (max-width: 480px) {
    .copyright, .system-info {
        font-size: 0.65rem;
    }
    
    .datetime .time {
        font-size: 0.7rem;
    }
    
    .date-info .date {
        font-size: 0.6rem;
    }
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.table th,
.table td {
    padding: .5rem .75rem; /* compact */
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
}

.table tr:hover {
    background-color: #f8f9fa;
}

/* Alert messages */
.alert {
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1rem;
}

.alert-info {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

.alert-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.alert-danger {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

/* Responsive design */
@media (max-width: 768px) {
    .header .container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-list {
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }
    
    .nav-link {
        text-align: center;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .card {
        padding: 1rem;
    }
}

/* Raw Signals Styles */
.signals-controls {
    margin-bottom: 2rem;
}

.signals-controls .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.directory-info {
    font-size: 0.85rem;
    color: #6c757d;
    font-family: 'Courier New', monospace;
}

.file-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-selector label {
    font-weight: 600;
    color: #495057;
}

.file-info {
    font-size: 0.9rem;
    color: #6c757d;
}

.signals-data .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.data-info {
    font-size: 0.9rem;
    color: #6c757d;
}

.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.search-box {
    flex: 1;
    max-width: 300px;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

.table-wrapper {
    max-height: 70vh;
    overflow: auto;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
}

/* Compact KPI table */
.kpi-table-wrap { margin-top: .5rem; }
.kpi-table { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border: 1px solid #e6e9ee; border-radius: 8px; overflow: hidden; table-layout: fixed; }
.kpi-table th { background: #f8f9fb; color:#6c757d; text-transform: uppercase; font-weight: 600; font-size: .78rem; padding: 4px 8px; border-bottom: 1px solid #e6e9ee; }
.kpi-section th { text-align: left; background:#eef1f6; color:#4b5563; font-size: .8rem; padding: 8px 12px; border-top: 1px solid #e6e9ee; }
.kpi-table td { padding: 6px 10px; border-bottom: 1px solid #f3f4f7; border-right: 1px solid #f3f4f7; vertical-align: middle; }
.kpi-table tr:last-child td { border-bottom: none; }
.kpi-table td:last-child { border-right: none; }
.kpi-k { display:block; color:#6c757d; font-size:.75rem; margin-bottom: 2px; }
.kpi-v { font-weight: 700; font-size: 1rem; }
.kpi-sub { display:block; font-size:.78rem; color:#6b7280; margin-top:2px; }
.kpi-spark svg { display:block; width:160px; height:34px; }
.kpi-pos { color:#059669; }
.kpi-neg { color:#dc2626; }

/* Small status dot */
.dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; vertical-align:middle; border:1px solid #cbd5e1; }
.dot.on { background:#22c55e; border-color:#16a34a; }
.dot.off { background:#e5e7eb; border-color:#cbd5e1; }

/* Compact spark-like bars for distribution */
.spark-bars { display:flex; align-items:flex-end; gap:6px; height:34px; padding:2px 0; }
.spark-bars .bwrap { display:flex; flex-direction:column; align-items:center; }
.spark-bars .bar { width: 10px; background: linear-gradient(180deg, #8b5cf6 0%, #6d28d9 100%); border-radius:3px 3px 0 0; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.spark-bars .lbl { font-size: 10px; color:#6b7280; margin-top: 2px; }

/* Inline layout for text + spark bars */
.kpi-inline-dist { display:flex; align-items:flex-end; gap:16px; }
.kpi-inline-dist .kpi-v { margin-right:8px; }

/* Profit bars color variants */
.spark-bars .bar.pos { background: linear-gradient(180deg, #10b981 0%, #059669 100%); }
.spark-bars .bar.neg { background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%); }

/* Modal (global) */
.gce-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2000;
    display: none;
}
.gce-modal {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(1000px, 95vw);
    max-height: 85vh;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
}
.gce-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #e6e9ee;
}
.gce-modal-title { font-weight: 600; }
.gce-modal-close {
    background: transparent; border: none; font-size: 20px; cursor: pointer;
}
.gce-modal-body { padding: 10px 14px; overflow: auto; }
.gce-modal-footer { padding: 8px 14px; border-top: 1px solid #e6e9ee; text-align: right; }

/* Simple flow layout */
.gce-flow-root { padding: 4px; }
.gce-flow-rule { margin: 12px 0; }
.gce-decision {
    display: inline-block;
    padding: 8px 10px;
    border: 2px solid #764ba2;
    color: #2c3e50;
    border-radius: 6px;
    background: #f9f7ff;
    font-weight: 600;
}
.gce-branches { display: flex; gap: 16px; margin-top: 8px; }
.gce-branch { flex: 1; border: 1px dashed #ddd; border-radius: 6px; padding: 8px; background:#fafafa; }
.gce-branch .label { font-size: .8rem; color: #6c757d; margin-bottom: 6px; }
.gce-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.gce-chip { background:#e9ecef; border-radius: 14px; padding: 3px 8px; font-size:.85rem; }

/* Diagram nodes + connectors */
.gce-scheme { position: relative; margin: 14px 0 22px; padding: 8px 4px; }
.gce-scheme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-auto-rows: auto;
    gap: 14px 18px;
    align-items: start;
}
.gce-node {
    padding: 10px 12px;
    background: #fff;
    border: 2px solid #764ba2;
    border-radius: 8px;
    color: #2c3e50;
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.gce-node .label { font-size: .75rem; color:#6c757d; margin-bottom: 6px; }
.gce-node.decision { grid-column: 2; }
.gce-node.then { grid-column: 1; }
.gce-node.else { grid-column: 3; }
.gce-scheme .center { grid-column: 2; }
.gce-scheme-svg { position: absolute; inset: 0; pointer-events: none; }
.gce-arrow { stroke: #764ba2; stroke-width: 2; fill: none; }

.table {
    margin-bottom: 0;
}

.table thead th {
    position: sticky;
    top: 0;
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    z-index: 10;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

.table td {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination-info {
    font-size: 0.9rem;
    color: #6c757d;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert {
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
}

.alert-warning {
    color: #856404;
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

/* Page header for Raw Signals */
.page-header {
    margin-bottom: 2rem;
    text-align: center;
}

.page-header h1 {
    color: #495057;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: #6c757d;
    font-size: 1.1rem;
}

/* Responsive design for Raw Signals */
@media (max-width: 768px) {
    .signals-controls .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .header-actions {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }
    
    .table-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        max-width: none;
    }
    
    .table-actions {
        justify-content: center;
    }
    
    .table-wrapper {
        max-height: 50vh;
    }
    
    .table td {
        max-width: 120px;
        font-size: 0.8rem;
    }
    
    .table-pagination {
        flex-direction: column;
        align-items: center;
    }
}
/* --- Institutional theme (compact, neutral) --- */
.card-flat {
    box-shadow: none !important;
    border: 1px solid #e6e9ee;
    border-radius: 8px;
}

.page-title-pro {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2d3d;
}

.text-subtle { color: #6b7280; font-size: 0.9rem; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin: 0 0 1rem 0;
}
.kpi {
    background: #fff;
    border: 1px solid #e6e9ee;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.kpi-value {
    font-weight: 600;
    font-size: 1.25rem;
    color: #0f172a; /* near-black */
}
.kpi-label {
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: .72rem;
    color: #6b7280;
    margin-bottom: 2px;
}

.form-pro { background:#f8f9fb; border:1px solid #e6e9ee; border-radius:8px; padding:12px; margin: 8px 0 14px; }
.form-pro-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap: 12px; align-items:end; }
.form-pro-label { display:block; font-size:.8rem; color:#4b5563; margin-bottom:4px; font-weight:500; }
.form-pro-control { width:100%; padding:8px 10px; border:1px solid #cbd5e1; border-radius:6px; background:#fff; height:36px; }
.form-pro-action { display:flex; align-items:flex-end; }

.btn-pro { background:#e8efff; color:#0f296a; border:1px solid #0f296a; border-radius:6px; padding:.5rem .9rem; font-weight:600; }
.btn-pro:hover { background:#dbe7ff; }

.table-pro { background:white; border:1px solid #e6e9ee; border-radius:8px; overflow:hidden; }
.table-pro { margin-top: .5rem; }
.table-pro .table { margin-top: 0; }
.table-pro .table thead th { background:#f2f4f7 !important; }
.table-pro .table td { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono','Courier New', monospace; font-size: 0.85rem; }

@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Sparklines */
.kpi-spark .spark-row { display:flex; gap:12px; align-items:center; margin-top:4px; }
.spark-item { display:flex; flex-direction:column; gap:2px; }
.spark-label { font-size:.7rem; color:#6b7280; }
.spark { display:block; }
.kpi .spark { margin-top: 4px; }
.spark-line { fill:none; stroke-width:1.5; }
.spark-line.all { stroke:#1f2d5a; }
.spark-line.buy { stroke:#166534; }
.spark-line.sell { stroke:#991b1b; }
.spark-line.equity { stroke:#0ea5e9; }
.spark-zero { stroke:#e5e7eb; stroke-width:1; }
.spark-overlay { fill:none; stroke-width:1.2; stroke-dasharray:3 3; opacity:.75; }
.spark-overlay.all { stroke:#1f2d5a; }
.spark-overlay.buy { stroke:#166534; }
.spark-overlay.sell { stroke:#991b1b; }
.qchart .spark { display:block; width:100%; height:36px; }

/* Price chart (base TF) */
.price-svg .bar { stroke:#9aa0a6; stroke-width:1; }
.price-svg .mk { stroke-width:1.2; }
.price-svg .mk.buy-open { fill:#15803d; stroke:#0a5a28; }
.price-svg .mk.sell-open { fill:#991b1b; stroke:#7f1d1d; }
.price-svg .mk.buy-close { fill:#ffffff; stroke:#15803d; }
.price-svg .mk.sell-close { fill:#ffffff; stroke:#991b1b; }
.price-chart-block { position: relative; }
.price-chart-block .pc-legend { pointer-events:none; }
.price-svg .pc-cross line { stroke:#6b7280; stroke-width:1; stroke-dasharray:4 3; }
.pc-toolbar .btn { font-size:.9rem; }

/* Rules box */
.rules-box { width:100%; border:1px solid #e6e9ee; border-radius:8px; background:#fff; margin:6px 0 16px; }
.rules-head { font-size:.78rem; color:#4b5563; padding:8px 10px; border-bottom:1px solid #e6e9ee; text-transform:uppercase; letter-spacing:.04em; }
.rules-pre { margin:0; padding:10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono','Courier New', monospace; font-size:.85rem; line-height:1.35; max-height:28vh; min-height:96px; overflow:auto; white-space:pre-wrap; word-break:break-word; }

/* Toggle switch (for Allow Trading) */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #e5e7eb; border: 1px solid #cbd5e1; border-radius: 9999px; transition: background .2s ease, border-color .2s ease, box-shadow .2s ease; }
.toggle-slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 2px; top: 50%; transform: translate(0, -50%); background: #ffffff; border-radius: 9999px; box-shadow: 0 1px 2px rgba(0,0,0,.15); transition: transform .2s ease; }
.toggle-switch input:checked + .toggle-slider { background: #22c55e; border-color: #16a34a; }
.toggle-switch input:checked + .toggle-slider:before { transform: translate(20px, -50%); }
.toggle-switch input:focus + .toggle-slider { box-shadow: 0 0 0 2px rgba(59,130,246,.25); }
.toggle-switch input:disabled + .toggle-slider { opacity: .6; cursor: not-allowed; }

/* Realtime mode badge */
.rt-badge { font-size:.78rem; color:#4b5563; border:1px solid #cbd5e1; background:#f1f5f9; border-radius:9999px; padding:2px 8px; }
.rt-badge.ok { color:#065f46; background:#ecfdf5; border-color:#059669; }
.rt-badge.err { color:#991b1b; background:#fef2f2; border-color:#dc2626; }
