/* components.css — reusable UI (cleaned) */

/* =========================
   Cards
========================= */
.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
  padding: 20px;
}

.card h3 {
  color: var(--primary-color);
  margin-bottom: 15px;
  font-size: 1.3rem;
}

.card p {
  margin-bottom: 15px;
  line-height: 1.5;
  color: #666;
}

.card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 15px;
}

.card-header h3 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--primary-color);
}

.card-header .card-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--secondary-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon {
  background: var(--secondary-color);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
}

.recent-contracts.card {
  background: #fff;
  padding: 1.5rem;
  border-radius: .5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
  margin-bottom: 2rem;
  max-width: 100%;
  min-width: 1160px;
  min-height: 400px;
  overflow: hidden;
}

/* =========================
   Buttons
========================= */
.btn {
  display: inline-block;
  padding: 10px 15px;
  background: var(--primary-color);
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.btn:hover {
  background: #55823B;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
}

.btn-outline:hover {
  background: var(--primary-color);
  color: #fff;
}

.btn-danger {
  background: #d9534f;
  color: #fff;
  border: 0;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-danger:hover {
  background: #c9302c;
}

.btn-amountperiod {
  background: #fff;
  color: var(--primary-color);
  padding: 10px 15px;
  border-radius: 4px;
  font-weight: 500;
}

.btn-amountperiod:hover {
  background: #55823B;
  color: #fff;
}

button:disabled {
  opacity: .3;
}

.reload-btn {
  width: 48px;
  height: 48px;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
}

.reload-btn:hover {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.reload-btn img {
  width: 28px;
  height: 28px;
  transform: rotate(45deg);
}

.sort-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 12px;
  margin-left: 4px;
  opacity: .5;
}

.sort-btn:hover {
  opacity: 1;
}

/* =========================
   Badges / Tags / Chips
========================= */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-buyer {
  background: #ecfdf5;
  color: #065f46;
}

.badge-seller {
  background: #fef3c7;
  color: #92400e;
}

.counterpart-tag.buyer {
  background: #ecfdf5;
  color: #065f46;
}

.counterpart-tag.seller {
  background: #fef3c7;
  color: #92400e;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #1e3a8a;
  font-size: 12px;
  border: 1px solid #c7d2fe;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip.active {
  background: #c7d2fe;
  color: #1e3a8a;
  border-color: #818cf8;
}

.biology-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 12px;
  font-weight: bold;
  border: 1px solid #a5d6a7;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.regulatory-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff3e0;
  color: #e65100;
  font-size: 12px;
  font-weight: bold;
  border: 1px solid #ffcc80;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.certificate-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ffebee;
  color: #c62828;
  font-size: 12px;
  font-weight: bold;
  border: 1px solid #ef9a9a;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.chip,
button.tf-chip--exclude {
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.tf-chip--exclude.active {
  background: #fecaca;
  color: #7f1d1d;
  border-color: #f87171;
}

/* =========================
   Tables
========================= */
.table-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
  width: 100%;
}

table,
.contracts-table {
  width: 100%;
  border-collapse: collapse;
}

table th,
table td {
  padding: .75rem 1rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

table th {
  background: var(--secondary-color);
  font-weight: 600;
}

table tr:hover {
  background: #f8f9fa;
}

#genericTable tbody tr:hover {
  background-color: #fff3f3;
  cursor: pointer;
}

#specificTable tbody tr:hover {
  background-color: #dfdfdf;
  cursor: pointer;
}

thead th[data-cert-header="1"][data-sort="asc"]::after,
thead th[data-bio-header="1"][data-sort="asc"]::after {
  content: "▲";
  margin-left: 4px;
  font-size: 11px;
}

thead th[data-cert-header="1"][data-sort="desc"]::after,
thead th[data-bio-header="1"][data-sort="desc"]::after {
  content: "▼";
  margin-left: 4px;
  font-size: 11px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.stats-table th,
.stats-table td {
  border: 1px solid #e5e7eb;
  padding: 6px 10px;
  text-align: left;
  font-size: 13px;
}

.stats-table th {
  background-color: #f3f4f6;
  font-weight: 600;
}

/* =========================
   Forms
========================= */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  font-size: 16px;
}

.form-control:focus {
  outline: 0;
  border-color: var(--primary-color);
}

.form-control:disabled,
.form-control[disabled],
.form-control[readonly],
.form-control[aria-disabled="true"] {
  background: #f5f6f8;
  color: #6b7280;
  border-color: #d1d5db;
  opacity: 1;
}

.form-control[readonly]:focus {
  border-color: #cbd5e1;
  box-shadow: none;
}

.help-text {
  font-size: .85rem;
  color: #666;
  margin-bottom: 10px;
}

.bio-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.bio-form-row {
  margin-bottom: 0.75rem;
}

.bio-form-row.wide-row {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
}

.bio-form-row.wide-row label {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* =========================
   Modals
========================= */
.modal {
  display: none;
  position: fixed;
  z-index: 1050;
  inset: 0;
  overflow-y: hidden;
  background: rgba(0,0,0,.5);
}

.modal-content {
  background: #fff;
  margin: 5vh auto;
  padding: 30px;
  border-radius: 8px;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 15px rgba(0,0,0,.3);
  position: relative;
}

.modal .close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 24px;
  font-weight: 700;
  color: #555;
  cursor: pointer;
}

.modal-footer:empty {
  display: none;
}

.modal-gap {
  height: 2rem;
  border-top: 1px solid #e5e7eb;
  margin-top: 1rem;
  opacity: 0.5;
}

body.modal-open {
  overflow: hidden;
  height: 100vh;
  position: fixed;
  width: 100%;
}

.modal-tab-panels {
  width: 100%;
}

.modal-tab-content .bio-form-grid {
  display: grid;
  gap: 0.75rem 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* =========================
   Tabs
========================= */
.tab-nav {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #ddd;
  margin-bottom: 1rem;
  padding-bottom: 0.25rem;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #444;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease-in-out;
}

.tab-btn:hover {
  color: #007bff;
}

.tab-btn.active {
  color: #007bff;
  border-color: #007bff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.empty-tab {
  color: #888;
  font-style: italic;
  padding: 1rem;
  text-align: center;
}

/* =========================
   Choices.js Dropdowns
========================= */
.choices {
  position: relative;
  width: 100%;
  margin-top: 0.25rem;
}

.choices__inner {
  min-height: 2.4rem;
  border-radius: 0.375rem;
  border: 1px solid #ccc;
  background-color: #fff;
}

.choices__list--dropdown {
  position: absolute !important;
  width: 100% !important;
  max-height: 220px !important;
  overflow-y: auto !important;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 9999;
}

.choices.is-open .choices__list--dropdown {
  opacity: 1;
  visibility: visible;
}

.choices__input {
  padding: 0.25rem 0.5rem;
}

#certGenericModal .choices__list--dropdown {
  max-height: 2200px !important;
}

/* =========================
   Stats & Summaries
========================= */
.stats-summary-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 1rem;
}

.stats-summary {
  flex: 1 1 45%;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.stats-summary h5 {
  margin-bottom: 0.75rem;
  color: #1f2937;
  font-size: 1rem;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 0.4rem;
}

.stats-grid-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  row-gap: 0.5rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  font-weight: 500;
  color: #4b5563;
}

.stat-value {
  font-weight: 600;
  color: #111827;
}

.stats-visualization {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 1.5rem;
}

.expand-toggle {
  margin-top: 6px;
  text-align: right;
}

/* =========================
   Products Layout
========================= */
.products-container.side-by-side {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  justify-content: space-between;
  margin-top: 1rem;
}

.products-column {
  flex: 1 1 45%;
  min-width: 300px;
}

/* =========================
   KPI Donut (SVG)
========================= */
.kpi-svg {
  --p: 0;
  --ring: #55823B;
  --track: rgba(245,245,245,.673);
  --thickness: 12;
  --r: 54;
  --circ: calc(2 * 3.14159265 * var(--r));
  width: 170px;
  aspect-ratio: 1/1;
  margin: 8px auto 16px;
}

.kpi-svg svg {
  width: 100%;
  height: auto;
  display: block;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

.kpi-svg circle {
  fill: none;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke-linecap: round;
}

.kpi-svg .track {
  stroke: var(--track);
  stroke-width: var(--thickness);
}

.kpi-svg .bar {
  stroke: var(--ring);
  stroke-width: var(--thickness);
  stroke-dasharray: var(--circ);
  stroke-dashoffset: calc(var(--circ) - (var(--p) * var(--circ) / 100));
  transition: stroke-dashoffset .6s ease;
}

.kpi-svg text {
  font-family: inherit;
  text-anchor: middle;
  dominant-baseline: middle;
  fill: var(--text-color);
}

.kpi-svg .value {
  font-weight: 700;
  font-size: 18px;
}

.kpi-svg .label {
  font-size: 12px;
  fill: #666;
}

/* =========================
   Utility Classes
========================= */
.action-buttons {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.row-error {
  background: #fe6c6c !important;
}

.buyer-id-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .1rem;
  margin-bottom: 1rem;
}

.supplier-info {
  display: flex;
  align-items: center;
  gap: .05rem;
}

.crm-link img {
  height: 1.2em;
  vertical-align: middle;
  cursor: pointer;
}

.buyer-id {
  font-weight: 700;
}

#chartContainer {
  height: 400px;
  align-items: center;
}

#labelsBlock,
#genericDropdownBlock {
  display: inline-block;
  vertical-align: top;
  margin-right: 1rem;
}

#genericDropdownBlock label {
  display: block;
  margin-bottom: .25rem;
}

.chart-mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.chart-mode-toggle label {
  font-size: 13px;
  color: #374151;
  cursor: pointer;
}

/* =========================
   Responsive
========================= */
@media (max-width: 768px) {
  .stats-summary {
    flex: 1 1 100%;
  }
}