/* ============================================
   P4U MISSION CONTROL - MASTER UI STYLES
   Pixel-Perfect Dark Theme
   ============================================ */

:root {
  /* Core Colors */
  --bg-primary: #0a0e14;
  --bg-secondary: #0f1419;
  --bg-tertiary: #14191f;
  --bg-card: #111723;
  --bg-card-hover: #151d2a;

  /* Borders & Dividers */
  --border-primary: #1a2332;
  --border-secondary: #243145;
  --border-accent: #2a3f5f;

  /* Text Colors */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-dim: #484f58;

  /* Status Colors */
  --status-ok: #3fb950;
  --status-ok-bg: #0d1117;
  --status-warn: #d29922;
  --status-warn-bg: #1c1812;
  --status-error: #f85149;
  --status-error-bg: #1c1314;
  --status-info: #58a6ff;
  --status-info-bg: #0c1419;

  /* Accent Colors */
  --accent-primary: #58a6ff;
  --accent-secondary: #8b949e;
  --accent-hover: #79c0ff;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 14px;
  overflow-x: hidden;
}

/* ============================================
   TOP BAR
   ============================================ */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.top-bar__left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.top-bar__logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.top-bar__logo-dot {
  color: var(--accent-primary);
}

.top-bar__badges {
  display: flex;
  gap: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.badge:hover {
  border-color: var(--border-secondary);
  background: var(--bg-card-hover);
}

.badge__status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-ok);
  animation: pulse 2s ease-in-out infinite;
}

.badge__status--warn {
  background: var(--status-warn);
}

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

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

.top-bar__actions {
  display: flex;
  gap: 8px;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-secondary);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn:active {
  transform: translateY(0);
}

.btn--primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn--icon {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
}

/* ============================================
   GRID LAYOUT
   ============================================ */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
  padding: 20px;
  max-width: 1920px;
  margin: 0 auto;
}

@media (min-width: 1400px) {
  .dashboard-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  padding: 16px;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.card:hover {
  border-color: var(--border-secondary);
  box-shadow: var(--shadow-md);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-primary);
}

.card__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.2px;
}

.card__action {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.card__action:hover {
  color: var(--accent-primary);
}

.card__body {
  color: var(--text-secondary);
}

.card--large {
  grid-column: span 2;
}

/* ============================================
   METRICS & KPIs
   ============================================ */

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-primary);
}

.metric-row:last-child {
  border-bottom: none;
}

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

.metric__value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.metric__value--small {
  font-size: 14px;
}

.metric__trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  font-size: 12px;
  color: var(--status-ok);
}

.metric__trend--down {
  color: var(--status-error);
}

/* ============================================
   STATUS INDICATORS
   ============================================ */

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-ok);
  margin-right: 8px;
}

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

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

/* ============================================
   LOGS DISPLAY
   ============================================ */

.logs-container {
  height: 220px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 12px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.5;
}

.logs-container::-webkit-scrollbar {
  width: 8px;
}

.logs-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.logs-container::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 4px;
}

.logs-container::-webkit-scrollbar-thumb:hover {
  background: var(--border-accent);
}

.log-entry {
  padding: 4px 0;
  color: var(--text-muted);
}

.log-entry__time {
  color: var(--text-dim);
  margin-right: 8px;
}

.log-entry__level--error {
  color: var(--status-error);
}

.log-entry__level--warn {
  color: var(--status-warn);
}

.log-entry__level--info {
  color: var(--status-info);
}

/* ============================================
   PHASE SELECTOR
   ============================================ */

.phase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 6px;
}

.phase-dot {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.phase-dot:hover {
  border-color: var(--border-accent);
  color: var(--text-secondary);
}

.phase-dot--active {
  background: var(--status-ok-bg);
  border-color: var(--status-ok);
  color: var(--status-ok);
}

.phase-dot--warn {
  background: var(--status-warn-bg);
  border-color: var(--status-warn);
  color: var(--status-warn);
}

.phase-dot--error {
  background: var(--status-error-bg);
  border-color: var(--status-error);
  color: var(--status-error);
}

/* ============================================
   STRATEGY CHEST
   ============================================ */

.strategy-chest {
  min-height: 400px;
}

.upload-zone {
  border: 2px dashed var(--border-secondary);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  background: var(--bg-secondary);
  transition: all var(--transition-base);
  cursor: pointer;
  margin-bottom: 16px;
}

.upload-zone:hover,
.upload-zone--dragging {
  border-color: var(--accent-primary);
  background: var(--bg-tertiary);
}

.upload-zone__icon {
  font-size: 48px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.upload-zone__text {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.upload-zone__hint {
  font-size: 12px;
  color: var(--text-muted);
}

.upload-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  margin-bottom: 8px;
}

.upload-item__icon {
  font-size: 20px;
}

.upload-item__info {
  flex: 1;
  min-width: 0;
}

.upload-item__name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item__meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.upload-item__status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--status-ok-bg);
  color: var(--status-ok);
}

.upload-item__status--uploading {
  background: var(--status-info-bg);
  color: var(--status-info);
}

.upload-item__status--error {
  background: var(--status-error-bg);
  color: var(--status-error);
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent-primary);
  transition: width var(--transition-base);
}

.analyst-notes {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  margin-top: 16px;
}

.analyst-notes:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.strategy-table {
  width: 100%;
  margin-top: 16px;
  border-collapse: collapse;
}

.strategy-table th {
  text-align: left;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-primary);
}

.strategy-table td {
  padding: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-primary);
}

.strategy-table tr:hover td {
  background: var(--bg-secondary);
}

.prob-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.prob-badge--high {
  background: var(--status-ok-bg);
  color: var(--status-ok);
}

.prob-badge--medium {
  background: var(--status-warn-bg);
  color: var(--status-warn);
}

.prob-badge--low {
  background: var(--status-error-bg);
  color: var(--status-error);
}

/* ============================================
   ALERTS & TOASTS
   ============================================ */

.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  min-width: 300px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast--error {
  border-color: var(--status-error);
}

.toast--warn {
  border-color: var(--status-warn);
}

.toast--success {
  border-color: var(--status-ok);
}

.toast__title {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

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

/* ============================================
   FOOTER
   ============================================ */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-primary);
  margin-top: 20px;
}

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

.footer__actions {
  display: flex;
  gap: 8px;
}

/* ============================================
   LOADING STATES
   ============================================ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-secondary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--status-ok); }
.text-warning { color: var(--status-warn); }
.text-error { color: var(--status-error); }

.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }

/* ============================================
   ALPACA TRADING STYLES
   ============================================ */

.badge--alpaca {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.goal-tracker {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.goal-status {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.goal-badge {
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.goal-badge--green {
  background: rgba(16, 185, 129, 0.2);
  color: var(--status-ok);
}

.goal-badge--yellow {
  background: rgba(245, 158, 11, 0.2);
  color: var(--status-warning);
}

.goal-badge--red {
  background: rgba(239, 68, 68, 0.2);
  color: var(--status-error);
}

.goal-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-bar {
  width: 100%;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  transition: width 0.5s ease-out;
  border-radius: 12px;
}

.progress-fill--green {
  background: linear-gradient(90deg, var(--status-ok) 0%, #34d399 100%);
}

.progress-fill--yellow {
  background: linear-gradient(90deg, var(--status-warning) 0%, #fbbf24 100%);
}

.progress-fill--red {
  background: linear-gradient(90deg, var(--status-error) 0%, #f87171 100%);
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.progress-labels span:nth-child(2) {
  font-weight: 600;
  color: var(--text-primary);
}

.goal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border-secondary);
}

.goal-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.goal-stat__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.goal-stat__value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-ok {
  color: var(--status-ok);
}

.status-error {
  color: var(--status-error);
}

.status-warning {
  color: var(--status-warning);
}

#alpaca-trades-table tbody tr:hover {
  background: var(--bg-hover);
}

#alpaca-trades-table tbody td {
  padding: 8px 12px;
}

#alpaca-trades-table tbody td strong {
  color: var(--text-primary);
}
