:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --gradient-primary: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-dark) 100%
  );
  --gradient-success: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
  --gradient-danger: linear-gradient(
    135deg,
    var(--danger) 0%,
    var(--danger-dark) 100%
  );
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

body {
  font-family: "Inter", sans-serif;
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  background-color: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
  background-image: radial-gradient(
      at 0% 0%,
      rgba(37, 99, 235, 0.1) 0px,
      transparent 50%
    ),
    radial-gradient(at 100% 100%, rgba(34, 197, 94, 0.1) 0px, transparent 50%);
}

.container {
  background-color: white;
  padding: 2rem;
  border-radius: 1.5rem;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 1.5rem;
  background: var(--gradient-primary);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 0.75rem;
}

.calorie-tracker {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background-color: var(--gray-50);
  border-radius: 1rem;
  border: 1px solid var(--gray-200);
  transition: transform 0.2s, box-shadow 0.2s;
}

.form-group {
  margin-bottom: 1.25rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--gray-700);
}

input[type="number"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: 0.75rem;
  font-size: 1rem;
  color: var(--gray-800);
  transition: all 0.2s;
  background-color: white;
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.upload-area {
  border: 2px dashed #ccc;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background-color: #f8f9fa;
  position: relative;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-area:hover {
  border-color: #007bff;
  background-color: #f0f7ff;
}

.upload-area.highlight {
  border-color: #28a745;
  background-color: #e8f5e9;
  transform: scale(1.02);
}

.upload-area p {
  margin: 0;
  color: #666;
  font-size: 1.1em;
}

.upload-area .mobile-text {
  display: none;
}

.upload-area img {
  max-width: 100%;
  max-height: 300px;
  margin-top: 10px;
  border-radius: 4px;
  display: none;
}

#preview {
  max-width: 100%;
  margin-top: 1rem;
  display: none;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

button {
  padding: 0.875rem 1.75rem;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

button.primary {
  background: var(--gradient-primary);
  color: white;
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

button.primary:disabled {
  background: var(--gray-300);
  transform: none;
  box-shadow: none;
  cursor: not-allowed;
}

.result {
  margin-top: 2rem;
  padding: 1.5rem;
  background-color: var(--gray-50);
  border-radius: 0.75rem;
  border: 1px solid var(--gray-200);
  display: none;
}

.food-item {
  margin: 1rem 0;
  padding: 1.25rem;
  background-color: white;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.food-item p {
  margin: 0.5rem 0;
  color: var(--gray-700);
}

.food-item strong {
  color: var(--gray-900);
}

.progress-bar {
  height: 0.75rem;
  background-color: var(--gray-200);
  border-radius: 9999px;
  margin: 1rem 0;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress {
  height: 100%;
  background: var(--gradient-success);
  transition: width 0.5s ease;
}

.progress.warning {
  background: var(--gradient-danger);
}

.warning {
  color: var(--danger);
  animation: pulse 2s infinite;
}

.reset-button {
  background-color: var(--danger);
  color: white;
  margin-top: 1rem;
}

.reset-button:hover {
  background-color: var(--danger-dark);
}

.totals {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gray-200);
}

.totals p {
  margin: 0.5rem 0;
  color: var(--gray-700);
}

.totals strong {
  color: var(--gray-900);
}

@media (max-width: 640px) {
  body {
    padding: 1rem;
  }

  .container {
    padding: 1.5rem;
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .upload-area {
    padding: 2rem;
  }

  button {
    width: 100%;
  }

  .settings-button {
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .modal-content {
    padding: 1.5rem;
  }

  .modal-actions {
    flex-direction: row;
    gap: 0.75rem;
  }

  .modal-actions button {
    width: auto;
    flex: 1;
  }

  .token-input-wrapper .toggle-visibility {
    width: auto;
  }

  .history-item {
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .history-item img {
    width: 100%;
    height: 160px;
    object-fit: cover;
  }

  .history-item-content {
    width: 100%;
  }

  .history-item-title {
    font-size: 1rem;
  }

  .history-item-details {
    font-size: 0.8125rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .history-item-date {
    margin-top: 0.25rem;
  }

  .history-item-actions {
    width: 100%;
    justify-content: flex-end;
    padding-top: 0.5rem;
    border-top: 1px solid var(--gray-200);
  }

  .history-item-actions button {
    padding: 0.75rem;
  }

  .history-item-actions button svg {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* Settings Button */
.settings-button {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  background: white;
  color: var(--gray-700);
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  padding: 0;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.settings-button:hover {
  transform: rotate(30deg);
  background: var(--gradient-primary);
  color: white;
}

.settings-button svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.modal.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background-color: white;
  padding: 2.5rem;
  border-radius: 1.5rem;
  width: 90%;
  max-width: 500px;
  position: relative;
  transform: translateY(20px);
  transition: transform 0.3s;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal.active .modal-content {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.modal-header {
  text-align: center;
  margin-bottom: 2rem;
}

.modal-header h2 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-header p {
  color: var(--gray-600);
  font-size: 0.875rem;
}

.token-input-wrapper {
  position: relative;
  margin-bottom: 1rem;
}

.token-input-wrapper input {
  width: 100%;
  padding: 1rem 1.25rem;
  padding-right: 3rem;
  border: 2px solid var(--gray-200);
  border-radius: 0.75rem;
  font-size: 1rem;
  color: var(--gray-800);
  transition: all 0.2s;
  background-color: white;
  font-family: monospace;
  letter-spacing: 0.05em;
}

.token-input-wrapper input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.token-input-wrapper .toggle-visibility {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.token-input-wrapper .toggle-visibility:hover {
  color: var(--gray-700);
}

.token-input-wrapper .toggle-visibility svg {
  width: 1.25rem;
  height: 1.25rem;
}

.token-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s;
}

.token-status.valid {
  background: var(--gradient-success);
  color: white;
}

.token-status.invalid {
  background: var(--gradient-danger);
  color: white;
}

.token-status svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.token-status span {
  flex-grow: 1;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.modal-actions button {
  flex: 1;
}

.modal-actions button.secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.modal-actions button.secondary:hover {
  background: var(--gray-200);
}

.token-info {
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--gray-50);
  border-radius: 0.75rem;
  font-size: 0.875rem;
  color: var(--gray-600);
}

.token-info ul {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
}

.token-info li {
  margin: 0.25rem 0;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.history-section {
  margin-top: 2rem;
  border: 1px solid var(--gray-200);
  border-radius: 0.75rem;
  overflow: hidden;
}

.history-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--gray-50);
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.history-toggle:hover {
  background: var(--gray-100);
}

.toggle-icon {
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.3s;
}

.history-toggle.active .toggle-icon {
  transform: rotate(180deg);
}

.history-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.history-content.active {
  max-height: 500px;
  overflow-y: auto;
}

.history-list {
  padding: 1rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.history-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 0.5rem;
}

.history-item-content {
  flex: 1;
}

.history-item-title {
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 0.25rem;
}

.history-item-details {
  font-size: 0.875rem;
  color: var(--gray-600);
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.history-item-actions {
  display: flex;
  gap: 0.5rem;
}

.history-item-actions button {
  padding: 0.5rem;
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.history-item-actions button:hover {
  color: var(--gray-700);
}

.history-item-actions button.delete:hover {
  color: var(--danger);
}

.history-item-actions button svg {
  width: 1.25rem;
  height: 1.25rem;
}

.history-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--gray-500);
}

.history-empty svg {
  width: 4rem;
  height: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.history-empty p {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--gray-700);
}

.history-empty span {
  font-size: 0.875rem;
}
