:root{
  --bg: #f0f4f8;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --brand: #4f46e5;
  --brand-700: #4338ca;
  --brand-light: #eef2ff;
  --accent: #10b981;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #e11d48;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  background-image: 
    radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.03) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
}

.container{ max-width: 900px; margin: 36px auto; padding: 0 16px; }
.site-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 32px 24px;
  border-radius: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
}
.title{ 
  margin:0; 
  font-size: 36px; 
  font-weight: 800; 
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle{ 
  margin:12px 0 0; 
  color: rgba(255,255,255,0.9); 
  font-size: 15px;
  font-weight: 400;
}
.site-header .row {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
  box-shadow: var(--shadow-lg);
}

.progress .progress-top{
  display:flex; 
  justify-content: space-between; 
  align-items:center; 
  margin-bottom:12px;
}
.progress .bar{ 
  width:100%; 
  height:12px; 
  background:#e5e7eb; 
  border-radius: 999px; 
  overflow:hidden; 
  position: relative;
}
.progress #progressBar{ 
  height:100%; 
  width:0%; 
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transition: width .4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.progress #progressBar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.grid{ display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.field{ grid-column: span 6; display:flex; flex-direction: column; }
.field.full{ grid-column: 1 / -1; }
.field.number-field { grid-column: span 2; }
/* Compact field for yes/no selects */
.field.compact-select { 
  grid-column: span 3; 
  max-width: 140px;
}
.field.compact-select .label {
  white-space: nowrap;
}

/* Spacing for applicant sections */
.field.number-field { 
  grid-column: span 2; 
}
.field.number-field .label {
  white-space: nowrap;
}

/* Step 4: Employment fields - narrower widths */
#step4Form .field[id$="_employment_status"] { grid-column: span 4; min-width: 180px; }
#step4Form .field[id$="_employed_employer_field"] { grid-column: span 4; }
#step4Form .field[id$="_employed_job_title_field"] { grid-column: span 4; }
#step4Form .field[id$="_employed_start_field"] { grid-column: span 4; max-width: 260px; }

#step4Form .field[id$="_self_employed_cis_field"] { grid-column: span 2; max-width: 160px; }
#step4Form .field[id$="_self_employed_start_field"] { grid-column: span 3; max-width: 240px; }
#step4Form .field[id$="_self_employed_start_field"] > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#step4Form .field[id$="_self_employed_job_title_field"] { grid-column: span 3; min-width: 200px; }

#step4Form .field[id$="_director_company_field"] { grid-column: span 4; }
#step4Form .field[id$="_director_shares_field"] { grid-column: span 2; max-width: 140px; }
#step4Form .field[id$="_employment_status_other_wrap"] { grid-column: span 4; }

#step4Form .field[id$="_employment_notes"] { grid-column: 1 / -1; }
#step4Form .field[id$="_employment_notes"] textarea { min-height: 120px; }

/* Style all number inputs (applicants and dependants) */
.field.number-field input[type="number"],
input[type="number"]#depCount { 
  width: 80px;
  text-align: center;
  padding-right: 6px; /* Slightly less padding for smaller arrows */
}

/* Number spinner: input with vertical stacked buttons to the right (inline layout) */
.number-spinner{ display:inline-flex; align-items:center; gap:8px; flex-wrap:nowrap; }
.number-spinner .input{ padding-right: 8px; }
.spin-vertical{ display:flex; flex-direction:column; gap:6px; margin-left:6px; }
.spin-btn{ width:40px; height:34px; border-radius:8px; border:1px solid rgba(15,23,42,0.06); background:linear-gradient(180deg,#fff,#fbfdff); color:var(--text); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; }
.spin-btn svg{ display:block; width:14px; height:14px; }
.spin-btn:hover{ box-shadow: 0 4px 10px rgba(2,6,23,0.06); }
.spin-btn:active{ transform: translateY(1px); }
.spin-btn:focus{ outline: 3px solid rgba(79,70,229,0.18); outline-offset: 2px; }
/* no extra rules for spin-up/down; icons handle appearance */

/* Stronger visible focus for keyboard users */
.spin-btn:focus-visible{ outline: 3px solid var(--brand); outline-offset: 3px; box-shadow: 0 4px 14px rgba(67,56,202,0.12); }

/* Make the spinners slightly smaller on narrow screens */
@media (max-width: 520px){
  .spin-vertical{ gap:4px; }
  .spin-btn{ width:34px; height:28px; }
  .number-spinner .input{ padding-right: 6px; }
}

/* Hide custom spinners on fine-pointer devices (desktop with mouse). Show only on coarse-pointer (touch) devices) */
@media (pointer: fine) {
  .spin-vertical{ display:none !important; }
  /* let native browser spin buttons be visible on desktop */
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button{ -webkit-appearance: inner-spin-button; margin: 0; }
}

@media (pointer: coarse) {
  /* keep custom spinners visible on touch devices */
  .spin-vertical{ display:flex !important; }
  /* hide native mobile spinner so we don't get duplicates */
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button{ -webkit-appearance: none; margin: 0; }
}


/* Bigger arrows for number inputs */
.field.number-field input[type="number"]::-webkit-inner-spin-button,
input[type="number"]#depCount::-webkit-inner-spin-button {
  opacity: 1;
  background: transparent;
  height: 1.4em;
  padding: 6px 4px;
  margin: 0;
  position: relative;
  right: 2px;
  cursor: pointer;
}

/* Keep native spin buttons visible where supported; custom mobile spinners were removed */

/* Firefox number input styling */
.field.number-field input[type="number"],
input[type="number"]#depCount {
  -moz-appearance: textfield;
  appearance: textfield;
}
.field.number-field input[type="number"]:hover::-webkit-inner-spin-button,
input[type="number"]#depCount:hover::-webkit-inner-spin-button {
  opacity: 1;
}

/* Immigration status fields (single .field elements moved next to full-country input) */
#a1_immigration_field, #a2_immigration_field {
  grid-column: span 6; /* same width as other .field elements */
}

.label{ font-size: 14px; color: var(--text); margin-bottom: 6px; }
.label.required::after{ content: ' *'; color: #dc2626; }

.input{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  transition: all 0.2s ease;
  background: #fff;
}
.input:hover {
  border-color: #cbd5e1;
}
.input:focus{ 
  outline: none;
  border-color: var(--brand); 
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.hint{ font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint.sanitize { color: #b45309; font-weight: 600; }

/* Keep small hints on one line where needed */
.hint.single-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Simple tooltip used for short helper hints */
.tooltip{
  display:inline-block;
  margin-left:8px;
  width:18px;height:18px;line-height:18px;text-align:center;border-radius:50%;
  background:#eef2ff;color:var(--brand);font-weight:700;font-size:12px;cursor:help;
}
.tooltip:focus{ outline:2px solid var(--brand); }
.tooltip::after{
  content: attr(data-tooltip);
  position: absolute;
  background: #0f172a; color:#fff; padding:8px 10px; border-radius:8px; font-size:13px;
  white-space: nowrap; transform: translateY(-6px); opacity:0; pointer-events:none; transition:opacity .12s ease;
  margin-top:6px; z-index:30;
}
.tooltip:hover::after, .tooltip:focus::after{ opacity:1; }
.legend{ 
  font-weight: 700; 
  margin-bottom: 12px;
  font-size: 18px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Legend icons for different sections */
.legend::before {
  font-size: 20px;
}
fieldset[class*="grid"] > .legend::before {
  content: '👤';
}
fieldset[id*="Address"] > .legend::before,
fieldset[id*="address"] > .legend::before {
  content: '🏠';
}
fieldset:has(#depList) > .legend::before {
  content: '👨‍👩‍👧‍👦';
}
.divider{ border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.hidden{ display:none; }

.actions{ 
  display: flex; 
  gap: 12px; 
  justify-content: flex-end; 
  align-items: center; 
}
.actions.between{ 
  justify-content: space-between; 
}
.actions.step3-actions {
  justify-content: space-between;
}
.actions.step3-actions button:first-child {
  margin-right: auto;
}
/* Keep other buttons right-aligned */
.actions.step3-actions button:not(:first-child) {
  margin-left: 0;
}

/* Add extra spacing above actions in form cards so buttons sit below card content */
.card .actions { margin-top: 12px; }

/* Increase spacing on desktop screens */
@media (min-width: 720px) {
  .card .actions { margin-top: 24px; }
}

.btn{ 
  border-radius: 12px; 
  padding: 12px 20px; 
  border: 1px solid transparent; 
  cursor: pointer; 
  font-weight: 600;
  font-size: 15px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn.primary{ 
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.btn.primary:hover{ 
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}
.btn.ghost{ 
  background: var(--brand-light); 
  color: var(--brand); 
  border: 1px solid #e0e7ff; 
}
.btn.ghost:hover{ 
  background: #e0e7ff;
  border-color: var(--brand);
}
/* Danger-styled button for destructive/clear actions */
.btn.danger{ 
  background:#fee2e2; 
  color:#b91c1c; 
  border:1px solid #fecaca; 
}
.btn.danger:hover{ 
  background:#fecaca; 
  color:#991b1b; 
  border-color:#fca5a5; 
}

.dep-card {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  background: linear-gradient(to bottom right, #ffffff, #fafbfe);
  transition: all 0.2s ease;
}
.dep-card:hover {
  border-color: var(--brand);
  border-style: solid;
  box-shadow: var(--shadow-sm);
}

.dep-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dep-badge {
  color: var(--brand);
  font-size: 15px;
}
.dep-fields {
  display: flex;
  flex-direction: row;
  gap: 12px;
}
.dep-fields .field {
  flex: 1;
  min-width: 0; /* Prevents flex items from overflowing */
}

/* Mobile layout - keep in one row */
@media (max-width: 720px) {
  .dep-fields {
    gap: 8px;
  }
  .dep-fields .field {
    flex: 0 1 33.333%;
  }
  .dep-fields .input {
    width: 100%;
  }
}

.invalid { outline: 2px solid #ef4444 !important; border-color: #ef4444 !important; }

.badge{
  display:inline-block; 
  font-size:12px; 
  padding:4px 10px; 
  border-radius:999px; 
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
  color:var(--brand);
  font-weight: 600;
  border: 1px solid rgba(102, 126, 234, 0.2);
}

.toast{
  position: fixed; bottom: 16px; right: 16px;
  background: var(--success); color: #fff; padding: 10px 14px; border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,.15); display:none;
}
.toast.show{ display:block; }
.toast.err{ background: var(--danger); }
/* Previous address card layout */
.prev-card { border: 1px solid #e5e7eb; border-radius: 14px; padding: 14px; margin-bottom: 12px; background:#fff; }
.prev-card .legend { font-weight: 600; margin-bottom: 8px; }
.grid.two { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.actions.end { display:flex; justify-content:flex-end; margin-top: 8px; }

/* Address history coverage status */
.coverage-status {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  position: relative;
}
.coverage-status::before {
  content: '⏳';
  margin-right: 8px;
}
.coverage-status[style*="color:#16a34a"] {
  background: linear-gradient(135deg, #dcfce7 0%, #86efac 100%);
  border-color: #86efac;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}
.coverage-status[style*="color:#16a34a"]::before {
  content: '✅';
}
.coverage-status[style*="color:#c2410c"] {
  background: linear-gradient(135deg, #fef2f2 0%, #fecaca 100%);
  border-color: #fecaca;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}
.coverage-status[style*="color:#c2410c"]::before {
  content: '⚠️';
}
#prevInfo { margin-bottom: 8px; font-size: 0.93rem; }
/* Previous address card layout */
.prev-card{
  border:1px solid #e6e8ef;
  border-radius:14px;
  padding:14px;
  margin-bottom:12px;
  background:#fff;
}
.prev-card .legend{ font-weight:600; margin-bottom:8px; }
.grid.two{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.actions.end{ display:flex; justify-content:flex-end; margin-top:8px; }
#prevInfo{ margin-bottom:8px; font-size:.93rem; }
/* Stack previous addresses vertically and full width */
#prevList, #a2_prevList {
  display:flex;
  flex-direction:column;
  gap:14px;
}
.prev-card{
  width:100%;
  border:1px solid #e6e8ef;
  border-radius:14px;
  padding:16px;
  background: linear-gradient(to bottom right, #ffffff, #f8fafc);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}
.prev-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--brand);
}
.prev-card .legend{ font-weight:600; margin-bottom:8px; }

/* same 2-col grid as current address */
.prev-card .grid.two{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:12px;
}
.prev-card .actions.end{
  display:flex;
  justify-content:flex-end;
  margin-top:8px;
}


@media (max-width: 720px){
  .field{ grid-column: 1 / -1; }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  overflow: auto;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--card);
  border-radius: 16px;
  max-width: 900px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 24px;
}
.btn-close {
  background: none;
  border: none;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 32px;
  height: 32px;
}
.btn-close:hover { color: var(--text); }
.modal-body {
  padding: 24px;
}
.report-section {
  margin-bottom: 24px;
}
.report-section h3 {
  font-size: 18px;
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.report-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.report-table th,
.report-table td {
  padding: 10px 12px;
  text-align: left;
  border: 1px solid var(--border);
}
.report-table th {
  background: var(--brand);
  color: white;
  font-weight: 600;
}
.report-table tr:nth-child(even) {
  background: #f8fafc;
}
.copy-btn {
  font-size: 13px;
  padding: 4px 12px;
  background: var(--border);
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.copy-btn:hover {
  background: #e2e8f0;
}

/* Copyable cell values */
.copyable {
  cursor: pointer;
  border-bottom: 1px dotted #cbd5e1;
}
.copyable:hover {
  background: #fff8e1;
}

/* Modal styles */
.modal {
  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;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.btn-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s;
}

.btn-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 80px);
}

/* Language selector styling */
.language-selector select {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  font-size: 15px;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
    margin: 20px auto;
  }

  .site-header {
    padding: 20px 16px;
    margin-bottom: 16px;
  }

  .site-header > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
  }

  .language-selector {
    width: 100%;
  }

  .language-selector select {
    width: 100% !important;
    min-width: 100% !important;
  }

  .title {
    font-size: 24px;
  }

  .subtitle {
    font-size: 14px;
  }

  /* Tooltip positioning on mobile */
  .tooltip {
    position: relative;
  }

  .tooltip::after {
    left: 50% !important;
    transform: translateX(-50%) translateY(-100%) !important;
    right: auto !important;
    white-space: normal !important;
    max-width: 200px !important;
    bottom: auto !important;
    top: -8px !important;
  }

  /* Grid - single column on mobile */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .field {
    grid-column: span 1 !important;
    max-width: 100% !important;
  }

  /* Step 4 employment fields */
  #step4Form .field[id$="_employment_status"],
  #step4Form .field[id$="_employed_employer_field"],
  #step4Form .field[id$="_employed_job_title_field"],
  #step4Form .field[id$="_employed_start_field"],
  #step4Form .field[id$="_self_employed_cis_field"],
  #step4Form .field[id$="_self_employed_start_field"],
  #step4Form .field[id$="_self_employed_job_title_field"],
  #step4Form .field[id$="_director_company_field"],
  #step4Form .field[id$="_director_shares_field"],
  #step4Form .field[id$="_employment_status_other_wrap"] {
    grid-column: span 1 !important;
    max-width: 100% !important;
  }

  /* Step 5 - override inline styles */
  #step5Form fieldset .grid[style] {
    grid-template-columns: 1fr !important;
  }

  #step5Form .field[style] {
    grid-column: span 1 !important;
  }

  #step5Form #purchase_price_field,
  #step5Form #property_type_field {
    grid-column: span 1 !important;
    justify-content: flex-start !important;
  }

  /* PDF Modal on mobile */
  .modal {
    padding: 0;
  }

  .modal-content {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0;
    margin: 0;
  }

  .modal-header {
    padding: 16px;
  }

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

  .modal-body {
    padding: 0;
    max-height: calc(100vh - 60px);
  }

  #pdfIframe {
    height: 100% !important;
  }

  /* Buttons */
  .actions {
    flex-direction: column;
    gap: 12px;
  }

  .actions .btn {
    width: 100%;
  }

  /* Form inputs */
  .input,
  .label {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  /* Fieldset legend */
  .legend {
    font-size: 18px;
  }

  /* Progress bar */
  .progress {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Dependants grid - single column */
  .dep-fields,
  .dep-fields .grid {
    grid-template-columns: 1fr !important;
  }
  
  .dep-fields .field {
    grid-column: span 1 !important;
  }

  /* Previous address cards */
  .prev-card .grid {
    grid-template-columns: 1fr !important;
  }

  /* Consent checkboxes on mobile */
  #step5Form fieldset:last-of-type .field {
    flex-direction: row !important;
    align-items: flex-start !important;
  }
}
