:root {
  --bg-primary: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --border-color: #374151;
  --border-subtle: #242f3e;
  
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-subtle: #6b7280;
  
  --color-inflow: #22c55e;
  --color-inflow-header: #15803d;
  --color-inflow-bg: rgba(34, 197, 94, 0.12);
  
  --color-outflow: #ef4444;
  --color-outflow-header: #b91c1c;
  --color-outflow-bg: rgba(239, 68, 68, 0.12);
  
  --color-brand: #3b82f6;
  --color-brand-hover: #2563eb;
  
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.12);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

body.light-theme {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #f1f5f9;
  --bg-card-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --color-inflow-header: #16a34a;
  --color-outflow-header: #dc2626;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 768px) {
  .app-container {
    padding: 1.5rem 2rem;
  }
}

/* Header */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

@media (min-width: 900px) {
  .app-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }
}

.kpi-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.kpi-value {
  font-size: 1.2rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.kpi-footnote {
  font-size: 0.7rem;
  margin-top: 0.35rem;
  color: var(--text-muted);
}

/* Layer & View Controls */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.layer-switch-group {
  display: flex;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  gap: 0.25rem;
}

.layer-btn {
  padding: 0.4rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.layer-btn.active {
  background-color: var(--color-brand);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

/* Executive Scorecard Panel */
.scorecard-panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  animation: fadeIn 0.2s ease-out;
}

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

.scorecard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.scorecard-grid-4 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .scorecard-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

.scorecard-col {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  text-align: center;
}

.sc-tag-sub {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #ef4444;
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 0.1rem 0.5rem;
  border-radius: 9999px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.sc-row-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 0.75rem;
}

.sc-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.sc-number {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sc-pct-box {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 2px dashed var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sc-pct-value {
  font-size: 1.5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
}

.sc-pct-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.btn-primary {
  background-color: var(--color-inflow);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: #16a34a;
}

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

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.7rem;
}

/* Horizontal Matrix Table (Company Format) */
.matrix-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.matrix-scroll-wrapper {
  overflow-x: auto;
  max-height: 650px;
}

.company-matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

.company-matrix-table th {
  padding: 0.6rem 0.85rem;
  font-weight: 700;
  background-color: var(--bg-card);
  border-bottom: 2px solid var(--border-color);
  border-right: 1px solid var(--border-subtle);
  white-space: nowrap;
  font-family: var(--font-sans);
  position: sticky;
  top: 0;
  z-index: 15;
}

.company-matrix-table td {
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.company-matrix-table tr:hover td {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Row Highlights Matching User's Image */
.row-inflow-header td {
  background-color: var(--color-inflow-header) !important;
  color: #ffffff !important;
  font-family: var(--font-sans);
  font-weight: 800;
  border-bottom: 1px solid #166534;
}

.row-outflow-header td {
  background-color: var(--color-outflow-header) !important;
  color: #ffffff !important;
  font-family: var(--font-sans);
  font-weight: 800;
  border-bottom: 1px solid #991b1b;
}

.row-group-sub td {
  background-color: var(--bg-card);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.72rem;
}

.row-highlight td {
  background-color: rgba(255, 255, 255, 0.04);
  font-weight: 800;
}

.text-inflow {
  color: var(--color-inflow);
}
.text-outflow {
  color: var(--color-outflow);
}
.text-subtle {
  color: var(--text-subtle);
}

.today-col {
  background-color: rgba(245, 158, 11, 0.15) !important;
  border-left: 2px solid var(--color-warning) !important;
  border-right: 2px solid var(--color-warning) !important;
}

.text-right {
  text-align: right;
}
.text-center {
  text-align: center;
}
.cursor-pointer {
  cursor: pointer;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}
.badge-closed {
  background-color: var(--color-inflow-bg);
  color: var(--color-inflow);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.badge-pending {
  background-color: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-planned {
  background-color: var(--border-subtle);
  color: var(--text-muted);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background-color: var(--bg-surface);
  z-index: 5;
}

.modal-body {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  background-color: var(--bg-surface);
  z-index: 5;
}

.modal-section-title {
  font-size: 0.75rem;
  font-weight: 800;
  margin-top: 0.5rem;
  margin-bottom: 0.35rem;
  letter-spacing: 0.03em;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input,
.form-select {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  color: var(--text-main);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--color-brand);
}

/* Mobile Bottom Nav */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0.5rem 1rem;
  z-index: 50;
}

@media (min-width: 768px) {
  .mobile-bottom-nav {
    display: none;
  }
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
}

.bottom-nav-item.active {
  color: var(--color-brand);
}

/* Floating Action Button (FAB) */
.fab-btn {
  position: fixed;
  bottom: 75px;
  right: 1.25rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border: none;
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 45;
}

@media (min-width: 768px) {
  .fab-btn {
    bottom: 2rem;
    right: 2rem;
  }
}

/* Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  transform: translateY(-20px);
  opacity: 0;
  transition: all 0.25s ease;
  pointer-events: auto;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.toast-success {
  border-color: var(--color-inflow);
}
.toast.toast-warning {
  border-color: var(--color-warning);
}
.toast.toast-danger {
  border-color: var(--color-outflow);
}
