:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --surface: #ffffff;
  --shadow: 0 10px 40px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --device-width: 375px;
  --device-height: 780px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #eef2ff 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.field input.invalid { border-color: var(--danger); }
.field-hint { display: block; margin-top: 4px; font-size: 0.75rem; color: var(--text-muted); }
.field-error { display: block; min-height: 16px; margin-top: 4px; font-size: 0.75rem; color: var(--danger); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-ordered { background: #f1f5f9; color: #64748b; }
.badge-payment_pending { background: #ffedd5; color: #c2410c; }
.badge-paid { background: #fce7f3; color: #be185d; }
.badge-payment_confirmed { background: #e0f2fe; color: #0369a1; }
.badge-confirmed { background: #e0f2fe; color: #0369a1; }
.badge-uploaded { background: #dbeafe; color: #1d4ed8; }
.badge-reviewed { background: #dcfce7; color: #15803d; }
.badge-need_fix { background: #fef3c7; color: #b45309; }
.badge-submitted { background: #e0e7ff; color: #4338ca; }
.badge-processed { background: #d1fae5; color: #047857; }
.badge-settled { background: #f3e8ff; color: #7e22ce; }
.badge-cancelled { background: #fee2e2; color: #b91c1c; }
.badge-pending { background: #fef3c7; color: #b45309; }
.badge-approved { background: #dcfce7; color: #15803d; }
.badge-rejected { background: #fee2e2; color: #b91c1c; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.lang-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.lang-bar select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(640px, 100%);
  max-height: 85vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.agreement-field { margin-top: 4px; }
.agreement-check {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.5;
}
.agreement-check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
}
.agreement-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
}
.agreement-link {
  font-size: inherit;
  font-weight: 600;
  padding: 0;
  line-height: inherit;
}
.agreement-modal {
  width: min(560px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.agreement-modal-body {
  overflow: auto;
  max-height: calc(80vh - 64px);
  line-height: 1.65;
  font-size: 0.88rem;
  color: var(--text);
}
.agreement-para {
  margin: 0 0 0.55em;
  white-space: pre-wrap;
  word-break: break-word;
}
.agreement-para:last-child { margin-bottom: 0; }

/* Portal */
.portal-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}
.portal-header { text-align: center; margin-bottom: 32px; }
.portal-header h1 { font-size: 2rem; font-weight: 700; }
.portal-header p { margin-top: 8px; color: var(--text-muted); }
.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-top: 24px;
}
.role-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.role-card h2 { font-size: 1.15rem; }
.role-card p { color: var(--text-muted); font-size: 0.9rem; flex: 1; }
.role-icon { font-size: 2rem; }
.demo-box {
  margin-top: 32px;
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 0.85rem;
  color: var(--primary-dark);
}
.demo-box code {
  background: rgba(255,255,255,0.7);
  padding: 1px 6px;
  border-radius: 4px;
}
