/* ==========================================================================
   PARCELLA.CSS - STILI INDIPENDENTI PER IL GENERATORE DI PARCELLA A4
   ========================================================================== */

:root {
  --bg-app: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #273549;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-focus: #10b981;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-red: #ef4444;
  --accent-red-hover: #dc2626;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-doc: 'Lora', Georgia, 'Times New Roman', serif;
  --doc-color: #111827;
  --doc-accent: #047857;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sheet: 0 25px 50px -12px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   LAYOUT PRINCIPALE
   ========================================================================== */

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   SIDEBAR FORM (PANNELLO SINISTRO)
   ========================================================================== */

.sidebar {
  width: 480px;
  min-width: 420px;
  max-width: 520px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

.sidebar-nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
}

.nav-hub-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.2s;
  flex-shrink: 0;
}

.nav-hub-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.doc-tabs-group {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px;
  border-radius: 8px;
  flex-grow: 1;
  gap: 3px;
}

.doc-tab-btn {
  flex: 1;
  text-align: center;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all 0.2s;
  white-space: nowrap;
}

.doc-tab-btn:hover {
  color: #fff;
}

.doc-tab-btn.active {
  background: var(--primary);
  color: #0f172a;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

/* CONTAINER SCROLLABILE DEL FORM */
.form-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 3rem 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.form-container::-webkit-scrollbar {
  width: 6px;
}
.form-container::-webkit-scrollbar-track {
  background: transparent;
}
.form-container::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

/* SEZIONI E FIELDSET */
.form-section {
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  margin-bottom: 1.25rem;
  transition: border-color 0.2s;
}

.section-custom-header {
  border-color: rgba(16, 185, 129, 0.35);
  background: linear-gradient(180deg, rgba(39, 53, 73, 0.95), rgba(30, 41, 59, 0.95));
}

.form-section:focus-within {
  border-color: rgba(16, 185, 129, 0.5);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  padding: 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--primary);
  color: #042f2e;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 50%;
}

/* UTILITY FLEX & SPACING */
.d-flex {
  display: flex;
}
.justify-between {
  justify-content: space-between;
}
.items-center {
  align-items: center;
}
.mb-2 {
  margin-bottom: 0.5rem;
}
.mt-2 {
  margin-top: 0.75rem;
}
.text-xs {
  font-size: 0.72rem;
}
.text-right {
  text-align: right;
}

/* CONTROLLI LOGO */
.logo-controls-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.file-input-hidden {
  display: none;
}

.file-upload-btn {
  cursor: pointer;
}

/* GRIGLIE E CAMPI */
.form-grid {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.span-2 {
  grid-column: span 2;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.form-grid .form-group {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.form-grid .form-group label {
  margin-bottom: 0.35rem;
}

.form-grid .form-group input,
.form-grid .form-group select {
  margin-top: auto;
}

label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: #34d399;
  cursor: pointer;
}

.checkbox-label input {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

input[type="text"],
textarea,
select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 0.825rem;
  padding: 0.55rem 0.75rem;
  outline: none;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Forzatura maiuscolo su campi anagrafici */
input[type="text"]:not(#input-clausola-iva):not(#input-clausola-inps),
#input-attivita-svolte {
  text-transform: uppercase;
}

#input-clausola-iva,
#input-clausola-inps {
  text-transform: none;
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.4;
}

#input-attivita-svolte {
  min-height: 140px;
}

/* SELETTORI GENERE TOGGLE */
.gender-toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.gender-radio {
  cursor: pointer;
  position: relative;
}

.gender-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-custom {
  display: block;
  padding: 0.5rem 0.65rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.gender-radio input:checked + .radio-custom {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--primary);
  color: #34d399;
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--primary);
}

/* PULSANTI UI */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: 0.825rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #059669, #047857);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

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

.btn-outline-danger {
  background: transparent;
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-outline-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-red);
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: #334155;
}

/* ==========================================================================
   AREA ANTEPRIMA PRINCIPALE (MAIN PREVIEW)
   ========================================================================== */

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #090d16;
  position: relative;
  overflow: hidden;
}

.preview-toolbar {
  height: 56px;
  padding: 0 1.5rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.badge-status {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sheet-dim-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-sidebar);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

#zoom-level {
  font-size: 0.75rem;
  min-width: 44px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 500;
}

/* SCROLL WRAPPER DEL FOGLIO */
.sheet-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2.5rem 1.5rem 4rem 1.5rem;
}

/* ==========================================================================
   FOGLIO A4 (210mm x 297mm) - PARCELLA
   ========================================================================== */

.a4-page {
  width: 210mm;
  min-height: 297mm;
  height: 297mm;
  max-height: 297mm;
  background: #ffffff;
  color: var(--doc-color);
  font-family: var(--font-doc);
  box-shadow: var(--shadow-sheet);
  box-sizing: border-box;
  padding: 13mm 18mm 12mm 18mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transform-origin: top center;
  transition: transform 0.15s ease-out;
  position: relative;
  overflow: hidden;
}

.border-b-subtle {
  border-bottom: 1px solid var(--border-color);
}

.opacity-disabled {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toggle-switch-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.toggle-switch-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-muted);
  border-radius: 50%;
  transition: all 0.25s ease;
}

.toggle-switch-card input:checked + .toggle-slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

.toggle-switch-card input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background-color: #ffffff;
}

.toggle-label {
  font-size: 0.825rem;
  color: #ffffff;
}

.hidden-element {
  visibility: hidden !important;
}

/* 1. HEADER CENTRATO CON LOGO */
.doc-header {
  text-align: center;
  margin-bottom: 0.9rem;
}

.header-logo {
  max-height: 54px;
  max-width: 180px;
  height: auto;
  width: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 0.35rem auto;
}

.header-logo.hidden-logo {
  display: none;
}

.header-circolo-name {
  font-family: var(--font-ui);
  font-size: 8.5pt;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1e3a29;
  text-transform: uppercase;
}

/* 2. SEZIONE ALTA SPLIT: COLLABORATORE (SX) & MARCA DA BOLLO (DX) */
.doc-top-split {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  font-size: 9.2pt;
  line-height: 1.35;
}

.collab-info-block {
  width: 65%;
  color: #1a1a1a;
}

.collab-name-heading {
  font-size: 10.5pt;
  font-weight: 700;
  color: #000000;
  margin-bottom: 0.15rem;
}

.collab-cf-row {
  margin-top: 0.15rem;
  font-size: 9pt;
  letter-spacing: 0.5px;
}

.bollo-box {
  width: 32%;
  display: flex;
  justify-content: flex-end;
}

.bollo-stamp {
  width: 145px;
  border: 1.5px dashed #64748b;
  background-color: #f8fafc;
  border-radius: 4px;
  padding: 8px 6px;
  text-align: center;
  font-family: var(--font-ui);
  color: #475569;
}

.bollo-title {
  font-size: 7pt;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #334155;
}

.bollo-amount {
  font-size: 11pt;
  font-weight: 700;
  color: #0f172a;
  margin: 2px 0;
}

.bollo-note {
  font-size: 5.8pt;
  color: #64748b;
  line-height: 1.1;
}

/* 3. DESTINATARIO (AL PRESIDENTE) - ALLINEATO A DESTRA */
.doc-recipient-block {
  font-size: 9pt;
  line-height: 1.35;
  color: #1f2937;
  margin-bottom: 0.85rem;
  text-align: right;
  margin-left: auto;
  width: auto;
  max-width: 65%;
}

.recipient-to {
  font-weight: 700;
  color: #000000;
  letter-spacing: 0.05em;
}

/* 4. TITOLO PARCELLA */
.doc-title-wrapper {
  text-align: center;
  margin: 0.65rem 0 0.75rem 0;
}

.doc-main-title {
  font-family: var(--font-doc);
  font-size: 12.5pt;
  font-weight: 700;
  color: #000000;
  letter-spacing: 0.03em;
}

/* 5. PREMESSA & CORPO */
.doc-body-paragraph {
  font-size: 9.3pt;
  line-height: 1.42;
  text-align: justify;
  text-justify: inter-word;
  color: #1a1a1a;
  margin-bottom: 0.45rem;
}

.text-justify {
  text-align: justify;
  text-justify: inter-word;
}

/* 6. AZIONE CENTRATA "DICHIARA" */
.doc-action-center {
  text-align: center;
  font-size: 10pt;
  font-weight: 700;
  margin: 0.45rem 0;
  letter-spacing: 0.08em;
  color: #000000;
}

/* 7. ATTIVITÀ EFFETTUATE */
.doc-activities-block {
  font-size: 9pt;
  line-height: 1.38;
  color: #1a1a1a;
  margin-bottom: 0.6rem;
}

.activities-intro {
  margin-bottom: 0.2rem;
}

.activity-item {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.activity-num {
  font-weight: 700;
}

.activity-desc {
  flex: 1;
  text-align: justify;
  text-justify: inter-word;
}

/* 8. PROSPETTO CONTEGGI */
.doc-payment-request {
  font-size: 9pt;
  line-height: 1.35;
  margin-bottom: 0.6rem;
}

.payment-intro {
  margin-bottom: 0.35rem;
}

.financial-summary-table {
  width: 330px;
  margin: 0.65rem auto;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 9pt;
}

.fin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2.5px 0;
}

.fin-label {
  color: #1f2937;
  font-weight: 500;
}

.fin-val {
  color: #111827;
  min-width: 105px;
  text-align: right;
}

.fin-deduction .fin-label {
  color: #1f2937;
}

.fin-deduction .fin-val {
  color: #111827;
}

.fin-divider {
  border-top: 1.25pt solid #1f2937;
  margin: 4px 0 5px 0;
}

.fin-total .fin-label {
  font-weight: 700;
  color: #000000;
}

.fin-total .fin-val {
  font-weight: 700;
  color: #000000;
  font-size: 9.5pt;
}

/* 9. CLAUSOLE FISCALI */
.doc-clauses {
  font-size: 8.6pt;
  line-height: 1.36;
  color: #27272a;
  margin-bottom: 0.5rem;
}

.clause-item {
  margin-bottom: 0.2rem;
}

/* 10. IBAN */
.doc-iban-section {
  font-size: 8.8pt;
  line-height: 1.35;
  color: #111827;
  margin-bottom: 0.65rem;
}

/* 11. SEZIONE FIRME (SX: REGOLARITÀ PRESIDENTE, DX: IN FEDE COLLABORATORE) */
.doc-signature-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 1.1rem;
  margin-bottom: 0.65rem;
  padding: 0 0.2rem;
}

.signature-box {
  width: 48%;
  font-size: 9pt;
  line-height: 1.35;
}

.left-box {
  text-align: left;
}

.right-box {
  text-align: right;
}

.sig-intro-regularity {
  font-style: italic;
  font-size: 8.5pt;
  color: #1f2937;
  margin-bottom: 0.25rem;
}

.invisible-placeholder {
  visibility: hidden !important;
  user-select: none;
}

.sig-role {
  font-size: 9pt;
  font-weight: 600;
  color: #111827;
  margin-bottom: 0.15rem;
}

.sig-name {
  font-size: 9pt;
  font-weight: 600;
  color: #111827;
  margin: 0.15rem 0 0.9rem 0;
  min-height: 1.2em;
}

.sig-line {
  letter-spacing: 2px;
  color: #555555;
  font-size: 8.5pt;
}

/* 12. FOOTER UFFICIALE LEGAMBIENTE */
.doc-footer {
  text-align: center;
  border-top: 0.75pt solid #9ca3af;
  padding-top: 0.4rem;
  margin-top: auto;
  font-family: var(--font-ui);
  font-size: 6.8pt;
  line-height: 1.35;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.footer-line1 {
  font-weight: 700;
  color: #111827;
  margin-bottom: 1px;
}

.footer-line2 {
  font-weight: 500;
  color: #4b5563;
  margin-bottom: 1px;
}

.footer-line3 {
  font-weight: 600;
  color: #374151;
}

/* UTILITIES ANTEPRIMA & TRASFORMAZIONE MAIUSCOLO */
[data-field]:not([data-field="clausola-iva"]):not([data-field="clausola-inps"]) {
  text-transform: uppercase;
}

.grammar-text {
  text-transform: none !important;
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

.font-mono {
  font-family: 'Courier New', Courier, monospace;
}

.preview-val.empty-field {
  display: inline-block;
  min-width: 40px;
  border-bottom: 1px dotted #94a3b8;
  color: #94a3b8;
  font-style: italic;
  font-size: 0.9em;
}

/* ==========================================================================
   STAMPA & ESPORTAZIONE PDF VETTORIALE (@MEDIA PRINT)
   ========================================================================== */

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html, body {
    width: 210mm !important;
    height: 297mm !important;
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .sidebar,
  .preview-toolbar,
  .brand,
  button,
  .zoom-controls {
    display: none !important;
  }

  .app-layout {
    display: block !important;
    height: auto !important;
    width: auto !important;
  }

  .preview-area {
    display: block !important;
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .sheet-wrapper {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .a4-page {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    max-height: 297mm !important;
    padding: 14mm 18mm 12mm 18mm !important;
    box-shadow: none !important;
    transform: none !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
  }

  .preview-val.empty-field {
    border-bottom: 1px dotted #555555;
    color: transparent;
  }

  .bollo-stamp {
    border-color: #333333 !important;
    background-color: transparent !important;
  }
}
