/* =========================================================================
   CRM BLACKLIST — design system condiviso (login / blacklist / audit).
   Stile vicino all'originale: Segoe UI, blu #4a90e2, card morbide,
   header sfumato blu. Tema chiaro di default, dark mode via [data-theme].
   ========================================================================= */

/* ----- Tema chiaro (default) ----- */
:root {
  --bg:            #f5f7fa;
  --surface:       #ffffff;   /* card / pannelli */
  --surface-2:     #f7f9fc;   /* aree tenui */
  --surface-3:     #f5f7fa;   /* status card / chip */
  --input-bg:      #ffffff;
  --border:        #e1e6ee;
  --border-bright: #d6dce6;

  --text:          #2c3e50;
  --text-dim:      #6b7a8d;
  --text-faint:    #9aa7b6;

  /* "accent" = palette viola/indaco (come il gradiente originale del login) */
  --accent:        #6c5ce7;
  --accent-2:      #764ba2;
  --accent-soft:   rgba(108, 92, 231, 0.10);
  --accent-line:   rgba(108, 92, 231, 0.30);

  --ok:            #2ecc71;
  --ok-soft:       rgba(46, 204, 113, 0.14);
  --err:           #e74c3c;
  --err-soft:      rgba(231, 76, 60, 0.12);
  --warn:          #f39c12;
  --warn-soft:     rgba(243, 156, 18, 0.16);
  --idle:          #95a5a6;

  --radius:        16px;
  --radius-sm:     8px;
  --shadow:        0 4px 6px rgba(40, 22, 90, 0.08);
  --shadow-lg:     0 12px 30px rgba(58, 30, 120, 0.14);
  --ring:          0 0 0 3px rgba(108, 92, 231, 0.15);
  --tr:            all 0.3s ease;

  /* gradiente viola dell'originale */
  --header-grad:   linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-tint:       radial-gradient(900px 480px at 50% -160px, rgba(118, 75, 162, 0.13), transparent 70%);

  --font-body:     'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --font-mono:     Consolas, 'SFMono-Regular', Menlo, 'Courier New', monospace;
}

/* ----- Tema scuro ----- */
[data-theme="dark"] {
  --bg:            #1a1a2e;
  --surface:       #16213e;
  --surface-2:     #131c33;
  --surface-3:     #0f1419;
  --input-bg:      #0f1419;
  --border:        #2c3e50;
  --border-bright: #34495e;

  --text:          #ecf0f1;
  --text-dim:      #aab4c0;
  --text-faint:    #7c8a99;

  --accent:        #8b7cf0;
  --accent-2:      #764ba2;
  --accent-soft:   rgba(139, 124, 240, 0.18);
  --accent-line:   rgba(139, 124, 240, 0.42);

  --ok-soft:       rgba(46, 204, 113, 0.16);
  --err-soft:      rgba(231, 76, 60, 0.16);
  --warn-soft:     rgba(243, 156, 18, 0.18);

  --shadow:        0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg:     0 12px 30px rgba(0, 0, 0, 0.45);
  --ring:          0 0 0 3px rgba(139, 124, 240, 0.22);
  --bg-tint:       radial-gradient(950px 520px at 50% -160px, rgba(118, 75, 162, 0.32), transparent 72%);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  background-image: var(--bg-tint);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.shell { max-width: 1200px; margin: 0 auto; padding: 28px 20px 56px; }

/* ===== Topbar / brand ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

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

.brand__mark {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--header-grad);
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 8px 20px -6px rgba(118, 75, 162, 0.6);
  flex-shrink: 0;
}

.brand__name {
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.15;
  background: var(--header-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--accent); /* fallback */
}
.brand__name b { font-weight: 700; }

.brand__sub {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ===== Buttons ===== */
.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: var(--tr);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn:active { transform: translateY(0); }

.btn--primary,
.btn--accent { background: var(--accent); color: #fff; }
.btn--primary:hover,
.btn--accent:hover { background: var(--accent-2); }

.btn--danger { background: var(--err); color: #fff; }
.btn--ghost {
  background: var(--surface);
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn--ghost:hover { background: var(--accent); color: #fff; }

.btn--sm { padding: 8px 14px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.6; pointer-events: none; }

/* ===== Panels / cards ===== */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.panel + .panel { margin-top: 22px; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 22px 28px;
  background: var(--header-grad);
}

.panel__title {
  font-weight: 600;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
}
.panel__title i { color: #fff; }

.panel__tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.panel__body { padding: 28px; }

/* ===== Pannello collassabile (dropdown) ===== */
.panel__head--toggle { cursor: pointer; user-select: none; }
.panel__head--toggle:focus-visible { outline: 3px solid rgba(255, 255, 255, 0.6); outline-offset: -3px; }

.panel__chevron {
  margin-left: 10px;
  font-size: 0.8em;
  color: rgba(255, 255, 255, 0.9);
  transition: transform 0.3s ease;
}
.collapsible:not(.is-collapsed) .panel__chevron { transform: rotate(180deg); }
.collapsible.is-collapsed .panel__body { display: none; }
.collapsible:not(.is-collapsed) .panel__body { animation: reveal 0.32s ease; }

/* ===== Form controls ===== */
.field { margin-bottom: 24px; }
.field__label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.field__label i { color: var(--accent); }

.input, .textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--input-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  transition: var(--tr);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.textarea { resize: vertical; min-height: 130px; line-height: 1.6; font-family: var(--font-mono); }

.form-actions {
  display: flex;
  gap: 14px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ===== Status LED ===== */
.led {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--idle);
}
.led--ok   { background: var(--ok);   animation: pulse-ok 1.8s infinite; }
.led--err  { background: var(--err);  animation: pulse-err 1.8s infinite; }
.led--warn { background: var(--warn); animation: pulse-warn 1s infinite; }
.led--idle { background: var(--idle); }

@keyframes pulse-ok {
  0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.6); }
  70%  { box-shadow: 0 0 0 10px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}
@keyframes pulse-err {
  0%   { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
  70%  { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}
@keyframes pulse-warn {
  0%   { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(243, 156, 18, 0); }
  100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); }
}

/* ===== Status grid (pannello CRM) ===== */
/* La summary vive sempre sull'header sfumato blu: testo chiaro per leggibilità in entrambi i temi */
.summary {
  display: flex;
  gap: 16px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.9);
}
.summary b { color: #fff; font-weight: 700; }
.summary .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 13px;
}

.status-card {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 15px 16px;
  background: var(--surface-3);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  transition: var(--tr);
}
.status-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.status-card.is-ok   { border-color: rgba(46, 204, 113, 0.4); }
.status-card.is-err  { border-color: rgba(231, 76, 60, 0.4); }
.status-card.is-warn { border-color: rgba(243, 156, 18, 0.4); }

.status-card .led { margin-top: 4px; }
.status-card__info { min-width: 0; flex: 1; }
.status-card__url {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-all;
}
.status-card__meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.status-card__meta .state-ok   { color: var(--ok);   font-weight: 600; }
.status-card__meta .state-err  { color: var(--err);  font-weight: 600; }
.status-card__meta .state-warn { color: var(--warn); font-weight: 600; }
.status-card__err {
  margin-top: 7px;
  font-size: 0.82rem;
  color: var(--err);
  display: flex;
  gap: 6px;
  align-items: flex-start;
  word-break: break-word;
}

.muted { color: var(--text-dim); }
.center { text-align: center; }

/* ===== Badge ===== */
.badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 13px;
  border-radius: 999px;
  color: #fff;
}
.badge--ok  { background: var(--ok); }
.badge--err { background: var(--err); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  border-radius: 12px;
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  min-width: 300px;
  max-width: 480px;
  animation: toast-in 0.5s ease, toast-out 0.5s ease 4.6s forwards;
}
.toast i { font-size: 1.5rem; }
.toast--ok  { background: var(--ok); }
.toast--err { background: var(--err); }

@keyframes toast-in  { from { transform: translateX(420px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateX(420px); opacity: 0; } }

/* ===== Reveal on load ===== */
.reveal { opacity: 0; transform: translateY(18px); animation: reveal 0.5s ease forwards; animation-delay: var(--d, 0s); }
@keyframes reveal { to { opacity: 1; transform: translateY(0); } }

/* ===== Theme switch (interruttore a levetta) ===== */
.theme-switch {
  position: relative;
  width: 68px; height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border-bright);
  background: var(--surface-2);
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow), inset 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: var(--tr);
}
.theme-switch:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.theme-switch:focus-visible { outline: none; box-shadow: var(--ring); }

.theme-switch__track {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 0.78rem;
  pointer-events: none;
}
.theme-switch__track .fa-sun  { color: #9785f2; }
.theme-switch__track .fa-moon { color: #b7acff; }

.theme-switch__thumb {
  position: absolute;
  top: 50%;
  left: 4px;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--header-grad);
  box-shadow: 0 2px 8px -1px rgba(58, 30, 120, 0.55);
  transition: left 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
html[data-theme="dark"] .theme-switch__thumb { left: calc(100% - 30px); }

/* ===== Responsive ===== */
@media (max-width: 620px) {
  .shell { padding: 20px 14px 44px; }
  .brand__name { font-size: 1.25rem; }
  .panel__title { font-size: 1.15rem; }
  .panel__head, .panel__body { padding: 18px 18px; }
  .status-grid { grid-template-columns: 1fr; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; justify-content: center; }
  .toast { left: 12px; right: 12px; min-width: auto; }
}
