/* ===== MT5 Manager Dashboard CSS ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base: #0f1117;
  --bg-card: #1a1d27;
  --bg-card2: #1e2130;
  --bg-hover: #252840;
  --border: #2a2d3e;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #4b5563;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --purple: #8b5cf6;
  --orange: #f97316;
  --radius: 12px;
  --sidebar-w: 240px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-logo {
  padding: 1.25rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-logo .icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.sidebar-logo .brand { font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.sidebar-logo .sub { font-size: 0.7rem; color: var(--text-secondary); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.75rem 0; }
.nav-section-title {
  padding: 0.75rem 1rem 0.25rem;
  font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
}
.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 1rem; cursor: pointer; border-radius: 0;
  color: var(--text-secondary); font-size: 0.875rem;
  transition: all 0.15s; position: relative;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: rgba(99,102,241,0.12); color: var(--accent-light); }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 4px; bottom: 4px;
  width: 3px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-item .icon { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer {
  padding: 0.75rem 1rem; border-top: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text-secondary);
}
.sidebar-footer .user-info { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-size: 1.1rem; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.content { padding: 1.5rem; flex: 1; }

.hamburger {
  display: none; cursor: pointer; background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 0.4rem 0.6rem; color: var(--text-primary); font-size: 18px;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title { font-size: 0.875rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.25rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; margin-bottom: 0.35rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-sub { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.25rem; }
.stat-change { font-size: 0.75rem; font-weight: 600; margin-top: 0.25rem; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* ===== ACCOUNT CARDS ===== */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.account-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; cursor: pointer;
  transition: all 0.2s; position: relative; overflow: hidden;
}
.account-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.account-card.bot-off { border-color: var(--red); }
.account-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.account-card.profit-positive::before { background: var(--green); }
.account-card.profit-negative::before { background: var(--red); }
.account-card.profit-neutral::before { background: var(--text-muted); }

.acc-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; }
.acc-name { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }
.acc-broker { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }
.acc-number { font-size: 0.7rem; color: var(--text-muted); font-family: monospace; }

.bot-status {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.7rem; font-weight: 600;
}
.bot-status.running { background: rgba(16,185,129,0.15); color: var(--green); }
.bot-status.stopped { background: rgba(239,68,68,0.15); color: var(--red); }
.bot-status .dot {
  width: 6px; height: 6px; border-radius: 50%;
}
.bot-status.running .dot { background: var(--green); animation: pulse 1.5s infinite; }
.bot-status.stopped .dot { background: var(--red); }

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

.acc-metrics {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem; margin-bottom: 1rem;
}
.acc-metric-label { font-size: 0.7rem; color: var(--text-secondary); }
.acc-metric-value { font-size: 1rem; font-weight: 700; margin-top: 0.15rem; }

.acc-footer {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem;
  gap: 0.5rem;
}

/* ===== TOGGLE ===== */
.toggle {
  position: relative; width: 40px; height: 22px; cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--text-muted); border-radius: 22px; transition: 0.3s;
}
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; transition: 0.3s;
}
.toggle input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
  text-align: left; padding: 0.6rem 0.75rem;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td {
  padding: 0.65rem 0.75rem; border-bottom: 1px solid rgba(42,45,62,0.5);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* ===== BADGES ===== */
.badge {
  display: inline-block; padding: 0.15rem 0.55rem;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600;
}
.badge-green { background: rgba(16,185,129,0.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-blue { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-gray { background: rgba(75,85,99,0.3); color: var(--text-secondary); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-light); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-outline {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== CHARTS ===== */
.chart-container { position: relative; }

/* ===== PROFIT/LOSS COLORS ===== */
.profit { color: var(--green); }
.loss { color: var(--red); }
.neutral { color: var(--text-secondary); }

/* ===== PAGE SECTIONS ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7); z-index: 1000;
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.75rem; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; margin-bottom: 0.3rem; }
.form-control {
  width: 100%; padding: 0.6rem 0.8rem;
  background: var(--bg-base); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary); font-size: 0.875rem; outline: none;
}
.form-control:focus { border-color: var(--accent); }
select.form-control { cursor: pointer; }

/* ===== HEATMAP ===== */
.heatmap-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; }
.heatmap-cell {
  aspect-ratio: 1; border-radius: 4px; display: flex; align-items: center;
  justify-content: center; font-size: 0.6rem; color: white; font-weight: 600;
  cursor: default;
}

/* ===== TABS ===== */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.tab-btn {
  padding: 0.6rem 1rem; cursor: pointer; background: none; border: none;
  color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent-light); border-bottom-color: var(--accent); }

/* ===== LOADING ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 3rem; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.75rem 1rem; font-size: 0.85rem;
  min-width: 240px; animation: slideIn 0.2s ease;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    transform: translateX(-240px); width: 240px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 99; display: none;
  }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .accounts-grid { grid-template-columns: 1fr; }
  .acc-metrics { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0.75rem 1rem; }
  .heatmap-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
