/* =========================================================
   CRUSCOTTO SCADENZE BANDI - COMUNE DI ESPERIA
   Design System & Mobile-First Responsive Stylesheet
   ========================================================= */

:root {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  /* State colors */
  --status-open: #ef4444;       /* 🔴 Aperto / In Scadenza */
  --status-upcoming: #f59e0b;   /* 🟡 In apertura */
  --status-sportello: #2563eb;  /* 🔵 Sportello continuo */
  --status-closed: #94a3b8;     /* ⚪ Chiuso */

  --badge-verificato: #10b981;
  --badge-condizionato: #f59e0b;
  --badge-da-verificare: #64748b;

  --primary-blue: #1e3a8a;
  --primary-accent: #3b82f6;
  --primary-hover: #1d4ed8;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ================= HEADER ================= */
.app-header {
  background-color: #0f172a;
  color: #ffffff;
  padding: 18px 0;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-icon {
  font-size: 28px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 10px;
  border-radius: var(--radius-md);
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand .subtitle {
  font-size: 0.85rem;
  color: #94a3b8;
  font-weight: 400;
}

.live-clock-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: #38bdf8;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ================= AUDIT BANNER ================= */
.audit-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin: 18px 0;
  box-shadow: var(--shadow-sm);
}

.audit-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.audit-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ecfdf5;
  color: #065f46;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  border: 1px solid #a7f3d0;
}

.stats-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-pill {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-elevated);
}

.pill-total { background: #f1f5f9; color: #334155; }
.pill-open { background: #fee2e2; color: #991b1b; }
.pill-warning { background: #fef3c7; color: #92400e; }
.pill-sportello { background: #dbeafe; color: #1e40af; }
.pill-verified { background: #d1fae5; color: #065f46; }

.audit-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  padding-top: 8px;
  margin-top: 6px;
}

/* ================= URGENT SECTION ================= */
.urgent-section {
  margin-bottom: 24px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

.badge-urgent {
  background: #fee2e2;
  color: #b91c1c;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-sportello {
  background: #dbeafe;
  color: #1e40af;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
}

.urgent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.urgent-card {
  background: #fff;
  border: 2px solid #ef4444;
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-md);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease;
}

.urgent-card:hover {
  transform: translateY(-2px);
}

.urgent-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
}

.countdown-box {
  background: #fef2f2;
  color: #dc2626;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.urgent-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
  line-height: 1.3;
}

.urgent-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.urgent-amount {
  font-weight: 700;
  color: #047857;
}

.urgent-condition-box {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #92400e;
  margin-bottom: 12px;
}

.urgent-action-btn {
  background: #ef4444;
  color: #ffffff;
  text-align: center;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-block;
  transition: background 0.15s ease;
}

.urgent-action-btn:hover {
  background: #dc2626;
}

/* ================= FILTERS CARD ================= */
.filter-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.search-bar-wrap {
  position: relative;
  margin-bottom: 14px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
}

#search-input {
  width: 100%;
  padding: 12px 38px 12px 40px;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: #fff;
}

.clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
}

.filters-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.filter-group select {
  padding: 8px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-main);
  outline: none;
}

.category-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.pill-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover {
  background: #e2e8f0;
}

.pill-btn.active {
  background: var(--primary-blue);
  color: #fff;
  border-color: var(--primary-blue);
}

/* ================= CHANNELS LIST ================= */
.channels-section {
  margin-bottom: 30px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.results-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-export-csv {
  background: #fff;
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s ease;
}

.btn-export-csv:hover {
  background: var(--bg-elevated);
}

.channels-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.channel-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.channel-semaforo {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.channel-main {
  min-width: 0;
}

.channel-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.channel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.tag-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.tag-cat { background: #e0e7ff; color: #3730a3; }
.tag-grado-verificato { background: #dcfce7; color: #166534; }
.tag-grado-condizionato { background: #fef3c7; color: #92400e; }
.tag-grado-da-verificare { background: #f1f5f9; color: #475569; }

.channel-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.channel-ente {
  font-weight: 500;
}

.channel-amount {
  color: #047857;
  font-weight: 600;
}

.channel-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.deadline-display {
  font-size: 0.85rem;
  font-weight: 700;
}

.deadline-red { color: #dc2626; }
.deadline-yellow { color: #d97706; }
.deadline-blue { color: #2563eb; }
.deadline-gray { color: #64748b; }

.btn-details {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
}

/* ================= SPORTELLO SECTION ================= */
.sportello-section {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 2px dashed var(--border-color);
  margin-bottom: 40px;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.sportello-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.sportello-card {
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.sportello-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.sportello-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1e3a8a;
  margin-bottom: 4px;
}

.sportello-card-ente {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sportello-card-amount {
  font-size: 0.8rem;
  font-weight: 600;
  color: #047857;
}

/* ================= MODAL ================= */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--bg-elevated);
  border: none;
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
  z-index: 10;
}

.modal-header {
  padding: 20px 20px 12px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 6px;
}

.modal-ente {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  background: var(--bg-elevated);
  padding: 12px;
  border-radius: var(--radius-md);
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-item .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
}

.info-item .val {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.info-item .val.highlight {
  color: #047857;
}

.modal-block h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: #1e293b;
}

.condizioni-box {
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: #92400e;
  line-height: 1.4;
}

.desc-text {
  font-size: 0.85rem;
  color: #334155;
  line-height: 1.4;
}

.file-code {
  display: block;
  background: #0f172a;
  color: #38bdf8;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: monospace;
  word-break: break-all;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  background: var(--primary-accent);
  color: #fff;
  text-decoration: none;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* ================= FOOTER ================= */
.app-footer {
  background: #0f172a;
  color: #94a3b8;
  padding: 24px 0;
  margin-top: 40px;
  font-size: 0.8rem;
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ================= MOBILE RESPONSIVENESS ================= */
@media (max-width: 640px) {
  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .live-clock-badge {
    align-self: flex-start;
  }

  .channel-card {
    grid-template-columns: auto 1fr;
    gap: 10px;
  }

  .channel-right {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 4px;
    text-align: left;
  }

  .filters-row {
    grid-template-columns: 1fr;
  }
}
