/* ============================================================
   Tavo — Components
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  font-size: var(--fs-base); font-weight: var(--fw-medium); line-height: 1;
  padding: 0 var(--sp-4); height: 40px; border-radius: var(--r-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast);
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--stone-75); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn--primary { --btn-bg: var(--brand); --btn-fg: #fff; --btn-bd: var(--brand); box-shadow: 0 1px 2px rgba(138,44,27,.35); }
.btn--primary:hover { --btn-bg: var(--brand-600); }
.btn--primary:active { --btn-bg: var(--brand-700); }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn--ghost:hover { --btn-bg: var(--stone-150); }
.btn--subtle { --btn-bg: var(--stone-100); --btn-bd: transparent; }
.btn--subtle:hover { --btn-bg: var(--stone-200); }
.btn--danger { --btn-fg: var(--danger-700); --btn-bd: var(--danger-50); --btn-bg: var(--danger-50); }
.btn--danger:hover { --btn-bg: #F6DEDB; }
.btn--data { --btn-bg: var(--data); --btn-fg: #fff; --btn-bd: var(--data); }
.btn--data:hover { --btn-bg: var(--data-600); }
.btn--lg { height: 48px; font-size: var(--fs-md); padding: 0 var(--sp-5); border-radius: var(--r); }
.btn--sm { height: 32px; font-size: var(--fs-sm); padding: 0 var(--sp-3); }
.btn--icon { width: 40px; padding: 0; }
.btn--icon.btn--sm { width: 32px; }
.btn--block { display: flex; width: 100%; }
.btn--pill { border-radius: var(--r-full); }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1;
  padding: 4px 9px; border-radius: var(--r-full);
  background: var(--stone-150); color: var(--text-2);
  letter-spacing: .01em;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--brand { background: var(--brand-50); color: var(--brand-700); }
.badge--data { background: var(--data-50); color: var(--data-600); }
.badge--success { background: var(--success-50); color: var(--success-700); }
.badge--warning { background: var(--warning-50); color: var(--warning-700); }
.badge--danger { background: var(--danger-50); color: var(--danger-700); }
.badge--info { background: var(--info-50); color: var(--info); }
.badge--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }
.badge--plan { text-transform: uppercase; letter-spacing: .06em; font-size: 10px; padding: 4px 8px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
}
.card--pad { padding: var(--sp-5); }
.card--hover { transition: box-shadow var(--t) var(--ease), transform var(--t) var(--ease), border-color var(--t); }
.card--hover:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.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-md); font-weight: var(--fw-semibold); }
.card__sub { font-size: var(--fs-sm); color: var(--text-3); margin-top: 2px; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-2); }
.field__hint { font-size: var(--fs-xs); color: var(--text-3); }
.field__error { font-size: var(--fs-xs); color: var(--danger-700); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 var(--sp-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font-size: var(--fs-base); transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 92px; padding: var(--sp-3); line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--stone-400); }
.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='%23625B51' 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 12px center; padding-right: 38px;
}
.input-group { position: relative; }
.input-group__icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-group__icon ~ .input { padding-left: 40px; }

/* Segmented control */
.segmented { display: inline-flex; background: var(--stone-150); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.segmented button {
  padding: 6px 14px; border-radius: 6px; font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--text-2); transition: color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.segmented button:hover[aria-pressed="false"] { color: var(--text); }

/* 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: 40px; height: 23px; border-radius: 999px; background: var(--stone-300); transition: background var(--t); flex: none; }
.switch__thumb { position: absolute; left: 3px; top: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--t) var(--ease); }
.switch input:checked ~ .switch__track { background: var(--brand); }
.switch input:checked ~ .switch__thumb { transform: translateX(17px); }
.switch input:focus-visible ~ .switch__track { box-shadow: var(--ring); }

/* Avatar */
.avatar {
  --sz: 36px; width: var(--sz); height: var(--sz); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  font-size: calc(var(--sz) * .38); font-weight: var(--fw-semibold); color: #fff;
  background: var(--brand); letter-spacing: .01em; text-transform: uppercase; overflow: hidden;
}
.avatar--sm { --sz: 28px; }
.avatar--lg { --sz: 48px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -10px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Progress bar */
.progress { height: 8px; border-radius: 999px; background: var(--stone-200); overflow: hidden; }
.progress__bar { height: 100%; border-radius: 999px; background: var(--data); transition: width var(--t-slow) var(--ease-out); }
.progress--warn .progress__bar { background: var(--warning); }
.progress--danger .progress__bar { background: var(--brand); }

/* Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th {
  text-align: left; font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .03em;
  text-transform: uppercase; color: var(--text-3); padding: 10px var(--sp-3); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 13px var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td, .table tbody tr:last-child td { border-bottom: none; }
.table tr.is-clickable { cursor: pointer; transition: background var(--t-fast); }
.table tr.is-clickable:hover { background: var(--stone-75); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tabs button {
  padding: 10px 14px; font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--t-fast), border-color var(--t-fast);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

/* Tooltip (title-style, CSS) */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
  background: var(--stone-900); color: #fff; font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap;
  padding: 5px 9px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity var(--t-fast), transform var(--t-fast); z-index: 50;
}
.tip:hover::after, .tip:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Skeleton */
.skeleton { position: relative; overflow: hidden; background: var(--stone-150); border-radius: var(--r-sm); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.6), transparent);
  transform: translateX(-100%); animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(19,18,16,.5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
  opacity: 0; animation: overlay-in var(--t) var(--ease) forwards;
}
@keyframes overlay-in { to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-xl);
  width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto;
  transform: translateY(12px) scale(.98); opacity: 0; animation: modal-in var(--t-slow) var(--ease-out) forwards;
}
@keyframes modal-in { to { transform: translateY(0) scale(1); opacity: 1; } }
.modal--wide { max-width: 720px; }
.modal--xwide { max-width: 940px; }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.modal__title { font-size: var(--fs-xl); }
.modal__sub { font-size: var(--fs-base); color: var(--text-3); margin-top: 4px; }
.modal__body { padding: var(--sp-2) var(--sp-5) var(--sp-5); }
.modal__foot { display: flex; gap: var(--sp-3); justify-content: flex-end; padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.modal__close { color: var(--text-3); border-radius: var(--r-sm); width: 34px; height: 34px; display: grid; place-items: center; transition: background var(--t-fast), color var(--t-fast); }
.modal__close:hover { background: var(--stone-150); color: var(--text); }

/* ---------- Toasts ---------- */
.toast-root { position: fixed; bottom: 20px; right: 20px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 12px; padding: 13px 15px;
  background: var(--stone-900); color: #fff; border-radius: var(--r); box-shadow: var(--shadow-lg);
  transform: translateX(120%); animation: toast-in var(--t-slow) var(--ease-out) forwards;
}
.toast.is-out { animation: toast-out var(--t) var(--ease) forwards; }
@keyframes toast-in { to { transform: translateX(0); } }
@keyframes toast-out { to { transform: translateX(120%); opacity: 0; } }
.toast__icon { flex: none; margin-top: 1px; }
.toast__icon svg { width: 20px; height: 20px; }
.toast__body { font-size: var(--fs-base); line-height: 1.4; }
.toast__title { font-weight: var(--fw-semibold); }
.toast__msg { color: rgba(255,255,255,.72); font-size: var(--fs-sm); margin-top: 2px; }
.toast--success .toast__icon { color: #6EDBA6; }
.toast--danger .toast__icon { color: #F09189; }
.toast--info .toast__icon { color: #8FC0F0; }

/* Empty state */
.empty { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--text-3); }
.empty__icon { width: 52px; height: 52px; margin: 0 auto var(--sp-4); color: var(--stone-400); background: var(--stone-100); border-radius: var(--r-lg); display: grid; place-items: center; }
.empty__icon svg { width: 26px; height: 26px; }
.empty__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-2); }
.empty__text { font-size: var(--fs-base); max-width: 340px; margin: 6px auto 0; }

/* Divider */
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-5) 0; }
