:root {
  --ink: #17303a;
  --muted: #55656d;
  --paper: #f8f7f2;
  --panel: rgba(255, 255, 255, 0.82);
  --line: #d4d8cf;
  --accent: #ff6b3d;
  --accent-alt: #1f9d8f;
  --danger: #c7362f;
  --shadow: 0 16px 40px rgba(20, 44, 61, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #ffe5d6, transparent 40%),
    radial-gradient(circle at 90% 20%, #cdf3ee, transparent 35%),
    linear-gradient(160deg, #f3f6ef 0%, #fbfaf5 45%, #eef8f6 100%);
  min-height: 100vh;
}

body.modal-open {
  overflow: hidden;
}

.bg-shape {
  position: fixed;
  width: 320px;
  height: 320px;
  border-radius: 42% 58% 70% 30% / 46% 35% 65% 54%;
  opacity: 0.3;
  filter: blur(6px);
  z-index: 0;
  animation: float 12s ease-in-out infinite alternate;
}

.bg-shape-left {
  background: #ff6b3d;
  left: -120px;
  top: 35%;
}

.bg-shape-right {
  background: #1f9d8f;
  right: -120px;
  top: 6%;
  animation-delay: 2s;
}

@keyframes float {
  from {
    transform: translateY(0) rotate(0deg);
  }
  to {
    transform: translateY(-32px) rotate(15deg);
  }
}

.layout {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 16px 44px;
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}

.brand-logo {
  display: block;
  height: 220px;
  width: auto;
  max-width: min(760px, 90vw);
  object-fit: contain;
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

h3 {
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 12px;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.legal-link {
  margin-top: 8px;
  font-size: 0.82rem;
}

.legal-link a,
.footer-note a {
  color: #0b786b;
  text-decoration: none;
  font-weight: 600;
}

.legal-link a:hover,
.footer-note a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.actions {
  display: grid;
  gap: 8px;
  min-width: 340px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  color: var(--ink);
}

.tab.active {
  background: linear-gradient(130deg, var(--accent), #ff875f);
  color: #fff;
  border-color: transparent;
}

.tab-panel {
  display: none;
  gap: 14px;
}

.tab-panel.active {
  display: grid;
}

.toast {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.toast.ok {
  background: rgba(31, 157, 143, 0.14);
  border-color: rgba(31, 157, 143, 0.4);
}

.toast.err {
  background: rgba(199, 54, 47, 0.12);
  border-color: rgba(199, 54, 47, 0.35);
}

.hidden {
  display: none;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.ticket-search-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: 16px;
  row-gap: 14px;
  align-items: start;
}

.ticket-search-grid > label:not(.checkbox-label) {
  grid-column: span 2;
  min-width: 0;
}

.cloudflare-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.cloudflare-grid button {
  align-self: end;
}

.cloudflare-entrypoint-form {
  margin-top: 10px;
}

label {
  font-size: 0.82rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

input,
select,
textarea,
button {
  font-family: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 9px 10px;
  color: var(--ink);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  border: 1px solid #a6b0b4;
}

textarea {
  resize: vertical;
}

button {
  border: none;
  background: linear-gradient(130deg, var(--accent), #ff875f);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease;
}

button.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost.danger {
  color: #8a201a;
  border-color: rgba(199, 54, 47, 0.4);
  background: rgba(199, 54, 47, 0.08);
}

button.ghost.mini-danger {
  padding: 6px 10px;
  font-size: 0.78rem;
  color: #8a201a;
  border-color: rgba(199, 54, 47, 0.42);
  background: rgba(199, 54, 47, 0.1);
}

button:hover {
  transform: translateY(-1px);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.checkbox-label input {
  width: auto;
}

.ticket-search-grid .checkbox-label {
  grid-column: 1 / span 6;
  align-self: center;
  margin: 0;
  padding-left: 2px;
}

.ticket-search-grid button {
  grid-column: 9 / span 4;
  justify-self: end;
  width: min(320px, 100%);
  min-height: 46px;
}

.kpi-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.kpi-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.45rem;
}

.nav-card {
  cursor: pointer;
}

.nav-card:hover {
  border-color: rgba(255, 107, 61, 0.45);
  box-shadow: 0 8px 22px rgba(255, 107, 61, 0.16);
}

.two-col {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-two-col {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ticket-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  align-items: end;
  margin: 8px 0;
}

.collapsible-panel .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.collapsible-panel .panel-head h2 {
  margin-bottom: 0;
}

.collapsible-panel .panel-toggle {
  padding: 6px 10px;
  min-height: 34px;
  min-width: 94px;
  font-size: 0.78rem;
  font-weight: 700;
}

.collapsible-panel.collapsed .panel-head {
  margin-bottom: 0;
}

.geo-filter-row {
  margin-bottom: 10px;
}

.geo-filter-row button {
  min-height: 42px;
}

.unique-visitor-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.uv-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.88);
}

.uv-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.uv-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
  line-height: 1.1;
}

#cloudflareDeviceStatus {
  margin: 2px 0 10px;
}

.ticket-detail-grid {
  margin-top: 8px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 10px;
  font-size: 0.82rem;
}

.ticket-detail-grid strong {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

thead {
  background: rgba(31, 157, 143, 0.08);
}

th,
td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #e6e9e3;
}

.check-col {
  width: 34px;
  min-width: 34px;
}

.bulk-controls {
  margin-bottom: 8px;
}

.muted-small {
  color: var(--muted);
  font-size: 0.82rem;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(255, 107, 61, 0.09);
}

.table-wrap {
  overflow-x: auto;
}

.chart-wrap {
  position: relative;
  min-height: 280px;
}

.geo-map {
  position: relative;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(160deg, rgba(227, 239, 246, 0.94), rgba(214, 230, 236, 0.94));
  margin-bottom: 10px;
}

.geo-map-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 20px;
}

.leaflet-container {
  font-family: "Space Grotesk", sans-serif;
}

.geo-popup {
  font-size: 0.82rem;
  line-height: 1.35;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 140px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
}

.activity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
}

.activity-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  font-size: 0.8rem;
}

.conversation-list {
  max-height: 360px;
}

.link-button {
  border: 1px solid var(--line);
  background: #fff;
  color: #0b786b;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
}

.link-button:hover {
  transform: none;
  text-decoration: underline;
}

.facets {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  border: 1px solid transparent;
}

.badge.quality_low {
  background: rgba(199, 54, 47, 0.16);
  border-color: rgba(199, 54, 47, 0.36);
}

.badge.quality_medium {
  background: rgba(255, 163, 69, 0.18);
  border-color: rgba(255, 163, 69, 0.34);
}

.badge.quality_high {
  background: rgba(31, 157, 143, 0.16);
  border-color: rgba(31, 157, 143, 0.34);
}

.badge.quality_unrated {
  background: rgba(85, 101, 109, 0.12);
  border-color: rgba(85, 101, 109, 0.3);
}

.badge.category_commerciale {
  background: rgba(31, 157, 143, 0.16);
  border-color: rgba(31, 157, 143, 0.34);
}

.badge.category_guasto,
.badge.category_security {
  background: rgba(199, 54, 47, 0.16);
  border-color: rgba(199, 54, 47, 0.32);
}

.badge.category_billing,
.badge.category_account,
.badge.category_feature,
.badge.category_how_to,
.badge.category_other {
  background: rgba(85, 101, 109, 0.12);
  border-color: rgba(85, 101, 109, 0.28);
}

.badge.open,
.badge.in_progress {
  background: rgba(255, 163, 69, 0.16);
  border-color: rgba(255, 163, 69, 0.32);
}

.badge.resolved,
.badge.closed {
  background: rgba(31, 157, 143, 0.16);
  border-color: rgba(31, 157, 143, 0.32);
}

.badge.escalated {
  background: rgba(199, 54, 47, 0.16);
  border-color: rgba(199, 54, 47, 0.32);
}

.footer-note {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.policy-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 26px 16px 42px;
  position: relative;
  z-index: 1;
}

.policy-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  padding: 22px;
  line-height: 1.58;
  font-size: 0.95rem;
}

.policy-content h1 {
  margin-bottom: 6px;
}

.policy-content h2 {
  margin-top: 18px;
  margin-bottom: 6px;
}

.policy-content ul {
  margin: 8px 0 12px 18px;
}

.policy-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 10px;
}

.policy-back {
  display: inline-block;
  margin-bottom: 14px;
  color: #0b786b;
  font-weight: 600;
  text-decoration: none;
}

.policy-back:hover {
  text-decoration: underline;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 14px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 30, 0.48);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: min(980px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.modal.modal-fullscreen {
  padding: 0;
}

.modal.modal-fullscreen .ticket-modal-card {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
  padding: 16px;
  overflow: auto;
}

.contact-spotlight {
  margin-bottom: 10px;
  border-radius: 14px;
  border: 1px solid rgba(31, 157, 143, 0.34);
  background: linear-gradient(130deg, rgba(31, 157, 143, 0.13), rgba(255, 107, 61, 0.11));
  padding: 10px;
}

.contact-hero-head {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.contact-hero-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.contact-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: #0b786b;
  text-decoration: none;
  font-weight: 700;
}

.contact-chip:hover {
  text-decoration: underline;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

@media (max-width: 1080px) {
  .brand-logo {
    height: 120px;
    max-width: min(520px, 92vw);
  }

  .ticket-grid,
  .two-col,
  .mini-two-col,
  .unique-visitor-summary {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .actions {
    min-width: 0;
    width: 100%;
  }

  .tabs {
    overflow-x: auto;
  }

  .footer-note {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 1500px) {
  .ticket-search-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .ticket-search-grid > label:not(.checkbox-label) {
    grid-column: span 2;
  }

  .ticket-search-grid .checkbox-label {
    grid-column: 1 / span 3;
  }

  .ticket-search-grid button {
    grid-column: 4 / span 3;
    width: 100%;
  }
}

@media (max-width: 860px) {
  .ticket-search-grid {
    grid-template-columns: 1fr;
  }

  .ticket-search-grid > label:not(.checkbox-label),
  .ticket-search-grid .checkbox-label,
  .ticket-search-grid button {
    grid-column: 1 / -1;
  }

  .ticket-search-grid button {
    width: 100%;
    justify-self: stretch;
  }
}
