:root {
  --hj-green: #1d6727;
  --hj-green-dark: #17431f;
  --hj-green-light: #e2f4e3;
  --hj-cream: #f8fbf6;
  --hj-shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
  --hj-shadow-md: 0 4px 12px -4px rgba(15,23,42,0.10);
  --hj-shadow-lg: 0 10px 25px -8px rgba(15,23,42,0.18);
  --hj-radius: 0.625rem;
}

body {
  font-feature-settings: "cv02","cv03","cv04","cv11";
  background:
    radial-gradient(1200px 600px at 95% -10%, rgba(92,184,103,0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(29,103,39,0.06), transparent 60%),
    linear-gradient(180deg, #f8fbf6 0%, #f3f7ee 100%);
  background-attachment: fixed;
}

/* Mounted-content fade-in. Subtle - 200ms, no slide. */
main > * { animation: hj-fade 200ms ease-out both; }
@keyframes hj-fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Sidebar collapsible groups */
details.hj-group > summary { list-style: none; }
details.hj-group > summary::-webkit-details-marker { display: none; }
details.hj-group > summary .hj-chev { transition: transform 150ms ease; display: inline-block; }
details.hj-group[open] > summary .hj-chev { transform: rotate(90deg); }

.hj-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: var(--hj-radius);
  box-shadow: var(--hj-shadow-sm);
  padding: 1rem;
  transition: box-shadow 160ms ease, transform 160ms ease, border-color 160ms ease;
}
/* Cards inside a parent that has data-cards-interactive get hover lift */
[data-cards-interactive] .hj-card:hover {
  box-shadow: var(--hj-shadow-md);
  border-color: #cfe6d2;
}
.hj-card-accent { border-left: 4px solid var(--hj-green); }
.hj-card-accent-warn { border-left: 4px solid #d97706; }
.hj-card-accent-error { border-left: 4px solid #dc2626; }
.hj-card-accent-info { border-left: 4px solid #2563eb; }

/* Page hero - consistent treatment for top-of-page titles */
.hj-page-hero {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 1rem;
}
.hj-page-hero h1 { font-size: 1.5rem; font-weight: 600; color: #0f172a; line-height: 1.2; }
.hj-page-hero .sub { font-size: 0.85rem; color: #64748b; margin-top: 0.25rem; }

.hj-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.42rem 0.9rem; border-radius: 0.45rem;
  font-size: 0.875rem; font-weight: 500; border: 1px solid transparent;
  transition: all 130ms ease; line-height: 1.2;
  text-decoration: none;
}
.hj-btn:hover { transform: translateY(-1px); box-shadow: var(--hj-shadow-md); }
.hj-btn:active { transform: translateY(0); box-shadow: var(--hj-shadow-sm); }
.hj-btn-primary {
  background: linear-gradient(180deg, #22832f, #1d6727);
  color: white; border-color: var(--hj-green);
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, var(--hj-shadow-sm);
}
.hj-btn-primary:hover { filter: brightness(1.05); }
.hj-btn-ghost { background: white; color: #334155; border-color: #cbd5e1; }
.hj-btn-ghost:hover { background: #f8fafc; border-color: #94a3b8; }
.hj-btn-danger { background: white; color: #b91c1c; border-color: #fca5a5; }
.hj-btn-danger:hover { background: #fef2f2; border-color: #f87171; }

/* Refined table */
table.hj-table { width: 100%; border-collapse: collapse; border-radius: 0.4rem; overflow: hidden; }
table.hj-table th, table.hj-table td {
  padding: 0.55rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  vertical-align: top;
}
table.hj-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
}
table.hj-table tbody tr { transition: background 100ms ease; }
table.hj-table tbody tr:hover { background: #f7fbf7; }
table.hj-table tbody tr:last-child td { border-bottom: 0; }
table.hj-table td.right, table.hj-table th.right { text-align: right; }

.flash {
  padding: 0.7rem 1rem; border-radius: 0.55rem;
  font-size: 0.875rem;
  box-shadow: 0 1px 2px rgba(15,23,42,0.05);
  display: flex; gap: 0.5rem; align-items: flex-start;
  animation: hj-fade 220ms ease-out both;
}
.flash::before { font-weight: 600; flex: 0 0 auto; }
.flash-info    { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.flash-info::before { content: "ℹ"; }
.flash-success { background: #dcfce7; color: #14532d; border: 1px solid #bbf7d0; }
.flash-success::before { content: "✓"; }
.flash-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }
.flash-warning::before { content: "⚠"; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-error::before { content: "✕"; }

/* Refined badges - subtle inset shadow + border */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem; font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.2;
}
.badge::before {
  content: ""; width: 0.4rem; height: 0.4rem; border-radius: 999px;
  background: currentColor; opacity: 0.55;
}
.badge-active      { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-sold        { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge-deceased    { background: #e2e8f0; color: #475569; border-color: #cbd5e1; }
.badge-quarantine  { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-transferred { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge-warn        { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
/* Variant without the leading dot for category-style chips */
.badge-plain::before { display: none; }

.tip { position: relative; cursor: help; border-bottom: 1px dotted #94a3b8; }
.tip[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 125%;
  left: 0;
  background: #0f172a;
  color: white;
  font-size: 0.7rem;
  padding: 0.45rem 0.7rem;
  border-radius: 0.4rem;
  white-space: pre-line;
  width: max-content;
  max-width: 280px;
  z-index: 50;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  opacity: 0; animation: hj-tip-in 80ms ease-out 100ms forwards;
}
@keyframes hj-tip-in { to { opacity: 1; } }

/* Refined KPI tile - subtle gradient, animated value entry */
.kpi-tile {
  background: linear-gradient(180deg, #ffffff, #fbfdfb);
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  padding: 1rem 1.1rem;
  position: relative; overflow: hidden;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.kpi-tile:hover {
  border-color: #94d39c; transform: translateY(-2px);
  box-shadow: 0 6px 14px -8px rgba(29,103,39,0.25);
}
.kpi-tile::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px; background: linear-gradient(90deg, var(--hj-green), #5cb867);
  opacity: 0; transition: opacity 160ms ease;
}
.kpi-tile:hover::after { opacity: 1; }
.kpi-tile .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: #64748b; font-weight: 500; }
.kpi-tile .value {
  font-size: 1.65rem; font-weight: 700; margin-top: 0.25rem;
  color: #0f172a; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  animation: hj-pop 280ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes hj-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.kpi-tile .sub { font-size: 0.7rem; color: #94a3b8; margin-top: 0.2rem; }
.kpi-tile .accent {
  position: absolute; right: -10px; top: -10px;
  font-size: 3.5rem; opacity: 0.08;
  transform: rotate(-8deg);
  transition: opacity 160ms ease, transform 320ms ease;
}
.kpi-tile:hover .accent { opacity: 0.18; transform: rotate(0); }

/* Section title - subtle accent bar on the left */
.section-title {
  font-size: 1.05rem; font-weight: 600; color: #0f172a;
  display: flex; align-items: center; gap: 0.55rem;
}
.section-title::before {
  content: ""; display: inline-block;
  width: 0.25rem; height: 1.05rem;
  background: var(--hj-green); border-radius: 999px;
}
.section-sub { font-size: 0.8rem; color: #64748b; margin-top: 0.15rem; }

/* Status dot helper */
.status-dot {
  display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 999px;
  margin-right: 0.35rem; vertical-align: 0.05em;
  box-shadow: 0 0 0 2px white;
}
.status-dot-ok    { background: #16a34a; }
.status-dot-warn  { background: #d97706; }
.status-dot-error { background: #dc2626; }
.status-dot-idle  { background: #94a3b8; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="number"], input:not([type]), select, textarea {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 0.4rem;
  padding: 0.42rem 0.65rem;
  font-size: 0.875rem;
  width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: #94a3b8;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #5cb867; box-shadow: 0 0 0 3px rgba(92,184,103,0.18);
}
input:disabled, select:disabled, textarea:disabled {
  background: #f8fafc; color: #94a3b8; cursor: not-allowed;
}
input:user-invalid, select:user-invalid, textarea:user-invalid,
form.submitted input:invalid, form.submitted select:invalid, form.submitted textarea:invalid {
  border-color: #dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,0.18);
}
input[readonly] { background: #f8fafc; color: #64748b; }
label { font-size: 0.85rem; color: #334155; display: inline-block; }
label:has(+ * :required) { font-weight: 500; }

button[disabled], .hj-btn[disabled] {
  opacity: 0.55; pointer-events: none; cursor: not-allowed;
}
.hj-btn[data-busy="1"]::before {
  content: "";
  display: inline-block; width: 0.85rem; height: 0.85rem;
  border-radius: 9999px;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: hj-spin 0.7s linear infinite;
  margin-right: 0.4rem; vertical-align: -2px;
}
@keyframes hj-spin { to { transform: rotate(360deg); } }

.label-req::after {
  content: " *"; color: #dc2626; font-weight: 600;
}

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

.help-card {
  background: white;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  padding: 1.25rem;
}

/* Empty-state refinement */
.hj-empty {
  text-align: center; padding: 2.5rem 1.5rem;
  border-radius: 0.7rem;
  background: linear-gradient(180deg, #fafdfa, #f3f7ee);
  border: 1px dashed #c1e7c5;
}
.hj-empty .icon { font-size: 2.4rem; opacity: 0.85; }
.hj-empty .text { font-size: 0.875rem; color: #475569; margin-top: 0.5rem; }
.hj-empty .cta { margin-top: 1rem; }

/* Scrollbar polish for sidebar (Webkit) */
nav::-webkit-scrollbar { width: 6px; }
nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 999px; }
nav::-webkit-scrollbar-track { background: transparent; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="number"], input:not([type]), select, textarea {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  width: 100%;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: #94a3b8;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #5cb867; box-shadow: 0 0 0 3px rgba(92,184,103,0.18);
}
input:disabled, select:disabled, textarea:disabled {
  background: #f8fafc; color: #94a3b8; cursor: not-allowed;
}
/* User-invalid: only after the user has interacted (no eager error styling on
   first paint). Native :user-invalid in modern browsers; fallback to :invalid
   inside a form that has the .submitted marker class set by smart-forms.js. */
input:user-invalid, select:user-invalid, textarea:user-invalid,
form.submitted input:invalid, form.submitted select:invalid, form.submitted textarea:invalid {
  border-color: #dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,0.18);
}
input[readonly] { background: #f8fafc; color: #64748b; }
label { font-size: 0.85rem; color: #334155; display: inline-block; }
/* Auto-marker for required inputs: '*' appended to the preceding label.
   Use .req-mark to opt out (e.g. labels for radio groups). */
label:has(+ * :required) { font-weight: 500; }

/* Submit buttons that disable themselves while the form is in flight */
button[disabled], .hj-btn[disabled] {
  opacity: 0.55; pointer-events: none; cursor: not-allowed;
}
.hj-btn[data-busy="1"]::before {
  content: "";
  display: inline-block; width: 0.85rem; height: 0.85rem;
  border-radius: 9999px;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: hj-spin 0.7s linear infinite;
  margin-right: 0.4rem; vertical-align: -2px;
}
@keyframes hj-spin { to { transform: rotate(360deg); } }

/* Visual hint that a label belongs to a required input.
   Uses :has so it only renders when the next selector finds a required field. */
.label-req::after {
  content: " *"; color: #dc2626; font-weight: 600;
}

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

.help-card {
  background: white;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
  padding: 1.25rem;
}
