/* MicroSenses Mini — Core Styles */
:root {
  --bg: #060612;
  --surface: #0d0d1a;
  --surface-2: #151528;
  --accent: #00e5ff;
  --accent-dim: rgba(0, 229, 255, 0.15);
  --text: #e0e0e0;
  --text-dim: #8888aa;
  --danger: #f44336;
  --warning: #ff9800;
  --success: #4caf50;
  --white: #ffffff;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Panels */
.panel { display: none; min-height: 100vh; padding: 1rem; }
.panel.active { display: block; }

/* Landing Panel */
#panel-landing {
  text-align: center;
  padding: 2rem 1rem;
}
#panel-landing h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--accent), #7c4dff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}
#panel-landing .subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 0.875rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--accent-dim); }

/* Auth Panel */
#panel-auth {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
#panel-auth.active { display: flex; }
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-card h2 {
  color: var(--accent);
  margin-bottom: 1.5rem;
  text-align: center;
}
.auth-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
}
#auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}
.auth-toggle {
  text-align: center;
  margin-top: 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.auth-toggle a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.auth-divider {
  display: flex;
  align-items: center;
  margin: 1.25rem 0;
  color: var(--text-dim);
  font-size: 0.8rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.1);
}
.auth-divider::before { margin-right: 0.75rem; }
.auth-divider::after { margin-left: 0.75rem; }
.btn-google {
  width: 100%;
  padding: 0.75rem;
  background: var(--white);
  color: #333;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* App Panel — Scanner */
#panel-app { padding: 1rem; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1rem;
}
.app-header h1 {
  font-size: 1.25rem;
  color: var(--accent);
}
.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
#credit-badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.scan-area {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  max-height: 60vh;
  margin-bottom: 1rem;
}
#scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
#scan-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}

.scan-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.duration-selector {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}
.duration-btn {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.duration-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
.scan-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  display: none;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}
.scan-timer {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  display: none;
}
#scan-error {
  color: var(--danger);
  text-align: center;
  font-size: 0.9rem;
  padding: 0.5rem;
  display: none;
}

/* Upload area */
.upload-section {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 0.5rem;
}
.upload-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px dashed rgba(255,255,255,0.2);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: center;
}
.upload-btn:hover { border-color: var(--accent); }

/* Results Panel */
#panel-results { padding: 1rem; }
.disclaimer-banner {
  background: rgba(255, 152, 0, 0.15);
  border: 1px solid var(--warning);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--warning);
  line-height: 1.4;
}
.image-analysis-banner {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-align: center;
}
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.result-card h3 {
  color: var(--accent);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}
.analysis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.analysis-table th, .analysis-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.analysis-table th {
  color: var(--text-dim);
  font-weight: 500;
}

.chart-container {
  position: relative;
  width: 100%;
  max-width: 350px;
  margin: 0 auto;
}
.chart-container canvas {
  width: 100% !important;
  height: auto !important;
}

.readiness-gauge {
  text-align: center;
  padding: 1rem;
}
.readiness-score {
  font-size: 3rem;
  font-weight: 800;
}
.readiness-label {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.fatigue-bar {
  height: 12px;
  background: var(--surface-2);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.fatigue-bar .fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
}

.results-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* History Panel */
#panel-history {
  position: fixed;
  top: 0; right: -320px;
  width: 320px;
  height: 100vh;
  background: var(--surface);
  box-shadow: -4px 0 24px rgba(0,0,0,0.5);
  transition: right 0.3s ease;
  z-index: 100;
  overflow-y: auto;
  padding: 1rem;
}
#panel-history.open { right: 0; }
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.history-header h2 { font-size: 1.1rem; color: var(--accent); }
.history-close {
  background: none; border: none;
  color: var(--text-dim); font-size: 1.5rem;
  cursor: pointer;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.2s;
}
.history-item:hover { background: rgba(0, 229, 255, 0.08); }
.history-icon { font-size: 1.25rem; }
.history-info { flex: 1; }
.history-score { font-weight: 600; }
.history-date { font-size: 0.75rem; color: var(--text-dim); }
.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { color: var(--accent); margin-bottom: 1rem; }

/* BIPA Modal */
.bipa-text {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1rem;
}
.bipa-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.bipa-checkbox input[type="checkbox"] {
  margin-top: 0.2rem;
  accent-color: var(--accent);
}
.bipa-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Paywall Modal */
.pricing-grid {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.pricing-card {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pricing-card .price {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}
.pricing-card .credits {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 300;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Footer */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1.6;
}
.footer a { color: var(--accent); text-decoration: none; }

/* Offline Banner */
.offline-banner {
  display: none;
  background: var(--warning);
  color: var(--bg);
  text-align: center;
  padding: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Print */
@media print {
  body { background: white; color: black; }
  .app-header, .scan-controls, .upload-section, .results-actions,
  .footer, #panel-history, .modal-overlay, .toast, .offline-banner { display: none !important; }
  .panel { padding: 0; }
  .result-card { box-shadow: none; border: 1px solid #ddd; }
}

/* Responsive */
@media (min-width: 768px) {
  .results-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 2.5rem; }
  #panel-landing h1 { font-size: 3.5rem; }
}

/* AdSense container */
.adsense-container {
  margin: 1rem 0;
  text-align: center;
  min-height: 100px;
}
