/* ===== CSS Custom Properties (Themes) ===== */
:root {
  /* Dark theme (default) */
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d2e;
  --bg-card: #1e2235;
  --bg-card-hover: #252a40;
  --bg-input: #151829;
  --border: #2a2f45;
  --text-primary: #e8eaf0;
  --text-secondary: #9498b0;
  --text-muted: #5f6380;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --accent-glow: rgba(108, 92, 231, 0.2);
  --success: #00d68f;
  --warning: #ffaa00;
  --danger: #ff5c5c;
  --energy-color: #ffd93d;
  --transport-color: #6c5ce7;
  --food-color: #00d68f;
  --waste-color: #ff6b6b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fb;
  --bg-input: #f0f2f5;
  --border: #e0e3eb;
  --text-primary: #1a1d2e;
  --text-secondary: #5f6380;
  --text-muted: #9498b0;
  --accent: #6c5ce7;
  --accent-hover: #5a4bd6;
  --accent-glow: rgba(108, 92, 231, 0.1);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.08);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ===== Buttons ===== */
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: inline; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ===== Main Grid Layout ===== */
.main-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

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

/* ===== Section Title ===== */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
}

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* ===== Input Panel ===== */
.input-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-card {
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
}

.accordion-header:hover {
  background: var(--bg-card-hover);
}

.accordion-icon {
  font-size: 1.15rem;
}

.chevron {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform var(--transition);
}

.accordion-header.active .chevron {
  transform: rotate(-135deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.35s ease;
  padding: 0 1rem;
}

.accordion-body.open {
  max-height: 500px;
  padding: 0 1rem 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field input,
.field select {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field select {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239498b0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* ===== Results Panel ===== */
.results-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Total Card */
.total-card {
  padding: 2rem;
  text-align: center;
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
}

.total-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.total-value #totalCO2 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.total-unit {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-indicator.low {
  background: rgba(0, 214, 143, 0.12);
  color: var(--success);
}

.status-indicator.medium {
  background: rgba(255, 170, 0, 0.12);
  color: var(--warning);
}

.status-indicator.high {
  background: rgba(255, 92, 92, 0.12);
  color: var(--danger);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Breakdown Grid */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

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

.breakdown-card {
  padding: 1.2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  transition: transform var(--transition), box-shadow var(--transition);
}

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

.breakdown-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.breakdown-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.breakdown-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.breakdown-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
}

[data-category="energy"] .breakdown-value { color: var(--energy-color); }
[data-category="transport"] .breakdown-value { color: var(--transport-color); }
[data-category="food"] .breakdown-value { color: var(--food-color); }
[data-category="waste"] .breakdown-value { color: var(--waste-color); }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

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

.chart-card {
  padding: 1.25rem;
}

.chart-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.chart-card canvas {
  max-height: 260px;
}

/* AI Card */
.ai-card {
  padding: 1.5rem;
}

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

.ai-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.ai-content {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.ai-placeholder {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-style: italic;
}

.ai-content h4 {
  color: var(--text-primary);
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
}

.ai-content ul {
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.ai-content li {
  margin-bottom: 0.35rem;
}

.ai-content strong {
  color: var(--text-primary);
}

.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.ai-error {
  color: var(--danger);
  padding: 1rem;
  text-align: center;
  background: rgba(255, 92, 92, 0.08);
  border-radius: var(--radius-sm);
}

/* Export */
.export-bar {
  display: flex;
  justify-content: flex-end;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  width: 90%;
  max-width: 440px;
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
}

.modal-body {
  padding: 1.5rem;
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

.privacy-note svg {
  flex-shrink: 0;
  margin-top: 2px;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer-note {
  margin-top: 0.25rem;
  font-size: 0.72rem;
}

.footer-powered {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.footer-powered a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-powered a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ===== Utilities ===== */
::selection {
  background: var(--accent);
  color: #fff;
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

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

/* Toast notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.35s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
