/* Trading Dashboard Pro - Styles */
/* Extracted from original trading-dashboard-v3.html */

:root {
  --bg: #071028;
  --card: rgba(255, 255, 255, 0.04);
  --muted: #9aa4b2;
  --accent: #60a5fa;
  --success: #34d399;
  --danger: #fb7185;
  --warning: #f59e0b;
}

body {
  font-family: Inter, system-ui;
  margin: 0;
  background: linear-gradient(180deg, #071028, #081428);
  color: #e6eef8;
  padding: 18px;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 10px;
  font-size: 22px;
}

h3 {
  margin: 6px 0;
  font-size: 16px;
}

.card {
  background: var(--card);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
  position: relative;
}

.card-expand {
  position: absolute;
  top: 12px;
  right: 12px;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.card-expand:hover {
  opacity: 1;
}

.card.fullscreen {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  bottom: 20px;
  z-index: 2000;
  overflow-y: auto;
  max-width: none;
  margin: 0;
  background: rgba(7, 16, 40, 0.98);
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(15px);
}

.card.fullscreen .chart-big,
.card.fullscreen .chart-med,
.card.fullscreen .chart-small {
  height: calc(100vh - 200px) !important;
}

label {
  font-size: 13px;
  color: var(--muted);
}

input[type="date"],
select,
input[type="file"],
input[type="text"] {
  background: #0b1220;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px;
  border-radius: 8px;
  color: #e6eef8;
  font-size: 13px;
}

button {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

button.small-btn {
  padding: 4px 8px;
  font-size: 11px;
}

button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.metric {
  font-weight: 700;
  font-size: 20px;
}

.chart-big {
  height: 420px !important;
}

.chart-med {
  height: 320px !important;
}

canvas {
  width: 100% !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 13px;
}

th {
  cursor: pointer;
  color: var(--muted);
  text-align: left;
  user-select: none;
}

th:hover {
  color: #fff;
}

tr.clickable {
  cursor: pointer;
  transition: background 0.2s;
}

tr.clickable:hover {
  background: rgba(255, 255, 255, 0.02);
}

.positive {
  color: var(--success);
  font-weight: 700;
}

.negative {
  color: var(--danger);
  font-weight: 700;
}

.neutral {
  color: var(--muted);
}

.small {
  font-size: 12px;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.detail-row {
  background: rgba(96, 165, 250, 0.04) !important;
}

.sub-detail-row {
  background: rgba(234, 179, 8, 0.04) !important;
}

.detail-table {
  margin: 12px 0;
  font-size: 12px;
}

.detail-table th {
  background: rgba(255, 255, 255, 0.02);
  font-size: 11px;
  font-weight: 600;
}

.detail-table td {
  padding: 6px 8px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.badge-buy {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.badge-sell {
  background: rgba(251, 113, 133, 0.15);
  color: var(--danger);
}

.badge-neutral {
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
}

.multi-select {
  background: #0b1220;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 8px;
  max-height: 200px;
  overflow-y: auto;
  min-width: 250px;
  position: absolute;
  z-index: 1000;
  margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: none;
}

.multi-select.show {
  display: block;
}

.multi-select label {
  display: block;
  padding: 4px 0;
  cursor: pointer;
  font-size: 13px;
}

.multi-select input[type="checkbox"] {
  margin-right: 6px;
}

.dropdown-trigger {
  cursor: pointer;
  background: #0b1220;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 12px;
  border-radius: 8px;
  min-width: 200px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.dropdown-trigger:hover {
  border-color: var(--accent);
}

.dropdown-trigger::after {
  content: "▼";
  font-size: 10px;
  margin-left: 8px;
}

.period-btn {
  padding: 6px 12px;
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.3);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #e6eef8;
  transition: all 0.2s;
}

.period-btn:hover,
.period-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.custom-period-inputs {
  display: none;
  margin-top: 8px;
}

.custom-period-inputs.show {
  display: flex;
  gap: 8px;
}

.filter-summary {
  background: rgba(96, 165, 250, 0.08);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  margin-top: 8px;
}

.heatmap-cell {
  padding: 8px;
  text-align: center;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.insight-card {
  border-left: 3px solid var(--warning);
  background: rgba(245, 158, 11, 0.06);
  padding: 12px;
  border-radius: 8px;
  margin: 8px 0;
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
}

#mcLoader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(7, 16, 40, 0.95);
  backdrop-filter: blur(10px);
  z-index: 9999;
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

#mcLoader.show {
  display: flex;
}

.mc-letters {
  display: flex;
  gap: 20px;
  font-size: 80px;
  font-weight: 700;
  letter-spacing: 10px;
}

.mc-letters span {
  background: linear-gradient(135deg, var(--accent), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pulse 1.5s ease-in-out infinite;
}

.mc-letters span:nth-child(1) {
  animation-delay: 0s;
}

.mc-letters span:nth-child(2) {
  animation-delay: 0.2s;
}

.loader-text {
  margin-top: 24px;
  font-size: 14px;
  color: var(--muted);
  animation: fadeInOut 2s ease-in-out infinite;
}

.spinner {
  margin-top: 16px;
  width: 40px;
  height: 40px;
  border: 3px solid rgba(96, 165, 250, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.7;
  }
}

@keyframes fadeInOut {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

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

.tooltip-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  text-align: center;
  line-height: 18px;
  border-radius: 50%;
  background: rgba(96, 165, 250, 0.2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: help;
  position: relative;
}

.tooltip-icon:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.95);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  white-space: normal;
  word-wrap: break-word;
  max-width: 450px;
  z-index: 1001;
  border: 1px solid rgba(96, 165, 250, 0.5);
  line-height: 1.4;
  text-align: left;
}

@media (min-width: 768px) {
  .tooltip-icon:hover::after {
    max-width: 650px;
  }
}

.insight-banner {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.15), rgba(52, 211, 153, 0.05));
  border-left: 4px solid var(--success);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(52, 211, 153, 0.2);
}

.insight-banner.negative {
  background: linear-gradient(135deg, rgba(251, 113, 133, 0.15), rgba(251, 113, 133, 0.05));
  border-left-color: var(--danger);
  border-bottom-color: rgba(251, 113, 133, 0.2);
}

.insight-banner .dismiss {
  cursor: pointer;
  opacity: 0.6;
  font-size: 18px;
  transition: opacity 0.2s;
  align-self: flex-start;
}

.insight-banner .dismiss:hover {
  opacity: 1;
}

.show-more-btn {
  padding: 6px 12px;
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.3);
  color: #e6eef8;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  margin-top: 8px;
  transition: all 0.2s;
}

.show-more-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

#insightsBanner {
  margin: 12px 0 16px;
}

#insightsBanner .insight-banner {
  margin: 8px 0;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Table detail row animations */
.detail-row {
  animation: slideDown 0.2s ease-in-out;
}

.sub-detail-row {
  animation: slideDown 0.2s ease-in-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDownBanner {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUpBanner {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-100%);
  }
}

/* Button hover effects */
button:not(:disabled) {
  transition: all 0.2s ease-in-out;
}

button:not(:disabled):hover {
  transform: translateY(-2px);
}

button:not(:disabled):active {
  transform: translateY(0);
}

/* Clickable table rows */
tr.clickable {
  transition: all 0.2s ease-in-out;
}

tr.clickable:hover {
  background: rgba(96, 165, 250, 0.06);
}

/* Fullscreen card animation */
.card.fullscreen {
  animation: expandCard 0.3s ease-out;
}

@keyframes expandCard {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#footer {
  text-align: center;
  padding: 20px;
  margin-top: 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
}

/* Tab Navigation */
.tab-navigation {
  display: flex;
  gap: 0;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 24px;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  padding: 16px 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
  position: relative;
  bottom: -2px;
}

.tab-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: #00d4aa;
  border-bottom-color: #00d4aa;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ============================================
   MOBILE RESPONSIVE DESIGN
   ============================================ */

/* Helper classes for responsive grids */
.responsive-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.responsive-grid-2-1 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.responsive-grid-3col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.header-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}

/* Tablets Portrait (640px+) */
@media (min-width: 640px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablets Landscape (768px+) */
@media (min-width: 768px) {
  .responsive-grid-2col,
  .responsive-grid-2-1 {
    grid-template-columns: 1fr 1fr;
  }

  .responsive-grid-2-1 {
    grid-template-columns: 2fr 1fr;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Mobile: Phones (max 640px) */
@media (max-width: 640px) {
  /* Fixed bottom tab navigation on mobile */
  .tab-navigation {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0;
    border-bottom: none;
    border-top: 2px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    background: rgba(7, 16, 40, 0.98);
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-top: 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    width: 100%;
  }

  .tab-btn {
    text-align: center;
    padding: 12px 24px;
    border-bottom: 3px solid transparent;
    border-left: none;
    bottom: auto;
    left: auto;
    flex: 1;
    position: relative;
  }

  .tab-btn.active {
    border-bottom-color: #00d4aa;
    border-left-color: transparent;
  }

  /* Optimize tab content spacing on mobile */
  .tab-content {
    padding-top: 8px;
  }

  body {
    padding: 12px;
    padding-bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  }

  h1 {
    font-size: 18px;
  }

  h3 {
    font-size: 14px;
  }

  .card {
    padding: 12px;
    margin-bottom: 12px;
  }

  .metric {
    font-size: 18px;
  }

  .chart-big {
    height: 250px !important;
  }

  .chart-med {
    height: 200px !important;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Stack all multi-column grids */
  .responsive-grid-2col,
  .responsive-grid-2-1,
  .responsive-grid-3col {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Tables: smaller padding and font size */
  th, td {
    padding: 6px 4px;
    font-size: 11px;
  }

  /* Hide less important columns on mobile */
  table th:last-child,
  table td:last-child {
    display: none;
  }

  /* Time of Day table should fit without scroll */
  .time-of-day-table {
    table-layout: fixed;
  }

  .time-of-day-table td,
  .time-of-day-table th {
    min-width: 0;
    padding: 2px;
  }

  /* Touch-friendly buttons */
  button {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 13px;
  }

  button.small-btn {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 11px;
  }

  .period-btn {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 11px;
  }

  /* Full-width dropdowns and inputs */
  .dropdown-trigger {
    width: 100%;
    max-width: 100%;
    min-width: auto;
  }

  .multi-select {
    width: calc(100vw - 40px);
    max-width: calc(100vw - 40px);
    min-width: auto;
  }

  input[type="date"],
  input[type="text"],
  input[type="file"] {
    width: 100%;
    max-width: 100%;
  }

  /* Header adjustments */
  .header-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .header-wrapper > h1 {
    margin-bottom: 0;
  }

  .header-wrapper > div {
    width: 100%;
  }

  /* Reduce fullscreen margins */
  .card.fullscreen {
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 16px;
  }

  /* Insight banner text size */
  .insight-banner {
    font-size: 12px;
    padding: 10px 12px;
  }

  /* Smaller badges */
  .badge {
    padding: 2px 6px;
    font-size: 10px;
  }

  /* Portfolio equity grid - optimize on mobile when isolated in Live tab */
  #portfolioEquity {
    margin-bottom: 16px;
    padding: 8px !important;
  }

  #portfolioEquity > div {
    gap: 10px;
  }

  /* Reduce portfolio value font sizes for mobile */
  #portfolioEquity .responsive-grid-2col > div > div[style*="font-size: 18px"] {
    font-size: 15px !important;
    font-weight: 600 !important;
  }

  /* Make portfolio labels more compact */
  #portfolioEquity .small {
    font-size: 11px !important;
    margin-bottom: 2px;
  }

  /* Specific portfolio value IDs */
  #accountEquity,
  #totalUnrealizedPnl,
  #cashBalance,
  #availableMargin {
    font-size: 15px !important;
    font-weight: 600 !important;
  }

  /* Improve chart container visibility on mobile */
  #historicalTab .card:has(canvas) {
    overflow: hidden;
  }

  /* Filter controls */
  .row {
    flex-direction: column;
    gap: 8px;
  }

  .custom-period-inputs {
    flex-direction: column;
  }

  .custom-period-inputs input {
    width: 100%;
  }
}

/* Mobile: Small Phones (max 480px) */
@media (max-width: 480px) {
  h1 {
    font-size: 16px;
  }

  .chart-big {
    height: 220px !important;
  }

  .chart-med {
    height: 180px !important;
  }

  /* Stack portfolio equity to single column */
  #portfolioEquity > div {
    grid-template-columns: 1fr !important;
  }

  /* Further optimize portfolio cards for small screens */
  #portfolioEquity {
    padding: 6px !important;
  }

  #accountEquity,
  #totalUnrealizedPnl,
  #cashBalance,
  #availableMargin {
    font-size: 14px !important;
  }

  /* Smaller period buttons */
  .period-btn {
    font-size: 10px;
    padding: 6px 8px;
  }

  /* Tighter spacing */
  .card {
    padding: 10px;
  }

  #footer {
    padding: 16px;
    margin-top: 24px;
    font-size: 11px;
  }
}

/* Landscape orientation adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .chart-big {
    height: 180px !important;
  }

  .chart-med {
    height: 150px !important;
  }
}

/* P/L Table detail row animations */
@keyframes slideDownFade {
  from {
    opacity: 0;
    max-height: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    max-height: 1000px;
    transform: translateY(0);
  }
}

.detail-row,
.sub-detail-row {
  animation: slideDownFade 0.3s ease-out;
  max-height: 1000px;
  overflow: hidden;
  transition: all 0.2s ease-out;
}
