:root {
  color-scheme: dark;
  --bg: #0b0f19;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --line: #374151;
  --blue: #0ea5e9;
  --blue-hover: #38bdf8;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --orange: #f59e0b;
  --orange-bg: rgba(245, 158, 11, 0.12);
  --accent: #6366f1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at left, #1e293b 0%, #0f172a 100%, var(--bg)) no-repeat fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(17, 24, 39, 0.8);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  backdrop-filter: blur(12px);
  z-index: 100;
}

.brand {
  font-weight: 800;
  color: #fff;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand::before {
  content: "⚡";
  font-size: 1.2rem;
}

nav { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: 0.95rem; }
nav a { transition: color 0.2s; }
nav a:hover { color: #fff; }

.inline-form { display: inline; }
button, .chip {
  border: 1px solid var(--line);
  background: #111827;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

button:hover, .chip:hover, .chip.selected {
  border-color: var(--blue);
  color: #fff;
  background: rgba(14, 165, 233, 0.1);
}

.chip.selected {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.page {
  max-width: 95%;
  margin: 0 auto;
  padding: 16px 24px;
}

/* Dashboard Header & Stats */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-card {
  background: rgba(17, 24, 39, 0.6);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-width: 105px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.stat-label {
  font-size: 0.725rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.positive-text { color: var(--green) !important; }
.negative-text { color: var(--red) !important; }

/* Filters */
.filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.refresh-btn {
  background: var(--panel);
  border-color: var(--line);
}

/* Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 1150px) {
  .dashboard-grid {
    grid-template-columns: 3fr 2fr;
    align-items: start;
  }
}

.table-column {
  min-width: 0; /* Prevents flex/grid blowouts */
}

.detail-column {
  position: sticky;
  top: 84px; /* header height + some space */
}

/* Panels */
.panel {
  background: rgba(17, 24, 39, 0.75);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
}

.compact-table-panel {
  padding: 0;
}

/* Compact Table Styles */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 0.85rem;
}

th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: rgba(17, 24, 39, 0.95);
  position: sticky;
  top: 0;
  z-index: 10;
}

tr.clickable {
  cursor: pointer;
  transition: background-color 0.15s, border-left 0.1s;
}

tr.clickable:hover {
  background: rgba(56, 189, 248, 0.04);
}

/* Active row indicator styling */
tr.active-row {
  background: rgba(14, 165, 233, 0.08) !important;
}

tr.active-row td {
  border-bottom-color: rgba(14, 165, 233, 0.3);
}

td strong {
  font-size: 0.9rem;
  color: #fff;
}

td small {
  display: inline-block;
  background: rgba(55, 65, 81, 0.5);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  margin-left: 6px;
  text-transform: uppercase;
}

/* Badges & Accents */
.side {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 6px;
  display: inline-block;
}
.side.long { background: var(--green-bg); color: #6ee7b7; }
.side.short { background: var(--red-bg); color: #fca5a5; }

.status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  display: inline-block;
}
.status.active { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }
.status.closed { background: var(--orange-bg); color: #fcd34d; }

.pnl {
  font-weight: 600;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 6px;
  display: inline-block;
}
.pnl.positive { background: var(--green-bg); color: #34d399; }
.pnl.negative { background: var(--red-bg); color: #f87171; }
.pnl.flat { background: rgba(156, 163, 175, 0.15); color: #d1d5db; }

.empty, .error {
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

/* Details Sidebar / View */
.detail-sidebar-panel {
  padding: 20px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
}

/* Empty State Styling */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-grow: 1;
  padding: 40px 20px;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.65;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  color: #fff;
  font-weight: 700;
}

.empty-state p {
  max-width: 320px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

/* Inline Detail Info Styling */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.detail-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pair-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
}

.timeframe-badge {
  font-size: 0.75rem;
  background: #374151;
  padding: 2px 8px;
  border-radius: 6px;
  color: #e5e7eb;
}

.btn-link {
  font-size: 0.85rem;
  color: var(--blue);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.4);
  transition: all 0.2s;
}

.btn-link:hover {
  border-color: var(--blue);
  color: #fff;
  background: rgba(14, 165, 233, 0.1);
}

.detail-status-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.status-badge, .pnl-badge, .score-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
}

.status-badge.active { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }
.status-badge.closed { background: var(--orange-bg); color: #f59e0b; }

.pnl-badge.positive { background: var(--green-bg); color: #10b981; }
.pnl-badge.negative { background: var(--red-bg); color: #ef4444; }
.pnl-badge.flat { background: rgba(156, 163, 175, 0.15); color: #9ca3af; }

.score-badge {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
}

/* Inline Chart Wrapper */
.inline-chart-wrap {
  width: 100%;
  height: 380px;
  background: #0b0f19;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  position: relative;
}

#chart {
  width: 100%;
  height: 100%;
}

.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 0.9rem;
}

/* Inline Metrics Grid */
.inline-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric-card {
  background: rgba(17, 24, 39, 0.4);
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
}

.metric-card.span-2 {
  grid-column: span 2;
}

.metric-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.metric-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: #e5e7eb;
}

.price-val {
  font-family: monospace;
  font-size: 0.95rem;
}

.stop-color { color: #fca5a5; }
.target-color { color: #86efac; }
.warn-color { color: var(--orange); }

/* Details Grid for full view detail.html */
.details-grid {
  margin-top: 18px;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.details-grid div {
  background: rgba(31, 41, 55, 0.5);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid var(--line);
}

.details-grid strong {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.details-grid span {
  font-size: 1rem;
  font-weight: 600;
}

/* Full Chart view details */
.chart-panel {
  padding: 16px;
}

/* Login Panel */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  padding: 32px;
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
}

.login-card label {
  display: block;
  margin: 16px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b0f19;
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: var(--blue);
  outline: none;
}

.login-card button {
  width: 100%;
  margin-top: 12px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  border: none;
  padding: 12px;
}

.login-card button:hover {
  background: var(--blue-hover);
}

/* Responsive adjustment */
@media (max-width: 1149px) {
  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .stats {
    width: 100%;
  }

  .stat-card {
    flex-grow: 1;
  }
  
  .detail-column {
    margin-top: 10px;
    position: static;
  }
}

