/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #fafafa;
  padding: 16px;
}

/* === Layout === */
#app {
  max-width: 900px;
  margin: 0 auto;
}

/* === Form === */
.form-container {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 24px;
}

.form-group {
  border: none;
  padding: 0;
  margin-bottom: 24px;
}

.form-group legend {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  padding-bottom: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid #eee;
  width: 100%;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  margin-bottom: 4px;
}

.field label .required-marker {
  color: #d32f2f;
  margin-left: 2px;
}

.field input,
.field select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.15);
}

.field input.field-error,
.field select.field-error {
  border-color: #d32f2f;
}

.field .field-error-message {
  color: #d32f2f;
  font-size: 12px;
  margin-top: 4px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
}

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

.btn-primary {
  background: #1976d2;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #1565c0;
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover:not(:disabled) {
  background: #d0d0d0;
}

.btn-danger {
  background: #d32f2f;
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #c62828;
}

/* === Button Spinner === */
.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* === Error Banner === */
.error-banner {
  background: #fdecea;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 12px 16px;
  margin-bottom: 16px;
  color: #611a15;
  font-size: 14px;
}

.error-banner.error-warning {
  background: #fff3e0;
  border-color: #ffe0b2;
  color: #663c00;
}

/* === Loading === */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e0e0e0;
  border-top-color: #1976d2;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.loading-message {
  color: #666;
  font-size: 14px;
}

/* === Skeleton === */
.skeleton-form {
  padding: 24px;
}

.skeleton-field {
  margin-bottom: 16px;
}

.skeleton-label {
  width: 120px;
  height: 14px;
  background: #e0e0e0;
  border-radius: 2px;
  margin-bottom: 8px;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-input {
  width: 100%;
  height: 36px;
  background: #e0e0e0;
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* === Search Dropdown === */
.search-dropdown-container {
  position: relative;
}

.search-dropdown-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.search-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.search-dropdown-item:hover {
  background: #f0f0f0;
}

.search-dropdown-empty {
  padding: 8px 12px;
  color: #999;
  font-style: italic;
  font-size: 13px;
}

.search-dropdown-loading {
  padding: 8px 12px;
  color: #666;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-dropdown-loading .spinner {
  width: 16px;
  height: 16px;
  margin-bottom: 0;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: #333;
}

.modal .field {
  margin-bottom: 12px;
}

.modal .btn {
  width: 100%;
  margin-top: 8px;
}

.modal .modal-error {
  color: #d32f2f;
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

/* === Retry Display === */
.retry-progress {
  background: #fff3e0;
  border: 1px solid #ffe0b2;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}

.retry-progress .attempt-counter {
  font-weight: 600;
  color: #e65100;
  margin-bottom: 4px;
}

.retry-progress .countdown {
  font-size: 13px;
  color: #666;
}

.retry-exhausted {
  background: #fdecea;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}

.retry-exhausted .error-detail {
  color: #611a15;
  margin-bottom: 12px;
}

/* === Success === */
.success-banner {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  color: #1b5e20;
  text-align: center;
  font-weight: 500;
}

/* === Waiting State === */
.waiting-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
  color: #999;
}

.waiting-state .waiting-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

/* === Connectivity Banner === */
.connectivity-banner {
  background: #fff3e0;
  border: 1px solid #ffe0b2;
  border-radius: 4px;
  padding: 8px 16px;
  margin-bottom: 12px;
  text-align: center;
  font-size: 13px;
  color: #e65100;
}
