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

/* Futura PT via Adobe Fonts — sostituire YOUR_KIT_ID in base.html */

:root {
  --bg:       #ffffff;
  --bg2:      #f4f8ef;
  --bg3:      #e9f1e2;
  --border:   rgba(87,138,43,0.15);
  --border2:  rgba(87,138,43,0.30);
  --text:     #1a2e0a;
  --muted:    #5e7a3e;
  --faint:    #c4d9b0;
  --green:    #578A2B;
  --green-bg: #e9f1e2;
  --teal:     #2d9e6b;
  --coral:    #e05252;
  --amber:    #c97b10;
  --purple:   #6d4faa;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-weight: 300;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── NAV ── */
nav {
  background: var(--green);
  border-bottom: 1px solid rgba(87,138,43,0.4);
  padding: 0 32px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.nav-brand {
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-size: 15px;
  font-weight: 500;
  color: #ffffff;
  text-decoration: none;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.nav-brand span { color: #d4edab; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.75);
}

.nav-right a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  transition: color .15s;
}

.nav-right a:hover { color: #ffffff; }

.badge-role {
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.4);
  color: rgba(255,255,255,0.85);
}

.badge-role.admin  { border-color: #d4edab; color: #d4edab; }
.badge-role.viewer { border-color: rgba(255,255,255,0.5); color: #ffffff; }

/* ── MAIN CONTENT ── */
main {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  padding: 40px max(24px, calc(50% - 480px)) 60px;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
  scrollbar-gutter: stable;
}

main::-webkit-scrollbar { width: 5px; }
main::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 3px; }
main::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ── FLASH MESSAGES ── */
.flash-list { list-style: none; margin-bottom: 24px; }

.flash {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 8px;
  border-left: 3px solid;
}

.flash.success { background: rgba(45,158,107,0.08);  border-color: var(--teal);  color: var(--teal); }
.flash.danger  { background: rgba(224,82,82,0.08);   border-color: var(--coral); color: var(--coral); }
.flash.warning { background: rgba(201,123,16,0.08);  border-color: var(--amber); color: var(--amber); }
.flash.info    { background: rgba(87,138,43,0.08);   border-color: var(--green); color: var(--green); }

/* ── CARD ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
}

/* ── FORM ELEMENTS ── */
label {
  display: block;
  font-size: 11px;
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-size: 14px;
  font-weight: 300;
  outline: none;
  transition: border-color .15s;
  margin-bottom: 18px;
}

input:focus,
textarea:focus,
select:focus { border-color: var(--green); box-shadow: none; }

textarea { resize: vertical; min-height: 72px; line-height: 1.5; }

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235e7a3e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; cursor: pointer; }

/* ── SPINNER ── */
#page-spinner {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.72);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.spinner-ring {
  width: 100px;
  height: 100px;
  border: 3px solid var(--border2);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.spinner-sm {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
  vertical-align: middle;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,46,10,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-dialog {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 16px;
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.modal-head h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 24px 32px 8px; }

.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 32px 24px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--bg);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}

.form-section {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 8px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.radio-group {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 0;
}

.field-error {
  display: block;
  font-size: 11px;
  color: var(--coral);
  margin-top: -12px;
  margin-bottom: 14px;
}

.radio-label input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

/* ── BUTTONS ── */
.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary { background: var(--green); color: #ffffff; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-danger {
  background: rgba(224,82,82,0.10);
  color: var(--coral);
  border: 1px solid rgba(224,82,82,0.3);
}
.btn-danger:hover { background: rgba(224,82,82,0.20); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { color: var(--text); border-color: rgba(87,138,43,0.5); }

.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: auto; }

/* ── LOGIN PAGE ── */
body.login-page main {
  flex: 1;
  max-width: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 48px 24px 40px;
}

.login-logo {
  display: block;
  height: 90px;
  width: auto;
  margin: 0 auto 40px;
}

.login-wrapper {
  width: 100%;
  max-width: 400px;
}

.login-header { text-align: center; margin-bottom: 32px; }

.login-header h1 {
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.login-header h1 span { color: var(--green); }
.login-header p { font-size: 12px; color: var(--muted); letter-spacing: 0.3px; }

/* ── FOOTER ── */
footer {
  flex-shrink: 0;
  width: 100%;
  text-align: center;
  padding: 8px;
  font-size: 11px;
  font-family: 'futura-pt', Futura, 'Century Gothic', sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg2);
  border-top: 1px solid var(--border);
}

tr.tr-link { cursor: pointer; transition: background .12s; }
tr.tr-link:hover { background: var(--bg2); }

/* ── SEARCH BAR ── */
.search-wrapper {
  margin-bottom: 24px;
  position: relative;
  max-width: 420px;
}

.search-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
}

.search-wrapper input[type="search"] {
  margin-bottom: 0;
  padding-left: 40px;
  background: var(--bg);
  border-color: var(--border2);
  border-radius: 10px;
  height: 2rem;
  width: 15rem;
}

/* ── RESPONSIVE (tablet/phone) ── */

/* Tabelle: wrap scrollabile invece di rompere il layout */
.card:has(table) { overflow-x: auto; }
.card:has(table) table { min-width: 480px; }

@media (max-width: 768px) {
  /* form a 2 colonne -> 1 colonna */
  .form-row { grid-template-columns: 1fr; gap: 0; }

  /* griglie inline a 2 colonne fisse -> 1 colonna */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  nav { padding: 0 16px; }
  .nav-right { gap: 12px; font-size: 11px; }

  .modal-head, .modal-foot { padding-left: 20px; padding-right: 20px; }
  .modal-body { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 480px) {
  /* griglie inline a 3 colonne fisse -> 1 colonna */
  [style*="grid-template-columns: repeat(3, 1fr)"],
  [style*="grid-template-columns: repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(3, 1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* righe flex header/stato che si schiacciano -> vanno a capo */
  [style*="display:flex"][style*="justify-content:space-between"],
  [style*="display: flex"][style*="justify-content:space-between"],
  [style*="display:flex"][style*="justify-content: space-between"] {
    flex-wrap: wrap;
    row-gap: 12px;
  }

  /* sidebar chat fissa (asta_in_corso.html) -> stack sopra i messaggi */
  [style*="display:flex; height:400px"] { flex-direction: column; height: auto !important; max-height: 70vh; }
  [style*="width:200px"] {
    width: 100% !important;
    max-height: 140px;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }

  nav { padding: 0 12px; height: auto; min-height: 52px; flex-wrap: wrap; row-gap: 6px; padding-top: 8px; padding-bottom: 8px; }
  .nav-right { gap: 8px; font-size: 10px; }

  footer { flex-direction: column; gap: 4px; }
  footer span + span { margin-left: 0 !important; border-left: none !important; padding-left: 0 !important; }

  #cookie-notice { flex-direction: column; align-items: stretch !important; text-align: center; }

  .search-wrapper, .search-wrapper input[type="search"] { width: 100%; max-width: none; }
}