/* Look & feel Muhajir: colori e font da app_muhajir (lib/core/theme/app_colors.dart, app_theme.dart).
   Font IBM Plex Sans Arabic (SIL Open Font License 1.1), servito in locale. */
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 400; font-display: swap; src: url("/brand/fonts/IBMPlexSansArabic-Regular.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 500; font-display: swap; src: url("/brand/fonts/IBMPlexSansArabic-Medium.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 600 700; font-display: swap; src: url("/brand/fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --bg: #f5f6f8;             /* sfondo pagina grigio chiaro, i riquadri restano bianchi */
  --surface: #ffffff;
  --field: #f3f4f6;          /* AppColors.surface: sfondo dei campi */
  --hover: #eef0f3;
  --text: #101828;           /* AppColors.ink */
  --text-2: #364153;         /* AppColors.ink2 */
  --muted: #4b5563;          /* aiuti e testi secondari: ~7.5:1 su bianco (AppColors.muted #6A7282 era ~4.8:1) */
  --placeholder: #6a7282;    /* AppColors.muted */
  --border: #e5e7eb;         /* AppColors.line: bordi dei riquadri */
  --field-border: #d0d5dd;   /* bordo dei campi, visibile anche sul grigio */
  --accent: #101828;         /* pulsanti principali e focus = ink */
  --brand: #ce3939;          /* AppColors.brand */
  --brand-strong: #b42d2d;   /* rosso più scuro per testi piccoli (link, errori, bollini): ~6:1 su bianco */
  --brand-soft: rgba(206, 57, 57, .08); /* AppColors.brandSoft */
  --danger: #b42d2d;
  --radius: 14px;            /* AppTheme.radius */
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

/* Niente riquadro grigio di iOS/Android quando si tocca un'etichetta o un pulsante */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background: var(--bg); line-height: 1.55; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--brand-strong); }

/* ---- Pagina ---- */
.page { max-width: 820px; margin: 0 auto; padding: 28px 20px 64px; }
.page-header { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.logo { display: block; height: 58px; width: auto; }
h1 { font-size: 1.75rem; line-height: 1.3; margin: 20px 0 0; font-weight: 700; letter-spacing: -.01em; }
.intro { color: var(--muted); font-size: 1rem; margin: 8px 0 24px; }

/* Lingua: menu a tendina (disegnato, non quello nativo del browser) */
.lang-menu { position: relative; }
.lang-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 8px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--field-border); border-radius: 999px;
  font-size: .9375rem; font-weight: 500;
}
.lang-toggle:hover { background: var(--hover); }
.lang-toggle[aria-expanded="true"] .lang-chevron { transform: rotate(180deg); }
.lang-chevron { color: var(--muted); transition: transform .15s; }
.lang-list {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 20; min-width: 170px;
  list-style: none; margin: 0; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
}
.lang-list button {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: 10px; background: transparent; color: var(--text);
  font-weight: 500; text-align: start;
}
.lang-list button:hover { background: var(--hover); }
.lang-list button[aria-current="true"] { background: var(--brand-soft); }
.lang-list button[aria-current="true"]::after { content: "✓"; color: var(--brand-strong); font-weight: 700; }

/* ---- Sezioni ---- */
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px 24px 24px;
  margin: 0 0 20px;
  min-width: 0;
}
legend { font-size: 1.0625rem; font-weight: 700; padding: 0 8px; color: var(--text); }
legend::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-inline-end: 8px; vertical-align: middle; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; position: relative; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
label, .label { font-size: .9375rem; font-weight: 600; color: var(--text-2); }
.req::after { content: " *"; color: var(--brand); }

/* ---- Campi ---- */
input, select, button { font: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  font-size: 1rem; /* 16px: evita anche lo zoom automatico di Safari iOS */
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
input:not([type=checkbox]):not([type=radio]):not([type=file]):hover, select:hover { border-color: #b8bec8; }
input:not([type=checkbox]):not([type=radio]):focus, select:focus {
  outline: none; background-color: var(--surface); border-color: var(--text); box-shadow: 0 0 0 3px rgba(16, 24, 40, .12);
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input::placeholder { color: var(--placeholder); opacity: 1; }

/* Menu: freccia disegnata, sempre a 14px dal bordo (a sinistra in arabo) */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-inline-end: 42px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234b5563' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
[dir=rtl] select { background-position: left 14px center; }

/* Campi paese: si scrive per cercare, ma hanno la freccia come gli altri menu */
input.select-search, .tags.has-chevron {
  cursor: pointer; padding-inline-end: 42px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234b5563' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: right 14px center !important; background-size: 12px 8px !important;
}
input.select-search:focus { cursor: text; }
input.select-search[aria-expanded="true"], .tags.has-chevron:has(input[aria-expanded="true"]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 6.5l5-5 5 5' fill='none' stroke='%234b5563' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
}
[dir=rtl] input.select-search, [dir=rtl] .tags.has-chevron { background-position: left 14px center !important; }
/* Cittadinanze: raggiunto il massimo il campo di ricerca sparisce e con lui la freccia */
.tags.has-chevron:has(input[hidden]) { background-image: none !important; padding-inline-end: 8px !important; }

/* Menu disegnati: il pulsante ha lo stesso aspetto dei campi */
.select-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  min-height: 48px; padding: 11px 14px; text-align: start;
  background: var(--field); color: var(--text); font-weight: 400;
  border: 1px solid var(--field-border); border-radius: var(--radius);
}
.select-toggle:hover { background: var(--field); border-color: #b8bec8; }
.select-toggle[aria-expanded="true"], .select-toggle:focus-visible {
  outline: none; background: var(--surface); border-color: var(--text); box-shadow: 0 0 0 3px rgba(16, 24, 40, .12);
}
.select-toggle.is-placeholder .select-text { color: var(--placeholder); }
.select-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-chevron { flex: none; color: var(--muted); transition: transform .15s; }
.select-toggle[aria-expanded="true"] .select-chevron { transform: rotate(180deg); }
.select-list li[aria-selected="true"] { font-weight: 600; }
.select-list li[aria-selected="true"]::after { content: " ✓"; color: var(--brand-strong); }
.field.invalid .select-toggle { border-color: var(--danger); }
input, select { scroll-margin-top: 12px; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 20px; height: 20px; margin: 0; flex: none; }

.hint { color: var(--muted); font-size: .875rem; line-height: 1.45; }
.error { color: var(--danger); font-size: .875rem; font-weight: 500; }
.field.invalid .hint { color: var(--danger); }
.field.invalid input:not([type=checkbox]):not([type=radio]), .field.invalid select,
.field.invalid .tags, .field.invalid .phone-row { border-color: var(--danger); }

/* Data di nascita: giorno / mese / anno */
.date-row { display: grid; grid-template-columns: 1fr 1.5fr 1.15fr; gap: 8px; }
.date-row .select-toggle { padding-inline: 12px; }

/* Telefono: prefisso e numero in un unico campo diviso */
.phone-row {
  display: flex; gap: 0; background: var(--field);
  border: 1px solid var(--field-border); border-radius: var(--radius);
}
.phone-row:focus-within { background: var(--surface); border-color: var(--text); box-shadow: 0 0 0 3px rgba(16, 24, 40, .12); }
.phone-row input:not([type=checkbox]):not([type=radio]) {
  border: 0 !important; box-shadow: none !important; background: transparent !important; border-radius: 0;
}
.phone-row .combo { flex: 0 0 112px; border-inline-end: 1px solid var(--field-border); }
.phone-row .suggestions { width: min(320px, 80vw); inset-inline-end: auto; }
.phone-row input { flex: 1; min-width: 0; }

/* Scelte a pulsanti (genere, sì/no): due pulsanti affiancati */
.radios { display: flex; gap: 8px; }
.radios label {
  flex: 1; display: flex; gap: 8px; align-items: center; justify-content: center;
  min-height: 48px; padding: 8px 12px; cursor: pointer;
  font-weight: 500; background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
  transition: border-color .15s, background-color .15s;
}
.radios label:hover { border-color: #b8bec8; }
.radios label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--text); }
.field.invalid .radios label { border-color: var(--danger); }

/* ---- Mansioni e cittadinanze (bollini) ---- */
.combo { position: relative; }
.tags {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 48px;
  padding: 6px 8px; border: 1px solid var(--field-border); border-radius: var(--radius); background: var(--field); cursor: text;
}
.tags:focus-within { background: var(--surface); border-color: var(--text); box-shadow: 0 0 0 3px rgba(16, 24, 40, .12); }
.tags input:focus { box-shadow: none !important; background: transparent !important; }
.tag-list { display: contents; list-style: none; margin: 0; padding: 0; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--brand-soft); color: var(--brand-strong); font-weight: 500;
  border-radius: 999px; padding: 3px 4px 3px 12px; font-size: .9375rem;
}
[dir=rtl] .tag { padding: 3px 12px 3px 4px; }
.tag button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0;
  width: 26px; height: 26px; border-radius: 50%; line-height: 1; font-weight: 400;
}
.tag button:hover { background: rgba(206, 57, 57, .14); }
.tags input { flex: 1; min-width: 140px; min-height: 34px !important; border: 0 !important; padding: 4px 6px !important; outline: none; }

.suggestions {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); z-index: 10;
  list-style: none; margin: 0; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
  max-height: 300px; overflow-y: auto;
}
.suggestions li { padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.suggestions li:hover { background: var(--hover); }
.suggestions li.active { background: var(--brand-soft); color: var(--text); }
.suggestions li small { color: var(--muted); }
.suggestions li.group-label { cursor: default; background: none; color: var(--muted); font-size: .8125rem; font-weight: 600; padding: 10px 12px 4px; }

/* ---- Pulsanti ---- */
button, .button {
  display: inline-block; border: 0; border-radius: var(--radius); padding: 12px 22px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background-color .15s, opacity .15s;
}
button:hover, .button:hover { background: #1f2937; }
button:disabled { opacity: .6; cursor: progress; }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--field-border); }
button.secondary:hover, .button.secondary:hover { background: var(--hover); }
#submit { width: 100%; min-height: 54px; margin-top: 12px; font-size: 1.0625rem; }
.form-error { color: var(--danger); font-weight: 600; margin: 8px 0 0; }

.success { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 24px; text-align: center; }
.success h2 { margin-top: 0; }
.success-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; margin-bottom: 16px;
  border-radius: 50%; background: #ecfdf3; color: #067647; /* verde "fatto": ~6:1 sul suo sfondo */
}

/* ---- Consensi: solo caselle e testo, niente riquadri ---- */
.consents { display: flex; flex-direction: column; gap: 2px; margin: 4px 4px 8px; }
.check-card { display: flex; gap: 12px; align-items: flex-start; padding: 4px 0; cursor: pointer; font-weight: 400; line-height: 1.5; color: var(--text); }
.check-card input { margin-top: 2px; }
.terms-link { color: var(--brand-strong); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.consents .error:not(:empty) { padding-inline-start: 32px; }

/* ---- Termini e informativa (finestra) ---- */
.terms-dialog {
  width: min(720px, calc(100vw - 32px)); max-height: min(88vh, 900px); padding: 0;
  border: 0; border-radius: 16px; box-shadow: 0 24px 64px rgba(16, 24, 40, .28); color: var(--text);
}
.terms-dialog[open] { display: flex; flex-direction: column; }
.terms-dialog::backdrop { background: rgba(16, 24, 40, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 1.125rem; margin: 0; }
.dialog-close { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; background: transparent; color: var(--text); border-radius: 50%; }
.dialog-close:hover { background: var(--hover); }
.dialog-body { padding: 4px 20px 20px; overflow-y: auto; line-height: 1.7; color: var(--text-2); }
.dialog-body h3 { font-size: 1.0625rem; margin: 20px 0 4px; color: var(--text); }
.dialog-body p { margin: 6px 0; }
.dialog-body ul { margin: 6px 0; padding-inline-start: 20px; }
.dialog-body mark { background: #fff1b8; color: var(--text); padding: 0 3px; border-radius: 3px; }
.terms-updated { color: var(--muted); font-size: .875rem; }
.dialog-foot { padding: 12px 20px; border-top: 1px solid var(--border); }
.dialog-foot button { width: 100%; min-height: 50px; }

/* ---- CV ---- */
.file-picker { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-input:focus-visible + .file-button { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-button { padding: 11px 20px; }
.file-name { color: var(--muted); font-size: .9375rem; overflow-wrap: anywhere; }
.file-name.has-file { color: var(--text); font-weight: 600; }


/* ---- Telefono ---- */
@media (max-width: 640px) {
  .page { padding: 16px 14px 40px; }
  .logo { height: 48px; }
  h1 { font-size: 1.375rem; margin-top: 16px; }
  .intro { margin: 6px 0 18px; }
  fieldset { padding: 14px 16px 18px; margin-bottom: 14px; }
  legend { padding: 0 6px; }
  .grid { grid-template-columns: 1fr; gap: 16px; }
  .suggestions { max-height: 45vh; }
  .suggestions li { padding: 12px; }
  .tag button { width: 30px; height: 30px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  .check-card { padding: 6px 0; }
  .consents .error:not(:empty) { padding-inline-start: 34px; }
  .file-button { width: 100%; text-align: center; padding: 13px; }
  /* Su telefono i termini occupano tutto lo schermo */
  .terms-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .dialog-head, .dialog-body, .dialog-foot { padding-inline: 16px; }
  .dialog-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* ---- Admin ---- */
body.admin { background: var(--bg); }
.admin-bar { padding: 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.admin-bar h1 { font-size: 1.3rem; margin: 0; }
.count { background: var(--brand-soft); color: var(--brand-strong); border-radius: 999px; padding: 0 10px; font-size: .9rem; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters input, .filters select { width: auto !important; }
.filters button, .filters .button { padding: 8px 16px; }
.table-wrap { overflow-x: auto; padding: 0 16px 32px; }
table { border-collapse: collapse; background: var(--surface); font-size: .875rem; }
th, td { border: 1px solid var(--border); padding: 6px 8px; text-align: start; white-space: nowrap; }
th { background: var(--field); position: sticky; top: 0; }
