:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #eaecf0;
  --border-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --tag-bg: #eff6ff;
  --tag-text: #1d4ed8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Header */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.search-box {
  flex: 1;
  max-width: 440px;
  min-width: 260px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Layout principale */
.layout {
  max-width: 1180px;
  margin: 24px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.sidebar-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.sidebar-heading + .nav-list {
  margin-bottom: 20px;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
}

.nav-link:hover {
  background: var(--tag-bg);
}

.nav-link.active {
  background: var(--tag-bg);
  font-weight: 600;
}

.sidebar-ai-card {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: var(--tag-bg);
  padding: 12px;
  font-size: 13px;
}

.sidebar-ai-card h2 { margin: 0; font-size: 14px; }
.sidebar-ai-card p { margin: 6px 0 8px; color: #344054; }
.sidebar-ai-card .ai-promo-link { display: inline-block; line-height: 24px; }

.ai-promo-link {
  color: var(--tag-text);
  font-weight: 600;
  text-underline-offset: 2px;
}

.ai-promo-link:hover { text-decoration-thickness: 2px; }

.coffee-link {
  display: grid;
  gap: 3px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #b9dceb;
  border-radius: 8px;
  background: #eaf6fb;
  color: #134766;
  text-decoration: none;
  text-align: center;
}
.coffee-link:hover { background: #d9eff9; border-color: #88bbd4; }
.coffee-link:focus-visible { outline: 2px solid #0076b6; outline-offset: 2px; }
.coffee-link span { color: #34576f; font-size: 12px; }

/* Contenuto */
.main-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.section-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.section-desc {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--muted);
}

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

.cards-grid + .section-title {
  margin-top: 24px;
}

.entry-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: #ffffff;
}

.badge {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
}

.entry-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.entry-desc {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.btn {
  margin-top: 6px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease;
}

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

.btn-secondary {
  background: #f2f4f7;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e4e7ec;
}

.header-add {
  margin: 0;
  padding: 11px 16px;
  font-size: 14px;
  white-space: nowrap;
}

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.content-column { min-width: 0; }
.main-card:focus { outline: none; }
.sync-status { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.sync-status:empty, [hidden] { display: none !important; }
.sync-status button { margin-left: 8px; }
.sync-status.is-error { color: #a62b24; }
.sync-status.is-success { color: #226342; }
.contribution-note {
  border-left: 3px solid var(--primary);
  background: var(--tag-bg);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 14px;
}
.contribution-note p { margin: 3px 0 0; color: #344054; }
.contribution-note p + p { margin-top: 8px; }
.entry-desc, .profile-bio, .detail-box a, .entry-title { overflow-wrap: anywhere; }
.entry-desc { white-space: pre-line; }
.profile-bio { white-space: pre-wrap; }
.profile-meta { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field.full-width { grid-column: 1 / -1; }
.form-field label { font-size: 14px; font-weight: 600; }
.field-control {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}
textarea.field-control { resize: vertical; min-height: 108px; }
.field-control:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.field-control[aria-invalid="true"] { border-color: #a62b24; }
.field-help { margin: 0; color: var(--muted); font-size: 12px; }
.field-error { margin: 0; font-size: 13px; color: #a62b24; }
.form-message { margin: 16px 0 0; color: #a62b24; font-size: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.btn.btn-danger { color: #fff; background: #a62b24; border-color: #a62b24; }
.btn.btn-danger:hover { background: #87231e; border-color: #87231e; }
.btn:disabled { opacity: 0.65; cursor: wait; }
.loading-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin-bottom: 24px; }
.loading-card { padding: 20px; border: 1px solid var(--border); border-radius: 12px; }
.loading-line { height: 12px; background: #eaecf0; border-radius: 4px; margin-bottom: 14px; }
.loading-line:first-child { width: 35%; }
.loading-line:nth-child(2) { width: 70%; height: 20px; }
.conflict-box { margin-top: 20px; padding: 16px; border: 1px solid #d0a355; border-radius: 8px; }
.conflict-box h3 { font-size: 15px; margin: 0 0 10px; }
.conflict-box p { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.conflict-box a { overflow-wrap: anywhere; }

/* Vista dettaglio scheda / pagina informativa */
.detail-box {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 14px;
}

.detail-box h3 {
  margin: 16px 0 6px;
  font-size: 15px;
}

.detail-box p, .detail-box ul {
  margin: 0 0 12px;
  font-size: 14px;
  color: #344054;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  font-size: 14px;
}

/* Footer */
.footer {
  max-width: 1180px;
  margin: 28px auto 40px;
  padding: 18px 24px 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.admin-link { display: inline-block; margin-left: 8px; color: inherit; font-size: 12px; text-underline-offset: 3px; }
.admin-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgb(16 24 40 / 18%);
}
.admin-dialog::backdrop { background: rgb(16 24 40 / 45%); }
.admin-dialog h2 { margin: 0 0 12px; font-size: 20px; }
.admin-dialog .section-desc { margin-bottom: 18px; }

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .form-grid, .loading-grid { grid-template-columns: 1fr; }
  .sidebar .nav-list { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-link { width: auto; }
}

@media (max-width: 520px) {
  .topbar { padding: 16px; }
  .layout { padding: 0 12px; margin-top: 16px; gap: 16px; }
  .main-card { padding: 20px 16px; }
  .search-box { min-width: 0; max-width: none; flex-basis: 100%; order: 3; }
  .header-add { white-space: normal; }
}
