/* ==========================================================================
   Components
   ========================================================================== */

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast);
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn--primary { background: var(--fp-red); color: #fff; }
.btn--primary:hover { background: var(--fp-red-hi); }

.btn--ghost {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--surface-4); border-color: var(--border-hi); }

.btn--quiet { background: transparent; color: var(--text-2); }
.btn--quiet:hover { background: var(--surface-3); color: var(--text); }

.btn--danger { background: transparent; color: var(--fp-red); border-color: rgba(200,0,0,.4); }
.btn--danger:hover { background: var(--red-bg); }

.btn--sm { height: 28px; padding: 0 10px; font-size: 11.5px; }
.btn--sm svg { width: 13px; height: 13px; }
.btn--lg { height: 40px; padding: 0 20px; font-size: 13.5px; }
.btn--icon { width: 30px; height: 30px; padding: 0; }
.btn--icon.btn--sm { width: 26px; height: 26px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: 0.42; pointer-events: none; }

/* --- Badges / pills ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--r-xs);
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--danger { background: var(--danger-bg); color: #FF6B6B; }
.badge--info { background: var(--info-bg); color: var(--info); }
.badge--neutral { background: var(--surface-4); color: var(--text-2); }
.badge--red { background: var(--fp-red); color: #fff; }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Stat tile ------------------------------------------------------------ */
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 15px 16px;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--fp-red);
  opacity: 0.85;
}
.stat__val {
  font-size: 25px;
  font-weight: var(--fw-extrabold);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}
.stat__delta { font-size: 11.5px; font-weight: var(--fw-semibold); margin-top: 5px; }
.stat__delta--up { color: var(--ok); }
.stat__delta--down { color: #FF6B6B; }
.stat__delta--flat { color: var(--text-3); }

/* --- Tables --------------------------------------------------------------- */
.tbl-wrap { overflow-x: auto; }
.tbl { font-size: 13px; min-width: 640px; }
.tbl thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  padding: 9px 14px;
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}
.tbl tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.tbl .col-tight { width: 1%; white-space: nowrap; }

/* --- Avatar --------------------------------------------------------------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--surface-4);
  color: var(--text);
  font-size: 11px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  flex: none;
  user-select: none;
}
.avatar--red { background: var(--fp-red); color: #fff; }
.avatar--wine { background: var(--fp-dark-maroon); color: var(--fp-soft-pink); }
.avatar--sm { width: 24px; height: 24px; font-size: 9.5px; }
.avatar--lg { width: 40px; height: 40px; font-size: 14px; }
.avatar--xl { width: 64px; height: 64px; font-size: 21px; }

.user-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-cell__name { font-weight: var(--fw-semibold); }

/* --- Forms ---------------------------------------------------------------- */
.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  font-size: 11px;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field__hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.field__req { color: var(--fp-red); }

.input,
.select,
.textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 11px;
  height: 34px;
  font-size: 13px;
  color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 76px; line-height: 1.55; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-hi); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--fp-red);
  background: var(--surface-3);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2374747A' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.input--sm, .select--sm { height: 28px; font-size: 12px; }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search svg {
  position: absolute;
  left: 10px;
  width: 14px; height: 14px;
  color: var(--text-3);
  pointer-events: none;
}
.search .input { padding-left: 31px; }

.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1 1 0; min-width: 0; }

/* --- Switch --------------------------------------------------------------- */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 34px; height: 19px;
  border-radius: var(--r-pill);
  background: var(--surface-4);
  border: 1px solid var(--border-hi);
  position: relative;
  transition: background var(--t-fast), border-color var(--t-fast);
  flex: none;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--n-300);
  transition: transform var(--t), background var(--t-fast);
}
.switch input:checked + .switch__track { background: var(--fp-red); border-color: var(--fp-red); }
.switch input:checked + .switch__track::after { transform: translateX(15px); background: #fff; }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--fp-red); outline-offset: 2px; }
.switch__text { font-size: 13px; }

/* --- Checkbox ------------------------------------------------------------- */
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__box {
  width: 16px; height: 16px;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border-hi);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.check__box::after {
  content: "";
  width: 8px; height: 4.5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) scale(0);
  transition: transform var(--t-fast);
  margin-top: -2px;
}
.check input:checked + .check__box { background: var(--fp-red); border-color: var(--fp-red); }
.check input:checked + .check__box::after { transform: rotate(-45deg) scale(1); }
.check input:focus-visible + .check__box { outline: 2px solid var(--fp-red); outline-offset: 2px; }

/* --- Radio ---------------------------------------------------------------- */
.radio { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.radio input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio__dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-hi);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.radio__dot::after {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  transform: scale(0);
  transition: transform var(--t-fast);
}
.radio input:checked + .radio__dot { border-color: var(--fp-red); background: var(--fp-red); }
.radio input:checked + .radio__dot::after { transform: scale(1); }

/* --- Tabs ----------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: 9px 13px;
  font-size: 12.5px;
  font-weight: var(--fw-semibold);
  color: var(--text-3);
  white-space: nowrap;
  transition: color var(--t-fast);
}
.tab:hover { color: var(--text-2); }
.tab.is-active { color: var(--text); }
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--fp-red);
}
.tab__count {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: var(--r-xs);
  background: var(--surface-4);
  font-size: 10.5px;
  color: var(--text-2);
}

/* --- Segmented control ---------------------------------------------------- */
.seg {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.seg button {
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: var(--fw-semibold);
  color: var(--text-3);
  border-radius: var(--r-xs);
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button:hover { color: var(--text-2); }
.seg button.is-active { background: var(--fp-red); color: #fff; }

/* --- Progress ------------------------------------------------------------- */
.bar {
  height: 5px;
  background: var(--surface-4);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  background: var(--fp-red);
  border-radius: var(--r-pill);
  transition: width var(--t);
}
.bar__fill--ok { background: var(--ok); }
.bar__fill--warn { background: var(--warn); }
.bar--lg { height: 8px; }

.meter { display: flex; align-items: center; gap: 9px; }
.meter .bar { flex: 1 1 auto; min-width: 60px; }
.meter__val {
  font-size: 11.5px;
  font-weight: var(--fw-semibold);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* --- Modal ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  animation: fade var(--t) both;
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  animation: pop var(--t) both;
  overflow: hidden;
}
.modal--wide { max-width: 760px; }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal__body { padding: 18px; overflow-y: auto; }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* --- Toast ---------------------------------------------------------------- */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  padding: 11px 14px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-left: 3px solid var(--fp-red);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-2);
  font-size: 12.5px;
  animation: slide-in var(--t) both;
}
.toast svg { width: 15px; height: 15px; flex: none; color: var(--fp-red); }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

/* --- Dropdown menu -------------------------------------------------------- */
.menu {
  position: absolute;
  min-width: 176px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-2);
  padding: 4px;
  z-index: 150;
  animation: pop var(--t-fast) both;
}
.menu__item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border-radius: var(--r-xs);
  font-size: 12.5px;
  color: var(--text-2);
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}
.menu__item:hover { background: var(--surface-4); color: var(--text); }
.menu__item svg { width: 14px; height: 14px; flex: none; }
.menu__item--danger { color: #FF6B6B; }
.menu__item--danger:hover { background: var(--red-bg); color: #FF6B6B; }
.menu__sep { height: 1px; background: var(--border); margin: 4px 0; }

/* --- Empty state ---------------------------------------------------------- */
.empty {
  padding: 44px 24px;
  text-align: center;
  color: var(--text-3);
}
.empty svg {
  width: 34px; height: 34px;
  margin: 0 auto 12px;
  color: var(--surface-4);
}
.empty__title { font-size: 14px; font-weight: var(--fw-semibold); color: var(--text-2); }
.empty__sub { font-size: 12.5px; margin-top: 5px; max-width: 380px; margin-inline: auto; }

/* --- Thumbnail (generated, no external images) ---------------------------- */
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-sm);
  overflow: hidden;
  background:
    linear-gradient(135deg, var(--fp-dark-maroon) 0%, var(--fp-near-black) 55%, #000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 1px, transparent 1px 13px);
  opacity: 0.6;
}
.thumb::after {
  content: "";
  position: absolute;
  right: -18%;
  top: 50%;
  width: 78px; height: 78px;
  transform: translateY(-50%) rotate(0deg);
  background: var(--fp-red);
  clip-path: polygon(0 0, 46% 0, 100% 50%, 46% 100%, 0 100%, 54% 50%);
  opacity: 0.28;
}
.thumb__initials {
  position: relative;
  font-size: 15px;
  font-weight: var(--fw-black);
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
}
.thumb--sm { width: 62px; border-radius: var(--r-xs); }
.thumb--sm .thumb__initials { font-size: 11px; }

/* --- Misc ----------------------------------------------------------------- */
.divider { height: 1px; background: var(--border); }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 9px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

.code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 1px 6px;
  color: var(--fp-soft-pink);
}

.drag-handle {
  color: var(--text-3);
  cursor: grab;
  display: inline-flex;
  padding: 2px;
  border-radius: var(--r-xs);
}
.drag-handle:hover { color: var(--text-2); background: var(--surface-3); }
.drag-handle:active { cursor: grabbing; }

.is-dragging { opacity: 0.4; }
.drop-target { box-shadow: inset 0 2px 0 var(--fp-red); }
