/* Fynanc1fy Theme - Based on theme.css from THEME_SUMMARY.md */

/* ============================================
   CSS Variables - Color System
   ============================================ */
:root {
  /* Brand Colors - Desaturated with Grey Tones */
  --primary: #3d82a5;
  --primary-rgb: 61, 130, 165;
  --success: #68a888;
  --success-rgb: 104, 168, 136;
  --danger: #d05965;
  --danger-rgb: 208, 89, 101;
  --warning: #d9884d;
  --warning-rgb: 217, 136, 77;
  --info: #3da5ba;
  --info-rgb: 61, 165, 186;
  --secondary: #6c757d;
  --secondary-rgb: 108, 117, 125;

  /* Theme Variables - Light Mode */
  --background: #ffffff;
  --text: #212529;
  --border: #dee2e6;
  --shadow: rgba(0, 0, 0, 0.1);
  --card-background: #ffffff;
  --table-background: #ffffff;
  --modal-background: #ffffff;

  /* Navigation Shell Dimensions */
  --sidebar-width: 260px;
  --header-height: 64px;
  --sidebar-bg: var(--background);
  --header-bg: var(--background);
}

/* Dark Mode Variables */
[data-theme="dark"],
body.dark-mode {
  --background: #1a1a2e;
  --text: #eee;
  --border: #444;
  --shadow: rgba(0, 0, 0, 0.5);
  --card-background: #16213e;
  --table-background: #16213e;
  --modal-background: #16213e;

  /* Bootstrap overrides for dark mode */
  --bs-body-bg: #1a1a2e;
  --bs-body-color: #eee;
  --bs-card-bg: #16213e;
  --bs-modal-bg: #16213e;
  --bs-table-bg: #16213e;
}

/* ============================================
   Navigation Shell Styles
   ============================================ */

/* App Shell Container */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--background);
}

/* --- Sidebar Navigation --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  transition: width 0.3s ease;
  z-index: 1000;
}

.brand-section {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.nav-section {
  padding: 24px 16px;
  flex-grow: 1;
  overflow-y: auto;
}

.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--secondary);
  font-weight: 700;
  margin-bottom: 12px;
  padding-left: 12px;
}

.nav-group {
  margin-bottom: 24px;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  margin-bottom: 4px;
  transition: all 0.2s;
  font-weight: 500;
  font-size: 14px;
}

.nav-link:hover {
  background: rgba(61, 130, 165, 0.1);
  color: var(--primary);
  transform: translateX(2px);
}

.nav-link.active {
  background: rgba(61, 130, 165, 0.15);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 18px;
  margin-right: 12px;
  width: 20px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}

/* --- User Profile Section --- */
.user-section {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--info));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
}

.user-info {
  flex-grow: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: block;
}

.user-role {
  font-size: 12px;
  color: var(--secondary);
  display: block;
}

/* --- Main Content Area --- */
.main-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-gray, #f7f9fb);
}

/* --- Top Header --- */
.top-header {
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  flex-shrink: 0;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--secondary);
}

.breadcrumb-item {
  color: var(--secondary);
  text-decoration: none;
}

.breadcrumb-item.active {
  color: var(--text);
  font-weight: 600;
}

.breadcrumb-separator {
  color: var(--secondary);
  font-size: 12px;
}

.header-actions {
  display: flex;
  gap: 16px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(0,0,0,0.05);
  color: var(--primary);
}

/* --- Content Viewport --- */
.content-viewport {
  flex-grow: 1;
  overflow-y: auto;
  padding: 32px;
  position: relative;
}

/* ============================================
   Performance Optimizations
   ============================================ */
.watchlist-table,
.dash-ag-grid {
  will-change: transform;
  transform: translateZ(0);
  -webkit-font-smoothing: antialiased;
}

/* ============================================
   Global Transitions
   ============================================ */
* {
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   Base Styles
   ============================================ */
body {
  background-color: var(--background);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
}

/* Dark mode body styles */
body.dark-mode {
  background-color: #1a1a2e !important;
  color: #eee !important;
}

/* Light mode body styles */
body.light-mode {
  background-color: #ffffff !important;
  color: #212529 !important;
}

/* ============================================
   Dashboard Grid Layout
   ============================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ============================================
   KPI Cards
   ============================================ */
.kpi-card,
.card {
  background-color: var(--card-background) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s;
}

/* Card body text color */
.card-body {
  color: var(--text) !important;
}

.kpi-card:hover,
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px var(--shadow);
  cursor: pointer;
}

/* KPI Card Text Styling */
.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--secondary) !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text) !important;
  line-height: 1.2;
}

.kpi-change {
  font-size: 0.75rem;
  color: var(--secondary) !important;
  margin-top: 0.25rem;
}

/* KPI Grid Layout */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

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

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

  .kpi-value {
    font-size: 1.25rem;
  }
}

/* ============================================
   Data Tables - AG Grid Specific
   ============================================ */
.dash-ag-grid,
.ag-theme-bootstrap,
.dash-table-container {
  background-color: var(--table-background);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* AG Grid Dark Mode Support */
body.dark-mode .ag-theme-bootstrap,
[data-theme="dark"] .ag-theme-bootstrap {
  --ag-background-color: var(--table-background);
  --ag-foreground-color: var(--text);
  --ag-header-background-color: var(--card-background);
  --ag-odd-row-background-color: rgba(255, 255, 255, 0.03);
  --ag-row-hover-color: rgba(61, 130, 165, 0.1);
  --ag-border-color: var(--border);
}

/* AG Grid Row Hover */
.ag-theme-bootstrap .ag-row-hover {
  background-color: rgba(61, 130, 165, 0.1);
}

/* Table Cell Transitions */
.dash-cell,
.ag-cell {
  transition: background-color 0.2s;
}

/* ============================================
   Chart Containers
   ============================================ */
.chart-container {
  background-color: var(--card-background);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 4px var(--shadow);
}

/* ============================================
   Buttons
   ============================================ */
.btn-custom,
.btn {
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s;
  padding: 0.5rem 1rem;
}

.btn-custom:hover,
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow);
}

/* Primary Button Styling */
.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: #2e6a8a;
  border-color: #2e6a8a;
}

/* Success Button */
.btn-success {
  background-color: var(--success);
  border-color: var(--success);
  color: white;
}

.btn-success:hover {
  background-color: #5a9175;
  border-color: #5a9175;
}

/* Danger Button */
.btn-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: white;
}

.btn-danger:hover {
  background-color: #b84751;
  border-color: #b84751;
}

/* ============================================
   Modals
   ============================================ */
.modal-content {
  background-color: var(--modal-background) !important;
  border: none;
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
}

.modal-header {
  background: linear-gradient(135deg, var(--primary), var(--info));
  color: white;
  border-bottom: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 1rem 1.5rem;
}

.modal-header.gradient-primary {
  background: linear-gradient(135deg, var(--primary), var(--info)) !important;
  color: white !important;
}

.modal-body {
  padding: 1.5rem;
  color: var(--text) !important;
  background-color: var(--modal-background) !important;
}

.modal-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  background-color: var(--modal-background) !important;
}

/* ============================================
   Tooltips
   ============================================ */
.tooltip {
  background-color: var(--card-background);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.875rem;
  box-shadow: 0 2px 8px var(--shadow);
}

/* ============================================
   Alerts
   ============================================ */
.alert {
  border-radius: 8px;
  border: none;
  box-shadow: 0 2px 4px var(--shadow);
}

.alert-success {
  background-color: rgba(104, 168, 136, 0.15);
  color: var(--success);
  border-left: 4px solid var(--success);
}

.alert-danger {
  background-color: rgba(208, 89, 101, 0.15);
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

.alert-warning {
  background-color: rgba(217, 136, 77, 0.15);
  color: var(--warning);
  border-left: 4px solid var(--warning);
}

.alert-info {
  background-color: rgba(61, 165, 186, 0.15);
  color: var(--info);
  border-left: 4px solid var(--info);
}

/* ============================================
   Forms
   ============================================ */
.form-control,
.form-select {
  background-color: var(--card-background) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.3s;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 0.2rem rgba(61, 130, 165, 0.25) !important;
  background-color: var(--card-background) !important;
  color: var(--text) !important;
}

/* Form labels */
.form-label {
  color: var(--text) !important;
}

/* ============================================
   Animations
   ============================================ */

/* Loading Spinner */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Alert Slide-In */
.alert-notification {
  animation: slideIn 0.3s ease-out;
}

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

/* Status Indicator Pulse */
.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
}

.status-indicator.online {
  background-color: var(--success);
  animation: pulse 2s infinite;
}

.status-indicator.offline {
  background-color: var(--danger);
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(104, 168, 136, 0.4);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(104, 168, 136, 0);
  }
}

/* Number Count-Up */
.number-animate {
  animation: countUp 1s ease-out;
}

@keyframes countUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Gradient Backgrounds
   ============================================ */
.gradient-primary {
  background: linear-gradient(135deg, var(--primary), var(--info));
  color: white;
}

.gradient-success {
  background: linear-gradient(135deg, #68a888, #4d7a64);
  color: white;
}

.gradient-danger {
  background: linear-gradient(135deg, #d05965, #b3424d);
  color: white;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .kpi-card,
  .card {
    padding: 1rem;
  }

  .chart-container {
    padding: 0.5rem;
  }

  /* Hide extra table columns on mobile */
  .ag-header-cell:nth-child(n+5),
  .ag-cell:nth-child(n+5) {
    display: none;
  }
}

/* Small Mobile (max-width: 576px) */
@media (max-width: 576px) {
  .dashboard-grid {
    gap: 0.5rem;
  }

  .modal-dialog {
    margin: 0.5rem;
  }

  .btn-group {
    flex-direction: column;
  }

  .btn-group .btn {
    border-radius: 6px !important;
    margin-bottom: 0.25rem;
  }
}

/* Print Media */
@media print {
  .sidebar-nav,
  .header,
  .btn,
  .btn-group,
  #refresh-interval {
    display: none;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-container,
  .kpi-card {
    page-break-inside: avoid;
  }
}

/* ============================================
   Accessibility
   ============================================ */
*:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Focus visible only for keyboard navigation */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================
   Custom Scrollbar
   ============================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background);
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ============================================
   Utility Classes
   ============================================ */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-info { color: var(--info) !important; }
.text-secondary { color: var(--secondary) !important; }

.bg-primary { background-color: var(--primary) !important; }
.bg-success { background-color: var(--success) !important; }
.bg-danger { background-color: var(--danger) !important; }
.bg-warning { background-color: var(--warning) !important; }
.bg-info { background-color: var(--info) !important; }
.bg-secondary { background-color: var(--secondary) !important; }

/* Portfolio Value Formatting */
.portfolio-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
}

/* Status Badge Styling */
.badge-status-active {
  background-color: var(--success);
  color: white;
}

.badge-status-suspended {
  background-color: var(--warning);
  color: white;
}

.badge-status-closed {
  background-color: var(--secondary);
  color: white;
}

/* Dashboard Header Styling */
.dashboard-header {
  background: linear-gradient(135deg, var(--primary), var(--info));
  color: white;
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 0;
  box-shadow: 0 4px 8px var(--shadow);
  position: relative;
}

/* Sticky Header Container */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 900;
  background-color: var(--background);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

/* Ensure navigation tabs have proper background in sticky mode */
.sticky-header #master-portfolio-navigation {
  background-color: var(--background);
  padding-top: 0.5rem;
}

/* Theme Toggle Button - KEEPING FOR BACKWARD COMPATIBILITY but overriding position for shell */
.theme-toggle {
  /* position: fixed;  <-- Removing fixed position for shell integration */
  /* top: 2rem; */
  /* right: 2rem; */
  /* z-index: 1000; */
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 0.75rem 1.5rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 8px var(--shadow);
}

.theme-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px var(--shadow);
  background-color: #2e6a8a;
}

/* Light mode specific styles */
body.light-mode {
  --background: #ffffff;
  --text: #212529;
  --border: #dee2e6;
  --shadow: rgba(0, 0, 0, 0.1);
  --card-background: #ffffff;
  --table-background: #ffffff;
  --modal-background: #ffffff;
}

body.light-mode .ag-theme-alpine-dark {
  /* Switch to light theme for AG-Grid in light mode */
  --ag-background-color: #ffffff;
  --ag-foreground-color: #212529;
  --ag-header-background-color: #f8f9fa;
  --ag-odd-row-background-color: rgba(0, 0, 0, 0.03);
  --ag-row-hover-color: rgba(61, 130, 165, 0.1);
  --ag-border-color: #dee2e6;
}

/* ============================================
   Version Badge (Git Info)
   ============================================ */
.version-info-container {
  position: absolute;
  bottom: 0.5rem;
  right: 1rem;
}

.version-badge {
  font-size: 0.7rem;
  font-family: 'Courier New', monospace;
  color: rgba(255, 255, 255, 0.8);
  padding: 0.25rem 0.5rem;
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.version-badge .bi-git {
  font-size: 0.8rem;
}

/* ============================================
   Context Navigation Styles (Added for Task 03)
   ============================================ */

/* Context Tabs Container */
.context-tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
  padding-bottom: 0;
  width: 100%;
}

/* Context Tab Item */
.context-tab {
  padding-bottom: 12px;
  color: var(--secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.context-tab:hover {
  color: var(--primary);
  text-decoration: none;
}

.context-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Fallback for disabled state */
.context-message {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--secondary);
  font-size: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  width: 100%;
}