body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background: #f4f6f7;
  color: #222;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* FILTERS (top bar) */
.filters-bar {
  width: 100%;
  box-sizing: border-box;
  padding: 16px 20px 12px; /* top 16px, left/right 20px, bottom 12px */
  background: #fff;
  border-bottom: 1px solid #e6e9eb;
  box-shadow: 0 1px 0 rgb(0 0 0 / 4%);
  position: sticky;
  top: 0;
  z-index: 1000;
  overflow-x: hidden; /* evita che contenuti larghi forzino scroll orizzontale */
}

.top-pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  justify-content: flex-end; /* allinea i controlli a destra su larghezza completa */
  width: 100%;
  box-sizing: border-box;
}

.top-pagination .page-indicator {
  font-size: 14px;
  color: #374151;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #e6eef8;
  min-width: 48px;
  text-align: center;
}

.top-pagination button {
  padding: 6px 10px;
  background: #fff;
  border: 1px solid #d6dde7;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.top-pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* sort toggle */
.sort-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid #d6dde7;
  border-radius: 6px;
}
.sort-toggle[aria-pressed="true"] {
  background: #eef2ff;
  border-color: #d0d7ff;
}
.sort-toggle:hover { background:#f8fafc; }

/* refresh button */
.refresh-btn {
  padding: 6px 10px;
  background: #fff;
  border: 1px solid #d6dde7;
  border-radius: 6px;
  cursor: pointer;
}
.refresh-btn:hover { background: #f8fafc; }

.pagination .page-indicator {
  font-size: 14px;
  color: #374151;
  padding: 6px 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid transparent;
  min-width: 48px;
  text-align: center;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (min-width: 900px) {
  /* position the top-pagination to the right of filters on large screens */
  .filters-bar {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  .filters {
    flex: 1 1 auto;
  }
  .top-pagination {
    margin-left: auto;
    margin-top: 0;
  }
}

.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  box-sizing: border-box;
  min-width: 0; /* evita che figli larghi forzino overflow */
}

.filter-item {
  display: flex;
  align-items: center;
  flex: 0 1 auto; /* può ridursi se lo spazio è limitato */
  min-width: 0; /* importantissimo per evitare overflow nel flex container */
}

.filter-item input[type="date"], .filter-item input[type="text"], .filter-item input, .filter-item select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d3d7db;
  background: #fff;
  font-size: 14px;
  color: #1f2933;
  max-width: 100%;
  box-sizing: border-box;
}

.filter-item.search {
  flex: 1 1 300px; /* prende lo spazio rimanente ma può ridursi */
  min-width: 140px;
}

.filter-item.date input {
  margin-left: 6px;
  margin-right: 0;
}

.filter-item.actions button {
  background: transparent;
  border: 1px solid #e1e6e9;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

@media (max-width: 800px) {
  .filters {
    gap: 8px;
  }
  .filter-item.search {
    flex-basis: 100%;
    order: -1; /* porta la search in cima su schermi piccoli */
  }
  .filter-item.date {
    flex-basis: 100%;
  }
  .filters-bar {
    padding: 12px 12px 10px;
  }
}

/* evita scroll orizzontale dell'intera pagina */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Toggle behaviour: when header has .collapsed the filters are hidden (mobile) */
.filters-bar.collapsed .filters {
  display: none;
}

/* Filters toggle button (hidden on desktop, visible on small screens) */
.filters-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d6dde7;
  background: #fff;
  cursor: pointer;
}
.filters-toggle:hover { background: #f8fafc; }

@media (max-width: 800px) {
  .filters-toggle { display: inline-flex; }
  .top-pagination { justify-content: space-between; }
}

/* MAIN */
.main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* Legacy .filters selector (not used) left here for safety */
.filters input,
.filters select {
  padding: 10px;
  width: 100%;
  border-radius: 6px;
  border: 1px solid #ccc;
  margin-bottom: 12px;
}

/* LOG CARD */
.log-card {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  padding: 18px;
  border-radius: 12px;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(2,6,23,0.06);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
  border-left: 6px solid transparent;
}

.log-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 10px 30px rgba(2,6,23,0.12);
}

/* COLORI */
.success {
  border-left-color: #4caf50;
}

.error {
  border-left-color: #e53935;
}

.warning {
  border-left-color: #ffb300;
}

/* PAGINAZIONE */
.pagination {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 8px 12px;
  border: none;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

.pagination button:hover {
  background: #eee;
}

/* DETTAGLI */
pre {
  background: #1e1e1e;
  padding: 15px;
  color: #eee;
  border-radius: 8px;
  overflow-x: auto;
}

/* Parsed date hint under each log for debugging/verification */
.parsed-date {
  margin-top: 8px;
}
.parsed-date small {
  color: #6b7280;
  font-size: 12px;
}
.parsed-date .raw {
  color: #9ca3af;
  font-size: 11px;
  margin-left: 8px;
}

/* Enhanced card layout */
.log-card .op-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.log-card .op-title {
  font-weight: 700;
  font-size: 18px;
  color: #071123;
  letter-spacing: 0.1px;
  text-transform: none; /* JS capitalizes */
}
.log-card .ts {
  font-size: 13px;
  color: #4b5563;
}

.log-card .op-left {
  display: flex;
  flex-direction: column;
}

.op-row .center {
  margin-top: 6px;
  font-size: 14px;
  background: transparent;
  padding: 0;
  border: none;
  font-style: italic;
}
.log-card .meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.log-card .client {
  font-size: 15px;
  color: #0b1220;
  font-weight: 600;
}
.log-card .center {
  font-size: 13px;
  color: #374151;
  padding: 0;
  border: none;
}
.log-card .appointment {
  font-size: 13px;
  color: #475569;
  background: rgba(99,102,241,0.06);
  padding: 4px 8px;
  border-radius: 8px;
}

.log-card .rinvio {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #0b1220;
  margin-top: 8px;
  background: linear-gradient(90deg, rgba(37,99,235,0.04), rgba(99,102,241,0.02));
  padding: 6px 10px;
  border-radius: 8px;
}
.log-card .rinvio .old, .log-card .rinvio .new {
  font-weight: 600;
  color: #0b1220;
}
.log-card .rinvio .arrow {
  font-weight: 700;
  color: #2563eb;
}

.log-card .purchase {
  margin-top: 8px;
  font-size: 14px;
  color: #04212b;
  display: flex;
  align-items: center;
  gap: 8px;
}
.log-card .purchase .amount {
  font-weight: 800;
  margin-left: 4px;
  color: #065f46;
}
.log-card .next-appt {
  margin-top: 6px;
  font-size: 13px;
  color: #374151;
}

/* accessibility: ensure focus visible */
.log-card:focus {
  outline: 3px solid rgba(59,130,246,0.16);
  outline-offset: 2px;
}

/* Detail page - organized sections */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(2,6,23,0.06);
}
.detail-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #071123;
}
.detail-back {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}
.detail-back:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

.detail-container { display: flex; flex-direction: column; gap: 18px; }

.detail-sections { display: flex; flex-direction: column; gap: 16px; }
.detail-section {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(2,6,23,0.06);
}
.section-title {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 700;
  color: #071123;
}
.section-body { display: flex; flex-direction: column; gap: 10px; }

.field-row { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid #f3f4f6; }
.field-row:last-child { border-bottom: none; }
.field-label { 
  font-weight: 600;
  color: #475569;
  min-width: 140px;
  font-style: italic;
}
.field-value { color: #0b1220; flex: 1; word-break: break-word; }

.detail-advanced {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(2,6,23,0.06);
}
.detail-advanced details { cursor: pointer; }
.detail-advanced summary { 
  font-weight: 600;
  color: #071123;
  padding: 8px 0;
  user-select: none;
}
.detail-advanced summary:hover { color: #2563eb; }
.raw-controls {
  display: flex;
  gap: 8px;
  margin: 12px 0 8px;
}
.raw-controls button {
  padding: 6px 12px;
  background: #eef2ff;
  border: 1px solid #d0d7ff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.detail-advanced pre {
  background: #0b1220;
  color: #e6f0f4;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
  max-height: 50vh;
}

.error { color: #e53935; font-weight: 600; padding: 12px; background: #ffebee; border-radius: 8px; }

@media (max-width: 900px) {
  .detail-sections { gap: 12px; }
  .field-label { min-width: 100px; }
}

