/* Reusable components. */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 20px 22px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 19px; font-weight: 800; color: var(--green-900); }
.link-more { font-size: 13px; font-weight: 600; white-space: nowrap; }

/* KPI card with progress ring: label + ring on top, value gets the full width */
.kpi { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 18px; }
.kpi-label { font-weight: 700; font-size: 14px; color: var(--green-900); grid-column: 1; grid-row: 1; align-self: center; }
.kpi-value { grid-column: 1 / -1; grid-row: 2; font-size: clamp(21px, 1.7vw, 26px); font-weight: 800; letter-spacing: -.02em; min-width: 0; white-space: nowrap; }
.ring { grid-column: 2; grid-row: 1; position: relative; width: 44px; height: 44px; display: grid; place-items: center; }
.ring svg.arc { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--sage-200); }
.ring .bar { stroke: var(--green-700); stroke-linecap: round; transition: stroke-dasharray .6s ease; }
.ring .glyph { width: 20px; height: 20px; color: var(--green-700); position: relative; }
.ring .glyph svg { width: 20px; height: 20px; }
.kpi-foot { grid-row: 3; grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--sage-100); color: var(--green-900); white-space: nowrap;
}
.chip.up { background: var(--delta-bg); color: var(--green-700); }
.chip.down, .chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.warn, .chip.amber { background: var(--amber-bg); color: var(--amber-ink); }
.chip.neutral { background: #ece8df; color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  padding: 0 18px; border-radius: 12px; border: 1px solid var(--border); background: var(--card);
  font-weight: 600; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--sage-100); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.btn.primary:hover { background: var(--green-900); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #8f2b21; }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled], .btn.is-loading { opacity: .65; pointer-events: none; }
.btn.is-loading::after, .htmx-request.btn::after {
  content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: none;
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th a { color: inherit; }
.table td { padding: 11px 12px; border-bottom: 1px solid #ebeadf; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href], .table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--sage-100); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.who { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.badge-ico {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--sage-100); color: var(--green-700); font-size: 13px; font-weight: 800; flex: none;
}
.badge-ico.amber { background: var(--amber-bg); color: var(--amber-ink); }

/* tabs, filters, pagination */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-weight: 600; font-size: 14px; color: var(--text); }
.tab:hover { text-decoration: none; background: var(--sage-100); }
.tab[aria-current="true"] { background: var(--green-900); border-color: var(--green-900); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 14px; }

/* forms */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: #fff; font: inherit; color: var(--text);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--sage-300); border-color: var(--green-500); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; font-weight: 600; }
.form-error { background: var(--danger-bg); color: var(--danger); padding: 10px 14px; border-radius: 12px; font-weight: 600; margin-bottom: 14px; }
.inline-filters .input, .inline-filters .select { min-height: 38px; padding: 6px 12px; width: auto; }

/* empty state + skeleton */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--sage-300); margin-bottom: 8px; }
.empty h3 { color: var(--green-900); font-size: 17px; margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, #eee8dc 25%, #f6f1e7 37%, #eee8dc 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 10px; min-height: 16px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 10px; }
.toast {
  min-width: 260px; max-width: 380px; padding: 12px 16px; border-radius: 14px; background: var(--green-900);
  color: #fff; box-shadow: var(--shadow-lg); font-weight: 600; animation: toast-in .2s ease;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--sage-200); display: grid; gap: 14px; }
.timeline li { position: relative; padding-left: 14px; }
.timeline li::before { content: ""; position: absolute; left: -22px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--green-700); }
.timeline small { color: var(--muted); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.chart-box { position: relative; height: 260px; }
.legend { display: grid; gap: 10px; align-content: center; }
.legend-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; font-size: 13px; }
.legend-row > :nth-child(3), .legend-row > :nth-child(4) { white-space: nowrap; }
.swatch { width: 12px; height: 12px; border-radius: 50%; }

/* upload field */
.dropzone { position: relative; display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; padding: 14px; border: 2px dashed var(--sage-300); border-radius: var(--radius-md); background: #fff; transition: background .15s, border-color .15s; }
.dropzone.is-over { background: var(--sage-100); border-color: var(--green-700); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dz-preview { width: 84px; height: 84px; border-radius: 14px; overflow: hidden; background: var(--sage-100); display: grid; place-items: center; }
.dz-preview.square img { width: 100%; height: 100%; object-fit: cover; }      /* square crop in the UI only */
.dz-preview img { max-width: 100%; max-height: 100%; object-fit: cover; width: 100%; height: 100%; }
.dz-file { font-weight: 800; color: var(--green-700); }
.dz-body { grid-column: 2; }
.dropzone:not(:has([data-preview-box]:not([hidden]))) .dz-body { grid-column: 1 / -1; }
.dz-text { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.dz-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dz-name { margin: 8px 0 0; font-size: 13px; color: var(--green-700); font-weight: 600; word-break: break-all; }
@media (hover: none) { .dz-text strong { display: none; } .dz-text { font-size: 13px; } }

.kpi-note { grid-column: 1 / -1; grid-row: 3; font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-foot { grid-row: 4; }
