:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-surface: rgba(17, 24, 39, 0.7);
  --bg-surface-hover: rgba(31, 41, 55, 0.8);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-bright: rgba(255, 255, 255, 0.16);
  --border-accent: rgba(99, 102, 241, 0.3);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-subtle: #6b7280;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  
  --accent: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.25);
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --cyan: #38bdf8;
  --rose: #f43f5e;
  --emerald: #34d399;
  --amber: #fbbf24;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.2);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body.dark-theme {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(6, 182, 212, 0.10) 0px, transparent 50%),
    radial-gradient(at 50% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Glass Card */
.glass-card {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  transition: var(--transition);
}

.glass-card:hover {
  border-color: var(--border-glass-bright);
}

/* Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-badge {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--primary-glow);
}

.brand-icon {
  width: 26px;
  height: 26px;
  color: #fff;
}

.brand-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.gradient-text {
  background: linear-gradient(135deg, #818cf8, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4338ca);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass-bright);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-accent {
  background: linear-gradient(135deg, #0891b2, #0284c7);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #06b6d4, #0369a1);
}

.btn-outline {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
}

.btn-outline:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.6);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* Sections */
.section-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-icon {
  width: 28px;
  height: 28px;
  color: #818cf8;
}

.section-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.input-controls {
  display: flex;
  gap: 10px;
}

/* Input Layout */
.input-layout {
  display: block;
  width: 100%;
}

.dropzone-box {
  border: 2px dashed rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-md);
  background: rgba(17, 24, 39, 0.4);
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  width: 100%;
}

.dropzone-box:hover, .dropzone-box.drag-over {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  transform: translateY(-2px);
}

.dropzone-box.has-file {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.05);
}

.loaded-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  color: #6ee7b7;
  font-weight: 500;
  margin-top: 6px;
}

.loaded-file-chip svg {
  width: 18px;
  height: 18px;
  color: #34d399;
}

.hidden-file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  width: 44px;
  height: 44px;
  color: #818cf8;
}

.dropzone-text {
  font-size: 1rem;
  color: var(--text-main);
}

.highlight {
  color: #818cf8;
  font-weight: 600;
  text-decoration: underline;
}

.file-format-note {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.run-action-bar {
  display: flex;
  align-items: center;
  gap: 20px;
}

.processing-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: #a5b4fc;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(99, 102, 241, 0.3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.kpi-card {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-icon {
  width: 22px;
  height: 22px;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
}

.kpi-subtext {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.highlight-glow {
  border-color: rgba(245, 158, 11, 0.4);
  box-shadow: 0 0 25px rgba(245, 158, 11, 0.15);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 24px;
}

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

.chart-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.card-header h3 svg {
  width: 18px;
  height: 18px;
  color: #818cf8;
}

.chart-wrapper {
  position: relative;
  height: 250px;
  width: 100%;
}

/* Table Section */
.table-section {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass-bright);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  width: 240px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-box input {
  background: transparent;
  border: none;
  color: var(--text-main);
  outline: none;
  font-size: 0.85rem;
  width: 100%;
}

.select-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass-bright);
  border-radius: var(--radius-md);
  color: var(--text-main);
  padding: 6px 12px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.select-input option {
  background: var(--bg-secondary);
  color: var(--text-main);
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  padding: 12px 14px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-glass-bright);
  cursor: pointer;
  user-select: none;
}

.data-table th svg {
  width: 14px;
  height: 14px;
  display: inline-block;
  vertical-align: middle;
  opacity: 0.5;
}

.data-table th:hover svg {
  opacity: 1;
}

.data-table td {
  padding: 14px;
  border-bottom: 1px solid var(--border-glass);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.text-right {
  text-align: right;
}

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

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-subtle {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.rate-badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  display: inline-block;
}

.rate-standard {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.rate-high {
  background: rgba(244, 63, 94, 0.18);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

.rate-low {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-sm {
  max-width: 480px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-glass-bright);
  padding-bottom: 14px;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-badge-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #818cf8;
}

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

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border-glass);
  padding-top: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.text-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass-bright);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  outline: none;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.auth-status-note {
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* Modal breakdown components */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.breakdown-stat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 12px;
}

.breakdown-stat .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.breakdown-stat .val {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 4px;
}

.items-list-box {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 14px;
}

.item-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.formula-callout {
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: #c7d2fe;
}

/* Utility Helpers */
.hidden { display: none !important; }
.hidden-fade {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  display: none;
}
.hidden-fade.show {
  opacity: 1;
  pointer-events: auto;
  display: block;
}

.text-cyan { color: var(--cyan); }
.text-amber { color: var(--amber); }
.text-rose { color: var(--rose); }
.text-emerald { color: var(--emerald); }
