/* ------------------------------------------------------------------
   AVI-OS — Component library
   Buttons, cards, inputs, badges, tables, progress, KPI cards,
   toasts, modals, info-dots
   ------------------------------------------------------------------ */

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 0 16px; height: 36px; border-radius: var(--r-md);
  font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: 500;
  border: 1px solid transparent; cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
  white-space: nowrap; text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.btn--primary   { background: var(--accent); color: var(--text-inverse); border-color: var(--accent); }
.btn--primary:hover { opacity: .88; }
.btn--secondary { background: var(--surface-2); color: var(--text-soft); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--border); color: var(--text); }
.btn--ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn--ghost:hover { background: var(--accent-soft); color: var(--text); }
.btn--danger    { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.btn--sm        { height: 28px; padding: 0 12px; font-size: var(--fs-xs); }
.btn--lg        { height: 44px; padding: 0 24px; font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn--icon      { width: 36px; padding: 0; }
.btn--icon.btn--sm { width: 28px; }
.btn:disabled   { opacity: .35; pointer-events: none; }

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
.card--glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}
.card--hover:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); cursor: pointer; }
.card--compact { padding: 14px 16px; }
.card__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card__title  { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.card__meta   { font-size: var(--fs-xs); color: var(--text-muted); }

/* ── KPI Cards ───────────────────────────────────────────────────── */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 18px 20px;
  transition: border-color var(--t-base);
}
.kpi:hover { border-color: var(--border-strong); }
.kpi__label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.kpi__val   { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: var(--tracking-tight); color: var(--text); font-family: var(--font-display); line-height: 1; }
.kpi__delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-xs); font-weight: 500; margin-top: 6px; }
.kpi__delta--up   { color: var(--ok); }
.kpi__delta--down { color: var(--bad); }
.kpi__sub   { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: 0.03em;
  border: 1px solid transparent;
}
.badge--ok      { background: var(--ok-bg);   color: var(--ok);   border-color: rgba(74,222,128,.25); }
.badge--warn    { background: var(--warn-bg);  color: var(--warn); border-color: rgba(251,191,36,.25); }
.badge--bad     { background: var(--bad-bg);   color: var(--bad);  border-color: rgba(248,113,113,.25); }
.badge--info    { background: var(--info-bg);  color: var(--info); border-color: rgba(96,165,250,.25); }
.badge--neutral { background: var(--accent-soft); color: var(--text-muted); border-color: var(--border); }
.badge--lg      { height: 24px; padding: 0 10px; font-size: var(--fs-xs); }

/* ── Form elements ───────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  -webkit-appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--border-strong); box-shadow: var(--ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; line-height: var(--lh-base); }
.label { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); margin-bottom: 5px; letter-spacing: 0.04em; text-transform: uppercase; }
.field { margin-bottom: 14px; }
.field--row { display: flex; gap: 10px; }
.field--row .field { flex: 1; margin-bottom: 0; }

/* ── Progress ────────────────────────────────────────────────────── */
.progress { height: 4px; background: var(--border); border-radius: var(--r-pill); overflow: hidden; }
.progress--sm { height: 3px; }
.progress--lg { height: 8px; }
.progress__bar { height: 100%; background: var(--accent); border-radius: var(--r-pill); transition: width var(--t-slow) var(--ease-out); }
.progress__bar--ok   { background: var(--ok); }
.progress__bar--warn { background: var(--warn); }
.progress__bar--bad  { background: var(--bad); }

/* ── Tables ──────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-muted);
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 11px 12px; color: var(--text-soft); font-size: var(--fs-sm); border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--accent-soft); }
.tbl td strong { color: var(--text); font-weight: 500; }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-region { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto;
  background: var(--glass-bg); backdrop-filter: var(--glass-blur-sm); -webkit-backdrop-filter: var(--glass-blur-sm);
  border: 1px solid var(--glass-border); border-radius: var(--r-lg);
  padding: 12px 16px; font-size: var(--fs-sm); color: var(--text);
  box-shadow: var(--shadow-lg); min-width: 240px; max-width: 360px;
  display: flex; align-items: flex-start; gap: 10px;
  animation: toastIn var(--t-base) var(--ease-out);
}
.toast--ok   { border-color: var(--ok);   color: var(--ok); }
.toast--bad  { border-color: var(--bad);  color: var(--bad); }
.toast--warn { border-color: var(--warn); color: var(--warn); }
@keyframes toastIn { from { opacity:0; transform: translateY(12px) scale(.96); } to { opacity:1; transform: none; } }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-root { position: fixed; inset: 0; z-index: 8888; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-root[aria-hidden="true"] { display: none; }
.modal {
  background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--r-2xl);
  box-shadow: var(--shadow-xl); padding: 28px 28px 24px;
  max-width: 520px; width: calc(100vw - 32px); max-height: 90dvh; overflow-y: auto;
  animation: modalIn var(--t-base) var(--ease-out);
}
@keyframes modalIn { from { opacity:0; transform: scale(.95); } to { opacity:1; transform: none; } }

/* ── Info dots & tutorial ────────────────────────────────────────── */
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: var(--r-pill);
  background: var(--accent-soft); border: 1px solid var(--glass-border);
  color: var(--text-muted); font-size: 9px; font-weight: 700;
  cursor: pointer; vertical-align: middle; margin-left: 5px;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.info-dot:hover { background: var(--accent); color: var(--text-inverse); }
.info-dot__tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--glass-bg); backdrop-filter: var(--glass-blur-sm); -webkit-backdrop-filter: var(--glass-blur-sm);
  border: 1px solid var(--glass-border); border-radius: var(--r-lg);
  padding: 8px 12px; font-size: var(--fs-xs); color: var(--text-soft);
  white-space: nowrap; max-width: 240px; white-space: normal;
  box-shadow: var(--shadow-md); pointer-events: none; opacity: 0;
  transition: opacity var(--t-fast); z-index: 9000;
}
.info-dot:hover .info-dot__tip { opacity: 1; }

/* ── Sidebar nav count ───────────────────────────────────────────── */
.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--accent); color: var(--text-inverse);
  border-radius: var(--r-pill); font-size: 10px; font-weight: 700;
}

/* ── Status chip ─────────────────────────────────────────────────── */
.status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); }
.status::before { content:''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status--draft   { color: var(--text-muted); }
.status--active  { color: var(--ok); }
.status--pending { color: var(--warn); }
.status--closed  { color: var(--bad); }
.status--paid    { color: var(--ok); }
.status--overdue { color: var(--bad); }

/* ── IB event pill ───────────────────────────────────────────────── */
.ib-event {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--r-lg);
  background: var(--glass-bg-light); border: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--text-muted);
}
.ib-event__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex-shrink: 0; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.3;} }
