/* ═══════════════════════════════════════════════════════
   People Sign — v3 Sidebar Layout
   Inspired by People Connect color palette
   ═══════════════════════════════════════════════════════ */

:root {
  --v2-bg: #f5f1eb;
  --v2-surface: #ffffff;
  --v2-surface-soft: #f2e7de;
  --v2-text: #2d241f;
  --v2-muted: #7a6c65;
  --v2-primary: #ea691b;
  --v2-primary-dark: #d45d14;
  --v2-primary-light: rgba(234, 105, 27, 0.08);
  --v2-accent: #5a3c37;
  --v2-accent-dark: #372827;
  --v2-border: rgba(79, 57, 52, 0.12);
  --v2-shadow: 0 18px 45px rgba(55, 40, 39, 0.12);
  --v2-shadow-sm: 0 2px 8px rgba(55, 40, 39, 0.06);
  --v2-radius-xl: 26px;
  --v2-radius-lg: 22px;
  --v2-radius-md: 14px;
  --v2-sidebar-width: 240px;
  --v2-sidebar-collapsed: 0px;
  --v2-topbar-height: 60px;
}

body {
  background: var(--v2-bg);
  color: var(--v2-text);
  font-family: 'Outfit', sans-serif;
  margin: 0;
  overflow-x: hidden;
}

/* ── Sidebar ── */
.v2-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--v2-sidebar-width);
  height: 100vh;
  background: var(--v2-surface);
  border-right: 1px solid var(--v2-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.v2-sidebar__brand {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--v2-border);
}

.v2-sidebar__logo {
  width: 42px;
  height: auto;
  display: block;
}

.v2-sidebar__brand-text {
  display: flex;
  flex-direction: column;
}

.v2-sidebar__kicker {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--v2-accent-dark);
  letter-spacing: 0.02em;
}

/* BU Switcher pills */
.v2-bu-switcher {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--v2-border);
}

.v2-bu-switcher__btn {
  flex: 1;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--v2-muted);
  transition: all 0.2s ease;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.v2-bu-switcher__btn:hover {
  background: var(--v2-primary-light);
  color: var(--v2-primary);
}

.v2-bu-switcher__btn--active {
  background: var(--v2-primary);
  color: #fff;
  cursor: default;
  box-shadow: 0 2px 8px rgba(234, 105, 27, 0.25);
}

.v2-bu-switcher__btn--active:hover {
  background: var(--v2-primary);
  color: #fff;
}

.v2-sidebar__nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.v2-sidebar__group {
  margin-bottom: 14px;
}

.v2-sidebar__group-label {
  padding: 8px 24px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--v2-muted);
}

.v2-sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 12px 2px 0;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--v2-text);
  text-decoration: none;
  transition: background 0.18s, color 0.18s;
  border-radius: 0 999px 999px 0;
}

.v2-sidebar__link:hover {
  background: var(--v2-surface-soft);
  color: var(--v2-primary);
}

.v2-sidebar__link--active {
  background: var(--v2-primary-light);
  color: var(--v2-primary);
  font-weight: 600;
}

.v2-sidebar__link--active .v2-sidebar__icon {
  color: var(--v2-primary);
}

.v2-sidebar__icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  color: var(--v2-muted);
  flex-shrink: 0;
}

.v2-sidebar__link:hover .v2-sidebar__icon {
  color: var(--v2-primary);
}

.v2-sidebar__footer {
  padding: 12px 20px;
  border-top: 1px solid var(--v2-border);
}

/* Sidebar user profile card */
.v2-sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  margin: 8px 12px 12px;
  border-top: 1px solid var(--v2-border);
}

.v2-sidebar__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--v2-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.v2-sidebar__user-info {
  min-width: 0;
  flex: 1;
}

.v2-sidebar__user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--v2-accent-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.v2-sidebar__user-role {
  font-size: 0.72rem;
  color: var(--v2-muted);
  font-weight: 500;
}

/* Avatar badge (small, for tables) */
.v2-avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--v2-surface-soft);
  color: var(--v2-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

/* Status-based avatar colors */
.v2-avatar-sm--signed       { background: #d1fae5; color: #065f46; }
.v2-avatar-sm--confirmed    { background: #dbeafe; color: #1e40af; }
.v2-avatar-sm--ready        { background: #cffafe; color: #155e75; }
.v2-avatar-sm--pending      { background: #fef3c7; color: #92400e; }
.v2-avatar-sm--draft        { background: #e2e8f0; color: #334155; }
.v2-avatar-sm--default      { background: var(--v2-surface-soft); color: var(--v2-accent); }

/* ── Sidebar overlay (mobile) ── */
.v2-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(45, 36, 31, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1035;
}

.v2-sidebar-overlay.active {
  display: block;
}

/* ── Main area ── */
.v2-main {
  margin-left: var(--v2-sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease;
}

/* ── Topbar ── */
.v2-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  height: var(--v2-topbar-height);
  background: var(--v2-surface);
  border-bottom: 1px solid var(--v2-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 1rem;
}

.v2-topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.v2-topbar__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--v2-accent-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.v2-topbar__title-section {
  flex-shrink: 0;
}

.v2-topbar__title-sep {
  color: var(--v2-muted, #9a8f87);
  font-weight: 400;
  opacity: 0.6;
  flex-shrink: 0;
}

.v2-topbar__title-item {
  font-weight: 600;
  color: var(--v2-muted, #6b5d55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.v2-topbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.v2-sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--v2-accent-dark);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.v2-sidebar-toggle:hover {
  background: var(--v2-surface-soft);
}

/* ── User chip (topbar version) ── */
.v2-user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.v2-user-chip__name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--v2-accent-dark);
}

.v2-user-chip__role {
  font-size: 0.75rem;
  color: var(--v2-muted);
  background: var(--v2-surface-soft);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

/* ── Content area ── */
.v2-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
}

/* ── Responsive: mobile sidebar ── */
@media (max-width: 991.98px) {
  .v2-sidebar {
    transform: translateX(-100%);
  }

  .v2-sidebar.open {
    transform: translateX(0);
  }

  .v2-main {
    margin-left: 0;
  }

  .v2-sidebar-toggle {
    display: block;
  }

  .v2-content {
    padding: 16px;
  }
}

/* ── Sidebar collapsed state (desktop) ── */
.v2-sidebar.collapsed {
  transform: translateX(calc(var(--v2-sidebar-width) * -1));
}

.v2-sidebar.collapsed ~ .v2-main {
  margin-left: 0;
}

.v2-sidebar.collapsed ~ .v2-main .v2-sidebar-toggle {
  display: block;
}

/* ═══════════════════════════════════════════════════════
   Components (preserved from v2)
   ═══════════════════════════════════════════════════════ */

.v2-shell {
  max-width: 1240px;
}

.v2-shell--narrow {
  max-width: 720px;
}

/* Guest / Public header */
.v2-hero,
.v2-guest-hero {
  background: #fff;
  border-radius: var(--v2-radius-xl);
  color: var(--v2-text, #2d241f);
  box-shadow: var(--v2-shadow);
  padding: 28px 30px;
}

/* Centramento verticale della login card */
.v2-guest-centered {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 3rem);
}

.v2-hero__brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.v2-logo {
  height: auto;
  display: block;
}

.v2-logo--light {
  filter: brightness(1.04);
}

.v2-kicker {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--v2-accent, #5a3c37);
  margin-bottom: 0.35rem;
}

.v2-page-title {
  margin: 0;
  font-size: clamp(1.8rem, 2vw, 2.35rem);
  font-weight: 700;
  color: var(--v2-text, #2d241f);
}

.v2-subtitle {
  margin-top: 0.25rem;
  color: rgba(45, 36, 31, 0.55);
}

/* Card */
.card.v2-card {
  border: 0;
  border-radius: var(--v2-radius-lg);
  box-shadow: var(--v2-shadow-sm);
}

.v2-muted {
  color: var(--v2-muted);
}

.v2-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--v2-accent-dark);
}

.v2-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0;
  background: none;
  color: var(--v2-muted);
  font-size: 0.8rem;
  font-weight: 600;
}
a.v2-pill { transition: color 0.15s; }
a.v2-pill:hover { color: var(--v2-primary); }

.code-soft {
  background: #f7eee8;
  padding: 0.15rem 0.45rem;
  border-radius: 0.45rem;
}

/* Copy-to-clipboard mini button */
.v2-copy-btn {
  color: var(--v2-muted);
  font-size: 0.78rem;
  vertical-align: middle;
  text-decoration: none !important;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
  cursor: pointer;
}

.v2-copy-btn:hover {
  color: var(--v2-primary);
  opacity: 1;
}

/* Sortable drag styles */
.v2-sortable-ghost {
  opacity: 0.4;
  background: rgba(234, 105, 27, 0.08) !important;
}

.v2-drag-handle:hover {
  opacity: 0.8 !important;
}

/* Form controls */
.alert,
.form-control,
.form-select,
.btn,
textarea,
input {
  border-radius: 999px !important;
}


/* Multi-line inputs keep softer radius */
textarea.form-control,
textarea,
select[multiple] {
  border-radius: 16px !important;
}

.alert {
  border: 0;
}

.form-control,
.form-select {
  border-color: var(--v2-border);
  box-shadow: none !important;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(234, 105, 27, 0.55);
}

.btn-primary {
  background: var(--v2-primary);
  border-color: var(--v2-primary);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--v2-primary-dark);
  border-color: var(--v2-primary-dark);
}

/* Ghost buttons — sfondo tenue, senza bordo visibile */
.btn-outline-dark {
  color: var(--v2-text);
  border: 1.5px solid transparent;
  background: var(--v2-surface-soft, #f5f0ec);
}

.btn-outline-dark:hover,
.btn-outline-dark:focus {
  background: rgba(234, 105, 27, 0.12);
  color: var(--v2-primary);
  border-color: transparent;
}

.btn-outline-secondary {
  color: var(--v2-muted);
  border: 1.5px solid transparent;
  background: var(--v2-surface-soft, #f5f0ec);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  background: rgba(234, 105, 27, 0.12);
  color: var(--v2-primary);
  border-color: transparent;
}

.btn-outline-danger {
  color: #dc3545;
  border: 1.5px solid transparent;
  background: rgba(220, 53, 69, 0.06);
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
  background: rgba(220, 53, 69, 0.14);
  color: #b02a37;
  border-color: transparent;
}

/* Tables */
.table > :not(caption) > * > * {
  padding: 0.9rem 0.8rem;
}

/* Auth card */
.v2-auth-card {
  background: rgba(255, 255, 255, 0.98);
  border-radius: var(--v2-radius-lg);
  box-shadow: var(--v2-shadow);
  border: 1px solid rgba(79, 57, 52, 0.08);
}

.v2-auth-hint {
  background: #fff6ec;
  border: 1px solid rgba(234, 105, 27, 0.18);
  color: #7b4b28;
}

/* Public header */
.v2-public-header {
  border-radius: var(--v2-radius-xl);
  overflow: hidden;
  box-shadow: var(--v2-shadow);
}

.v2-public-header__logo {
  background: #fff;
  padding: 20px 28px;
  display: flex;
  align-items: center;
}

/* Language toggle */
.v2-lang-toggle {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}
.v2-lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 24px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  color: var(--v2-muted, #7a6c65);
  background: rgba(0,0,0,0.04);
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.5px;
}
.v2-lang-btn:hover {
  background: rgba(0,0,0,0.10);
  color: var(--v2-text, #2d241f);
  text-decoration: none;
}
.v2-lang-btn.v2-lang-active {
  background: var(--v2-primary, #c9561a);
  color: #fff;
}
.v2-lang-btn.v2-lang-active:hover {
  background: var(--v2-primary-dark, #a84710);
  color: #fff;
}

.v2-public-header__logo {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.v2-public-header__title {
  background: linear-gradient(135deg, var(--v2-accent-dark) 0%, #5f433d 52%, #6e4f47 100%);
  color: #fff;
  padding: 20px 28px;
}

.v2-public-header__title .v2-page-title {
  font-size: clamp(1.5rem, 2vw, 1.9rem);
  color: #fff;
}

.v2-public-header__title .v2-subtitle {
  margin-top: 0.2rem;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.92rem;
}

@media (max-width: 991.98px) {
  .v2-public-header__logo {
    padding: 16px 20px;
  }
  .v2-public-header__title {
    padding: 16px 20px;
  }
  .v2-hero,
  .v2-guest-hero {
    padding: 22px 20px;
  }
  .v2-hero__brand {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ═══════════════════════════════════════════════════════
   Accordion, Stepper, Documents (preserved from v2)
   ═══════════════════════════════════════════════════════ */

.v2-accordion__header {
  background: #fff;
  border: 0;
  padding: 18px 22px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.v2-accordion__header:hover {
  background: #faf6f3;
}

.v2-accordion__icon {
  font-size: 1.25rem;
  color: var(--v2-primary);
}

.v2-accordion__chevron {
  font-size: 0.75rem;
  color: var(--v2-muted);
  transition: transform 0.25s ease;
}

.v2-accordion__header[aria-expanded="true"] .v2-accordion__chevron {
  transform: rotate(180deg);
}

.v2-accordion__header .v2-section-title {
  line-height: 1.3;
}

.v2-stepper {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.v2-step {
  display: flex;
  gap: 0.7rem;
  padding: 0.6rem 0;
  position: relative;
}

.v2-step:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 14px;
  top: calc(0.6rem + 28px);
  bottom: 0;
  width: 2px;
  background: var(--v2-border);
}

.v2-step--done:not(:last-child)::before {
  background: var(--v2-primary);
}

.v2-step__indicator {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  flex-shrink: 0;
  background: var(--v2-surface-soft);
  color: var(--v2-muted);
  border: 2px solid var(--v2-border);
  position: relative;
  z-index: 1;
}

.v2-step--active .v2-step__indicator {
  background: #fff;
  border-color: var(--v2-primary);
  color: var(--v2-primary);
}

.v2-step--done .v2-step__indicator {
  background: var(--v2-primary);
  border-color: var(--v2-primary);
  color: #fff;
}

.v2-step--locked .v2-step__indicator {
  opacity: 0.45;
}

.v2-step__content {
  flex: 1;
  min-width: 0;
  padding-top: 0.2rem;
}

.v2-step__label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--v2-text);
}

.v2-step--locked .v2-step__label,
.v2-step--locked .v2-step__hint {
  opacity: 0.45;
}

.v2-step__link {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--v2-text);
  text-decoration: none;
}

.v2-step__link:hover {
  color: var(--v2-primary);
}

.v2-step__hint {
  font-size: 0.78rem;
  color: var(--v2-muted);
  margin-top: 0.2rem;
}

.v2-ack-bar {
  background: rgba(234, 105, 27, 0.08);
  border: 1px solid rgba(234, 105, 27, 0.2);
  border-radius: var(--v2-radius-md);
  padding: 0.85rem 1.2rem;
}

.v2-intro {
  background: var(--v2-surface);
  border-radius: var(--v2-radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 12px rgba(55, 40, 39, 0.05);
  line-height: 1.65;
  color: var(--v2-text);
}

.v2-guide {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-radius: var(--v2-radius-md);
  background: #fff8f0;
  border: 1px solid rgba(234, 105, 27, 0.18);
  color: #7b4b28;
  font-size: 0.9rem;
  line-height: 1.45;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(55, 40, 39, 0.06);
}

.v2-guide__icon {
  color: var(--v2-primary);
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.v2-ack-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--v2-accent-dark);
  margin: 0;
}

.v2-ack-label .form-check-input {
  margin: 0;
  flex-shrink: 0;
}

.v2-ack-label .form-check-input:checked {
  background-color: var(--v2-primary);
  border-color: var(--v2-primary);
}

.v2-ack-hint {
  margin-top: 0.45rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  color: #b02a37;
  background: rgba(220, 53, 69, 0.06);
  border-radius: 0.4rem;
}

.v2-ack-label .form-check-input:disabled {
  opacity: 0.4;
}

.v2-doc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.v2-doc-badge--pending {
  background: rgba(234, 105, 27, 0.1);
  color: var(--v2-primary-dark);
}

.v2-doc-badge--done {
  background: rgba(25, 135, 84, 0.1);
  color: #198754;
}

.v2-signed-complete {
  background: var(--v2-surface);
  border-radius: var(--v2-radius-xl);
  padding: 3rem 2rem;
  text-align: center;
  box-shadow: var(--v2-shadow);
}

.v2-signed-complete__icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(25, 135, 84, 0.1);
  color: #198754;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 1rem;
}

.v2-signed-complete h3 {
  font-weight: 700;
  color: var(--v2-text);
}

.v2-popover {
  --bs-popover-max-width: 260px;
  --bs-popover-bg: var(--v2-accent-dark);
  --bs-popover-body-color: #fff;
  --bs-popover-border-color: var(--v2-accent-dark);
  --bs-popover-body-padding-x: 0.85rem;
  --bs-popover-body-padding-y: 0.65rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  border-radius: var(--v2-radius-md);
  box-shadow: 0 8px 24px rgba(55, 40, 39, 0.2);
}

.v2-popover .popover-arrow::after {
  border-left-color: var(--v2-accent-dark);
}

/* Loading overlay */
.v2-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(45, 36, 31, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.v2-loading-overlay__card {
  background: #fff;
  border-radius: var(--v2-radius-lg);
  padding: 2rem 2.5rem;
  text-align: center;
  box-shadow: 0 20px 50px rgba(55, 40, 39, 0.2);
  max-width: 340px;
}

.v2-loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--v2-surface-soft);
  border-top-color: var(--v2-primary);
  border-radius: 50%;
  animation: v2-spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

.v2-loading-text {
  font-weight: 600;
  color: var(--v2-text);
  font-size: 0.95rem;
}

/* ═══════════════════════════════════════════════════════
   Document preview
   ═══════════════════════════════════════════════════════ */

.document-preview {
  color: #302624;
  font-size: 16px;
}

.doc-tab {
  display: inline-block;
  min-width: 1em;
  overflow: hidden;
  vertical-align: baseline;
  color: transparent;
}

.doc-spacer {
  display: inline-block;
  width: 6em;
}

.doc-list-marker {
  display: inline-block;
  min-width: 2.5em;
  margin-left: -2.8em;
  font-weight: 600;
  color: #493934;
  text-align: right;
  padding-right: 0.3em;
}

.document-line:has(.doc-list-marker) {
  min-height: 1.5em;
  overflow: visible;
}

.v2-doc-logo {
  max-width: 180px;
  max-height: 80px;
  height: auto;
  display: block;
}

.document-line {
  margin-bottom: 0.15rem;
}

.document-line-empty {
  margin-bottom: 0.1rem;
  min-height: 0.6em;
}

.doc-prefilled-value {
  display: inline-block;
  min-width: 3ch;
  padding: 0 0.1rem;
  border-bottom: 1px solid rgba(73, 57, 52, 0.35);
  font-weight: 600;
}

/* Campo precompilato dal database, ma editabile dal firmatario */
.doc-control.doc-prefilled {
  font-weight: 600;
  border-bottom: 1px dashed rgba(73, 57, 52, 0.3) !important;
}

/* Campo precompilato + sola lettura (template lock_prefilled_fields = 1):
   il firmatario vede il valore ma non puo' modificarlo. */
.doc-control.doc-locked {
  background: rgba(73, 57, 52, 0.10) !important;
  cursor: not-allowed;
  border-bottom: 1px solid rgba(73, 57, 52, 0.45) !important;
}
.doc-control.doc-locked:focus { outline: none !important; }
.doc-choice input[disabled] + span { opacity: 0.7; }

.doc-control {
  vertical-align: baseline;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: rgba(73, 57, 52, 0.06);
  border-radius: 0.35rem !important;
  padding: 0.1rem 0.35rem;
  font: inherit;
  line-height: inherit;
}

.doc-control:focus {
  background: rgba(234, 105, 27, 0.08);
}

.doc-control-input,
.doc-control-select {
  display: inline;
  width: auto;
  min-width: 5ch;
}

/* Span nascosto per misurare la larghezza del testo (auto-size) */
.doc-control-sizer {
  position: absolute;
  visibility: hidden;
  white-space: pre;
  font: inherit;
  padding: 0 0.35rem;
  pointer-events: none;
}

input.doc-control[type="date"] {
  min-width: 13ch;
}

.doc-control-textarea {
  display: inline-block;
  min-width: 20ch;
  min-height: 1.8em;
  resize: vertical;
}

.doc-control.doc-required-missing,
.doc-choice-group.doc-required-missing,
.doc-choice.doc-required-missing {
  background: rgba(220, 53, 69, 0.08);
  border-radius: 0.45rem;
}

.doc-choice.doc-required-missing input[type="checkbox"],
.doc-choice.doc-required-missing input[type="radio"],
.doc-choice-group.doc-required-missing input[type="checkbox"],
.doc-choice-group.doc-required-missing input[type="radio"] {
  outline: 2px solid rgba(220, 53, 69, 0.45);
  outline-offset: 1px;
}

.doc-choice-group {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
}

.doc-choice-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-right: 0.2rem;
}

.doc-choice-inline input[type="radio"],
.doc-choice-inline input[type="checkbox"] {
  margin: 0;
  transform: translateY(-0.02rem) scale(0.95);
}

.signature-preview-box {
  display: inline-block;
  padding: 0.45rem 0.7rem;
  border: 1px dashed rgba(73, 57, 52, 0.35);
  border-radius: 0.6rem;
  background: #fbf7f4;
}

.signature-preview-note {
  color: #72564d;
  font-style: italic;
}

/* ═══════════════════════════════════════════════════════
   Public footer
   ═══════════════════════════════════════════════════════ */

.v2-public-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.v2-public-shell > .container-fluid {
  flex: 1;
}
.v2-public-footer {
  margin-top: auto;
  padding: 1.5rem 1rem;
  background: #493934;
  color: rgba(255,255,255,0.7);
  font-size: 0.82rem;
  line-height: 1.6;
}
.v2-footer-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.v2-footer-brand {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.9);
}
.v2-footer-sep {
  margin: 0 0.25rem;
  opacity: 0.5;
}
.v2-footer-links {
  display: flex;
  gap: 1.25rem;
}
.v2-footer-links a {
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: color 0.15s;
}
.v2-footer-links a:hover {
  color: #fff;
  text-decoration: underline;
}
.v2-footer-legal {
  color: rgba(255,255,255,0.4);
  font-size: 0.75rem;
  line-height: 1.5;
}
.v2-footer-legal a {
  color: rgba(255,255,255,0.5);
  text-decoration: none;
}
.v2-footer-legal a:hover {
  color: rgba(255,255,255,0.8);
}

/* ── Collapsible panel chevron rotation ── */
[data-bs-toggle="collapse"] .fa-chevron-down {
  transition: transform 0.25s ease;
}

[data-bs-toggle="collapse"][aria-expanded="true"] .fa-chevron-down {
  transform: rotate(180deg);
}

/* ═══════════════════════════════════════════════════════
   DataTables theme overrides
   ═══════════════════════════════════════════════════════ */

.dataTables_wrapper .dataTables_length select {
  border-color: var(--v2-border) !important;
  border-radius: var(--v2-radius-md) !important;
  min-width: 5rem !important;
  padding-left: 0.75rem !important;
  padding-right: 2rem !important;
  text-align: center;
}

.dataTables_wrapper .dataTables_filter input {
  border-color: var(--v2-border) !important;
  border-radius: var(--v2-radius-md) !important;
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: rgba(234, 105, 27, 0.55) !important;
  box-shadow: none !important;
}

.dataTables_wrapper .dataTables_info {
  color: var(--v2-muted);
  font-size: 0.85rem;
}

/* Circular pagination (Bootstrap 5 DataTables) */
.dataTables_wrapper .dataTables_paginate .pagination {
  gap: 4px;
  align-items: center;
}

.dataTables_wrapper .dataTables_paginate .page-item .page-link {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0 !important;
  border-radius: 50% !important;
  border: none !important;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--v2-text);
  background: transparent;
  transition: background 0.18s, color 0.18s;
  line-height: 1;
  box-shadow: none !important;
}

.dataTables_wrapper .dataTables_paginate .page-item.active .page-link,
.dataTables_wrapper .dataTables_paginate .page-item.active .page-link:hover {
  background: var(--v2-primary-light) !important;
  color: var(--v2-primary) !important;
  border: none !important;
  font-weight: 700;
}

.dataTables_wrapper .dataTables_paginate .page-item .page-link:hover {
  background: var(--v2-surface-soft);
  color: var(--v2-text);
}

.dataTables_wrapper .dataTables_paginate .page-item.disabled .page-link {
  color: var(--v2-muted);
  opacity: 0.4;
  background: transparent;
}

.dataTables_wrapper .dataTables_paginate .page-item:first-child .page-link,
.dataTables_wrapper .dataTables_paginate .page-item:last-child .page-link {
  width: 34px;
  height: 34px;
  font-size: 0.8rem;
}

/* Teal badge (sistema/AI) */
.v2-badge-teal {
  background: #ccfbf1;
  color: #115e59;
}

/* Pill-shaped badges & dropdowns */
.badge {
  border-radius: 999px !important;
}

.dropdown-menu {
  border-radius: var(--v2-radius-lg) !important;
  overflow: hidden;
}

table.dataTable thead th {
  border-bottom-color: var(--v2-border) !important;
}

/* Remove row borders from tables inside cards */
.v2-card .table > :not(caption) > * > *,
.v2-card table.dataTable tbody td,
.v2-card table.dataTable tbody th {
  border-bottom: none !important;
}

table.dataTable tbody td,
table.dataTable tbody th {
  border-bottom-color: transparent !important;
}

table.dataTable tbody tr:hover,
.v2-card .table tbody tr:hover {
  background-color: rgba(45, 36, 31, 0.04) !important;
}
table.dataTable tbody tr:hover > td,
.v2-card .table tbody tr:hover > td,
.v2-card .table tbody tr:hover > th {
  background-color: rgba(45, 36, 31, 0.04) !important;
}

/* Back links */
.btn-link {
  color: var(--v2-text, #333);
  text-decoration: none;
}
.btn-link:hover {
  color: var(--v2-primary, #ea691b);
}

/* Clickable name hints */
a.v2-name-link {
  color: #9f4200;
  text-decoration: none;
  transition: color 0.15s;
}
a.v2-name-link:hover {
  color: var(--v2-primary, #ea691b);
  text-decoration: underline;
}

/* Fix DataTables search/length margins */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
  margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
  margin-top: 1rem;
}

/* ═══════════════════════════════════════════════════════
   Topbar icons (notification / help / logout)
   ═══════════════════════════════════════════════════════ */
.v2-topbar__icons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.v2-topbar__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--v2-muted);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  text-decoration: none;
  position: relative;
}

.v2-topbar__icon-btn:hover {
  background: var(--v2-surface-soft);
  color: var(--v2-primary);
}

.v2-topbar__icon-btn--logout {
  color: var(--v2-muted);
}

.v2-topbar__icon-btn--logout:hover {
  background: rgba(220, 53, 69, 0.08);
  color: #dc3545;
}

.v2-topbar__separator {
  width: 1px;
  height: 24px;
  background: var(--v2-border);
  margin: 0 6px;
}

/* ═══════════════════════════════════════════════════════
   Progress bar (research list)
   ═══════════════════════════════════════════════════════ */
.v2-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

.v2-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--v2-surface-soft);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}

.v2-progress-bar__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  background: var(--v2-primary);
}

.v2-progress-bar__fill--complete {
  background: #198754;
}

.v2-progress-bar__fill--partial {
  background: var(--v2-primary);
}

.v2-progress-bar__fill--zero {
  background: var(--v2-border);
}

.v2-progress-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--v2-text);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════
   Statistics cards (research list bottom)
   ═══════════════════════════════════════════════════════ */
.v2-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.v2-stat-card {
  background: var(--v2-surface);
  border-radius: var(--v2-radius-lg);
  padding: 20px 22px;
  box-shadow: var(--v2-shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: box-shadow 0.2s, transform 0.2s;
}

.v2-stat-card:hover {
  box-shadow: 0 4px 16px rgba(55, 40, 39, 0.1);
  transform: translateY(-1px);
}

.v2-stat-card__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.v2-stat-card__icon--primary {
  background: var(--v2-primary-light);
  color: var(--v2-primary);
}

.v2-stat-card__icon--success {
  background: rgba(25, 135, 84, 0.1);
  color: #198754;
}

.v2-stat-card__icon--warning {
  background: rgba(255, 193, 7, 0.12);
  color: #cc9a06;
}

.v2-stat-card__icon--info {
  background: rgba(13, 110, 253, 0.1);
  color: #0d6efd;
}

.v2-stat-card__body {
  flex: 1;
  min-width: 0;
}

.v2-stat-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--v2-accent-dark);
  line-height: 1.2;
}

.v2-stat-card__label {
  font-size: 0.8rem;
  color: var(--v2-muted);
  font-weight: 500;
  margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════
   Airier table rows
   ═══════════════════════════════════════════════════════ */
.v2-card .table > :not(caption) > * > * {
  padding: 1rem 0.85rem;
}

.v2-card .table thead th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--v2-muted);
  border-bottom: 2px solid var(--v2-border) !important;
}

table.dataTable tbody tr,
.v2-card .table tbody tr {
  transition: background-color 0.15s ease;
}

/* ═══════════════════════════════════════════════════════
   Action buttons: borderless ghost style
   ═══════════════════════════════════════════════════════ */
.v2-card .table td .btn-outline-dark.btn-sm,
.v2-card .table td .btn-outline-secondary.btn-sm,
.v2-card .table td .dropdown > .btn-outline-secondary.btn-sm {
  border: none;
  background: transparent;
  color: var(--v2-muted);
  box-shadow: none;
}
.v2-card .table td .btn-outline-dark.btn-sm:hover,
.v2-card .table td .btn-outline-secondary.btn-sm:hover,
.v2-card .table td .dropdown > .btn-outline-secondary.btn-sm:hover {
  color: var(--v2-primary);
  background: var(--v2-primary-light);
}

/* ═══════════════════════════════════════════════════════
   Orange checkboxes & radio (override Bootstrap blue)
   ═══════════════════════════════════════════════════════ */
.form-check-input:checked {
  background-color: var(--v2-primary);
  border-color: var(--v2-primary);
}
.form-check-input:focus {
  border-color: var(--v2-primary);
  box-shadow: 0 0 0 0.2rem var(--v2-primary-light);
}

/* ═══════════════════════════════════════════════════════
   v2-search autocomplete (filter ricerche, schema picker, ...)
   Pattern riutilizzabile: wrap + input + dropdown con items
   ═══════════════════════════════════════════════════════ */
.v2-search-wrap {
  position: relative;
  display: block;
}
.v2-search-input {
  width: 100%;
  border: 1.5px solid var(--v2-border, #e8e0db) !important;
  border-radius: 6px !important;
  padding: 5px 12px 5px 32px !important;
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  box-sizing: border-box;
  margin: 0;
}
.v2-search-input:focus {
  border-color: var(--v2-primary) !important;
  box-shadow: 0 0 0 3px var(--v2-primary-light) !important;
}
.v2-search-input:disabled {
  background: var(--v2-surface-soft, #f5f0ec);
  cursor: not-allowed;
}
.v2-search-icon {
  position: absolute !important;
  left: 10px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  color: var(--v2-muted, #7a6c65);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  margin: 0 !important;
}
/* Fallback defensivo per lo schema picker, così la posizione rimane
   corretta anche se il browser fa una race con FontAwesome o se il
   wrap viene ri-renderizzato dopo un collapse Bootstrap. */
.schema-picker {
  position: relative !important;
  display: block !important;
}
.schema-picker > .v2-search-icon {
  position: absolute !important;
  left: 12px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
}
.schema-picker > .v2-search-input {
  padding-left: 34px !important;
}
.v2-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 100;
  background: #fff;
  border: 1.5px solid var(--v2-border, #e8e0db);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 280px;
  overflow-y: auto;
  display: none;
}
.v2-search-dropdown.open { display: block; }
.v2-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--v2-text, #2d241f);
  transition: background 0.1s;
  border-bottom: 1px solid var(--v2-surface-soft, #f5f0ec);
}
.v2-search-item:last-child { border-bottom: none; }
.v2-search-item:hover,
.v2-search-item--focused {
  background: var(--v2-primary-light);
  color: var(--v2-primary);
}
.v2-search-item--active {
  background: var(--v2-primary);
  color: #fff;
  font-weight: 600;
}
.v2-search-item--active:hover {
  background: var(--v2-primary-dark);
  color: #fff;
}
.v2-search-item-name { font-weight: 600; font-size: 13px; }
.v2-search-item-code { font-size: 12px; opacity: 0.6; margin-left: 6px; }
.v2-search-item-count {
  font-size: 11px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.v2-search-item--active .v2-search-item-count { background: rgba(255, 255, 255, 0.25); }
.v2-search-empty {
  padding: 12px 14px;
  color: var(--v2-muted);
  font-size: 13px;
  text-align: center;
}
