/* Stili specifici della pagina admin. Riusa le variabili e i componenti
   di base da style.css. */

.admin-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.admin-userbox {
  display: flex; align-items: center; gap: 10px; font-size: 13px;
  color: var(--text-muted);
}
.admin-userbox strong { color: var(--text); }
.admin-userbox .back-link {
  color: var(--accent); text-decoration: none; font-size: 13px;
  border: 1px solid var(--border); padding: 4px 10px; border-radius: 4px;
  background: #fff;
}
.admin-userbox .back-link:hover { background: var(--accent-bg); }
.admin-userbox .secondary {
  background: #fff; border: 1px solid var(--border); padding: 4px 10px;
  border-radius: 4px; font-size: 13px; cursor: pointer;
}
.admin-userbox .secondary:hover { background: #f4f4f4; }

/* ---------- Login ---------- */

.login-card { max-width: 420px; margin: 40px auto; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; }
.login-form input {
  padding: 8px 10px; border: 1px solid #d0d0d0; border-radius: 4px; font-size: 14px;
}
.login-form button {
  margin-top: 6px; padding: 10px; background: #0a66c2; color: #fff; border: 0;
  border-radius: 4px; font-size: 14px; cursor: pointer;
}
.login-form button:hover { background: #084e96; }
.login-form button:disabled { background: #888; cursor: not-allowed; }
.login-error {
  background: #fff0f0; border: 1px solid #f3b8b8; color: #a01515; padding: 8px 10px;
  border-radius: 4px; font-size: 13px;
}

/* ---------- File dati ---------- */

.data-files {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px; margin: 12px 0 18px;
}
.data-file {
  border: 1px solid #e0e0e0; border-radius: 6px; padding: 14px;
  background: #fafafa; display: flex; flex-direction: column; gap: 8px;
}
.data-file h3 { margin: 0; font-size: 14px; color: #1a1a1a; }
.data-file .meta { font-size: 12px; color: #666; }
.data-file .meta.missing { color: #c14040; font-weight: 600; }
.data-file .file-row {
  display: flex; gap: 8px; align-items: center; margin-top: 4px;
}
.data-file input[type=file] { flex: 1; font-size: 12px; }
.data-file button {
  padding: 6px 12px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.data-file button:hover { background: #084e96; }
.data-file button:disabled { background: #888; cursor: not-allowed; }
.data-file .upload-status { font-size: 12px; min-height: 16px; }
.data-file .upload-status.ok { color: #198038; }
.data-file .upload-status.err { color: #c14040; }

.reimport-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap; padding-top: 10px;
  border-top: 1px solid #e0e0e0;
}
.reimport-row button.primary {
  padding: 10px 18px; background: #c1392b; color: #fff; border: 0;
  border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.reimport-row button.primary:hover { background: #a52d20; }
.reimport-row button.primary:disabled { background: #888; cursor: not-allowed; }

.reimport-result {
  margin-top: 10px; padding: 10px 12px; border-radius: 4px;
  font-size: 13px; background: #eff7ee; border: 1px solid #b9deb1; color: #186118;
}
.reimport-result.err { background: #fff0f0; border-color: #f3b8b8; color: #a01515; }
.reimport-result table { width: 100%; margin-top: 6px; font-size: 12px; }
.reimport-result td { padding: 2px 6px; }

/* ---------- Loghi ---------- */

.logo-toolbar {
  display: flex; gap: 12px; align-items: center; margin: 10px 0 14px;
  flex-wrap: wrap;
}
.logo-toolbar input[type=search] {
  padding: 6px 10px; border: 1px solid #d0d0d0; border-radius: 4px;
  font-size: 13px; min-width: 240px;
}
.inline-check {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  cursor: pointer;
}

.logo-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 12px;
}
.logo-card {
  border: 1px solid #e0e0e0; border-radius: 6px; background: #fff;
  display: flex; flex-direction: column; padding: 10px; gap: 8px;
}
.logo-card .meta { font-size: 12px; line-height: 1.4; }
.logo-card .meta .piva { font-family: 'Courier New', monospace; font-size: 11px; }
.logo-card .meta .sito { color: #666; word-break: break-all; }
.logo-card .meta .counts { color: #666; font-size: 11px; margin-top: 2px; }

.logo-card .logo-empty {
  font-size: 11px; color: #999; padding: 8px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa; text-align: center;
}
.logo-card .logo-rows {
  display: flex; flex-direction: column; gap: 6px;
}
.logo-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px; border: 1px solid #e8e8e8; border-radius: 4px; background: #fcfcfc;
}
.logo-row .preview {
  width: 70px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #f7f7f7; border-radius: 3px;
}
.logo-row .preview img { max-height: 40px; max-width: 64px; object-fit: contain; }
.logo-row .logo-info { flex: 1; font-size: 11px; min-width: 0; }
.logo-row .pattern-label { font-size: 12px; color: #1a1a1a; margin-bottom: 2px; }
.logo-row .pattern-label code {
  background: #fff3c4; padding: 1px 5px; border-radius: 3px;
  font-family: 'Courier New', monospace; font-size: 11px;
}
.logo-row .muted { color: #888; }
.logo-row .del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.logo-row .del:hover { background: #c14040; }

.logo-card .add-form {
  margin-top: 4px; padding: 8px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 6px;
}
.logo-card .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.logo-card .add-form .pattern-input {
  padding: 5px 8px; font-size: 12px; border: 1px solid #d0d0d0; border-radius: 3px;
}
.logo-card .add-form-row {
  display: flex; gap: 6px; align-items: center;
}
.logo-card .add-form input[type=file] { flex: 1; font-size: 11px; min-width: 0; }
.logo-card .add-form button.upload {
  padding: 5px 12px; font-size: 12px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer;
}
.logo-card .add-form button.upload:hover { background: #084e96; }
.logo-card .add-form button.upload:disabled { background: #888; cursor: not-allowed; }
.logo-card .status { font-size: 11px; min-height: 14px; }
.logo-card .status.ok { color: #198038; }
.logo-card .status.err { color: #c14040; }

/* ---------- Storico PUN / PSV (ultimi 12 mesi) ---------- */

.storico-indici { margin: 12px 0; }
.storico-indici .loading, .storico-indici .empty {
  font-size: 12px; color: #888; padding: 8px 0;
}
.storico-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.storico-table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.3px; color: #666; font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid #e0e0e0;
}
.storico-table tbody td {
  padding: 6px 8px; border-bottom: 1px solid #f0f0f0; vertical-align: middle;
}
.storico-table .st-mese { white-space: nowrap; }
.storico-table .st-mese span.muted {
  display: block; font-size: 11px; color: #999;
  font-family: 'Courier New', monospace;
}
.storico-table input[type=number] {
  width: 130px; max-width: 100%; padding: 5px 8px; font-size: 13px;
  border: 1px solid #d0d0d0; border-radius: 3px;
  font-family: 'Courier New', monospace;
}
.storico-table .st-actions { white-space: nowrap; text-align: right; }
.storico-table .st-save {
  padding: 5px 12px; font-size: 12px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer;
}
.storico-table .st-save:hover { background: #084e96; }
.storico-table .st-del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; margin-left: 6px;
}
.storico-table .st-del:hover { background: #c14040; }

.storico-add {
  margin: 4px 0 6px; padding: 10px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 8px;
}
.storico-add .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.storico-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.storico-add-row input {
  padding: 6px 8px; font-size: 13px; border: 1px solid #d0d0d0; border-radius: 3px;
}
.storico-add-row input[type=number] { flex: 1; min-width: 150px; font-family: 'Courier New', monospace; }
.storico-add-row button {
  padding: 6px 14px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.storico-add-row button:hover { background: #084e96; }
.storico-add-row button:disabled { background: #888; cursor: not-allowed; }
.storico-status { font-size: 12px; min-height: 14px; }
.storico-status.ok { color: #198038; }
.storico-status.err { color: #c14040; }

/* ---------- Offerte singole (override Portale) ---------- */

.single-offer-add {
  margin: 4px 0 14px; padding: 10px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 8px;
}
.single-offer-add .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.single-offer-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.single-offer-add-row input[type=file] { flex: 1; min-width: 220px; font-size: 12px; }
.single-offer-add-row button {
  padding: 6px 14px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.single-offer-add-row button:hover { background: #084e96; }
.single-offer-add-row button:disabled { background: #888; cursor: not-allowed; }
.single-offer-status { font-size: 12px; min-height: 14px; }
.single-offer-status.ok { color: #198038; }
.single-offer-status.err { color: #c14040; }

.single-offers-list { display: flex; flex-direction: column; gap: 8px; }
.single-offers-list .loading, .single-offers-list .empty {
  font-size: 12px; color: #888; padding: 8px 0;
}
.so-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fff;
}
.so-row .so-info { flex: 1; min-width: 0; }
.so-row .so-head { display: flex; align-items: center; gap: 8px; }
.so-row code { font-size: 12px; color: #333; }
.so-row .muted { font-size: 11px; }
.so-row .muted.warn { color: #b07a00; }
.so-badge {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.3px; color: #fff; border-radius: 3px; padding: 1px 6px;
}
.so-badge.so-luce { background: #c1392b; }
.so-badge.so-gas { background: #0a8f4f; }
.so-badge.so-warn { background: #b07a00; }
.so-tags { margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.so-sim, .so-db { font-size: 11px; }
.so-sim.ok, .so-db.ok { color: #198038; }
.so-sim.no, .so-db.no { color: #b07a00; }
.so-row .so-del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.so-row .so-del:hover { background: #c14040; }

/* ---------- Offerte escluse dalla comparazione ---------- */
.exclusions-add {
  margin: 4px 0 14px; padding: 10px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 8px;
}
.exclusions-add .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.exclusions-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.exclusions-add-row input[type=text] { flex: 1; min-width: 200px; font-size: 13px; padding: 6px 8px; }
.exclusions-add-row button {
  padding: 6px 14px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.exclusions-add-row button:hover { background: #084e96; }
.exclusions-add-row button:disabled { background: #888; cursor: not-allowed; }
.exclusions-status { font-size: 12px; min-height: 14px; }
.exclusions-status.ok { color: #198038; }
.exclusions-status.err { color: #c14040; }

.exclusions-list { display: flex; flex-direction: column; gap: 8px; }
.exclusions-list .loading, .exclusions-list .empty {
  font-size: 12px; color: #888; padding: 8px 0;
}
.ex-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fff;
}
.ex-row .ex-info { flex: 1; min-width: 0; }
.ex-row .ex-head { display: flex; align-items: center; gap: 8px; }
.ex-row code { font-size: 12px; color: #333; }
.ex-row .muted { font-size: 11px; }
.ex-tags { margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.ex-row .ex-del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.ex-row .ex-del:hover { background: #c14040; }

/* ---------- Whitelist "Carica PDF" ---------- */
.bill-whitelist {
  display: flex; flex-direction: column; gap: 6px;
  margin: 12px 0;
}
.bill-whitelist .loading, .bill-whitelist .empty {
  font-size: 12px; color: #888; padding: 8px 0;
}
.bw-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px;
  background: #fff;
}
.bw-row .bw-handle {
  color: #aaa; font-size: 14px; cursor: grab; user-select: none;
  width: 14px; flex-shrink: 0;
}
.bw-row .bw-nome {
  flex: 1; min-width: 0;
  padding: 5px 8px; font-size: 13px;
  border: 1px solid transparent; border-radius: 3px;
  background: transparent;
}
.bw-row .bw-nome:focus {
  outline: none; border-color: #0a66c2; background: #fff;
}
.bw-row .bw-piva {
  font-family: 'Courier New', monospace; font-size: 12px;
  color: #555; flex-shrink: 0;
}
.bw-row .bw-counts {
  font-size: 11px; color: #888; flex-shrink: 0; white-space: nowrap;
}
.bw-row .bw-counts.warn { color: #b07a00; }
.bw-row .bw-del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.bw-row .bw-del:hover { background: #c14040; }

.bill-whitelist-add {
  margin-top: 4px; padding: 10px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 8px;
}
.bill-whitelist-add .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.bill-whitelist-add-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.bill-whitelist-add-row input[type=text] {
  padding: 6px 8px; font-size: 13px; border: 1px solid #d0d0d0; border-radius: 3px;
}
.bill-whitelist-add-row #bwAddNome { flex: 1; min-width: 180px; }
.bill-whitelist-add-row #bwAddPiva { flex: 1; min-width: 160px; font-family: 'Courier New', monospace; }
.bill-whitelist-add-row button {
  padding: 6px 14px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer;
}
.bill-whitelist-add-row button:hover { background: #084e96; }
.bill-whitelist-status { font-size: 12px; min-height: 14px; }
.bill-whitelist-status.ok { color: #198038; }
.bill-whitelist-status.err { color: #c14040; }

.bill-whitelist-actions {
  display: flex; gap: 10px; align-items: center; margin-top: 8px;
}
.bill-whitelist-actions button { padding: 6px 14px; font-size: 13px; cursor: pointer; }
.bill-whitelist-actions button:disabled { opacity: 0.5; cursor: not-allowed; }
#bwDirty { font-size: 12px; }
#bwDirty.dirty { color: #b07a00; font-weight: 600; }

/* ---------- Recapiti fornitori (override telefono / sito) ---------- */

.contatti-add {
  margin: 4px 0 14px; padding: 10px; border: 1px dashed #d0d0d0;
  border-radius: 4px; background: #fafafa;
  display: flex; flex-direction: column; gap: 8px;
}
.contatti-add .add-form-title {
  font-size: 11px; color: #666; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px;
}
.contatti-add-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.contatti-add-row select,
.contatti-add-row input[type=text] {
  padding: 6px 8px; font-size: 13px; border: 1px solid #d0d0d0; border-radius: 3px;
}
.contatti-add-row #ctChiave { flex: 1; min-width: 170px; font-family: 'Courier New', monospace; }
.contatti-add-row #ctSito { flex: 1; min-width: 160px; }
.contatti-add-row #ctTelefono { flex: 1; min-width: 140px; }
.contatti-add-row button {
  padding: 6px 14px; font-size: 13px; background: #0a66c2; color: #fff;
  border: 0; border-radius: 3px; cursor: pointer;
}
.contatti-add-row button:hover { background: #084e96; }
.contatti-add-row button:disabled { opacity: 0.5; cursor: not-allowed; }
.contatti-status { font-size: 12px; min-height: 14px; }
.contatti-status.ok { color: #198038; }
.contatti-status.err { color: #c14040; }

.contatti-list { display: flex; flex-direction: column; gap: 8px; }
.contatti-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fff;
}
.contatti-row .contatti-key { flex: 1; min-width: 0; }
.contatti-row .contatti-scope {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.3px; color: #fff; background: #0a66c2;
  border-radius: 3px; padding: 1px 6px; margin-right: 6px;
}
.contatti-row code { font-size: 12px; color: #333; }
.contatti-row .muted { font-size: 11px; }
.contatti-row .muted.warn { color: #b07a00; }
.contatti-row .contatti-vals { font-size: 13px; color: #333; flex-shrink: 0; text-align: right; }
.contatti-row .contatti-vals .muted { font-size: 12px; }
.contatti-row .contatti-del {
  background: #888; color: #fff; border: 0; border-radius: 3px;
  width: 26px; height: 26px; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.contatti-row .contatti-del:hover { background: #c14040; }

@media (max-width: 600px) {
  .reimport-row { flex-direction: column; align-items: stretch; }
  .reimport-row button.primary { width: 100%; }
  .bw-row .bw-counts { display: none; }
  .contatti-row { flex-wrap: wrap; }
  .contatti-row .contatti-vals { text-align: left; }
}
