/* Components in the AD brand style (see Stile-promting-ai/04-componenti.md). */

/* ---------- Buttons: one primary (blue fill, ink text) per view ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.75rem; padding: 0 1.125rem;
  border: 1.5px solid transparent; border-radius: var(--radius);
  font-family: var(--font-display); font-size: 1rem; font-weight: 650; line-height: 1;
  white-space: nowrap; text-decoration: none !important; background: transparent; color: var(--ink);
  transition: background-color var(--duration-ui) ease-out, color var(--duration-ui) ease-out, border-color var(--duration-ui) ease-out;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn .icon { width: 17px; height: 17px; }

.btn-primary, .btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover, .btn-accent:hover { background: var(--accent-hover); }
.btn-secondary { border-color: var(--ink); color: var(--ink); }
.btn-secondary:hover { background: var(--ink); color: var(--bg); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--surface); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--bg); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--surface); text-decoration: underline !important; }

.btn-sm { min-height: 2.25rem; padding: 0 .75rem; font-size: var(--fs-ui); }
.btn-lg { min-height: 3rem; padding: 0 1.375rem; }
.btn-block { width: 100%; }
.btn-icon { width: 2.75rem; padding: 0; }
.btn-icon.btn-sm { width: 2.25rem; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid var(--ink); border-right-color: transparent; border-radius: 50%;
  animation: spin .6s linear infinite;
}
.btn-primary.is-loading::after { border-color: var(--on-accent); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: .5rem; }
.field + .field { margin-top: 1.125rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-row > .field + .field { margin-top: 0; }
.field-row + .field, .field + .field-row, .field-row + .field-row { margin-top: 1.125rem; }
.label { font-family: var(--font-display); font-size: var(--fs-ui); font-weight: 600; color: var(--ink); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.hint { font-size: var(--fs-caption); color: var(--muted); }
.field-error { display: flex; gap: 4px; align-items: center; font-size: var(--fs-ui); font-weight: 550; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: 2.75rem; padding: .625rem .875rem;
  font-family: var(--font-display); font-size: 1rem; color: var(--ink);
  background: var(--bg); border: 1.5px solid var(--field-border); border-radius: var(--radius);
  transition: border-color var(--duration-ui) ease-out;
}
.textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 2.25rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7A8C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center; background-size: 16px;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--focus); outline-offset: 1px; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface); border-color: var(--rule); color: var(--muted); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input-sm, .select-sm { min-height: 2.5rem; font-size: var(--fs-ui); padding-top: .4rem; padding-bottom: .4rem; }
.input-code { font-family: var(--font-mono); font-size: 1.25rem; letter-spacing: .3em; text-align: center; min-height: 3rem; }

.input-group { position: relative; }
.input-group .input { padding-right: 3rem; }
.input-group .input-addon {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 2.5rem; height: 2.5rem; display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--radius); color: var(--muted);
}
.input-group .input-addon:hover { color: var(--ink); background: var(--surface); }
.input-icon { position: relative; display: block; }
.input-icon > svg { position: absolute; left: .875rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 2.5rem; }

.check { display: inline-flex; align-items: flex-start; gap: .625rem; cursor: pointer; font-size: var(--fs-ui); color: var(--ink); line-height: 1.4; }
.check input {
  appearance: none; flex-shrink: 0; width: 1.125rem; height: 1.125rem; margin: 1px 0 0;
  border: 1.5px solid var(--field-border); border-radius: 3px; background: var(--bg);
  display: grid; place-items: center; cursor: pointer;
}
.check input::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--on-accent); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { opacity: 1; }
.check input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.check input:disabled { opacity: .5; cursor: not-allowed; }

.password-meter { height: 4px; border-radius: 2px; background: var(--rule); overflow: hidden; }
.password-meter > span { display: block; height: 100%; width: 0; background: var(--danger); transition: width var(--duration-ui); }

/* ---------- Panels: flat, outlined, no shadow ---------- */
.card { background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius-media); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: .875rem 1.25rem; border-bottom: 1px solid var(--rule); min-height: 3.25rem; }
.card-header h2, .card-header h3 { font-size: 1.125rem; font-weight: 750; font-stretch: 85%; }
.card-header .muted { font-size: var(--fs-caption); }
.card-body { padding: 1.25rem; }
.card-footer { display: flex; justify-content: flex-end; gap: .75rem; padding: .875rem 1.25rem; border-top: 1px solid var(--rule); }
.card-link { font-size: var(--fs-ui); font-weight: 600; color: var(--link); }

/* ---------- Key figures: one strip of cells ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1.5px solid var(--ink); border-bottom: 1px solid var(--rule); }
.stat { padding: 1rem 1.25rem 1.125rem 0; display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.stat + .stat { padding-left: 1.25rem; border-left: 1px solid var(--rule); }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover .stat-value { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: .2em; }
.stat-label { font-size: var(--fs-caption); font-weight: 600; color: var(--muted); }
.stat-value { font-size: 2rem; font-weight: 800; font-stretch: 75%; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.stat-foot { font-size: var(--fs-caption); color: var(--muted); }

/* ---------- Status: dot + word (colour never alone) ---------- */
.badge { display: inline-flex; align-items: center; gap: .4em; font-family: var(--font-display); font-size: var(--fs-caption); font-weight: 650; color: var(--ink); white-space: nowrap; }
.badge::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; border: 1.5px solid currentColor; flex-shrink: 0; }
.badge-info::before { background: var(--accent); border-color: var(--accent); }
.badge-success::before { background: var(--success); border-color: var(--success); }
.badge-warning { color: var(--warning); }
.badge-warning::before { background: var(--warning); border-color: var(--warning); }
.badge-danger { color: var(--danger); }
.badge-danger::before { background: var(--danger); border-color: var(--danger); }
.badge-neutral { color: var(--muted); }

.tag { display: inline-flex; align-items: center; padding: .1875rem .5rem; border: 1px solid var(--rule); border-radius: 3px; font-size: var(--fs-caption); font-weight: 500; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-family: var(--font-display); font-size: var(--fs-ui); }
.table th { text-align: left; padding: .625rem 1.25rem; font-size: var(--fs-caption); font-weight: 650; color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--rule); white-space: nowrap; }
.table td { padding: .75rem 1.25rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
.table .actions { text-align: right; white-space: nowrap; }
.table .text-right { text-align: right; }

/* ---------- People ---------- */
.avatar { width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: var(--surface); color: var(--ink); border: 1px solid var(--rule); font-size: var(--fs-caption); font-weight: 700; }
.avatar-lg { width: 2.75rem; height: 2.75rem; font-size: var(--fs-ui); }
.person { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.person-name { font-weight: 650; }
.person-meta { font-size: var(--fs-caption); color: var(--muted); }

.progress { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: .75rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--rule); }
.list > li:last-child > .list-item, .list > .list-item:last-child, .list > li.list-item:last-child { border-bottom: 0; }
a.list-item { color: inherit; text-decoration: none; }
a.list-item:hover { background: var(--surface-hover); }
.list-icon { width: 2rem; height: 2rem; border-radius: var(--radius); display: grid; place-items: center; background: var(--surface); color: var(--muted); flex-shrink: 0; }
.list-icon .icon { width: 16px; height: 16px; }
.list-title { font-weight: 650; }
.list-meta { font-size: var(--fs-caption); color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: .25rem 1.25rem; }
.timeline li { position: relative; padding: .625rem 0 .625rem 1.375rem; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 1.05rem; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 6px; top: 1.75rem; bottom: -.4rem; width: 1px; background: var(--rule); }
.timeline li:last-child::after { display: none; }

/* ---------- Notices ---------- */
.alert { display: flex; gap: .75rem; padding: .875rem 1rem; border: 1px solid var(--rule); border-left: 3px solid var(--muted); border-radius: var(--radius); background: var(--surface); font-size: var(--fs-ui); color: var(--ink); }
.alert .icon { margin-top: 1px; }
.alert-info { border-left-color: var(--accent); }
.alert-info .icon { color: var(--link); }
.alert-warning { border-left-color: var(--warning); }
.alert-warning .icon { color: var(--warning); }
.alert-danger { border-left-color: var(--danger); }
.alert-danger .icon { color: var(--danger); }
.alert-success { border-left-color: var(--success); }
.alert-success .icon { color: var(--success); }
.alert-title { font-weight: 700; margin-bottom: 2px; }

/* ---------- Empty states: a sentence and an action, left-aligned ---------- */
.empty { padding: 2rem 1.5rem; display: flex; flex-direction: column; align-items: flex-start; gap: .375rem; }
.empty-icon { display: none; }
.empty-title { font-size: 1.25rem; font-weight: 750; font-stretch: 85%; }
.empty-text { font-family: var(--font-text); font-size: var(--fs-body); color: var(--muted); max-width: 52ch; }
.empty .btn { margin-top: .625rem; }
.empty-compact { padding: 1.25rem; }

.skeleton { display: block; border-radius: var(--radius); background: var(--surface); }
.skeleton-line { height: 12px; margin: 8px 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.5rem; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 .75rem; margin-bottom: -1px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; border: 1.5px solid var(--field-border); border-radius: var(--radius); overflow: hidden; }
.segmented button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .375rem; min-height: 2.5rem; padding: 0 .75rem; border: 0; background: transparent; color: var(--ink); font-size: var(--fs-ui); font-weight: 600; }
.segmented > * + * { border-left: 1px solid var(--field-border) !important; }
.segmented button:hover { background: var(--surface); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.segmented .icon { width: 16px; height: 16px; }

/* ---------- Dropdown menus ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 14rem;
  background: var(--bg); border: 1.5px solid var(--ink); border-radius: var(--radius-media);
  padding: .375rem; display: none;
}
.dropdown-menu.is-open { display: block; }
.dropdown-menu.align-left { right: auto; left: 0; }
.dropdown-menu.drop-up { top: auto; bottom: calc(100% + 6px); }
.dropdown-item { display: flex; align-items: center; gap: .625rem; width: 100%; min-height: 2.5rem; padding: 0 .625rem; border: 0; border-radius: var(--radius); background: none; color: var(--ink); font-size: var(--fs-ui); font-weight: 550; text-align: left; text-decoration: none !important; }
.dropdown-item:hover, .dropdown-item:focus-visible { background: var(--surface); outline: none; }
.dropdown-item .icon { width: 16px; height: 16px; color: var(--muted); }
.dropdown-item.danger, .dropdown-item.danger .icon { color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--rule); margin: .375rem -.375rem; }
.dropdown-header { padding: .5rem .625rem .625rem; }

/* ---------- Dialogs ---------- */
dialog.modal {
  width: min(32rem, calc(100vw - 2rem)); padding: 0; margin: auto;
  border: 1.5px solid var(--ink); border-radius: var(--radius-media);
  background: var(--bg); color: var(--ink);
}
dialog.modal::backdrop { background: var(--backdrop); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.5rem 1.5rem 0; }
.modal-header h2 { font-size: 2rem; font-weight: 800; font-stretch: 65%; line-height: 1; }
.modal-header p { margin-top: .5rem; color: var(--muted); font-family: var(--font-text); font-size: var(--fs-body); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin: 0 1.5rem; padding: 1.125rem 0 1.5rem; border-top: 1px solid var(--rule); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 90; right: var(--gutter); bottom: 1.25rem; display: flex; flex-direction: column; gap: .625rem; width: min(26rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: .625rem; padding: .875rem 1rem; border-radius: var(--radius-media); background: var(--ink); color: var(--bg); font-weight: 600; font-size: var(--fs-ui); animation: toast-in 180ms var(--ease-out); }
.toast.is-leaving { animation: toast-out 160ms var(--ease-out) forwards; }
.toast .icon { margin-top: 1px; }
.toast-error { background: var(--danger); color: var(--bg); }
.toast-msg { flex: 1; }
.toast-close { border: 0; background: none; color: inherit; opacity: .7; padding: 0; }
.toast-close:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

kbd, .kbd { display: inline-flex; align-items: center; min-height: 1.25rem; padding: 0 .375rem; border-radius: 3px; border: 1px solid var(--field-border); color: var(--muted); font-family: var(--font-display); font-size: 11px; font-weight: 600; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: .75rem 1.25rem; border-top: 1px solid var(--rule); font-size: var(--fs-ui); color: var(--muted); font-variant-numeric: tabular-nums; }
.pagination .row { --gap: 6px; }

.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--field-border); font-family: var(--font-mono); }
.secret { font-family: var(--font-mono); font-size: var(--fs-sm); word-break: break-all; padding: .625rem .75rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--rule); }
.qr { width: 11rem; height: 11rem; padding: .625rem; border-radius: var(--radius-media); background: #fff; border: 1px solid var(--rule); }
.qr svg, .qr img { width: 100%; height: 100%; }

.dl { display: grid; grid-template-columns: 10rem 1fr; gap: 0; margin: 0; }
.dl dt { padding: .5rem 0; font-size: var(--fs-caption); color: var(--muted); border-bottom: 1px solid var(--rule); }
.dl dd { margin: 0; padding: .5rem 0; font-weight: 550; border-bottom: 1px solid var(--rule); }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; padding-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--rule); }
}
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { border-bottom: 0; padding-bottom: 0; }
  .table th, .table td { padding-left: .875rem; padding-right: .875rem; }
  .stat-value { font-size: 1.625rem; }
}

/* Profile photo */
.avatar.has-photo { overflow: hidden; padding: 0; background: var(--surface); }
.avatar.has-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-xl { width: 5rem; height: 5rem; font-size: 1.5rem; }
.avatar-edit { display: flex; align-items: center; gap: 1.25rem; }
.avatar-edit label.btn { cursor: pointer; }
.avatar-edit form:focus-within label.btn { outline: 2px solid var(--focus, var(--accent)); outline-offset: 2px; }
