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

:root {
  --bg-color: #f8f9fa;
  --card-bg: #ffffff;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --candy-pink: #fd79a8;
  --candy-blue: #74b9ff;
  --candy-green: #55efc4;
  --candy-yellow: #ffeaa7;
  --candy-purple: #a29bfe;
  --candy-orange: #fab1a0;
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 8px 32px rgba(116, 185, 255, 0.25);
}

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

/* Login Page */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 48px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-soft);
}

.login-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--candy-pink), #f3fe9b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e9ecef;
  border-radius: 12px;
  font-size: 16px;
  transition: all 0.3s ease;
  background: #f8f9fa;
}

.form-input:focus {
  outline: none;
  border-color: var(--candy-blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(116, 185, 255, 0.15);
}

.btn {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #8ec6ff, #9bc3fe);
  color: white;
  box-shadow: 0 4px 16px rgba(116, 185, 255, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(116, 185, 255, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.error-message {
  background: rgba(253, 121, 168, 0.1);
  color: #e84393;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 20px;
  display: none;
}

/* App Page */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 100px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  margin-bottom: 16px;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-logout {
  padding: 8px 16px;
  background: transparent;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-logout:hover {
  border-color: var(--candy-pink);
  color: var(--candy-pink);
}

/* Upload Section */
.upload-section {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-soft);
}

.upload-area {
  border: 2px dashed #dee2e6;
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--candy-blue);
  background: rgba(116, 185, 255, 0.05);
}

.upload-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, #fe8a8a, #9fdbff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-icon svg {
  width: 32px;
  height: 32px;
  stroke: white;
}

.upload-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.upload-hint {
  font-size: 12px;
  color: #adb5bd;
}

.file-input {
  display: none;
}

.camera-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 24px;
  background: linear-gradient(135deg, #ffa6c6, var(--candy-orange));
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.35s ease;
}

.camera-btn:hover {
  transform: translateY(-2px);
}

/* Preview */
.preview-container {
  display: none;
  margin-top: 16px;
}

.preview-image {
  width: 100%;
  border-radius: 12px;
  max-height: 300px;
  object-fit: contain;
  background: #f8f9fa;
}

.preview-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.btn-analyze {
  flex: 1;
  padding: 14px;
  background: #92d5ff;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(116, 185, 255, 0.4);
}

.btn-cancel {
  padding: 14px 24px;
  background: #f1f3f4;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Loading */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e9ecef;
  border-top-color: var(--candy-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Result Card */
.result-section {
  display: none;
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-glow);
  animation: slideUp 0.4s ease;
}

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

.result-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-badge {
  padding: 4px 12px;
  background: #9fbaf7;
  color: #ffffff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.result-grid {
  display: grid;
  gap: 12px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #f1f3f4;
}

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

.result-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.result-value {
  font-weight: 600;
  font-size: 14px;
  text-align: right;
}

.result-price {
  color: #e84393;
  font-size: 20px;
}

/* History Section */
.history-section {
  margin-top: 32px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  gap: 12px;
  align-items: center;
}

.history-image {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  background: #f1f3f4;
}

.history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row-1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}

.history-unit-tag {
  flex-shrink: 0;
  padding: 2px 8px;
  background: #9fbaf7;
  color: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.history-price {
  color: #e84393;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  margin-left: auto;
}

.history-row-2 {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-meta {
  color: var(--text-secondary);
  font-size: 12px;
}

.history-delete {
  padding: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #adb5bd;
}

.history-delete:hover {
  color: #e84393;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1001;
}

.toast.show {
  opacity: 1;
}

/* Mobile Optimizations */
@media (max-width: 480px) {
  .login-card {
    padding: 32px 24px;
  }

  .app-container {
    padding: 12px;
  }
}

/* Safe Area for iOS */
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Modal Overlay */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Image Preview Modal */
.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: all 0.2s ease;
  z-index: 2001;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.modal-image {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Detail Modal */
.detail-modal-content {
  background: var(--card-bg);
  border-radius: 20px;
  width: 90%;
  max-width: 400px;
  max-height: 85vh;
  overflow: hidden;
  animation: slideUpModal 0.3s ease;
}

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

.detail-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f1f3f4;
}

.detail-modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.detail-modal-close {
  width: 36px;
  height: 36px;
  background: #f1f3f4;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.detail-modal-close:hover {
  background: #e9ecef;
  color: var(--text-primary);
}

.detail-modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(85vh - 60px);
}

.detail-image-wrapper {
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  background: #f8f9fa;
}

.detail-image {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.detail-image:hover {
  transform: scale(1.02);
}

.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #f8f9fa;
  border-radius: 12px;
}

.detail-item-price {
  background: linear-gradient(135deg, rgb(253 121 121 / 10%), rgb(181 155 254 / 10%));
}

.detail-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.detail-value {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}

.detail-price {
  color: #e84393;
  font-size: 20px;
}

/* History card clickable */
.history-card {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

.history-card:active {
  transform: translateY(0);
}

.history-image {
  cursor: pointer;
}

/* Pagination */
.pagination {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
  padding: 16px 0;
}

.pagination.show {
  display: flex;
}

.pagination-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: #f1f3f4;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
  background: #e9ecef;
}

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

.pagination-info {
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: center;
}
