/* ======================================================================
   ANAGRAFICA EDITOR — design pulito coerente con Ecosistema
   v1.0.7.0
   ====================================================================== */

:root {
  --aed-navy: #1a2f66;
  --aed-navy-soft: #2c4a8e;
  --aed-green: #2e7d32;
  --aed-orange: #ee7b00;
  --aed-purple: #6d28d9;
  --aed-text: #212430;
  --aed-text-soft: #6b7280;
  --aed-text-mute: #9aa0ab;
  --aed-border: #e5e7eb;
  --aed-border-light: #f3f4f6;
  --aed-bg: #ffffff;
  --aed-bg-soft: #fafbfc;
  --aed-bg-hover: #f6f7f8;
  --aed-blue-light: #eef2fa;
}

/* ─── HEADER ────────────────────────────────────────────────────────── */

.aed-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.aed-pending-badge {
  background: #fff8eb;
  color: #b8590c;
  border: 1px solid #f4c895;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.aed-pending-badge.aed-pending-zero {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

/* ─── BUTTONS ───────────────────────────────────────────────────────── */

.aed-btn {
  border: 1px solid var(--aed-border);
  background: var(--aed-bg);
  color: var(--aed-text);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.aed-btn:hover {
  border-color: var(--aed-navy);
  background: var(--aed-bg-hover);
}

.aed-btn-primary {
  background: var(--aed-navy);
  color: #fff;
  border-color: var(--aed-navy);
}

.aed-btn-primary:hover {
  background: var(--aed-navy-soft);
  border-color: var(--aed-navy-soft);
}

.aed-btn-secondary {
  background: transparent;
}

.aed-btn-export {
  background: var(--aed-green);
  color: #fff;
  border-color: var(--aed-green);
  font-weight: 600;
}

.aed-btn-export:hover {
  background: #1f6627;
  border-color: #1f6627;
}

/* ─── TOOLBAR ───────────────────────────────────────────────────────── */

.aed-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--aed-bg);
  border: 1px solid var(--aed-border);
  border-radius: 8px;
}

.aed-search {
  flex: 1;
  min-width: 250px;
  max-width: 480px;
  padding: 8px 14px;
  border: 1px solid var(--aed-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.aed-search:focus {
  border-color: var(--aed-navy);
}

.aed-select {
  padding: 8px 12px;
  border: 1px solid var(--aed-border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--aed-bg);
  cursor: pointer;
  font-family: inherit;
  min-width: 200px;
}

.aed-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--aed-text-soft);
  cursor: pointer;
  user-select: none;
}

.aed-count {
  font-size: 12px;
  color: var(--aed-text-soft);
  font-weight: 500;
}

/* ─── LAYOUT ────────────────────────────────────────────────────────── */

.aed-layout {
  display: grid;
  grid-template-columns: 1fr 480px;
  gap: 16px;
  min-height: calc(100vh - 220px);
  transition: grid-template-columns 0.2s ease;
}

/* Quando nessun dipendente è selezionato, il pannello destro si riduce */
.aed-layout.is-collapsed {
  grid-template-columns: 1fr 80px;
}

@media (max-width: 1280px) {
  .aed-layout {
    grid-template-columns: 1fr 420px;
  }
  .aed-layout.is-collapsed {
    grid-template-columns: 1fr 70px;
  }
}

@media (max-width: 1024px) {
  .aed-layout {
    grid-template-columns: 1fr;
  }
  .aed-layout.is-collapsed {
    grid-template-columns: 1fr;
  }
}

/* ─── TABLE ─────────────────────────────────────────────────────────── */

.aed-table-wrap {
  background: var(--aed-bg);
  border: 1px solid var(--aed-border);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 220px);
}

.aed-table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
  font-size: 10px;
}

.aed-table thead {
  position: sticky;
  top: 0;
  background: var(--aed-bg-soft);
  z-index: 1;
}

.aed-table th {
  text-align: left;
  padding: 6px 8px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--aed-text-soft);
  border-bottom: 1px solid var(--aed-border);
  white-space: nowrap;
}

.aed-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--aed-border-light);
  vertical-align: middle;
}

.aed-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.aed-table tbody tr:hover {
  background: var(--aed-bg-hover);
}

.aed-table tbody tr.is-selected {
  background: var(--aed-blue-light);
}

.aed-table tbody tr.is-selected td:first-child {
  border-left: 3px solid var(--aed-navy);
  padding-left: 5px;
}

.aed-name {
  font-weight: 600;
  color: var(--aed-text);
  font-size: 11px;
  line-height: 1.25;
}

.aed-codifica {
  font-size: 9px;
  color: var(--aed-text-mute);
  font-family: monospace;
  margin-top: 1px;
  letter-spacing: -0.3px;
}

.aed-mansione {
  color: var(--aed-text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10.5px;
}

.aed-entity {
  color: var(--aed-text-soft);
  font-size: 10.5px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aed-capo {
  color: var(--aed-text-soft);
  font-size: 10.5px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aed-ceon {
  font-size: 9px;
  color: var(--aed-navy);
  background: var(--aed-blue-light);
  padding: 2px 6px;
  border-radius: 9px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  display: inline-block;
}

/* Colonna CEO-N: larghezza minima per evitare wrap */
.aed-table th:nth-child(5),
.aed-table td:nth-child(5) {
  min-width: 56px;
  white-space: nowrap;
}

/* Colonna Mod. (icona pending): larghezza fissa minima */
.aed-table th:nth-child(6),
.aed-table td:nth-child(6) {
  min-width: 32px;
  text-align: center;
}

.aed-row-pending {
  color: var(--aed-orange);
  font-size: 13px;
  display: inline-block;
}

.aed-muted {
  color: var(--aed-text-mute);
  font-style: italic;
}

.aed-loading, .aed-error, .aed-empty {
  text-align: center;
  padding: 40px;
  color: var(--aed-text-mute);
  font-size: 13px;
}

.aed-error {
  color: #b91c1c;
}

/* ─── EDIT PANEL ────────────────────────────────────────────────────── */

.aed-edit-panel {
  background: var(--aed-bg);
  border: 1px solid var(--aed-border);
  border-radius: 8px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.aed-edit-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  color: var(--aed-text-mute);
  font-size: 13px;
  text-align: center;
  flex: 1;
}

.aed-edit-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* Quando il pannello è collapsed (nessun dipendente selezionato) */
.aed-layout.is-collapsed .aed-edit-panel {
  background: var(--aed-bg-soft);
}

.aed-layout.is-collapsed .aed-edit-empty {
  padding: 40px 6px;
}

.aed-layout.is-collapsed .aed-edit-empty-text {
  display: none;
}

.aed-layout.is-collapsed .aed-edit-empty-icon {
  font-size: 28px;
  opacity: 0.3;
  margin-bottom: 0;
}

.aed-edit-loading {
  padding: 40px;
  text-align: center;
  color: var(--aed-text-mute);
}

.aed-edit-header {
  background: var(--aed-navy);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.aed-edit-title {
  font-size: 15px;
  font-weight: 600;
}

.aed-edit-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}

.aed-edit-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 20px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}

.aed-edit-close:hover {
  color: #fff;
}

.aed-edit-body {
  padding: 18px;
  flex: 1;
}

.aed-field {
  margin-bottom: 16px;
}

.aed-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--aed-text-soft);
  margin-bottom: 6px;
}

.aed-field input[type="text"],
.aed-field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--aed-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
}

.aed-field input[type="text"]:focus,
.aed-field textarea:focus {
  border-color: var(--aed-navy);
}

.aed-field-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--aed-text);
  cursor: pointer;
}

/* ─── CAPO SELECTOR (autocomplete dropdown) ─────────────────────────── */

.aed-capo-selector {
  position: relative;
}

.aed-capo-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--aed-blue-light);
  border: 1px solid var(--aed-navy);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--aed-navy);
  margin-bottom: 6px;
}

.aed-capo-empty {
  padding: 8px 12px;
  background: var(--aed-bg-soft);
  border: 1px dashed var(--aed-border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--aed-text-mute);
  font-style: italic;
  margin-bottom: 6px;
}

.aed-capo-remove {
  background: transparent;
  border: none;
  color: var(--aed-navy);
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  padding: 0 4px;
  line-height: 1;
}

.aed-capo-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--aed-border);
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
  box-sizing: border-box;
}

.aed-capo-search:focus {
  border-color: var(--aed-navy);
}

.aed-capo-results {
  max-height: 240px;
  overflow-y: auto;
  background: var(--aed-bg);
  border: 1px solid var(--aed-border);
  border-radius: 6px;
  margin-top: 4px;
  display: none;
}

.aed-capo-results:not(:empty) {
  display: block;
}

.aed-capo-option {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--aed-border-light);
  transition: background 0.1s;
}

.aed-capo-option:last-child {
  border-bottom: none;
}

.aed-capo-option:hover {
  background: var(--aed-blue-light);
}

.aed-capo-opt-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--aed-text);
}

.aed-capo-opt-meta {
  font-size: 10px;
  color: var(--aed-text-soft);
  margin-top: 1px;
}

.aed-capo-noresults {
  padding: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--aed-text-mute);
  font-style: italic;
}

/* ─── ACTIONS ───────────────────────────────────────────────────────── */

.aed-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--aed-border-light);
}

.aed-edit-actions .aed-btn {
  flex: 1;
}

/* ─── HISTORY ───────────────────────────────────────────────────────── */

.aed-edit-history {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--aed-border-light);
}

.aed-edit-history summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--aed-text-soft);
  padding: 4px 0;
  user-select: none;
}

.aed-edit-history summary:hover {
  color: var(--aed-navy);
}

.aed-hist-item {
  font-size: 11px;
  padding: 8px 10px;
  margin: 6px 0;
  background: var(--aed-bg-soft);
  border-radius: 5px;
  border-left: 2px solid var(--aed-navy);
}

.aed-hist-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
  color: var(--aed-text-mute);
}

.aed-hist-when {
  font-family: monospace;
}

.aed-hist-who {
  font-weight: 600;
  color: var(--aed-text-soft);
}

.aed-hist-body {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.aed-hist-field {
  font-weight: 700;
  color: var(--aed-navy);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.5px;
}

.aed-hist-old {
  color: var(--aed-text-mute);
  text-decoration: line-through;
  font-size: 11px;
}

.aed-hist-arrow {
  color: var(--aed-text-mute);
  font-size: 11px;
}

.aed-hist-new {
  color: var(--aed-green);
  font-weight: 600;
  font-size: 11px;
}

.aed-hist-note {
  font-style: italic;
  color: var(--aed-text-soft);
  margin-top: 4px;
  font-size: 10px;
}

/* ─── TOAST ─────────────────────────────────────────────────────────── */

.aed-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s;
}

.aed-toast-success {
  background: var(--aed-green);
  color: #fff;
}

.aed-toast-error {
  background: #dc2626;
  color: #fff;
}

.aed-toast-info {
  background: var(--aed-navy);
  color: #fff;
}

.aed-toast-fade {
  opacity: 0;
}

/* ─── MODAL COHERENCE ──────────────────────────────────────────────── */

.aed-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 61, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: aed-fade-in 0.15s ease;
}

@keyframes aed-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.aed-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: 760px;
  width: calc(100% - 40px);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: aed-slide-up 0.18s ease;
}

@keyframes aed-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

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

.aed-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--aed-navy);
  margin-bottom: 4px;
}

.aed-modal-subtitle {
  font-size: 12px;
  color: var(--aed-text-soft);
}

.aed-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--aed-text-mute);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  transition: background 0.1s;
}

.aed-modal-close:hover {
  background: var(--aed-bg-hover);
  color: var(--aed-text);
}

.aed-modal-info {
  padding: 14px 24px;
  background: var(--aed-bg-soft);
  border-bottom: 1px solid var(--aed-border-light);
}

.aed-coh-explain {
  font-size: 12px;
  color: var(--aed-text);
  line-height: 1.6;
}

.aed-coh-explain code {
  background: #fff;
  border: 1px solid var(--aed-border);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 11px;
  color: var(--aed-navy);
}

.aed-modal-stats {
  display: flex;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--aed-border-light);
}

.aed-stat {
  flex: 1;
  background: var(--aed-bg-soft);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
}

.aed-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--aed-navy);
  line-height: 1.1;
}

.aed-stat-label {
  font-size: 11px;
  color: var(--aed-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.aed-stat-warn {
  background: #fff5e6;
  border: 1px solid #f5a623;
}

.aed-stat-warn .aed-stat-value {
  color: #c77700;
}

.aed-stat-ok {
  background: #e8f5e9;
  border: 1px solid #4caf50;
}

.aed-stat-ok .aed-stat-value {
  color: #2e7d32;
}

.aed-coh-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0 24px;
  max-height: 320px;
}

.aed-coh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 16px 0;
}

.aed-coh-table thead {
  position: sticky;
  top: 0;
  background: #fff;
}

.aed-coh-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--aed-text-soft);
  border-bottom: 2px solid var(--aed-border);
}

.aed-coh-table td {
  padding: 10px;
  border-bottom: 1px solid var(--aed-border-light);
  vertical-align: middle;
}

.aed-coh-table tr:last-child td {
  border-bottom: none;
}

.aed-coh-name {
  font-weight: 600;
  color: var(--aed-text);
}

.aed-coh-arrow {
  color: var(--aed-text-mute);
  font-size: 14px;
  font-weight: 700;
}

.aed-coh-capo {
  color: var(--aed-text);
  font-size: 11px;
}

.aed-coh-capo-meta {
  font-size: 10px;
  color: var(--aed-text-mute);
  font-family: monospace;
  margin-top: 2px;
}

.aed-ceon-error {
  background: #fde7e7;
  color: #c62828;
}

.aed-ceon-target {
  background: #e8f5e9;
  color: #2e7d32;
}

.aed-coh-empty {
  text-align: center;
  padding: 32px 16px !important;
}

.aed-coh-empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.aed-coh-empty-msg {
  font-size: 14px;
  font-weight: 600;
  color: var(--aed-navy);
}

.aed-coh-empty-sub {
  font-size: 12px;
  color: var(--aed-text-soft);
  margin-top: 4px;
}

.aed-coh-hint {
  padding: 10px 24px 14px;
  font-size: 11px;
  color: var(--aed-text-soft);
  background: var(--aed-bg-soft);
  border-top: 1px solid var(--aed-border-light);
}

.aed-modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 24px;
  border-top: 1px solid var(--aed-border);
  background: #fff;
}

.aed-modal-footer .aed-btn {
  min-width: 100px;
}

.aed-btn-primary {
  background: var(--aed-navy);
  color: #fff;
  border: 1px solid var(--aed-navy);
}

.aed-btn-primary:hover {
  background: #1a3270;
}

.aed-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
