/* ============================================================
   CCNL Smart – style.css
   Design: editorial/refined — ink on paper meets digital clarity
   ============================================================ */

/* ---------- CSS VARIABLES ---------- */
:root {
  --blue:       #1d4ed8;
  --blue-light: #dbeafe;
  --blue-dark:  #1e3a8a;
  --ink:        #111827;
  --ink-mid:    #374151;
  --ink-soft:   #6b7280;
  --ink-muted:  #9ca3af;
  --surface:    #f9fafb;
  --white:      #ffffff;
  --border:     #e5e7eb;
  --border-mid: #d1d5db;
  --gold:       #b45309;
  --gold-bg:    #fef3c7;

  /* Category colors */
  --cat-stipendi:   #1d4ed8;
  --cat-ferie:      #059669;
  --cat-malattia:   #dc2626;
  --cat-straordinari: #7c3aed;
  --cat-orario:     #0891b2;
  --cat-permessi:   #d97706;
  --cat-contratto:  #374151;
  --cat-diritti:    #be185d;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.15), 0 8px 20px rgba(0,0,0,.08);
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- HEADER ---------- */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
  color: var(--ink);
}

.logo-mark {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.6rem;
  color: var(--blue);
  line-height: 1;
}

.logo-text {
  font-size: 1.05rem;
  font-weight: 300;
  letter-spacing: .01em;
}

.logo-text strong { font-weight: 600; }

.badge-ccnl {
  font-size: .72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--blue);
  background: var(--blue-light);
  padding: .25rem .65rem;
  border-radius: 999px;
}

/* ---------- HERO / SEARCH ---------- */
.hero {
  background: linear-gradient(160deg, #0f1f5c 0%, #1d4ed8 55%, #2563eb 100%);
  padding: 3.5rem 1.5rem 2.8rem;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '§';
  font-family: 'DM Serif Display', serif;
  position: absolute;
  right: -2rem;
  top: -3rem;
  font-size: 20rem;
  color: rgba(255,255,255,.04);
  pointer-events: none;
  line-height: 1;
}

.hero-inner {
  max-width: 780px;
  margin: 0 auto;
  position: relative;
}

.hero-eyebrow {
  font-size: .78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.6);
  margin-bottom: .75rem;
}

.hero-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 400;
  color: var(--white);
  line-height: 1.15;
  margin-bottom: .75rem;
}

.hero-title em {
  font-style: italic;
  color: #93c5fd;
}

.hero-sub {
  font-size: .95rem;
  color: rgba(255,255,255,.7);
  margin-bottom: 2rem;
  max-width: 520px;
}

/* SEARCH BOX */
.search-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .15rem .15rem .15rem 1.25rem;
  box-shadow: var(--shadow-lg);
  transition: box-shadow .2s;
}

.search-box:focus-within {
  box-shadow: 0 20px 48px rgba(0,0,0,.2), 0 0 0 3px rgba(255,255,255,.4);
}

.search-icon {
  font-size: 1.2rem;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--ink);
  background: transparent;
  padding: .85rem 0;
}

.search-input::placeholder { color: var(--ink-muted); }

.search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  padding: .5rem .75rem;
  font-size: .9rem;
  border-radius: var(--radius-sm);
  transition: color .15s;
}
.search-clear:hover { color: var(--ink); }

/* FILTER BUTTONS */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1.25rem;
}

.filter-btn {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.85);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-family: 'DM Sans', sans-serif;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.filter-btn:hover {
  background: rgba(255,255,255,.22);
  color: var(--white);
}

.filter-btn.active {
  background: var(--white);
  border-color: var(--white);
  color: var(--blue-dark);
}

/* ---------- MAIN CONTENT ---------- */
.content {
  max-width: 780px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ---------- RESULTS HEADER ---------- */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.results-count {
  font-size: .88rem;
  color: var(--ink-soft);
  font-weight: 500;
}

/* AI BUTTON */
.ai-btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  background: linear-gradient(135deg, #0f1f5c, #1d4ed8);
  color: var(--white);
  border: none;
  border-radius: 999px;
  padding: .5rem 1.1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(29,78,216,.3);
  transition: transform .15s, box-shadow .15s;
}

.ai-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(29,78,216,.4);
}

.ai-btn:active { transform: translateY(0); }

.ai-icon { font-size: 1rem; }

.ai-btn--center { display: flex; margin: 1rem auto 0; }

/* ---------- RESULT CARDS ---------- */
.results-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.result-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.4rem;
  cursor: pointer;
  transition: box-shadow .18s, border-color .18s, transform .18s;
  animation: fadeSlideIn .25s ease both;
}

.result-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-mid);
  transform: translateY(-2px);
}

.result-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .6rem;
}

.result-card-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.3;
  flex: 1;
}

.result-card-title mark {
  background: var(--gold-bg);
  color: var(--gold);
  border-radius: 3px;
  padding: 0 2px;
}

.result-badge {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .25rem .6rem;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.result-card-snippet {
  font-size: .9rem;
  color: var(--ink-mid);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-card-snippet mark {
  background: var(--gold-bg);
  color: var(--gold);
  border-radius: 3px;
  padding: 0 2px;
}

.result-card-arrow {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: .75rem;
  font-size: .8rem;
  color: var(--ink-muted);
  gap: .3rem;
}

/* ---------- CATEGORY BADGE COLORS ---------- */
.badge-stipendi   { background: #eff6ff; color: var(--cat-stipendi); }
.badge-ferie      { background: #ecfdf5; color: var(--cat-ferie); }
.badge-malattia   { background: #fef2f2; color: var(--cat-malattia); }
.badge-straordinari { background: #f5f3ff; color: var(--cat-straordinari); }
.badge-orario     { background: #ecfeff; color: var(--cat-orario); }
.badge-permessi   { background: #fffbeb; color: var(--cat-permessi); }
.badge-contratto  { background: #f9fafb; color: var(--cat-contratto); }
.badge-diritti    { background: #fdf2f8; color: var(--cat-diritti); }

/* ---------- EMPTY STATE ---------- */
.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
}

.empty-icon {
  font-size: 3rem;
  color: var(--ink-muted);
  margin-bottom: 1rem;
}

.empty-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  color: var(--ink-mid);
  margin-bottom: .5rem;
}

.empty-sub {
  font-size: .9rem;
  color: var(--ink-soft);
  max-width: 380px;
  margin: 0 auto;
}

/* ---------- AI PANEL ---------- */
.ai-panel {
  margin-top: 1.5rem;
  background: var(--white);
  border: 1px solid var(--blue-light);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-md);
  overflow: hidden;
  animation: fadeSlideIn .3s ease;
}

.ai-panel-inner { padding: 1.4rem; }

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
}

.ai-panel-icon {
  color: var(--blue);
  font-size: 1.1rem;
}

.ai-panel-title {
  font-weight: 600;
  font-size: .95rem;
  color: var(--blue-dark);
  flex: 1;
}

.ai-panel-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: .9rem;
  padding: .25rem .5rem;
  border-radius: var(--radius-sm);
  transition: color .15s;
}
.ai-panel-close:hover { color: var(--ink); }

.ai-answer {
  font-size: .95rem;
  line-height: 1.7;
  color: var(--ink-mid);
  white-space: pre-wrap;
}

.ai-panel-note {
  margin-top: 1rem;
  font-size: .76rem;
  color: var(--ink-muted);
  border-top: 1px solid var(--border);
  padding-top: .75rem;
}

/* Loading dots */
.ai-loading {
  display: flex;
  gap: .4rem;
  padding: .5rem 0;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  animation: bounce .8s infinite;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(.8); opacity: .5; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* API Key input */
.api-key-row {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.api-key-row label {
  font-size: .85rem;
  font-weight: 500;
  color: var(--ink-mid);
}

.api-key-input {
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  padding: .6rem .9rem;
  font-family: monospace;
  font-size: .88rem;
  outline: none;
  transition: border-color .15s;
}

.api-key-input:focus { border-color: var(--blue); }

.api-key-save {
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: .6rem 1.2rem;
  font-family: 'DM Sans', sans-serif;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  align-self: flex-start;
  transition: background .15s;
}
.api-key-save:hover { background: var(--blue-dark); }

/* ---------- WELCOME STATE ---------- */
.welcome-state { animation: fadeSlideIn .35s ease; }

.welcome-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.4rem;
  color: var(--ink);
  margin-bottom: 1.25rem;
  font-weight: 400;
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: 2.5rem;
}

.quick-link {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .45rem 1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: .84rem;
  color: var(--ink-mid);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.quick-link:hover {
  background: var(--blue-light);
  border-color: #bfdbfe;
  color: var(--blue-dark);
}

/* Salary table */
.salary-preview {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.salary-preview-title {
  font-size: .92rem;
  font-weight: 600;
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

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

.salary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}

.salary-table th {
  background: #f3f4f6;
  padding: .65rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
}

.salary-table td {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink-mid);
}

.salary-table tr:last-child td { border-bottom: none; }

.salary-table tr:hover td { background: #f9fafb; }

.highlight-row td {
  background: var(--blue-light) !important;
  color: var(--blue-dark) !important;
  font-weight: 600;
}

.salary-note {
  font-size: .76rem;
  color: var(--ink-muted);
  padding: .65rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------- MODAL ---------- */
/* Modal overlay: nascosto di default, visibile solo con .is-open */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

/* NON blocchiamo mai body overflow: lo scroll della pagina
   rimane sempre libero. Il modal è position:fixed e non ne ha bisogno. */
.modal-overlay.is-open {
  display: flex;
  animation: fadeIn .2s ease;
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn .25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.4rem .75rem;
  position: sticky;
  top: 0;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.modal-badge { /* same as result-badge */ }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 1rem;
  padding: .25rem .5rem;
  border-radius: var(--radius-sm);
  transition: color .15s;
}
.modal-close:hover { color: var(--ink); }

.modal-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 400;
  padding: 1.25rem 1.4rem .75rem;
  line-height: 1.3;
}

.modal-body {
  padding: 0 1.4rem 1.5rem;
  font-size: .96rem;
  line-height: 1.75;
  color: var(--ink-mid);
  white-space: pre-wrap;
}

/* ---------- ANIMATIONS ---------- */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* Animation delay for staggered cards */
.result-card:nth-child(1)  { animation-delay: .03s; }
.result-card:nth-child(2)  { animation-delay: .06s; }
.result-card:nth-child(3)  { animation-delay: .09s; }
.result-card:nth-child(4)  { animation-delay: .12s; }
.result-card:nth-child(5)  { animation-delay: .15s; }
.result-card:nth-child(6)  { animation-delay: .18s; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 600px) {
  .hero { padding: 2.5rem 1rem 2rem; }
  .hero-title { font-size: 1.75rem; }
  .content { padding: 1.5rem 1rem 3rem; }
  .modal-card { max-height: 90vh; border-radius: var(--radius-md); }
  .salary-table th, .salary-table td { padding: .5rem .75rem; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .ai-btn--center { margin-top: 1rem; }
}

@media (max-width: 400px) {
  .filter-btn { font-size: .75rem; padding: .3rem .7rem; }
  .header-inner { padding: 0 1rem; }
}
