/* ============================================================
   TRIVOLO — Component Library
   Depends on colors_and_type.css (tokens).
   Class-based, framework-agnostic. Prefix: .tv-
   ============================================================ */

/* ---------------------------------------------------------
   BUTTONS
   --------------------------------------------------------- */
.tv-btn {
  --_bg: transparent;
  --_fg: var(--text);
  --_bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: var(--w-bold);
  line-height: 1;
  letter-spacing: -0.005em;
  padding: 0 var(--space-6);
  height: 44px;
  border-radius: 12px;
  background: var(--_bg);
  color: var(--_fg);
  border: 1px solid var(--_bd);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  user-select: none;
}
.tv-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.tv-btn .tv-ico { width: 18px; height: 18px; flex: none; }

/* Primary — terracota */
.tv-btn--primary {
  --_bg: var(--action);
  --_fg: #fff;
  box-shadow: var(--glow);
}
.tv-btn--primary:hover    { --_bg: var(--action-deep); transform: translateY(-2px); box-shadow: 0 12px 28px rgba(214,58,111,0.38); }
.tv-btn--primary:active   { --_bg: var(--terracota-700); transform: translateY(0); box-shadow: 0 2px 8px rgba(214,58,111,0.30); }

/* Outline */
.tv-btn--outline {
  --_bg: var(--bg-raised);
  --_fg: var(--text);
  --_bd: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.tv-btn--outline:hover  { --_bd: var(--terracota-500); --_fg: var(--terracota-600); background: var(--terracota-050); }
.tv-btn--outline:active { background: var(--terracota-100); }

/* Ghost */
.tv-btn--ghost {
  --_bg: transparent;
  --_fg: var(--text-2);
}
.tv-btn--ghost:hover  { --_fg: var(--text); background: var(--bg-sunken); }
.tv-btn--ghost:active { background: var(--sand-200); }

/* Premium — gold */
.tv-btn--premium {
  --_bg: var(--amber);
  --_fg: var(--plum);
  box-shadow: 0 2px 6px rgba(46,27,44,0.10), 0 10px 24px rgba(242,169,59,0.34);
}
.tv-btn--premium:hover { --_bg: var(--dourado-600); transform: translateY(-1px); }

/* Sizes */
.tv-btn--sm { height: 38px; font-size: var(--text-sm); padding: 0 var(--space-5); border-radius: 11px; }
.tv-btn--lg { height: 52px; font-size: var(--text-md); padding: 0 var(--space-8); border-radius: 14px; }
.tv-btn--icon { padding: 0; width: 44px; }
.tv-btn--block { width: 100%; }

/* Disabled */
.tv-btn:disabled, .tv-btn[aria-disabled="true"] {
  opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none !important;
}

/* Loading */
.tv-btn[data-loading="true"] { color: transparent !important; pointer-events: none; position: relative; }
.tv-btn[data-loading="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--_fg); animation: tv-spin 0.7s linear infinite;
}
@keyframes tv-spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------
   FORM CONTROLS
   --------------------------------------------------------- */
.tv-field { display: flex; flex-direction: column; gap: var(--space-2); }
.tv-label { font-size: var(--text-sm); font-weight: var(--w-semibold); color: var(--text); }
.tv-label .tv-opt { font-weight: var(--w-regular); color: var(--text-3); }
.tv-help { font-size: var(--text-sm); color: var(--text-2); }
.tv-error-text { font-size: var(--text-sm); color: var(--danger); font-weight: var(--w-medium); }

.tv-input, .tv-select, .tv-textarea {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border-input);
  border-radius: 11px;
  padding: 0 var(--space-4);
  height: 46px;
  width: 100%;
  transition: var(--transition);
  box-shadow: var(--shadow-inset);
}
.tv-textarea { padding: var(--space-3) var(--space-4); height: auto; min-height: 110px; resize: vertical; line-height: var(--leading-normal); }
.tv-input::placeholder, .tv-textarea::placeholder { color: var(--text-3); }
.tv-input:hover, .tv-select:hover, .tv-textarea:hover { border-color: var(--border-strong); }
.tv-input:focus, .tv-select:focus, .tv-textarea:focus {
  outline: none; border-color: var(--terracota-500); background: var(--bg-raised);
  box-shadow: var(--shadow-focus);
}
.tv-input:disabled, .tv-select:disabled, .tv-textarea:disabled {
  opacity: 0.55; cursor: not-allowed; background: var(--bg-sunken);
}
.tv-input[aria-invalid="true"], .tv-textarea[aria-invalid="true"] {
  border-color: var(--danger); background: var(--danger-100);
}
.tv-input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(178,69,43,0.22); }

/* Input with leading icon / affix */
.tv-input-wrap { position: relative; display: flex; align-items: center; }
.tv-input-wrap .tv-ico { position: absolute; left: var(--space-4); width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.tv-input-wrap .tv-input { padding-left: calc(var(--space-4) + 26px); }

.tv-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B5540' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-10);
  cursor: pointer;
}

/* Checkbox + radio */
.tv-check, .tv-radio {
  appearance: none; width: 20px; height: 20px; flex: none;
  border: 1.5px solid var(--border-input); background: var(--bg-inset);
  cursor: pointer; transition: var(--transition); position: relative;
}
.tv-check { border-radius: 6px; }
.tv-radio { border-radius: 50%; }
.tv-check:hover, .tv-radio:hover { border-color: var(--terracota-500); }
.tv-check:checked, .tv-radio:checked { background: var(--terracota-500); border-color: var(--terracota-500); }
.tv-check:checked::after {
  content: ""; position: absolute; left: 6px; top: 2.5px; width: 5px; height: 10px;
  border: solid var(--text-on-brand); border-width: 0 2px 2px 0; transform: rotate(42deg);
}
.tv-radio:checked::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--text-on-brand); }
.tv-check:focus-visible, .tv-radio:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* Toggle */
.tv-toggle { appearance: none; width: 44px; height: 26px; border-radius: var(--radius-pill);
  background: var(--sand-300); cursor: pointer; transition: var(--transition); position: relative; flex: none; }
.tv-toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: var(--transition); }
.tv-toggle:checked { background: var(--terracota-500); }
.tv-toggle:checked::after { transform: translateX(18px); }
.tv-toggle:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ---------------------------------------------------------
   BADGES & TAGS
   --------------------------------------------------------- */
.tv-badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-xs); font-weight: var(--w-semibold); letter-spacing: 0.01em;
  padding: 4px 10px; border-radius: var(--radius-pill); line-height: 1.4;
}
.tv-badge .tv-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tv-badge--success { background: var(--success-100); color: var(--verde-700); }
.tv-badge--warning { background: var(--warning-100); color: var(--dourado-600); }
.tv-badge--danger  { background: var(--danger-100);  color: var(--danger); }
.tv-badge--info    { background: var(--info-100);    color: var(--medio); }
.tv-badge--brand   { background: var(--terracota-100); color: var(--terracota-700); }
.tv-badge--premium { background: var(--escuro); color: var(--dourado); }
.tv-badge--neutral { background: var(--bg-sunken); color: var(--text-2); }

.tv-tag {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); font-weight: var(--w-medium); color: var(--text);
  background: var(--bg-raised); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: var(--radius-sm); transition: var(--transition);
}
.tv-tag--removable { padding-right: 8px; }
.tv-tag .tv-x { width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center;
  justify-content: center; color: var(--text-3); cursor: pointer; transition: var(--transition); }
.tv-tag .tv-x:hover { background: var(--danger-100); color: var(--danger); }

/* ---------------------------------------------------------
   CARDS
   --------------------------------------------------------- */
.tv-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  transition: var(--transition);
}
.tv-card--interactive { cursor: pointer; }
.tv-card--interactive:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--border-strong); }

/* Product card */
.tv-product { padding: 0; overflow: hidden; }
.tv-product__media {
  aspect-ratio: 4/3; background: var(--bg-sunken); position: relative;
  background-image: repeating-linear-gradient(135deg, rgba(107,85,64,0.06) 0 12px, transparent 12px 24px);
  display: flex; align-items: center; justify-content: center;
}
.tv-product__media .tv-ph { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); }
.tv-product__body { padding: var(--space-4) var(--space-5) var(--space-5); }
.tv-product__name { font-size: var(--text-md); font-weight: var(--w-semibold); color: var(--text); margin: 0 0 4px; }
.tv-product__price { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: var(--w-bold); letter-spacing: -0.02em; color: var(--text); }
.tv-product__meta { font-size: var(--text-sm); color: var(--text-2); }

/* Balance / finance card */
.tv-balance {
  background: var(--escuro);
  background-image: var(--noise);
  color: var(--text-on-dark);
  border: none;
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-6) var(--space-5);
  position: relative;
  overflow: hidden;
}
.tv-balance::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px;
  border-radius: 50%; background: radial-gradient(circle, rgba(242,169,59,0.22), transparent 70%);
}
.tv-balance__label { font-size: var(--text-sm); color: var(--text-on-dark-2); letter-spacing: 0.02em; }
.tv-balance__value { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 3rem; font-weight: var(--w-bold); letter-spacing: -0.03em;
  line-height: 1; margin: var(--space-2) 0 var(--space-3); }
.tv-balance__value .tv-cur { font-family: var(--font-numeric); font-size: 1.25rem; font-weight: var(--w-medium); color: var(--text-on-dark-2); margin-right: 6px; vertical-align: 0.18em; }
.tv-balance__delta { font-size: var(--text-sm); display: inline-flex; align-items: center; gap: 6px; color: var(--dourado); }

/* ---------------------------------------------------------
   TABLE
   --------------------------------------------------------- */
.tv-table-wrap { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.tv-table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.tv-table thead th {
  text-align: left; font-size: var(--text-xs); font-weight: var(--w-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-3);
  padding: var(--space-4) var(--space-5); background: var(--bg-sunken); border-bottom: 1px solid var(--border);
}
.tv-table tbody td { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.tv-table tbody tr:last-child td { border-bottom: none; }
.tv-table tbody tr { transition: background var(--dur) var(--ease); }
.tv-table tbody tr:hover { background: var(--terracota-050); }
.tv-table .tv-num { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-weight: var(--w-semibold); font-size: 1rem; letter-spacing: -0.01em; }

/* ---------------------------------------------------------
   MODAL / OVERLAY
   --------------------------------------------------------- */
.tv-overlay { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: var(--space-6); z-index: 100; }
.tv-modal {
  background: var(--bg-raised); border-radius: var(--radius-2xl); box-shadow: var(--shadow-xl);
  max-width: 460px; width: 100%; padding: var(--space-8); border: 1px solid var(--border);
  animation: tv-pop var(--dur-slow) var(--ease-out);
}
@keyframes tv-pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
.tv-modal__title { font-family: var(--font-display); font-size: var(--display-sm); font-weight: var(--w-semibold); margin: 0 0 var(--space-2); }
.tv-modal__body { color: var(--text-2); line-height: var(--leading-normal); }
.tv-modal__actions { display: flex; gap: var(--space-3); justify-content: flex-end; margin-top: var(--space-6); }

/* ---------------------------------------------------------
   AVATAR
   --------------------------------------------------------- */
.tv-avatar { width: 40px; height: 40px; border-radius: var(--radius-pill); background: var(--terracota-100);
  color: var(--terracota-700); display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--w-bold); font-size: var(--text-sm); flex: none; overflow: hidden; }

/* ---------------------------------------------------------
   SIDEBAR NAV
   --------------------------------------------------------- */
.tv-nav { display: flex; flex-direction: column; gap: 2px; }
.tv-nav__item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  color: var(--text-on-dark-2); font-size: var(--text-base); font-weight: var(--w-medium);
  cursor: pointer; transition: var(--transition); text-decoration: none;
}
.tv-nav__item .tv-ico { width: 20px; height: 20px; flex: none; }
.tv-nav__item:hover { background: rgba(243,234,223,0.07); color: var(--text-on-dark); }
.tv-nav__item--active { background: rgba(214,58,111,0.16); color: #F7B9CE; }
.tv-nav__item--active .tv-ico { color: var(--terracota-300); }
.tv-nav__group-label { font-size: var(--text-xs); letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--text-on-dark-2); opacity: 0.6; padding: var(--space-3) var(--space-4) var(--space-2); }
