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

:root {
  --primary-color: #2563eb;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --background: #f8fafc;
  --surface: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

header {
  background: var(--primary-color);
  color: white;
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.settings-btn {
  position: absolute;
  right: 1rem;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.2s;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

main {
  flex: 1;
  padding: 1.5rem;
}

.section {
  margin-bottom: 2rem;
}

.section.hidden {
  display: none;
}

.section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* Capture Buttons */
.capture-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Buttons */
.btn {
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

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

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

/* Image Preview */
.image-preview {
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  margin-bottom: 1rem;
  background: #f1f5f9;
}

.image-preview img {
  width: 100%;
  height: auto;
  display: block;
}

/* Rotation Controls */
.rotation-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 1rem 0;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 1.5rem;
  min-width: 60px;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  gap: 0.75rem;
  flex-direction: column;
}

/* Processing Section */
#processing-section {
  text-align: center;
  padding: 3rem 1rem;
}

.loader {
  border: 4px solid var(--border);
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

#processing-text {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.processing-detail {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Contact Form */
.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

.form-row .form-group-small {
  flex: 0 0 auto;
  min-width: 100px;
}

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

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.875rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
}

/* Footer */
footer {
  background: var(--background);
  padding: 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}

/* Responsive */
@media (max-width: 640px) {
  main {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.25rem;
  }
}

/* Update Notification Banner */
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, var(--primary-color), #1d4ed8);
  color: white;
  padding: 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: slideDown 0.3s ease-out;
}

.update-banner.hidden {
  display: none;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.update-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.update-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.update-text {
  flex: 1;
}

.update-text strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.update-text p {
  font-size: 0.875rem;
  margin: 0;
  opacity: 0.9;
}

.update-banner .btn {
  flex-shrink: 0;
  background: white;
  color: var(--primary-color);
  font-weight: 600;
}

.update-banner .btn:hover {
  background: #f1f5f9;
}

.btn-icon {
  background: none;
  border: none;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  opacity: 0.8;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  opacity: 1;
}

/* PWA Install Prompt */
.install-prompt {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  background: white;
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  display: none;
  align-items: center;
  gap: 1rem;
  z-index: 1000;
}

.install-prompt.show {
  display: flex;
}

.install-prompt button {
  padding: 0.5rem 1rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
}

/* Settings Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 0.3s ease-out;
}

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

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

.modal-header h2 {
  font-size: 1.25rem;
  margin: 0;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: right;
}

.settings-section {
  margin-bottom: 2rem;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.settings-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.settings-description a {
  color: var(--primary-color);
  text-decoration: none;
}

.settings-description a:hover {
  text-decoration: underline;
}

.settings-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

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

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: background 0.2s;
}

.radio-group label:hover {
  background: var(--background);
}

.radio-group input[type='radio'] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}

.radio-group span {
  font-size: 0.9375rem;
}

.api-test-result {
  font-size: 0.875rem;
  margin-top: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
}

.api-test-result.success {
  background: #d1fae5;
  color: #065f46;
}

.api-test-result.error {
  background: #fee2e2;
  color: #991b1b;
}

/* Responsive for update banner */
@media (max-width: 640px) {
  .update-content {
    flex-wrap: wrap;
  }

  .update-text {
    flex-basis: 100%;
  }

  .update-banner .btn {
    width: auto;
  }

  .modal-content {
    width: 95%;
    max-height: 95vh;
  }

  .settings-btn {
    font-size: 1.25rem;
    padding: 0.375rem;
  }
}
