:root {
  --bg-color: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.7);
  --card-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-color: #38bdf8;
  --accent-hover: #0284c7;
  --success-color: #22c55e;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --input-bg: rgba(15, 23, 42, 0.8);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* System font stack: zero CDN, zero download, instant render, works everywhere forever */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  padding: 2rem 2rem 0 2rem;
  background-image: 
    radial-gradient(circle at 15% 50%, rgba(56, 189, 248, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 85% 30%, rgba(34, 197, 94, 0.05) 0%, transparent 50%);
  display: flex;
  flex-direction: column;
}

.dashboard-container {
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  flex: 1 0 auto;
}

header {
  margin-bottom: 2rem;
  text-align: center;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(to right, var(--accent-color), var(--success-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

header p {
  color: var(--text-muted);
}

/* Tabs */
.tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.tab-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

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

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

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

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

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

/* Glassmorphism Cards */
.card {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
  will-change: transform;
}

/* Metrics Section */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metric-card {
  text-align: center;
}

.metric-title {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.metric-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
}

.metric-value.success { color: var(--success-color); }
.metric-value.accent { color: var(--accent-color); }

/* Charts Section */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card h3 {
  margin-bottom: 1rem;
  color: var(--text-main);
  font-size: 1.25rem;
  font-weight: 600;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Forms */
.form-card {
  max-width: 800px;
  margin: 0 auto;
}

.form-card h2 {
  margin-bottom: 0.5rem;
  color: var(--accent-color);
}

.form-subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

fieldset {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

legend {
  padding: 0 0.5rem;
  color: var(--accent-color);
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-group input {
  width: 100%;
  box-sizing: border-box;
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-group input:focus {
  border-color: var(--accent-color);
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s ease;
}

.btn.primary {
  background: var(--accent-color);
  color: white;
  width: 100%;
  font-size: 1.1rem;
  margin-top: 1rem;
}

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

.btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn.danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
  border: 1px solid rgba(239, 68, 68, 0.5);
}

.btn.danger:hover {
  background: rgba(239, 68, 68, 0.4);
}

/* Data Table */
.table-container {
  overflow: auto;
  margin-top: 1rem;
  max-height: 70vh; /* Virtual scroll viewport */
  position: relative;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 1rem;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

th {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--accent-color);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 4;
}

/* Sticky first two columns */
#data-table th:nth-child(1),
#data-table td:nth-child(1) {
  position: sticky;
  left: 0;
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  background-color: #1e293b; /* Match card background */
  z-index: 2;
}

#data-table th:nth-child(2),
#data-table td:nth-child(2) {
  position: sticky;
  left: 100px;
  width: 180px;
  min-width: 180px;
  max-width: 180px;
  background-color: #1e293b;
  z-index: 2;
  box-shadow: inset -1px 0 0 var(--card-border); /* Separator line */
}

#data-table th:nth-child(1),
#data-table th:nth-child(2) {
  z-index: 5; /* Above both sticky-left columns AND sticky-top header */
  background-color: #273449; /* Slightly lighter for header */
}

#data-table tbody tr:hover td:nth-child(1),
#data-table tbody tr:hover td:nth-child(2) {
  background-color: #263348; /* Match row hover state */
}

tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.btn-action {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  margin: 0 2px;
  transition: all 0.2s ease;
}

.btn-edit:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--accent-color);
}

.btn-delete:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger-color);
}

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

@media (max-width: 768px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    flex-direction: column;
    gap: 1rem;
  }
}

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

.pdf-link {
  color: var(--accent-color);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-color);
  transition: color 0.2s ease, border-bottom-color 0.2s ease;
}

.pdf-link:hover {
  color: var(--success-color);
  border-bottom-color: var(--success-color);
}

/* Dashboard Widgets Column Layout */
.dashboard-widgets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
}

/* Custom Progress Bar for ROI */
.roi-progress-bar {
  width: 100%;
  height: 12px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--card-border);
}

.roi-progress-fill {
  height: 100%;
  background: linear-gradient(to right, var(--accent-color), var(--success-color));
  border-radius: 6px;
  transition: width 0.5s ease-out;
}

/* Mini Table Dashboard Specific Styling */
.dashboard-table th {
  background-color: rgba(255, 255, 255, 0.02);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--card-border);
}

.dashboard-table td {
  padding: 0.75rem;
  font-size: 0.9rem;
}

/* Tooltip Styles */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 11px;
  font-style: italic;
  font-family: serif;
  margin-left: 6px;
  cursor: help;
  position: relative;
  vertical-align: middle;
}

.info-icon:hover {
  background-color: var(--accent-color);
  color: #fff;
}

.info-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  width: max-content;
  max-width: 250px;
  background-color: #1e293b;
  color: #fff;
  text-align: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 100;
  white-space: normal;
  line-height: 1.4;
  text-transform: none;
  pointer-events: none;
}

.info-icon::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  border-width: 4px;
  border-style: solid;
  border-color: #1e293b transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 100;
  pointer-events: none;
}

.info-icon:hover::after,
.info-icon:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Back to Top Button */
#back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  background-color: var(--accent-color);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 1000;
}

#back-to-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#back-to-top:hover {
  background-color: #0284c7;
  transform: translateY(-3px) scale(1.05);
}

/* System Status Bar (Bottom) */
.system-status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 0.8rem 1.5rem;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 2rem auto 0;
  max-width: 1400px;
  width: 100%;
}

/* Header Status Panels */
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 1rem;
}

.header-status-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
  padding-top: 0.3rem;
}

.header-status-panel.left-panel {
  align-items: flex-start;
  padding-left: 1rem;
}

.header-status-panel.right-panel {
  align-items: flex-end;
  padding-right: 1rem;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-variant-numeric: tabular-nums;
}

.status-icon {
  font-size: 0.9rem;
  opacity: 0.8;
}

.auth-status {
  color: var(--accent-color);
}
