@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #8b5cf6;
  --primary-glow: rgba(139, 92, 246, 0.5);
  --secondary: #3b82f6;
  --accent: #10b981;
  --bg-dark: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.7);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', sans-serif;
}

body {
  background: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.15) 0, transparent 50%),
    radial-gradient(at 100% 0%, rgba(59, 130, 246, 0.15) 0, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
}

.container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

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

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

header p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Glass Card Style */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: var(--glass-shadow);
  transition: var(--transition);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-4px);
}

/* Dashboard Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-label {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
}

.stat-value.balance { color: var(--accent); }
.stat-value.spent { color: var(--primary); }
.stat-value.initial { color: var(--secondary); }

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-weight: 500;
  color: var(--text-muted);
}

input[type="number"], input[type="text"], input[type="password"] {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  color: white;
  font-size: 1rem;
  outline: none;
  transition: var(--transition);
  width: 100%;
}

.input-with-status {
  position: relative;
  display: flex;
  align-items: center;
}

.status-badge {
  position: absolute;
  right: 0.75rem;
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.active {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.inactive {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.1);
}

.btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px 0 var(--primary-glow);
}

.btn:hover {
  filter: brightness(1.1);
  transform: scale(1.02);
}

.btn:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

/* Navigation */
.main-nav {
  display: flex;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 0.5rem;
  gap: 0.5rem;
  margin-bottom: 2rem;
  position: sticky;
  top: 1rem;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 500;
  transition: var(--transition);
}

.nav-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}

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

/* Views */
.view {
  display: none;
  flex-direction: column;
  gap: 2rem;
  animation: fadeIn 0.4s ease-out;
}

.view.active {
  display: flex;
}

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

/* Upload Area */
.upload-options {
  display: flex;
  gap: 1rem;
}

.upload-area {
  border: 2px dashed var(--glass-border);
  border-radius: 16px;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
}

.upload-area:hover {
  border-color: var(--primary);
  background: rgba(139, 92, 246, 0.05);
}

.upload-area input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-area span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Camera Modal */
.camera-modal {
  position: fixed;
  inset: 0;
  background: #000;
  display: none;
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.camera-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-controls {
  position: absolute;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 2rem;
}

.camera-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.camera-btn.primary {
  width: 80px;
  height: 80px;
  background: white;
  padding: 6px;
}

.camera-btn.primary .capture-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #000;
  background: white;
}

.camera-btn.secondary {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  color: white;
}

.camera-btn:hover {
  transform: scale(1.1);
}

.camera-btn:active {
  transform: scale(0.9);
}

/* Items List */
.items-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.receipt-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  animation: slideIn 0.3s ease-out;
}

.item-info {
  display: flex;
  flex-direction: column;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.item-name {
  font-weight: 600;
}

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

.item-price {
  font-weight: 700;
  color: var(--primary);
}

.delete-btn {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  z-index: 10;
}

.delete-btn:hover {
  background: #ef4444;
  color: white;
  transform: scale(1.1);
}

.delete-btn:active {
  transform: scale(0.9);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(139, 92, 246, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* No API Key Banner */
.no-api-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  flex-wrap: wrap;
}

.banner-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 140px;
}

.banner-text strong {
  color: var(--text-main);
  font-size: 0.9rem;
}

.banner-text span {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.btn-banner-cta {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-banner-cta:hover {
  filter: brightness(1.15);
  transform: scale(1.03);
}

/* Manual Entry Section */
.manual-entry-section {
  margin-top: 1rem;
  border-top: 1px solid var(--glass-border);
  padding-top: 1rem;
}

.manual-grid {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Settings helpers */
.setting-description {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.setting-description strong {
  color: var(--text-main);
}

/* API Setup Steps */
.api-steps {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.api-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Toast Notification */
#app-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: rgba(30, 41, 59, 0.97);
  color: var(--text-main);
  padding: 0.85rem 1.5rem;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 2000;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90vw;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: var(--glass-shadow);
}

#app-toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 600px) {
  header h1 { font-size: 2rem; }
  .card { padding: 1.5rem; }
  .stat-value { font-size: 1.5rem; }
  .upload-options { flex-direction: column; }
  .no-api-banner { flex-direction: column; text-align: center; }
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 2rem 1rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.app-footer a:hover {
  color: #fff;
  text-decoration: underline;
}

/* Animazione per suggerire il prossimo passo */
.pulse-glow {
  animation: pulseGlow 1.5s infinite;
}

@keyframes pulseGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    transform: scale(1);
  }
}
