/* ---------------------------------------------------------
   7. Cards / surface panels
   --------------------------------------------------------- */
/* Cards/panels (docs/ui/DESIGN_CONTRACT.md §4): flat surface, 1px hairline
   border, no resting shadow — the Registro identity is ledger-flat, not
   elevated. --shadow-pop is reserved for floating layers only. */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card__header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.card__title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
}

.card__body { padding: var(--sp-5); }

.card-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-6);
}
.card-form h2 {
  font-size: var(--text-lg);
  line-height: 1.3;
  margin-bottom: var(--sp-4);
}

/* KPI cards grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.kpi-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-5);
}

.kpi-card--link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color var(--motion-fast) var(--ease),
              transform var(--motion-fast) var(--ease);
}

/* Flat identity: hover/focus lift with a border-color change + a 1px
   translate, no shadow (resting surfaces never get one — §3). The focus
   ring still uses --shadow-focus, which is the accent halo, not elevation. */
.kpi-card--link:hover {
  border-color: var(--accent-fill);
  transform: translateY(-1px);
}

.kpi-card--link:focus-visible {
  border-color: var(--accent-fill);
  box-shadow: var(--shadow-focus);
  transform: translateY(-1px);
}

.kpi-card--link.is-active,
.kpi-card--link[aria-current="page"] {
  background: var(--accent-soft);
  border-color: var(--accent-fill);
}

/* KPI tone modifiers: status meaning is a small dot beside the label plus
   the value colour — never a border/bar (§0.4 bans accent bars outright,
   including the top hairline this used before). Always paired with text. */
.kpi-card--ok   .kpi-card__label,
.kpi-card--warn .kpi-card__label,
.kpi-card--bad  .kpi-card__label {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
.kpi-card--ok   .kpi-card__label::before,
.kpi-card--warn .kpi-card__label::before,
.kpi-card--bad  .kpi-card__label::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  flex-shrink: 0;
}
.kpi-card--ok   .kpi-card__label::before { background: var(--st-ok); }
.kpi-card--warn .kpi-card__label::before { background: var(--st-warn); }
.kpi-card--bad  .kpi-card__label::before { background: var(--st-bad); }
.kpi-card--ok   .kpi-card__value { color: var(--st-ok); }
.kpi-card--warn .kpi-card__value { color: var(--st-warn); }
.kpi-card--bad  .kpi-card__value { color: var(--st-bad); }

.kpi-card__label {
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--sp-2);
}

.kpi-card__value {
  font-size: var(--text-3xl);
  font-weight: 650;
  line-height: 1;
  color: var(--accent-ink);
}

.kpi-count {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1;
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.kpi-card__sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--sp-1);
}

.dashboard-section {
  margin-bottom: var(--sp-6);
}

.dashboard-section > h2 {
  font-size: var(--text-lg);
  line-height: 1.3;
  margin-bottom: var(--sp-3);
  color: var(--color-text);
}

.dashboard-kpi-group {
  margin-bottom: 0;
}

/* The board wrapper + its header row (eyebrow/h2/Personalizza link) were
   retired in UI v3 L11: "Personalizza" now lives in the page_header actions
   (app/dashboard.py) and the grid renders directly under the toolbar. */
.dashboard-widget-grid {
  align-items: start;
  display: grid;
  gap: var(--sp-4);
  /* Uniform responsive grid (UI v3 L11): every widget shares the same
     minimum width and stretches evenly to fill the row instead of a fixed
     2/3-column breakpoint that left empty space when fewer widgets render.
     Widgets that must own the full row use --wide, not a column count. */
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  min-width: 0;
}

.dashboard-widget-grid > *,
.dashboard-section,
.dashboard-widget {
  min-width: 0;
}

.dashboard-widget {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Wide variant: action panels (quick-add, OCR) always render as their own
   full-width block (domain/dashboard_widgets.py _wrap_widget_grid keeps
   them OUT of any .dashboard-widget-grid — UI v3 L11), so no grid-column
   span is needed here; this just lays their content out horizontally on
   desktop instead of a tall column. */
@media (min-width: 760px) {
  .dashboard-widget--wide .dashboard-widget__body {
    align-items: start;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-5);
  }

  .dashboard-widget--wide .dashboard-widget__body > * {
    flex: 1 1 16rem;
    margin: 0;
    min-width: 0;
  }

  .dashboard-widget--wide .quick-add {
    align-items: start;
    display: flex;
    flex: 3 1 32rem;
    flex-wrap: wrap;
    gap: var(--sp-5);
  }

  .dashboard-widget--wide .quick-add > * {
    flex: 1 1 16rem;
    margin: 0;
    min-width: 0;
  }

  /* The OCR drop zone keeps the full row width ("trascina qui" must span
     the card — user feedback); only the summary sits above it. */
  .dashboard-widget--wide .dashboard-ocr {
    display: grid;
    flex: 1 1 100%;
    gap: var(--sp-3);
  }
}

/* Scroll variant: the governance/operations pair keeps one fixed height so
   the two cards always align vertically; longer content scrolls inside. */
.dashboard-widget--scroll {
  height: 26rem;
}

.dashboard-widget--scroll .dashboard-widget__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.dashboard-widget__head {
  align-items: start;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: var(--sp-3);
  justify-content: space-between;
  padding: var(--sp-4);
}

.dashboard-widget__tag {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  margin: 0 0 var(--sp-1);
  text-transform: uppercase;
}

.dashboard-widget__title {
  color: var(--color-text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.dashboard-widget__open {
  color: var(--accent-ink);
  flex: 0 0 auto;
  font-size: var(--text-sm);
  font-weight: 650;
  text-decoration: none;
}

.dashboard-widget__open:hover {
  text-decoration: underline;
}

.dashboard-widget__body {
  display: grid;
  gap: var(--sp-3);
  padding: var(--sp-4);
}

.dashboard-onboarding {
  display: grid;
  gap: var(--sp-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.dashboard-onboarding__item {
  align-items: center;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: grid;
  gap: var(--sp-2);
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  min-height: 2.75rem;
  padding: var(--sp-2) var(--sp-3);
}

.dashboard-onboarding__index {
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text-muted);
  display: inline-flex;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: var(--text-xs);
  font-weight: 700;
  height: 1.65rem;
  justify-content: center;
  width: 1.65rem;
}

.dashboard-onboarding__label {
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 650;
  min-width: 0;
}

.dashboard-onboarding__link {
  color: var(--accent-ink);
  font-size: var(--text-sm);
  font-weight: 650;
  text-decoration: none;
}

.dashboard-onboarding__link:hover {
  text-decoration: underline;
}

@media (max-width: 520px) {
  .dashboard-onboarding__item {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .dashboard-onboarding__link {
    grid-column: 2 / -1;
  }
}

.dashboard-widget__metric {
  align-items: center;
  align-self: start;
  color: inherit;
  display: inline-flex;
  gap: var(--sp-2);
  text-decoration: none;
}

.dashboard-widget__metric:hover .dashboard-widget__number {
  text-decoration: underline;
}

.dashboard-widget__metric:focus-visible {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-focus);
  outline: none;
}

/* The headline count stays ink-colored and moderate in size; severity is a
   small status dot beside it (user feedback: huge red numbers were too loud). */
.dashboard-widget__number {
  color: var(--color-text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 2.1rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
}

.dashboard-widget__donut {
  display: flex;
  justify-content: center;
  padding: var(--sp-2) 0;
}

/* Keep the two side-by-side donuts on the same level: the chart renders
   first in the card body, so variable-length context text can't push it
   down (user tweak 05/07). */
.dashboard-widget--scroll .dashboard-widget__donut {
  order: -1;
}

.dashboard-widget__metric::before {
  background: var(--st-ok);
  border-radius: 50%;
  content: "";
  flex: 0 0 auto;
  height: 0.55rem;
  width: 0.55rem;
}

.dashboard-widget--warn .dashboard-widget__metric::before {
  background: var(--st-warn);
}

.dashboard-widget--bad .dashboard-widget__metric::before {
  background: var(--st-bad);
}

.dashboard-widget__context,
.dashboard-widget__summary {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.45;
  margin: 0;
}

.dashboard-widget__context {
  font-weight: 600;
}

.dashboard-widget__facts {
  display: grid;
  gap: var(--sp-2);
  grid-template-columns: 1fr;
}

.dashboard-widget__fact {
  align-items: center;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  display: grid;
  gap: var(--sp-2);
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 2.75rem;
  padding: var(--sp-2) var(--sp-3);
  text-decoration: none;
}

.dashboard-widget__fact:hover {
  border-color: var(--color-border-strong);
  text-decoration: none;
}

.dashboard-widget__fact:focus-visible {
  border-color: var(--accent-fill);
  box-shadow: var(--shadow-focus);
  outline: none;
}

.dashboard-widget__fact-label {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  min-width: 0;
  text-transform: uppercase;
}

.dashboard-widget__fact-value {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.dashboard-widget__fact-sub {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  grid-column: 1 / -1;
  line-height: 1.35;
}

.dashboard-widget__fact--ok .dashboard-widget__fact-value {
  color: var(--st-ok);
}

.dashboard-widget__fact--warn .dashboard-widget__fact-value {
  color: var(--st-warn);
}

.dashboard-widget__fact--bad .dashboard-widget__fact-value {
  color: var(--st-bad);
}

body[data-area="dashboard"] .site-main {
  padding-top: var(--sp-4);
}

body[data-area="dashboard"] .page-header {
  margin-bottom: var(--sp-3);
  padding-bottom: var(--sp-3);
}

body[data-area="dashboard"] .toolbar {
  margin-bottom: var(--sp-3);
}

body[data-area="dashboard"] .quick-add {
  display: grid;
  gap: var(--sp-4);
  align-items: end;
  margin: 0;
  padding: 0;
}

body[data-area="dashboard"] .quick-add__intro {
  min-width: 0;
  position: relative;
}

body[data-area="dashboard"] .quick-add__eyebrow {
  color: var(--accent-ink);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: var(--sp-1);
  text-transform: uppercase;
}

body[data-area="dashboard"] .quick-add h2 {
  color: var(--color-text);
  font-size: var(--text-xl);
  line-height: 1.2;
  margin: 0;
}

body[data-area="dashboard"] .quick-add__title-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

body[data-area="dashboard"] .quick-add__copy {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.45;
  max-width: 26rem;
}

body[data-area="dashboard"] .quick-add__info {
  margin-left: 0;
  position: relative;
}

body[data-area="dashboard"] .quick-add__info > summary {
  font-size: var(--text-xs);
  width: 1.35rem;
  height: 1.35rem;
}

body[data-area="dashboard"] .quick-add__info .info__body {
  position: absolute;
  z-index: 30;
  left: 0;
  top: calc(100% + var(--sp-2));
  width: min(20rem, calc(100vw - 2rem));
  margin-top: 0;
  /* Floating popover — the one legitimate use of --shadow-pop in this file. */
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
  line-height: 1.45;
}

body[data-area="dashboard"] .quick-add__form {
  gap: var(--sp-2);
}

body[data-area="dashboard"] .quick-add__form select,
body[data-area="dashboard"] .quick-add__form input[type="search"] {
  min-height: 2.5rem;
  font-size: var(--text-sm);
  background: var(--color-surface);
  border-color: var(--color-border);
}

body[data-area="dashboard"] .quick-add__form select:hover:not(:focus),
body[data-area="dashboard"] .quick-add__form input[type="search"]:hover:not(:focus) {
  border-color: color-mix(in srgb, var(--color-border) 60%, var(--color-text));
}

body[data-area="dashboard"] .quick-add__form select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
}

body[data-area="dashboard"] .quick-add__form select:focus,
body[data-area="dashboard"] .quick-add__form input[type="search"]:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
  outline: none;
}

body[data-area="dashboard"] .quick-add__form button {
  min-height: 2.45rem;
  padding-left: var(--sp-5);
  padding-right: var(--sp-5);
}

body[data-area="dashboard"] .quick-add__setup {
  display: flex;
  align-items: end;
  justify-content: flex-start;
}

body[data-area="dashboard"] .dashboard-section {
  margin: 0;
}

body[data-area="dashboard"] .dashboard-section > h2 {
  margin-bottom: var(--sp-2);
}

body[data-area="dashboard"] .kpi-card {
  padding: var(--sp-4);
}

@media (min-width: 1024px) {
  body[data-area="dashboard"] .quick-add {
    grid-template-columns: minmax(13rem, 0.72fr) minmax(0, 2fr);
  }

  body[data-area="dashboard"] .quick-add--empty {
    grid-template-columns: minmax(13rem, 1fr) auto;
  }
}

@media (min-width: 760px) {
  .dashboard-widget__number {
    font-size: 3.8rem;
  }
}
