@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

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

:root {
  /* Modern color palette */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;

  /* Neutral colors */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;

  /* Text */
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;

  /* Borders */
  --border-color: #e5e7eb;
  --border-hover: #d1d5db;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Sidebar specific */
  --sidebar-bg: #1f2937;
  --sidebar-text: #e5e7eb;
  --sidebar-hover: #374151;
  --sidebar-active: #4f46e5;
}

/* Dark Theme */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: #312e81;
  --success: #34d399;
  --success-light: #064e3b;
  --danger: #f87171;
  --danger-light: #7f1d1d;
  --warning: #fbbf24;
  --warning-light: #78350f;

  --gray-50: #111827;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-300: #4b5563;
  --gray-400: #6b7280;
  --gray-500: #9ca3af;
  --gray-600: #d1d5db;
  --gray-700: #e5e7eb;
  --gray-800: #f3f4f6;
  --gray-900: #f9fafb;

  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-tertiary: #374151;

  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-tertiary: #9ca3af;

  --border-color: #374151;
  --border-hover: #4b5563;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);

  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-hover: #1e293b;
  --sidebar-active: #6366f1;
}

/* Dark Theme Element Overrides */
[data-theme="dark"] .stat-card {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="dark"] .stat-card .stat-value,
[data-theme="dark"] .stat-card p {
  color: var(--text-primary);
}

[data-theme="dark"] .stat-card h3 {
  color: var(--text-secondary);
}

[data-theme="dark"] .stat-card small {
  color: var(--text-tertiary);
}

[data-theme="dark"] .upcoming-payments-section,
[data-theme="dark"] .dashboard-section,
[data-theme="dark"] .content-card,
[data-theme="dark"] .card {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="dark"] .entity-table,
[data-theme="dark"] table {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .entity-table th,
[data-theme="dark"] table th {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .entity-table td,
[data-theme="dark"] table td {
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .entity-table tbody tr:hover,
[data-theme="dark"] table tbody tr:hover {
  background: var(--bg-secondary);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  border-color: var(--primary);
}

[data-theme="dark"] .modal-content {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

[data-theme="dark"] .modal-content h2 {
  color: var(--text-primary);
}

[data-theme="dark"] label {
  color: var(--text-secondary);
}

[data-theme="dark"] .btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .btn-secondary:hover {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .section-header h2,
[data-theme="dark"] .dashboard-header h2 {
  color: var(--text-primary);
}

[data-theme="dark"] .filter-dropdown {
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

[data-theme="dark"] .filter-dropdown-input {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-menu {
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-item {
  color: var(--text-primary);
}

[data-theme="dark"] .dropdown-item:hover {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .entity-card {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="dark"] .entity-card-label {
  color: var(--text-secondary);
}

[data-theme="dark"] .entity-card-value {
  color: var(--text-primary);
}

[data-theme="dark"] .detail-grid {
  background: var(--bg-secondary);
}

[data-theme="dark"] .detail-label {
  color: var(--text-secondary);
}

[data-theme="dark"] .detail-value {
  color: var(--text-primary);
}

[data-theme="dark"] .pnl-summary-card {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="dark"] .pnl-summary-card .card-title {
  color: var(--text-secondary);
}

[data-theme="dark"] .pnl-summary-card .card-value {
  color: var(--text-primary);
}

[data-theme="dark"] .investments-table {
  background: var(--bg-tertiary);
}

[data-theme="dark"] .opex-grid,
[data-theme="dark"] .opex-card {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="dark"] .opex-card-header {
  color: var(--text-primary);
}

[data-theme="dark"] .date-range-picker {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  padding: 0;
}

/* ============================================
   APP LAYOUT - SIDEBAR + MAIN CONTENT
   ============================================ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--gray-900);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 1000;
  transition: width 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 60px;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 1.25rem 0.5rem;
}

.sidebar.collapsed .sidebar-nav {
  padding: 1rem 0.5rem;
}

.sidebar.collapsed .sidebar-nav .nav-btn {
  justify-content: center;
  padding: 0.875rem 0.5rem;
  font-size: 0;
}

.sidebar.collapsed .sidebar-footer {
  padding: 1rem 0.5rem;
}

.sidebar.collapsed .user-info-sidebar {
  display: none;
}

.sidebar.collapsed .btn-logout-sidebar {
  justify-content: center;
  padding: 0.875rem 0.5rem;
  font-size: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  border-bottom: 1px solid var(--gray-700);
}

.sidebar-logo {
  font-size: 1.25rem;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-logo {
  opacity: 0;
  width: 0;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: var(--gray-700);
}

.toggle-icon {
  width: 20px;
  height: 2px;
  background: var(--gray-400);
  position: relative;
  transition: all 0.3s;
}

.toggle-icon::before,
.toggle-icon::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 2px;
  background: var(--gray-400);
  left: 0;
  transition: all 0.3s;
}

.toggle-icon::before { top: -6px; }
.toggle-icon::after { top: 6px; }

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.sidebar-nav .nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  margin-bottom: 0.25rem;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  color: var(--gray-400);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  white-space: nowrap;
}

.sidebar-nav .nav-btn:hover {
  background: var(--gray-800);
  color: white;
}

.sidebar-nav .nav-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Submenu styles */
.nav-item-with-submenu {
  position: relative;
}

.nav-btn.has-submenu {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.submenu-arrow {
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.nav-item-with-submenu.open .submenu-arrow {
  transform: rotate(180deg);
}

.submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: var(--gray-800);
  border-radius: 0.5rem;
  margin: 0.25rem 0 0.25rem 0.75rem;
}

.nav-item-with-submenu.open .submenu {
  max-height: 400px;
}

.submenu-btn {
  width: 100%;
  display: block;
  padding: 0.625rem 1rem;
  background: transparent;
  border: none;
  color: var(--gray-400);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  border-left: 2px solid transparent;
}

.submenu-btn:hover {
  background: var(--gray-700);
  color: white;
  border-left-color: var(--primary);
}

.submenu-btn.active {
  background: var(--gray-700);
  color: var(--primary);
  border-left-color: var(--primary);
}

/* Hide submenu when sidebar is collapsed */
.sidebar.collapsed .submenu {
  display: none;
}

.sidebar.collapsed .submenu-arrow {
  display: none;
}

.nav-icon {
  font-size: 1.125rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.nav-text {
  overflow: hidden;
  transition: opacity 0.3s, width 0.3s;
}

.sidebar.collapsed .nav-text {
  opacity: 0;
  width: 0;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--gray-700);
}

.user-info-sidebar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--gray-400);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
}

.btn-logout-sidebar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: transparent;
  border: 1px solid var(--gray-700);
  border-radius: 0.5rem;
  color: var(--gray-400);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  white-space: nowrap;
}

.btn-logout-sidebar:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.sidebar.collapsed .btn-logout-sidebar .nav-text,
.sidebar.collapsed .user-info-sidebar .nav-text {
  opacity: 0;
  width: 0;
}

/* Theme Toggle */
.theme-toggle-wrapper {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.theme-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--sidebar-hover);
  border: 1px solid var(--gray-700);
  border-radius: 0.5rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--gray-600);
  border-color: var(--gray-600);
}

.theme-toggle-icon {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle-icon svg {
  width: 18px;
  height: 18px;
}

.theme-toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--gray-600);
  border-radius: 12px;
  transition: background 0.3s ease;
}

.theme-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

[data-theme="dark"] .theme-toggle-switch {
  background: var(--primary);
}

[data-theme="dark"] .theme-toggle-switch::after {
  transform: translateX(20px);
}

.sidebar.collapsed .theme-toggle {
  padding: 0.75rem;
  justify-content: center;
}

.sidebar.collapsed .theme-toggle-icon span,
.sidebar.collapsed .theme-toggle-switch {
  display: none;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
  background: var(--bg-secondary);
}

.sidebar.collapsed ~ .main-content,
body.sidebar-collapsed .main-content {
  margin-left: 70px;
}

/* Legacy container support */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--gray-900);
  margin: 0;
  letter-spacing: -0.025em;
}

/* Sections */
.section {
  display: none;
  padding: 2rem 2.5rem;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

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

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-header h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.025em;
}

.section-header div {
  display: flex;
  gap: 0.75rem;
}

/* Buttons */
.btn-primary {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.btn-secondary {
  padding: 0.75rem 1.5rem;
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

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

/* Dashboard Header with Date Filter */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.dashboard-header h2 {
  margin: 0;
}

.date-filter-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Custom Dropdown */
.custom-dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background: white;
  cursor: pointer;
  min-width: 160px;
  transition: all 0.2s;
}

.dropdown-toggle:hover {
  border-color: var(--primary);
}

.dropdown-toggle:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.dropdown-arrow {
  margin-left: auto;
  color: var(--gray-500);
  transition: transform 0.2s;
}

.custom-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.custom-dropdown.open .dropdown-toggle {
  border-color: var(--primary);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--primary);
  border-top: none;
  border-bottom-left-radius: 0.5rem;
  border-bottom-right-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
  overflow: hidden;
}

.custom-dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.dropdown-item:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
}

.dropdown-item.selected {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

.custom-date-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.custom-date-range span {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.date-input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: white;
  cursor: pointer;
}

.date-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.btn-apply-date {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-apply-date:hover {
  background: var(--primary-hover);
}

.date-range-display {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Stats Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

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

@media (max-width: 900px) {
  .dashboard-grid,
  .dashboard-grid.three-col {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 500px) {
  .dashboard-grid,
  .dashboard-grid.three-col {
    grid-template-columns: 1fr;
  }
}

.stat-card {
  background: white;
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  border-radius: 0.75rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 120px;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary);
}

.stat-card h3 {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.stat-card .stat-value,
.stat-card p {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
  letter-spacing: -0.025em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card small {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-top: auto;
}

.stat-card.highlight-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  border-color: var(--primary);
}

.stat-card.highlight-card h3 {
  color: rgba(255, 255, 255, 0.85);
}

.stat-card.highlight-card .stat-value {
  color: white;
}

.stat-card.highlight-card small {
  color: rgba(255, 255, 255, 0.75);
}

.stat-card.danger-card {
  background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
  border-color: var(--danger);
}

.stat-card.danger-card h3 {
  color: rgba(255, 255, 255, 0.85);
}

.stat-card.danger-card .stat-value {
  color: white;
}

.stat-card.danger-card small {
  color: rgba(255, 255, 255, 0.75);
}

/* Dashboard Sections */
.dashboard-sections {
  margin-top: 2rem;
}

.upcoming-payments-section {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.upcoming-payments-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.upcoming-table-container {
  overflow-x: auto;
}

.upcoming-table {
  width: 100%;
  border-collapse: collapse;
  border: none;
  box-shadow: none;
}

.upcoming-table thead {
  background: var(--gray-50);
}

.upcoming-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.upcoming-table td {
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.upcoming-table tbody tr:hover {
  background: var(--gray-50);
}

.upcoming-table tbody tr:last-child td {
  border-bottom: none;
}

.publisher-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.publisher-name {
  font-weight: 500;
  color: var(--text-primary);
}

.payment-status {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  display: inline-block;
  width: fit-content;
}

.payment-status.status-overdue {
  background: var(--danger-light);
  color: var(--danger);
}

.payment-status.status-partial {
  background: var(--warning-light);
  color: var(--warning);
}

.payment-status.status-outstanding {
  background: var(--gray-100);
  color: var(--gray-600);
}

.amount-cell {
  font-weight: 600;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}

.no-data {
  text-align: center;
  color: var(--text-tertiary);
  padding: 2rem !important;
}

/* Tables */
table {
  width: 100%;
  background: white;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

thead {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

th {
  padding: 1rem 1.5rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

td {
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: var(--bg-secondary);
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="month"],
textarea,
select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  transition: all 0.2s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Date input wrapper for full clickability */
.date-input-wrapper {
  position: relative;
  cursor: pointer;
}

.date-input-wrapper input[type="date"],
.date-input-wrapper input[type="month"] {
  cursor: pointer;
}

/* Make date and month inputs fully clickable everywhere - v3 */
input[type="date"],
input[type="month"] {
  cursor: pointer !important;
  position: relative;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  background: transparent !important;
  bottom: 0 !important;
  color: transparent !important;
  cursor: pointer !important;
  height: auto !important;
  left: 0 !important;
  position: absolute !important;
  right: 0 !important;
  top: 0 !important;
  width: auto !important;
  opacity: 0 !important;
  z-index: 2 !important;
}

/* Firefox support */
input[type="date"]::-moz-calendar-picker-indicator,
input[type="month"]::-moz-calendar-picker-indicator {
  background: transparent !important;
  bottom: 0 !important;
  color: transparent !important;
  cursor: pointer !important;
  height: auto !important;
  left: 0 !important;
  position: absolute !important;
  right: 0 !important;
  top: 0 !important;
  width: auto !important;
  opacity: 0 !important;
  z-index: 2 !important;
}

/* Ensure number inputs behave normally */
input[type="number"] {
  cursor: text !important;
  position: static !important;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  position: static !important;
  opacity: 1;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: white;
  margin: 2rem;
  padding: 2.5rem;
  border-radius: 1rem;
  width: 100%;
  max-width: 900px;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease;
}

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

.modal-content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 2rem;
  letter-spacing: -0.025em;
}

.close {
  color: var(--text-tertiary);
  float: right;
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}

.close:hover {
  color: var(--text-primary);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--gray-300);
  transition: 0.3s;
  border-radius: 28px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* Action Buttons */
.action-btn {
  padding: 0.5rem 1rem;
  margin: 0 0.25rem;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.action-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--border-hover);
}

.action-btn.edit:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.action-btn.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-light);
}

/* Activity Rows */
.activity-row {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.activity-row:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

.activity-header {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  word-break: break-word;
}

.revenue-activity-row {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Tom Select Styling */
.ts-wrapper.single .ts-control {
  background: white !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 0.5rem !important;
  padding: 0.625rem 1rem !important;
  min-height: 42px !important;
  color: var(--text-primary) !important;
  font-size: 0.875rem !important;
}

.ts-wrapper.single .ts-control input {
  color: var(--text-primary) !important;
}

.ts-wrapper.single .ts-control:focus-within {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--primary-light) !important;
}

.ts-dropdown {
  background: white !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 0.5rem !important;
  box-shadow: var(--shadow-lg) !important;
  margin-top: 0.25rem !important;
}

.ts-dropdown .option {
  padding: 0.75rem 1rem !important;
  color: var(--text-primary) !important;
  border-radius: 0.25rem !important;
  margin: 0.25rem 0.5rem !important;
  font-size: 0.875rem !important;
}

.ts-dropdown .option:hover {
  background: var(--bg-secondary) !important;
}

.ts-dropdown .option.active {
  background: var(--primary) !important;
  color: white !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 5px;
}

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

/* Report Tabs */
.report-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: -2px;
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Entity List */
.entity-list {
  display: grid;
  gap: 1.25rem;
}

/* Entity Cards */
.entity-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

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

.entity-card h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 1rem;
  word-break: break-word;
}

.entity-card-content {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.entity-card-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.875rem;
}

.entity-card-label {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 120px;
  flex-shrink: 0;
}

.entity-card-value {
  color: var(--text-primary);
  word-break: break-word;
  flex: 1;
}

.entity-card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 0;
  }

  header {
    padding: 1.5rem 1rem;
  }

  .section {
    padding: 0 1rem 1.5rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-header h2 {
    font-size: 1.25rem;
  }

  .modal-content {
    margin: 1rem;
    padding: 1.5rem;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .stat-card .stat-value,
  .stat-card p {
    font-size: 1.5rem;
  }

  .entity-card-row {
    flex-direction: column;
    gap: 0.25rem;
  }

  .entity-card-label {
    min-width: auto;
  }

  .action-btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.875rem;
  }

  th, td {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
  }
}

/* Loading State */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 2s ease-in-out infinite;
}

/* Badge Styles */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
}

/* OPEX Styles */
.opex-categories {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.opex-category-btn {
  padding: 0.625rem 1.25rem;
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  font-family: inherit;
}

.opex-category-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.opex-category-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3);
}

.opex-entry-section {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.opex-entry-section h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 1.5rem;
}

.opex-items-list {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.opex-item-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.25rem;
  display: grid;
  gap: 0.75rem;
}

.opex-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.opex-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.opex-monthly-values {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
}

.opex-month-input {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.opex-month-input label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.opex-month-input input {
  padding: 0.5rem;
  font-size: 0.875rem;
}

.opex-table-container {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  margin-top: 2rem;
}

.opex-table-container h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 1.5rem;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

#opex-consolidated-table {
  min-width: 1400px;
  margin: 0;
  border: none;
}

#opex-consolidated-table th {
  white-space: nowrap;
  background: var(--bg-secondary);
  font-size: 0.75rem;
  padding: 0.875rem 1rem;
}

#opex-consolidated-table td {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  padding: 0.875rem 1rem;
}

#opex-consolidated-table td:first-child {
  text-align: left;
  font-weight: 600;
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
}

#opex-consolidated-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--bg-secondary);
  z-index: 2;
}

#opex-consolidated-table tbody tr:hover td:first-child {
  background: var(--bg-secondary);
}

.opex-total-row td {
  font-weight: 700;
  background: var(--primary-light) !important;
  color: var(--primary);
  border-top: 2px solid var(--primary);
}

.opex-category-total-row td {
  font-weight: 600;
  background: var(--bg-tertiary) !important;
  border-top: 1px solid var(--border-hover);
}

/* Small buttons for table actions */
.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  margin: 0 3px;
  white-space: nowrap;
  display: inline-block;
}

.btn-small:hover {
  background: var(--bg-secondary);
  border-color: var(--border-hover);
}

.btn-small.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-small.btn-success:hover {
  background: #059669;
  border-color: #059669;
}

.btn-small.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

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

/* Payment button - cleaner design */
.btn-small.btn-payment {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-small.btn-payment:hover {
  background: #5568d3;
  border-color: #5568d3;
}

/* Table action cell - keep buttons on one line */
table td:last-child {
  white-space: nowrap;
}

table td {
  vertical-align: middle;
}

/* Revenue Tracker Table - Sortable and Filterable */
.revenue-tracker-table {
  overflow: visible;
}

.revenue-tracker-table thead {
  overflow: visible;
}

.revenue-tracker-table th {
  position: relative;
  overflow: visible;
}

.revenue-tracker-table .th-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.revenue-tracker-table .sortable-label {
  cursor: pointer;
  user-select: none;
  flex: 1;
  transition: color 0.2s;
}

.revenue-tracker-table .sortable-label:hover {
  color: var(--primary);
}

.revenue-tracker-table .filter-icon {
  cursor: pointer;
  font-size: 16px;
  color: var(--text-tertiary);
  padding: 0.25rem 0.375rem;
  border-radius: 4px;
  transition: all 0.2s;
  user-select: none;
  min-width: 24px;
  text-align: center;
}

.revenue-tracker-table .filter-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.revenue-tracker-table .filter-icon.active {
  color: var(--primary);
  font-weight: bold;
}

.filter-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: white;
  border: 2px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  padding: 0.75rem;
  z-index: 10000;
  width: 240px;
  box-sizing: border-box;
}

.filter-dropdown-input {
  width: 100%;
  padding: 0.5rem;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: white;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.filter-dropdown-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

/* OPEX Controls and Year Selector */
.opex-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.year-select {
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 2px solid var(--primary);
  border-radius: 0.5rem;
  background: white;
  color: var(--primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236366f1' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  min-width: 120px;
}

.year-select:hover {
  background-color: var(--primary-light);
}

.year-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* New OPEX Horizontal Table */
.opex-horizontal-table {
  min-width: 100%;
  border-collapse: collapse;
}

.opex-horizontal-table th {
  background: #1f2937 !important;
  color: #ffffff !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  padding: 14px 12px !important;
  text-align: center !important;
  white-space: nowrap;
  min-width: 80px;
  border: none !important;
}

.opex-horizontal-table th.category-col {
  text-align: left !important;
  min-width: 200px;
  position: sticky;
  left: 0;
  z-index: 12;
  background: #1f2937 !important;
}

.opex-horizontal-table th.total-col {
  background: #111827 !important;
}

.opex-horizontal-table td {
  padding: 0.875rem 0.75rem;
  text-align: right;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border-color);
}

.opex-horizontal-table td:first-child {
  text-align: left;
  font-weight: 500;
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
  border-right: 1px solid var(--border-color);
}

.opex-horizontal-table td.total-col {
  font-weight: 700;
  background: var(--bg-secondary);
}

.opex-horizontal-table tbody tr:hover td {
  background: var(--primary-light);
}

.opex-horizontal-table tbody tr:hover td:first-child {
  background: var(--primary-light);
}

.opex-horizontal-table tbody tr:hover td.total-col {
  background: #ddd8ff;
}

/* Category header row */
.opex-horizontal-table .category-header-row td {
  background: var(--bg-tertiary);
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--gray-800);
  border-top: 2px solid var(--border-color);
}

.opex-horizontal-table .category-header-row:hover td {
  background: var(--bg-tertiary);
}

/* Category subtotal row */
.opex-horizontal-table .category-subtotal-row td {
  background: var(--bg-secondary);
  font-weight: 600;
  font-style: italic;
  color: var(--gray-700);
  border-bottom: 2px solid var(--border-color);
}

.opex-horizontal-table .category-subtotal-row:hover td {
  background: var(--bg-secondary);
}

/* Total OPEX row */
.opex-horizontal-table .opex-total-row td {
  background: #e5e7eb;
  color: #1f2937;
  font-weight: 700;
  font-size: 0.9375rem;
  border-top: 2px solid #9ca3af;
}

.opex-horizontal-table .opex-total-row:hover td {
  background: #e5e7eb;
}

/* Grand total row */
.opex-horizontal-table .grand-total-row td {
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.9375rem;
  border-top: 3px solid var(--primary-hover);
}

.opex-horizontal-table .grand-total-row:hover td {
  background: var(--primary);
}

/* Editable cells */
.opex-horizontal-table td.editable {
  cursor: pointer;
  position: relative;
}

.opex-horizontal-table td.editable:hover::after {
  content: '✏️';
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  opacity: 0.5;
}

/* Media Cost row styling */
.opex-horizontal-table .media-cost-row td {
  color: var(--primary);
}

.opex-horizontal-table .media-cost-row td:first-child::before {
  content: '📺 ';
}

/* Empty value styling */
.opex-horizontal-table td.empty-value {
  color: var(--text-tertiary);
}

/* Updated table container for new design */
.opex-table-container {
  margin-top: 0;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.opex-table-container .table-wrapper {
  border-radius: 0.75rem;
  overflow-x: auto;
  overflow-y: visible;
  box-shadow: var(--shadow-md);
  background: white;
}

/* Ensure table header is visible */
.opex-horizontal-table thead {
  position: relative;
  z-index: 10;
}

.opex-horizontal-table thead tr {
  background: #1f2937 !important;
}

/* Action column for delete buttons */
.opex-horizontal-table th.action-col,
.opex-horizontal-table td.action-col {
  width: 50px;
  min-width: 50px;
  text-align: center;
  padding: 0.5rem;
}

.opex-horizontal-table td.action-col {
  background: white;
}

.opex-horizontal-table tbody tr:hover td.action-col {
  background: var(--primary-light);
}

.opex-horizontal-table .grand-total-row td.action-col,
.opex-horizontal-table .media-cost-row td.action-col {
  background: transparent;
}

.btn-delete-small {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
  transition: all 0.2s ease;
}

.btn-delete-small:hover {
  background: var(--danger);
  color: white;
}

/* Category row styling */
.opex-horizontal-table .category-row td {
  background: white;
}

.opex-horizontal-table .category-row:hover td {
  background: var(--primary-light);
}

.opex-horizontal-table .category-name-cell {
  font-weight: 500;
}

.opex-horizontal-table .amount-cell {
  font-variant-numeric: tabular-nums;
}

/* ============================================
   MEDIA COST STATUS BADGES
   ============================================ */

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

/* Full Payment - Soft Green */
.status-full-payment {
  background: #d1fae5;
  color: #065f46;
}

/* Overdue - Soft Red */
.status-overdue {
  background: #fee2e2;
  color: #991b1b;
}

/* Outstanding - Soft Yellow/Amber */
.status-outstanding {
  background: #fef3c7;
  color: #92400e;
}

/* Partially Paid - Soft Blue */
.status-partial {
  background: #dbeafe;
  color: #1e40af;
}

/* Invoice Received - Soft Purple */
.status-invoice {
  background: #ede9fe;
  color: #5b21b6;
}

/* Media Cost Table Styles */
.media-cost-table .action-buttons {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.btn-view {
  background: #e0e7ff !important;
  color: #3730a3 !important;
}

.btn-view:hover {
  background: #c7d2fe !important;
}

.btn-payment {
  background: #d1fae5 !important;
  color: #065f46 !important;
}

.btn-payment:hover {
  background: #a7f3d0 !important;
}

/* Detail Grid for View Modal */
.detail-grid {
  display: grid;
  gap: 0.75rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.detail-label {
  font-weight: 500;
  color: var(--text-secondary);
}

.detail-value {
  font-weight: 500;
  color: var(--text-primary);
}

/* Form Row for side-by-side inputs */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

/* ============================================
   P&L SECTION STYLES
   ============================================ */

.pnl-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.pnl-date-filter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Ensure P&L dropdown menu displays items vertically */
#pnl-dropdown-menu {
  display: none !important;
}

#pnl-date-dropdown.open #pnl-dropdown-menu {
  display: block !important;
}

#pnl-dropdown-menu .dropdown-item {
  display: block;
  width: 100%;
}

/* P&L Summary Cards */
.pnl-summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}

@media (max-width: 1100px) {
  .pnl-summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .pnl-summary-cards {
    grid-template-columns: 1fr;
  }
}

.pnl-card {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.pnl-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.pnl-card h4 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.pnl-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gray-900);
  margin: 0;
  letter-spacing: -0.025em;
}

.pnl-card.revenue-card {
  border-left: 4px solid var(--success);
}

.pnl-card.expense-card {
  border-left: 4px solid var(--danger);
}

.pnl-card.profit-card {
  border-left: 4px solid var(--primary);
}

.pnl-card.investment-card {
  border-left: 4px solid var(--warning);
}

/* P&L Charts Row */
.pnl-charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 1000px) {
  .pnl-charts-row {
    grid-template-columns: 1fr;
  }
}

.pnl-chart-container {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.pnl-chart-container h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1rem;
}

.pnl-chart-container canvas {
  max-height: 350px;
}

/* P&L Statement Section */
.pnl-statement-section {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.pnl-statement-section h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1rem;
}

/* P&L Table */
.pnl-table {
  min-width: 1200px;
  border-collapse: collapse;
  border: none;
}

.pnl-table th {
  background: #1f2937;
  color: white;
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.875rem 0.75rem;
  text-align: center;
  white-space: nowrap;
  min-width: 75px;
}

.pnl-table th:first-child {
  text-align: left;
  min-width: 160px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: #1f2937;
}

.pnl-table th.total-col {
  background: #111827;
  min-width: 100px;
}

.pnl-table td {
  padding: 0.875rem 0.75rem;
  text-align: right;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border-color);
}

.pnl-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
}

.pnl-table td.total-col {
  font-weight: 700;
  background: var(--bg-secondary);
}

/* P&L Row Types */
.pnl-revenue-row td {
  background: #d1fae5;
}

.pnl-revenue-row td:first-child {
  background: #d1fae5;
}

.pnl-expense-row td {
  background: #fff;
}

.pnl-subtotal-row td {
  background: #fee2e2;
  font-weight: 600;
}

.pnl-subtotal-row td:first-child {
  background: #fee2e2;
}

.pnl-profit-row td {
  background: #eef2ff;
  font-weight: 700;
  font-size: 0.875rem;
}

.pnl-profit-row td:first-child {
  background: #eef2ff;
}

/* Profit colors */
.profit-positive {
  color: #059669 !important;
}

.profit-negative {
  color: #dc2626 !important;
}

.empty-value {
  color: var(--text-tertiary);
}

/* P&L Investments Section */
.pnl-investments-section {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.pnl-investments-section h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1rem;
}

/* Investments Table */
.investments-table {
  width: 100%;
  border-collapse: collapse;
}

.investments-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
}

.investments-table td {
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.investments-table tbody tr:hover {
  background: var(--bg-secondary);
}

.investments-table .amount-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--success);
}
