/* =========================================================================
   components.css — reusable component styles (spec Section 13). Card, button,
   chip, badge, table, form, modal, toast, tabs, timeline, skeleton, states.
   Pill buttons / rounded cards / chips echo iNSPO/components.jpg.
   ========================================================================= */

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 var(--sp-4);
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  will-change: transform;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-mid) var(--ease),
    transform var(--dur-fast) var(--ease-spring);
}
.btn:hover { transform: none; }
.btn:active { transform: scale(0.98); transition-duration: var(--dur-fast); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: none;
}
.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, white);
  box-shadow: none;
}
.btn--secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: var(--surface-hover); box-shadow: none; }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn--danger {
  background: var(--status-danger);
  color: #fff;
  box-shadow: none;
}
.btn--danger:hover {
  background: color-mix(in srgb, var(--status-danger) 88%, black);
  box-shadow: none;
}
.btn--sm { height: 28px; padding: 0 10px; font-size: var(--fs-caption); gap: 4px; }
.btn--block { width: 100%; }

/* --- Cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-mid) var(--ease), transform var(--dur-mid) var(--ease-spring),
    border-color var(--dur-mid) var(--ease);
}
.card--pad-0 { padding: 0; }
.card--clickable { cursor: pointer; }
.card--clickable:hover,
a.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
  border-color: var(--border-strong);
  text-decoration: none;
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card__title { font-size: var(--fs-h6); font-weight: var(--fw-semibold); margin: 0; }
.card__link { font-size: var(--fs-small); }

.grid { display: grid; gap: var(--sp-5); }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* --- KPI / stat card ----------------------------------------------------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-mid) var(--ease), background var(--dur-mid) var(--ease),
    box-shadow var(--dur-mid) var(--ease), transform var(--dur-mid) var(--ease-spring);
}
.stat__label { color: var(--text-muted); font-size: var(--fs-small); margin-bottom: var(--sp-2); }
.stat__value { font-size: var(--fs-h2); font-weight: var(--fw-bold); line-height: 1; letter-spacing: -0.02em; }
.stat__sub { color: var(--text-faint); font-size: var(--fs-caption); margin-top: var(--sp-2); }
.stat--clickable { cursor: pointer; }
.stat--clickable:hover {
  border-color: var(--border-strong);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
}
.stat--clickable:active { transform: translateY(-1px) scale(0.99); }

/* --- Badges & chips ------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: var(--fw-medium);
  line-height: 1.5;
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  background: transparent;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; opacity: 0.9; }
.badge--neutral { color: var(--status-neutral); background: color-mix(in srgb, var(--status-neutral) 8%, transparent); }
.badge--info    { color: var(--status-info);    background: color-mix(in srgb, var(--status-info) 8%, transparent); }
.badge--warn    { color: var(--status-warn);    background: color-mix(in srgb, var(--status-warn) 8%, transparent); }
.badge--success { color: var(--status-success); background: color-mix(in srgb, var(--status-success) 8%, transparent); }
.badge--danger  { color: var(--status-danger);  background: color-mix(in srgb, var(--status-danger) 8%, transparent); }
.badge--purple  { color: var(--status-purple);  background: color-mix(in srgb, var(--status-purple) 8%, transparent); }
.badge--accent  { color: var(--text-muted); background: var(--surface-2); border-color: var(--border); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-caption);
  color: var(--text);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip button {
  border: 0; background: none; color: var(--text-faint); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0;
}
.chip button:hover { color: var(--text); }

/* --- Tables -------------------------------------------------------------- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body);
}
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  text-align: left;
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
table.data thead th.sortable { cursor: pointer; }
table.data thead th.sortable:hover { color: var(--text); }
table.data thead th .sort-ind { color: var(--accent); margin-left: 4px; }
table.data tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr { transition: background var(--dur-fast) var(--ease); }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr:last-child td { border-bottom: 0; }

.table-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.selection-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}
.selection-bar.hidden { display: none; }
table.data th.col-select,
table.data td.col-select {
  width: 32px;
  text-align: center;
  padding-inline: 8px;
  vertical-align: middle;
}
table.data .col-select input[type='checkbox'] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  opacity: 0.75;
}
table.data .col-select input[type='checkbox']:hover,
table.data .col-select input[type='checkbox']:checked {
  opacity: 1;
}
table.data tbody tr.is-selected { background: color-mix(in srgb, var(--accent) 8%, transparent); }
table.data tbody tr.is-selected:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pagination {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  justify-content: flex-end;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-small);
  color: var(--text-muted);
  flex-wrap: wrap;
}
.pagination select { width: auto; }

/* --- Forms --------------------------------------------------------------- */
.form-grid { display: grid; gap: var(--sp-4); }
.form-grid--2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-section { margin-bottom: var(--sp-6); }
.form-section > h3 {
  font-size: var(--fs-h6);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-small); font-weight: var(--fw-medium); color: var(--text-muted); }
.field .req { color: var(--status-danger); }
.field .hint { font-size: var(--fs-caption); color: var(--text-faint); }
.field .error-text { font-size: var(--fs-caption); color: var(--status-danger); }
.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--status-danger); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 var(--sp-4);
  height: 40px;
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-mid) var(--ease),
    background var(--dur-fast) var(--ease);
}
input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: var(--border-strong);
}
textarea { height: auto; padding: var(--sp-3) var(--sp-4); min-height: 90px; resize: vertical; line-height: var(--lh-normal); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}
/* Checkboxes/radios must not inherit text-field sizing (width:100% / height:40px). */
input[type='checkbox'],
input[type='radio'] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
  box-shadow: none;
}
input[type='checkbox']:hover:not(:focus),
input[type='radio']:hover:not(:focus) {
  border-color: transparent;
}
input[type='checkbox']:focus,
input[type='radio']:focus {
  border-color: transparent;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type='checkbox']:disabled,
input[type='radio']:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: nowrap;
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: var(--fs-small);
  line-height: 1.35;
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.check-row:hover {
  background: var(--surface-hover);
}
.check-row:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.6;
}
.check-row:has(input:disabled):hover {
  background: transparent;
}
.check-row__label {
  flex: 1;
  min-width: 0;
}
.check-list__group {
  font-size: var(--fs-small);
  color: var(--text-muted);
  padding: 8px 10px 2px;
}
.check-row--nested {
  padding-left: calc(10px + 1.15rem);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238eb69b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: var(--sp-6);
}
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .prefix { position: absolute; left: var(--sp-4); color: var(--text-faint); pointer-events: none; }
.input-affix input { padding-left: var(--sp-6); }

.search-input {
  position: relative;
  flex: 1;
  max-width: 460px;
}
.search-input input { padding-left: 32px; height: 32px; border-radius: 8px; font-size: var(--fs-small); }
.search-input .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { display: none; }
.switch .track {
  width: 40px; height: 22px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border); position: relative;
  transition: background var(--dur-fast) var(--ease);
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--text-muted);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.switch input:checked + .track { background: var(--accent-strong); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--green-100); }

/* --- Modal / dialog ------------------------------------------------------ */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  box-shadow: var(--shadow-lift);
}
dialog.modal[open] { animation: modal-in var(--dur-mid) var(--ease-out); }
dialog.modal[open]::backdrop { animation: backdrop-in var(--dur-mid) var(--ease); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal__head { display: flex; justify-content: space-between; align-items: center; padding: var(--sp-5); border-bottom: 1px solid var(--border); }
.modal__title { font-size: var(--fs-h5); font-weight: var(--fw-semibold); margin: 0; }
.modal__body { padding: var(--sp-5); }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }

/* Status picker (readable alternative to native <select> in dark theme) */
.status-pick {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.status-pick__option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.status-pick__option:hover {
  border-color: var(--border-strong);
}
.status-pick__option.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-raised));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.status-pick__option--danger.is-selected {
  border-color: var(--status-danger);
  background: color-mix(in srgb, var(--status-danger) 12%, var(--bg-raised));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-danger) 16%, transparent);
}
.status-pick__label {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-body);
  color: var(--text);
}
.status-pick__hint {
  font-size: var(--fs-caption);
  color: var(--text-muted);
}
.status-pick__option--forward .status-pick__hint { color: var(--accent-strong, var(--accent)); }
.status-pick__option--back .status-pick__hint { color: var(--status-warn, #c9a227); }
.status-pick__option--danger .status-pick__hint { color: var(--status-danger); }

/* --- Toast --------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  animation: toast-in var(--dur-mid) var(--ease);
}
.toast--success { border-left: 3px solid var(--status-success); }
.toast--error { border-left: 3px solid var(--status-danger); }
.toast--info { border-left: 3px solid var(--status-info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Tabs ---------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--sp-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
}
.tab {
  padding: var(--sp-3) var(--sp-4);
  border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font: inherit; font-weight: var(--fw-medium);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Status stepper ------------------------------------------------------ */
.stepper { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.stepper__step {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--fs-small); color: var(--text-muted);
}
.stepper__step.done { color: var(--status-success); border-color: color-mix(in srgb, var(--status-success) 40%, var(--border)); }
.stepper__step.current { color: var(--text-on-accent); background: var(--accent); border-color: var(--accent); font-weight: var(--fw-semibold); }

/* --- Timeline ------------------------------------------------------------ */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item {
  position: relative;
  padding: 0 0 var(--sp-4) var(--sp-6);
  border-left: 2px solid var(--border);
}
.timeline__item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: -7px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-raised);
}
.timeline__time { font-size: var(--fs-caption); color: var(--text-faint); }
.timeline__body { font-size: var(--fs-small); }

/* --- Skeleton / states --------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
.skeleton--line { height: 14px; margin-bottom: var(--sp-2); }
.skeleton--row { height: 44px; margin-bottom: 2px; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.state {
  text-align: center;
  padding: var(--sp-7) var(--sp-5);
  color: var(--text-muted);
}
.state__icon { color: var(--text-faint); margin-bottom: var(--sp-3); }
.state__title { font-size: var(--fs-h6); color: var(--text); margin-bottom: var(--sp-2); }
.state__msg { font-size: var(--fs-small); margin-bottom: var(--sp-4); }
.state--error .state__icon { color: var(--status-danger); }

/* --- Simple SVG bar chart ------------------------------------------------ */
.bars { display: flex; flex-direction: column; gap: var(--sp-3); }
.bar-row { display: grid; grid-template-columns: 60px 1fr auto; align-items: center; gap: var(--sp-3); font-size: var(--fs-small); }
.bar-track { background: var(--surface-2); border-radius: var(--radius-pill); height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--green-600), var(--green-400)); }

/* --- Definition list (summary panels) ------------------------------------ */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-5); align-items: baseline; }
.dl dt { color: var(--text-muted); font-size: var(--fs-small); }
.dl dd { margin: 0; font-weight: var(--fw-medium); }

/* --- Search dropdown ----------------------------------------------------- */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  z-index: 50;
  max-height: 60vh;
  overflow: auto;
  padding: var(--sp-2);
  transform-origin: top center;
  animation: dropdown-in var(--dur-mid) var(--ease-out);
}
@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.search-results__group-label { font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); padding: var(--sp-2) var(--sp-3); }
.search-results__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.search-results__item:hover,
.search-results__item:focus-visible {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
  transform: translateX(2px);
  outline: none;
}
.search-results__item.muted { color: var(--text-muted); }

/* --- Dropzone ------------------------------------------------------------ */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.dropzone.dragover { border-color: var(--accent); background: var(--surface-hover); }

.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-5) 0; }
.stack > * + * { margin-top: var(--sp-3); }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }

/* =========================================================================
   Component additions — classes emitted by the JS components in
   public/js/components/*. Kept here so the design system stays in one place.
   ========================================================================= */

/* --- Form field (BEM names emitted by components/forms.js) ---------------- */
.field__label { font-size: var(--fs-small); font-weight: var(--fw-medium); color: var(--text-muted); }
.field__req { color: var(--status-danger); }
.field__hint { font-size: var(--fs-caption); color: var(--text-faint); }
.field__error { font-size: var(--fs-caption); color: var(--status-danger); min-height: 0; }
.field--error input,
.field--error select,
.field--error textarea { border-color: var(--status-danger); }
.field--error input:focus,
.field--error select:focus,
.field--error textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-danger) 22%, transparent); }
.field--full { grid-column: 1 / -1; }

.form-grid--1 { grid-template-columns: 1fr; }
.form-actions {
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border);
}
.form-section { grid-column: 1 / -1; font-size: var(--fs-h6); margin: var(--sp-3) 0 0; }

/* amount + currency-code suffix */
.input-group { position: relative; display: flex; align-items: center; width: 100%; }
.input-group input { padding-right: 56px; }
.input-suffix {
  position: absolute; right: 1px; top: 1px; bottom: 1px;
  display: grid; place-items: center; padding: 0 var(--sp-3);
  color: var(--text-faint); font-size: var(--fs-small); font-weight: var(--fw-semibold);
  background: var(--surface-2); border-left: 1px solid var(--border);
  border-radius: 0 var(--radius-md) var(--radius-md) 0; pointer-events: none;
}

.input-with-icon { position: relative; display: flex; align-items: center; flex: 1; min-width: 180px; }
.input-with-icon .icon { position: absolute; left: 10px; color: var(--text-faint); pointer-events: none; width: 14px; height: 14px; }
.input-with-icon input { padding-left: 32px; border-radius: 8px; height: 32px; font-size: var(--fs-small); }

/* --- FilterBar (components/filter-bar.js) -------------------------------- */
.filterbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3);
}
.filterbar__controls { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; flex: 1; }
.filterbar__controls select {
  width: auto;
  min-width: 112px;
  height: 32px;
  padding: 0 28px 0 10px;
  font-size: var(--fs-small);
  border-radius: 8px;
  color: var(--text-muted);
}
.filterbar__search { flex: 1; }
.filterbar__action { flex: none; }
.filterbar__action .btn { height: 32px; }

/* --- Charts (components/charts.js) --------------------------------------- */
.barlist { display: flex; flex-direction: column; gap: var(--sp-3); }
.barlist__row { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: var(--sp-3); font-size: var(--fs-small); }
.barlist__label { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barlist__track { background: var(--surface-2); border-radius: var(--radius-pill); height: 10px; overflow: hidden; }
.barlist__fill { height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--green-600), var(--green-400)); transition: width var(--dur-mid) var(--ease); }
.barlist__value { font-variant-numeric: tabular-nums; color: var(--text); font-weight: var(--fw-medium); }

.donut-wrap { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }
.donut { position: relative; border-radius: 50%; flex: none; }
.donut__hole {
  position: absolute; inset: var(--donut-thickness, 16px);
  background: var(--surface); border-radius: 50%;
  display: grid; place-items: center; text-align: center;
}
.donut__total { font-size: var(--fs-h5); font-weight: var(--fw-bold); line-height: 1; }
.donut__label { font-size: var(--fs-caption); color: var(--text-faint); }
.donut__legend { display: flex; flex-direction: column; gap: var(--sp-2); }
.donut__legend-item { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-small); }
.donut__swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* --- FileUpload (components/file-upload.js) ------------------------------ */
.file-upload { display: flex; flex-direction: column; gap: var(--sp-3); }
.file-upload__cat { display: flex; flex-direction: column; gap: 6px; max-width: 240px; }
.dropzone.is-drag { border-color: var(--accent); background: var(--surface-hover); }
.dropzone.is-busy { opacity: 0.7; pointer-events: none; }
.dropzone__text { margin-top: var(--sp-2); }
.dropzone__hint { font-size: var(--fs-caption); color: var(--text-faint); margin-top: 4px; }
.dropzone__status { margin-top: var(--sp-2); font-size: var(--fs-small); }
.link { color: var(--accent); cursor: pointer; }
.text-ok { color: var(--status-success); }
.text-danger { color: var(--status-danger); }

/* --- Detail page scaffolding (used by pages) ---------------------------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: var(--sp-5); align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.section-title { font-size: var(--fs-h6); margin: 0 0 var(--sp-3); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-5); align-items: baseline; }
.kv dt { color: var(--text-muted); font-size: var(--fs-small); }
.kv dd { margin: 0; }
.list-reset { list-style: none; margin: 0; padding: 0; }

/* --- Auth / login screen ----------------------------------------------- */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
  background:
    radial-gradient(120% 90% at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.auth__card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  padding: var(--sp-7);
}
.auth__brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.auth__brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-weight: var(--fw-bold);
  color: var(--accent-contrast);
  background: var(--accent);
}
.auth__brand-name { font-weight: var(--fw-semibold); letter-spacing: 0.02em; }
.auth__title { font-size: var(--fs-h4); margin: 0 0 var(--sp-2); }
.auth__subtitle { color: var(--text-muted); font-size: var(--fs-small); margin: 0 0 var(--sp-6); }
.auth__form { display: flex; flex-direction: column; gap: var(--sp-4); }
.auth__form .btn { margin-top: var(--sp-2); }
.auth__error {
  font-size: var(--fs-small);
  color: var(--status-danger);
  background: color-mix(in srgb, var(--status-danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--status-danger) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
}
.auth__footnote {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-6);
  color: var(--text-faint);
  font-size: var(--fs-caption);
}
.auth__footnote .icon { flex: none; }

.auth__card--loading { text-align: center; }
.auth__loader {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--sp-5);
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: auth-spin 0.75s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

.auth__branch-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.auth__branch-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.auth__branch-item:hover:not(:disabled) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  transform: translateY(-1px);
}
.auth__branch-item:disabled { opacity: 0.6; cursor: wait; }
.auth__branch-item--central {
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 6%, var(--bg-raised));
}
.auth__branch-item strong { font-weight: var(--fw-semibold); }
.auth__branch-item .muted { font-size: var(--fs-caption); }

.sidebar__workspace {
  margin: 0 var(--sp-3) var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg-raised));
}
.sidebar__workspace-label {
  font-size: var(--fs-caption);
  color: var(--text-faint);
  margin-bottom: 2px;
}
.sidebar__workspace-name {
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar__workspace .btn { width: 100%; }
.app.sidebar-collapsed .sidebar__workspace { display: none; }
