/* Stili delle pagine del core: home, agenti, notifiche, profilo, ricerca, docs, app. */

/* ── Home ────────────────────────────────────────────────── */
.home-hero {
  position: relative;
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-6);
  min-height: 180px;
  padding: var(--space-8);
  margin-bottom: var(--space-8);
  border-radius: var(--radius-xl);
  overflow: hidden;
  color: #fff;
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 90%, black), var(--accent) 55%, color-mix(in oklab, var(--accent) 70%, #c2410c));
}
.home-hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.home-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgb(0 0 0 / 0.45), rgb(0 0 0 / 0.1)); }
.home-hero > * { position: relative; z-index: 1; }
.home-hero__greeting { font-family: var(--font-serif); font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; text-wrap: balance; }
.home-hero__sub { margin-top: var(--space-2); opacity: 0.9; max-width: 56ch; }
.home-hero__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.home-hero .btn--secondary { background: rgb(255 255 255 / 0.14); border-color: rgb(255 255 255 / 0.3); color: #fff; backdrop-filter: blur(6px); }
.home-hero .btn--secondary:hover { background: rgb(255 255 255 / 0.24); }
@media (max-width: 700px) { .home-hero { flex-direction: column; align-items: flex-start; padding: var(--space-6); } }

.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-8); align-items: start; }
.home-grid__main { display: flex; flex-direction: column; min-width: 0; }
.home-grid__main > .section:last-child { margin-bottom: 0; }
.home-grid__aside { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
/* Nessun lavoro in corso né widget home.sidebar: l'aside sparisce e il contenuto usa tutta la larghezza. */
.home-grid__aside:not(:has(> :not([hidden]))) { display: none; }
.home-grid:not(:has(> .home-grid__aside > :not([hidden]))) { grid-template-columns: minmax(0, 1fr); }
.home-sections { display: flex; flex-direction: column; gap: var(--space-6); min-width: 0; }
.home-sections:empty { display: none; }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr; } }

.resume-list { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.resume {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: inherit; text-decoration: none;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast);
}
.resume:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.resume__body { flex: 1; min-width: 0; }
.resume__title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume__meta { font-size: var(--text-xs); color: var(--text-subtle); margin-top: 2px; display: flex; gap: var(--space-2); min-width: 0; white-space: nowrap; }
.resume__meta > span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.resume__meta > time { flex: none; }
.resume > .icon { flex: none; align-self: center; color: var(--text-subtle); }

/* Home: griglia agenti a 3 colonne su desktop (6 card = 3+3, niente posti vuoti) */
.home-agents { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }

/* ── Card agente ─────────────────────────────────────────── */
.agent-card {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-5);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: inherit; text-decoration: none;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast);
  position: relative; overflow: hidden;
}
.agent-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--agent-color, var(--accent)); opacity: 0.9; }
.agent-card:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.agent-card__head { display: flex; align-items: flex-start; gap: var(--space-3); }
.agent-card__name { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.agent-card__name { font-weight: 600; font-size: var(--text-lg); font-family: var(--font-serif); letter-spacing: -0.01em; }
.agent-card__cat { font-size: var(--text-xs); color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.06em; }
.agent-card__desc { color: var(--text-muted); font-size: var(--text-sm); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.agent-card__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-top: auto; flex-wrap: wrap; }
.agent-card__badges { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.agent-card--compact { padding: var(--space-3) var(--space-4); flex-direction: row; align-items: center; }
.agent-card--compact .agent-card__desc { -webkit-line-clamp: 1; }
.agents-toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
@media (max-width: 600px) {
  .agents-toolbar { flex-wrap: nowrap; }
  .agents-toolbar .toolbar__spacer { display: none; }
  .agents-toolbar .input-group { flex: 1 1 auto; min-width: 0; max-width: none; }
  .toolbar .toolbar__search { flex: 1 1 100%; max-width: none; }
  .toolbar .toolbar__search + .toolbar__spacer { display: none; }
}
.agents-toolbar .input-group { flex: 1 1 260px; max-width: 420px; }
.agents-list .agent-card { flex-direction: row; align-items: center; }

/* ── Notifiche ───────────────────────────────────────────── */
.notif-toolbar { display: flex; gap: var(--space-2); align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: var(--space-4); }
.notif-list { display: flex; flex-direction: column; min-width: 0; }
.notif-list > .notif-group:first-child { margin-top: 0; }
.notif-list .list-item { border-radius: 0; padding: var(--space-3) var(--space-4); }
@media (max-width: 640px) {
  .notif-list .list-item__title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
.notif-group { margin: var(--space-5) 0 var(--space-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); font-weight: 600; }

/* ── Profilo ─────────────────────────────────────────────── */
.profile-head { display: flex; align-items: center; gap: var(--space-5); margin-bottom: var(--space-6); flex-wrap: wrap; }
.profile-head__avatar { position: relative; }
.profile-head__avatar .avatar { --avatar-size: 88px; font-size: 2rem; }
.profile-head__edit { position: absolute; right: -4px; bottom: -4px; box-shadow: var(--shadow); background: var(--surface); }
.profile-head__name { font-family: var(--font-serif); font-size: var(--text-2xl); font-weight: 600; }
.profile-head__meta { color: var(--text-muted); display: flex; gap: var(--space-3); flex-wrap: wrap; font-size: var(--text-sm); }
/* Form del profilo: larghezza di lettura, non 1200px per un campo */
.profile-tabs .card:has(> .card__body > .form) { max-width: 760px; }
.profile-tabs .theme-picker { max-width: 520px; }
.token-row code { font-size: var(--text-xs); }
.token-new { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-3); background: var(--success-soft); border-radius: var(--radius); flex-wrap: wrap; }
.token-new code { flex: 1; min-width: 200px; word-break: break-all; background: var(--surface); padding: var(--space-2); border-radius: var(--radius-sm); }

/* ── Ricerca ─────────────────────────────────────────────── */
.search-box { margin-bottom: var(--space-6); }
.search-box .input { min-height: 50px; font-size: var(--text-lg); padding-left: 48px; }
.search-box .input-group > .icon { left: 16px; width: 22px; height: 22px; }
.search-results { display: flex; flex-direction: column; gap: var(--space-2); }
.search-result { display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: inherit; text-decoration: none; }
.search-result:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.search-result__type { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-subtle); }
.search-result__title { font-weight: 500; }
.search-result__snippet { color: var(--text-muted); font-size: var(--text-sm); margin-top: 2px; }
.search-facets { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }

/* ── Documentazione ──────────────────────────────────────── */
.page-root--docs { min-width: 0; }
.docs { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--space-8); align-items: start; }
.docs__nav { position: sticky; top: calc(var(--topbar-height) + var(--space-4)); max-height: calc(100dvh - var(--topbar-height) - 48px); overflow: auto; font-size: var(--text-sm); }
.docs__nav a { display: block; padding: 6px var(--space-3); border-radius: var(--radius-sm); color: var(--text-muted); }
.docs__nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.docs__nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.docs__nav-group { margin: var(--space-3) var(--space-3) var(--space-1); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-subtle); font-weight: 600; }
.docs__body { min-width: 0; max-width: 80ch; display: flex; flex-direction: column; gap: var(--space-6); }
.docs__toc { position: sticky; top: calc(var(--topbar-height) + var(--space-4)); min-width: 0; }
.docs__toc > .docs__nav { position: static; max-height: calc(100dvh - var(--topbar-height) - 48px); }
.docs__toc-summary { display: none; }
.docs__onpage { padding-bottom: var(--space-3); margin-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
@media (max-width: 900px) {
  .docs__toc { position: static; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
  .docs__toc-summary { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-4); cursor: pointer; font-weight: 600; font-size: var(--text-sm); list-style: none; }
  .docs__toc-summary::-webkit-details-marker { display: none; }
  .docs__toc-chevron { margin-left: auto; transition: transform var(--duration); color: var(--text-subtle); }
  .docs__toc[open] .docs__toc-chevron { transform: rotate(180deg); }
  .docs__toc > .docs__nav { max-height: none; padding: 0 var(--space-2) var(--space-3); }
}
.docs__body .md h2, .docs__body .md h3 { margin-top: var(--space-8); }
@media (max-width: 900px) { .docs { grid-template-columns: 1fr; } .docs__nav { position: static; max-height: none; } }

/* ── Testo markdown fuori dalla chat (docs, descrizioni) ─── */
.md { line-height: var(--leading-loose); overflow-wrap: break-word; }
.md > * + * { margin-top: var(--space-3); }
.md .md-heading { margin-top: var(--space-6); font-family: var(--font-serif); letter-spacing: -0.01em; }
.md h2.md-heading { font-size: var(--text-xl); }
.md h3.md-heading { font-size: var(--text-lg); }
.md h4.md-heading, .md h5.md-heading, .md h6.md-heading { font-size: var(--text-md); font-family: var(--font-sans); }
.md .md-list { padding-left: 1.4em; }
.md .md-list .md-list { margin-top: var(--space-1); }
.md .md-list li + li { margin-top: 4px; }
.md .md-task { list-style: none; display: flex; gap: var(--space-2); align-items: flex-start; margin-left: -1.4em; }
.md .md-task input { margin-top: 5px; }
.md .md-quote { margin: var(--space-3) 0; padding: var(--space-2) var(--space-4); border-left: 3px solid var(--accent-soft-2); background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-muted); }
.md .md-quote > * + * { margin-top: var(--space-2); }
.md .md-hr { margin: var(--space-6) 0; }
.md .md-code-inline { padding: 1px 5px; border-radius: var(--radius-xs); background: var(--surface-2); border: 1px solid var(--border); font-size: 0.88em; }
.md .md-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.md .md-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.md .md-table th, .md .md-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md .md-table th { background: var(--surface-2); font-weight: 600; }
/* Celle con la larghezza minima delle parole: la tabella scorre in .md-table-wrap invece di spezzare «Font/e» */
.md .md-table th, .md .md-table td { overflow-wrap: normal; word-break: normal; }
.md ul:not([class]), .md ol:not([class]) { padding-left: 1.4em; }
.md .md-table tbody tr:last-child td { border-bottom: 0; }
.md .md-image { padding: 0; border: 0; background: none; cursor: zoom-in; display: block; max-width: 100%; }
.md .md-image img { border-radius: var(--radius); max-height: 480px; }
.md .md-figure { margin: var(--space-4) 0; }
.md .md-figure figcaption { font-size: var(--text-xs); color: var(--text-subtle); margin-top: var(--space-1); text-align: center; }
.md .md-link__ext { opacity: 0.6; margin-left: 2px; }
.md .md-callout { margin: var(--space-3) 0; }
.md .md-callout__body > * + * { margin-top: var(--space-2); }
.md .md-chart { min-height: 320px; margin: var(--space-3) 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.md .md-chart--pending { display: flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 120px; color: var(--text-muted); font-size: var(--text-sm); }
.md .md-chart__raw { font-size: var(--text-xs); padding: var(--space-3); overflow: auto; }
.md .code-block { margin: var(--space-3) 0; }
.md p.md-p:first-child { margin-top: 0; }

/* Citazioni [n] */
.cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; height: 1.4em; padding: 0 0.35em; margin: 0 1px;
  vertical-align: 0.15em;
  border: 1px solid var(--accent-soft-2); border-radius: var(--radius-xs);
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 0.72em; font-weight: 600; line-height: 1;
  cursor: pointer;
  transition: background var(--duration-fast), transform var(--duration-fast);
}
.cite:hover, .cite[aria-expanded="true"] { background: var(--accent-soft-2); transform: translateY(-1px); }
.cite--unknown { opacity: 0.6; border-style: dashed; }
.cite-group { white-space: nowrap; }
.cite-popover {
  position: fixed; z-index: var(--z-popover);
  padding: var(--space-3) var(--space-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: menu-in var(--duration) var(--ease-out);
  font-size: var(--text-sm);
}
.cite-popover__head { display: flex; gap: var(--space-2); align-items: flex-start; padding-right: 28px; }
.cite-popover__n { display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none; border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text); font-size: var(--text-xs); font-weight: 600; }
.cite-popover__title { font-weight: 600; }
.cite-popover__meta { color: var(--text-subtle); font-size: var(--text-xs); }
.cite-popover__snippet { margin: var(--space-3) 0 0; padding: var(--space-2) var(--space-3); border-left: 3px solid var(--accent-soft-2); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted); max-height: 180px; overflow: auto; }
.cite-popover__actions { margin-top: var(--space-3); display: flex; justify-content: flex-end; }
.cite-popover__close { position: absolute; top: 6px; right: 6px; }

/* Lista fonti */
.sources { margin-top: var(--space-4); border-top: 1px solid var(--border); padding-top: var(--space-2); font-size: var(--text-sm); }
.sources__summary { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; color: var(--text-muted); font-weight: 500; list-style: none; padding: var(--space-1) 0; }
.sources__summary::-webkit-details-marker { display: none; }
.sources__chevron { margin-left: auto; transition: transform var(--duration); }
.sources[open] .sources__chevron { transform: rotate(180deg); }
.sources__list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.source { display: flex; gap: var(--space-2); align-items: flex-start; }
.source__n { display: inline-grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text); font-size: var(--text-xs); font-weight: 600; }
.source__body { min-width: 0; }
.source__title { font-weight: 500; }
.source__meta { color: var(--text-subtle); font-size: var(--text-xs); margin-left: var(--space-2); }
.source__snippet { color: var(--text-muted); font-size: var(--text-xs); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Form: colore, immagine, tag ─────────────────────────── */
.form-color__row { display: flex; gap: var(--space-2); align-items: center; }
.form-color__row .input[type="text"] { max-width: 120px; }
.form-color__swatches { display: flex; gap: 6px; margin-top: var(--space-2); flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); background: var(--swatch); cursor: pointer; transition: transform var(--duration-fast); }
.swatch:hover { transform: scale(1.15); }
.form-image { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.form-image__preview { width: 64px; height: 64px; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); padding: 4px; }
.form-image__actions { display: flex; gap: var(--space-2); }
.form-tags__list { margin-bottom: var(--space-2); }
.form-tags__list .pill__remove { width: 18px; height: 18px; }
.field--switch .switch { min-height: 40px; }
.switch__label { font-weight: 500; font-size: var(--text-sm); }
.form-nested { padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.radio-group { display: flex; flex-direction: column; gap: var(--space-2); }

/* ── Pagina app (generica) ───────────────────────────────── */
.page-root--app { min-height: 50vh; }
.app-root { min-width: 0; }

/* ── Pagina di errore (404/403/500) ──────────────────────── */
.page-root--error { display: flex; flex-direction: column; justify-content: center; min-height: 60vh; }
.page-root--error p, .page-root--error .empty__text { text-wrap: balance; }
.app-loading { display: flex; align-items: center; gap: var(--space-2); color: var(--text-muted); padding: var(--space-8); justify-content: center; }

/* ── Guida (iframe) ─────────────────────────────────────── */
.guide-frame { display: block; width: 100%; height: calc(100dvh - var(--topbar-height) - var(--space-12)); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.guide-frame--auto { min-height: 60vh; overflow: hidden; }

/* ── Scheda "stato" generica ─────────────────────────────── */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ── Toolbar generica di pagina ──────────────────────────── */
.toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-5); }
.toolbar__search { flex: 1 1 240px; max-width: 420px; }
.toolbar__spacer { flex: 1; }

/* ── Sheet laterale ──────────────────────────────────────── */
.dialog--sheet { width: var(--sheet-width, 480px); max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border-radius: 0; border-right: 0; }
.dialog--sheet[open] { animation: sheet-in-right var(--duration-slow) var(--ease-out); }
@keyframes sheet-in-right { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Tabella: stato vuoto dentro le celle ───────────────── */
.table-empty { padding: 0 !important; }
.table-status:empty { display: none; }
.agent-card--compact .agent-card__head, .agents-list .agent-card__head { align-items: center; }
