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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Malgun Gothic', '맑은 고딕',
    'Helvetica Neue', Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Page Layout ===== */
.page-wrapper {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Page Title ===== */
.page-title {
  font-size: 18px;
  font-weight: 700;
  color: #222;
  text-align: center;
  margin-bottom: 20px;
}

/* ===== Language Bar ===== */
.lang-bar {
  display: flex;
  width: fit-content;
  margin-left: auto;
  margin-bottom: 16px;
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  overflow: hidden;
}

.lang-btn {
  background: #fff;
  border: none;
  border-right: 1px solid #d0d5dd;
  padding: 8px 16px;
  font-size: 13px;
  color: #555;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:last-child {
  border-right: none;
}

.lang-btn:hover {
  background: #f0f2f5;
  color: #3b5998;
}

.lang-btn.active {
  background: #3b5998;
  color: #fff;
}

/* ===== Container (Card) ===== */
.container {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 32px 28px;
}

/* ===== Form Header ===== */
.form-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid #222;
}

.form-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: #222;
  margin-bottom: 6px;
}

.form-desc {
  font-size: 13px;
  color: #888;
}

/* ===== Form Groups ===== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.required {
  color: #e74c3c;
}

/* ===== Form Controls ===== */
.form-control {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-size: 14px;
  color: #333;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-control:disabled,
.form-control[readonly] {
  background: #f9f9f9;
  color: #666;
  cursor: not-allowed;
}

.form-control.error {
  border-color: #e74c3c;
}

.form-control.error:focus {
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

/* ===== Address Section (Reference Layout) ===== */
.address-section {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
}

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

.address-section-label {
  flex-shrink: 0;
  width: 120px;
  padding: 20px 16px;
  background: #f9f9f9;
  font-size: 14px;
  font-weight: 500;
  color: #555;
}

.required-dot {
  color: #e74c3c;
  font-size: 16px;
  vertical-align: middle;
}

.address-section-fields {
  flex: 1;
  min-width: 0;
  background: #fff;
  padding: 20px 24px;
}

.english-notice {
  font-size: 13px;
  color: #e74c3c;
  margin-bottom: 14px;
  line-height: 1.4;
}

.addr-field {
  margin-bottom: 10px;
}

.addr-field:last-child {
  margin-bottom: 0;
}

.addr-field .form-control,
.address-section-fields .form-control {
  height: 40px;
  font-size: 14px;
  border: 1px solid #d0d5dd;
  border-radius: 3px;
}

.addr-field .form-control:focus,
.address-section-fields .form-control:focus {
  border-color: #3b82f6;
  box-shadow: none;
}

.address-section-fields .field-error {
  margin-top: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #e74c3c;
}

/* Postal Code Row */
.postal-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.postal-input {
  max-width: 200px;
}

.no-postal-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #555;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 400 !important;
}

.no-postal-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #3b82f6;
}

/* ===== Select Wrapper ===== */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
}

.select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #999;
  pointer-events: none;
}

/* ===== Loading Indicator ===== */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #888;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #ddd;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Field Hints & Errors ===== */
.field-hint {
  margin-top: 6px;
  font-size: 12px;
  color: #999;
}

.field-error {
  margin-top: 6px;
  font-size: 12px;
  color: #e74c3c;
}

/* ===== Address Preview ===== */
.address-preview {
  margin-top: 24px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.address-preview h3 {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 10px;
}

.preview-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.preview-row:last-child {
  margin-bottom: 0;
}

.preview-label {
  display: inline-block;
  min-width: 32px;
  padding: 2px 6px;
  background: #e2e8f0;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  text-align: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.preview-row p {
  font-size: 14px;
  color: #222;
  line-height: 1.5;
  word-break: break-word;
}

/* ===== Buttons ===== */
.form-actions {
  margin-top: 20px;
}

.btn-primary {
  display: block;
  width: 100%;
  height: 48px;
  background: #3b5998;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  letter-spacing: 0.02em;
}

.btn-primary:hover {
  background: #2d4373;
}

.btn-primary:active {
  background: #23345a;
}

.btn-reset {
  display: inline-block;
  height: 36px;
  padding: 0 16px;
  background: #fff;
  color: #888;
  border: 1px solid #d0d5dd;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset:hover {
  background: #f5f5f5;
  color: #555;
  border-color: #999;
}

.btn-secondary {
  display: inline-block;
  height: 36px;
  padding: 0 16px;
  margin-top: 8px;
  background: #fff;
  color: #3b82f6;
  border: 1px solid #3b82f6;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #3b82f6;
  color: #fff;
}

/* ===== API Config ===== */
.api-config {
  margin-top: 20px;
}

.api-config details {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0;
}

.api-config summary {
  padding: 14px 20px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  user-select: none;
}

.api-config summary:hover {
  color: #333;
}

.api-config-body {
  padding: 0 20px 20px;
}

.api-section {
  margin-bottom: 4px;
}

.api-config-body label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
}

.api-config-body .field-hint {
  margin-top: 10px;
}

.api-config-body .field-hint a {
  color: #3b82f6;
  text-decoration: none;
}

.api-config-body .field-hint a:hover {
  text-decoration: underline;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: #10b981;
}

.toast.error {
  background: #e74c3c;
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Responsive - Mobile ===== */
@media (max-width: 480px) {
  .page-wrapper {
    padding: 12px 12px 32px;
  }

  .container {
    padding: 24px 18px;
    border-radius: 6px;
  }

  .form-header h2 {
    font-size: 18px;
  }

  .lang-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .form-control {
    height: 42px;
    font-size: 16px; /* Prevent iOS zoom */
  }

  .address-section {
    flex-direction: column;
  }

  .address-section-label {
    width: auto;
    padding: 12px 16px;
  }

  .address-section-fields {
    padding: 16px;
  }

  .postal-input {
    max-width: 160px;
  }

  .btn-primary {
    height: 48px;
    font-size: 15px;
  }

}

/* ===== Responsive - Tablet ===== */
@media (min-width: 481px) and (max-width: 768px) {
  .page-wrapper {
    padding: 16px 16px 36px;
  }
}
