/* Style variables and reset */
:root {
  --bg-gradient: linear-gradient(135deg, #fff3e0 0%, #e3f2fd 100%);
  --card-bg: rgba(255, 255, 255, 0.9);
  --card-border: rgba(255, 255, 255, 0.6);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --success: #16a34a;
  --success-hover: #15803d;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow: 0 15px 35px rgba(0, 0, 0, 0.08), 0 5px 15px rgba(0, 0, 0, 0.04);
  --border-radius: 24px;
  
  /* Font size variables */
  --font-xs: 0.75rem;
  --font-sm: 0.875rem;
  --font-md: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.25rem;
  --font-2xl: 1.5rem;
  --font-3xl: 1.875rem;
}

/* Accessible Font Scales */
body[data-font-size="small"] {
  --font-xs: 0.65rem; --font-sm: 0.75rem; --font-md: 0.875rem;
  --font-lg: 1rem; --font-xl: 1.125rem; --font-2xl: 1.35rem; --font-3xl: 1.6rem;
}
body[data-font-size="medium"] {
  /* Default browser size */
}
body[data-font-size="large"] {
  --font-xs: 0.85rem; --font-sm: 1rem; --font-md: 1.125rem;
  --font-lg: 1.25rem; --font-xl: 1.5rem; --font-2xl: 1.75rem; --font-3xl: 2.1rem;
}
body[data-font-size="xlarge"] {
  --font-xs: 1rem; --font-sm: 1.15rem; --font-md: 1.35rem;
  --font-lg: 1.5rem; --font-xl: 1.75rem; --font-2xl: 2.1rem; --font-3xl: 2.5rem;
}

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

body {
  font-family: 'Outfit', 'Noto Sans Thai', -apple-system, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 0;
  margin: 0;
  overflow-x: hidden;
}

/* Main Container */
.app-container {
  width: 100%;
  max-width: 600px;
  background: transparent;
  display: flex;
  flex-direction: column;
  padding: 16px;
  position: relative;
}

/* Header & Controls */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: var(--font-3xl);
}

.logo-text h1 {
  font-size: var(--font-lg);
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}

.logo-text p {
  font-size: var(--font-xs);
  color: var(--text-secondary);
}

/* Top control settings bar */
.top-controls {
  display: flex;
  gap: 8px;
}

.control-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: var(--font-lg);
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.control-btn:hover {
  transform: scale(1.05);
}

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

/* Card Stack */
.card-stack {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
  min-height: 480px;
  perspective: 1000px;
}

/* Individual Question Card */
.q-card {
  width: 100%;
  height: 100%;
  min-height: 480px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: absolute;
  transform-origin: 50% 99%;
  backface-visibility: hidden;
  touch-action: none; /* Crucial for custom touch handlers */
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.step-indicator {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--primary);
  background: rgba(2, 132, 199, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
}

.voice-replay-btn {
  background: #f1f5f9;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: var(--font-md);
  color: var(--text-secondary);
}

.voice-replay-btn:hover {
  background: #e2e8f0;
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 16px 0;
}

.question-text {
  font-size: var(--font-2xl);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 12px;
}

.question-subtext {
  font-size: var(--font-md);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Swipe overlay badges */
.swipe-badge {
  position: absolute;
  top: 30px;
  padding: 8px 18px;
  border-radius: 12px;
  font-size: var(--font-xl);
  font-weight: 900;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  border: 4px solid currentColor;
}

.swipe-badge.yes {
  left: 30px;
  color: var(--success);
  transform: rotate(-15deg);
}

.swipe-badge.no {
  right: 30px;
  color: var(--danger);
  transform: rotate(15deg);
}

/* Giant Accessible Controls at Bottom */
.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 10px;
}

.btn-action {
  height: 68px;
  border-radius: var(--border-radius);
  border: 0;
  font-size: var(--font-xl);
  font-weight: 900;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.btn-action:active {
  transform: scale(0.96);
}

.btn-action.no {
  background: #fee2e2;
  color: var(--danger);
  border: 2px solid rgba(220, 38, 38, 0.2);
}

.btn-action.no:hover {
  background: #fecaca;
}

.btn-action.yes {
  background: #dcfce7;
  color: var(--success);
  border: 2px solid rgba(22, 163, 74, 0.2);
}

.btn-action.yes:hover {
  background: #bbf7d0;
}

/* Multi-select Grid / Custom Touch Grid */
.multi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-top: 14px;
}

.grid-item {
  background: white;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: var(--font-md);
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.01);
}

.grid-item.selected {
  border-color: var(--primary);
  background: #f0f9ff;
  color: var(--primary);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.1);
}

.grid-item-icon {
  font-size: var(--font-3xl);
}

/* Search Dropdown / List Selection */
.search-container {
  width: 100%;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-input {
  width: 100%;
  height: 52px;
  border-radius: 14px;
  border: 2px solid #cbd5e1;
  padding: 0 16px;
  font-size: var(--font-md);
  font-family: inherit;
  outline: none;
  background: white;
}

.search-input:focus {
  border-color: var(--primary);
}

.search-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: white;
  display: flex;
  flex-direction: column;
}

.search-item {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: var(--font-md);
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}

.search-item:last-child {
  border-bottom: 0;
}

.search-item:hover, .search-item.active {
  background: #f0f9ff;
  color: var(--primary);
}

/* Results view */
.results-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 40px;
}

.result-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 24px;
  backdrop-filter: blur(10px);
}

.result-header {
  font-size: var(--font-xl);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 16px;
  border-bottom: 2px dashed #cbd5e1;
  padding-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fee-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: var(--font-md);
  font-weight: 700;
}

.fee-row.total {
  margin-top: 14px;
  border-top: 1px solid #e2e8f0;
  padding-top: 14px;
  font-size: var(--font-xl);
  color: var(--primary);
  font-weight: 900;
}

.fee-value {
  font-size: var(--font-lg);
  color: var(--text-primary);
}

.fee-row.total .fee-value {
  font-size: var(--font-2xl);
  color: var(--primary);
}

.doc-list {
  margin-left: 20px;
  margin-top: 10px;
}

.doc-list li {
  margin-bottom: 8px;
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.4;
}

.badge-product {
  display: inline-block;
  background: rgba(2, 132, 199, 0.1);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: var(--font-sm);
  font-weight: 800;
  margin-bottom: 6px;
}

.badge-sale {
  display: inline-block;
  background: #f1f5f9;
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: var(--font-sm);
  font-weight: 800;
  margin-left: 6px;
}

.result-card.license-item {
  border-left: 6px solid var(--primary);
}

/* Branch Detail Map Card */
.map-embed {
  margin-top: 12px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
}

.branch-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  margin-top: 8px;
}

.branch-link:hover {
  text-decoration: underline;
}

/* Action row for sharing or printing results */
.results-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-result-action {
  height: 56px;
  border-radius: 16px;
  border: 0;
  font-weight: 800;
  font-size: var(--font-md);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.btn-result-action.restart {
  background: white;
  border: 2px solid #e2e8f0;
  color: var(--text-secondary);
}

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

.btn-result-action.print:hover {
  background: var(--primary-hover);
}

/* Dialog Modal for Text Size */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  border-radius: var(--border-radius);
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  font-size: var(--font-xl);
  font-weight: 800;
  text-align: center;
}

.font-options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.font-option-btn {
  height: 52px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  background: white;
  font-size: var(--font-md);
  font-weight: 700;
  cursor: pointer;
}

.font-option-btn.active {
  border-color: var(--primary);
  background: #f0f9ff;
  color: var(--primary);
}

.modal-close-btn {
  height: 48px;
  background: #e2e8f0;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  font-size: var(--font-md);
  cursor: pointer;
}

/* Loading Panel */
.loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 480px;
  text-align: center;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Tinder circular controls bar */
.bottom-controls-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin-top: 15px;
  width: 100%;
}

.btn-tinder {
  border: 0;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.06);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  background: white;
}

.btn-tinder:active {
  transform: scale(0.85);
}

.btn-tinder.large {
  width: 72px;
  height: 72px;
  font-size: 32px;
}

.btn-tinder.small {
  width: 50px;
  height: 50px;
  font-size: 20px;
  border: 1px solid #e2e8f0;
}

.btn-tinder.back {
  color: #eab308;
}
.btn-tinder.back:hover {
  background: #fef9c3;
  border-color: #facc15;
}

.btn-tinder.no {
  color: var(--danger);
  border: 2px solid rgba(220, 38, 38, 0.1);
}
.btn-tinder.no:hover {
  background: #fee2e2;
  transform: scale(1.05);
}

.btn-tinder.yes {
  color: var(--success);
  border: 2px solid rgba(22, 163, 74, 0.1);
}
.btn-tinder.yes:hover {
  background: #dcfce7;
  transform: scale(1.05);
}

.btn-tinder.reset {
  color: #64748b;
}
.btn-tinder.reset:hover {
  background: #f1f5f9;
}

/* Branch select buttons and scroll wrapper */
.branches-wrapper::-webkit-scrollbar {
  width: 6px;
}

.branches-wrapper::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 10px;
}

.branches-wrapper::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.branch-select-btn {
  background: white;
  border: 2px solid #cbd5e1;
  padding: 14px 16px;
  border-radius: 16px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.01);
}

.branch-select-btn:hover {
  border-color: var(--primary) !important;
  background: #f0f9ff !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(2, 132, 199, 0.1) !important;
}

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

/* Highlighted Interactive Document Checklist */
.highlight-docs {
  background: #fefcf0 !important;
  border: 3px solid #eab308 !important;
  border-left: 8px solid #ca8a04 !important;
  border-radius: var(--border-radius);
  color: #713f12 !important;
  padding: 24px !important;
  box-shadow: 0 10px 25px rgba(234, 179, 8, 0.15) !important;
  animation: pulse-border 2s infinite ease-in-out;
}

@keyframes pulse-border {
  0% { box-shadow: 0 10px 25px rgba(234, 179, 8, 0.15); }
  50% { box-shadow: 0 10px 30px rgba(234, 179, 8, 0.3); }
  100% { box-shadow: 0 10px 25px rgba(234, 179, 8, 0.15); }
}

.highlight-docs .result-header {
  color: #854d0e !important;
  border-bottom: 2px dashed #fef08a !important;
}

.doc-checkbox-item {
  transition: all 0.2s ease;
}

.doc-checkbox-item:hover {
  border-color: #eab308 !important;
  box-shadow: 0 4px 8px rgba(113, 63, 18, 0.08) !important;
}

.doc-checkbox-item:has(input:checked) {
  background: #f4f4f5 !important;
  border-color: #e4e4e7 !important;
  opacity: 0.7;
}

.doc-checkbox-item:has(input:checked) label {
  text-decoration: line-through;
  color: #a1a1aa !important;
}

/* Print CSS overrides */
@media print {
  body {
    background: white;
    color: black;
  }
  .app-container {
    max-width: 100%;
    padding: 0;
  }
  header, .top-controls, .bottom-controls-bar, .results-actions {
    display: none !important;
  }
  .result-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }
}
