/* ============================================================
   AffiWave - Component Library
   ============================================================ */

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-sans); font-weight: 600; font-size: var(--t-sm);
  line-height: 1; white-space: nowrap; border: 1px solid transparent;
  border-radius: var(--r-md); padding: 11px 18px; cursor: pointer;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  text-decoration: none; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn svg { width: 18px; height: 18px; }

.btn-primary { background: var(--brand-500); color: #fff; box-shadow: var(--sh-xs); }
.btn-primary:hover { background: var(--brand-600); box-shadow: var(--sh-brand); }
.btn-ink { background: var(--ink-900); color: #fff; }
.btn-ink:hover { background: var(--ink-700); }
.btn-secondary { background: var(--n-0); color: var(--text-strong); border-color: var(--border-strong); box-shadow: var(--sh-xs); }
.btn-secondary:hover { background: var(--n-50); border-color: var(--n-300); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--n-100); }
.btn-blue { background: var(--blue-500); color: #fff; }
.btn-blue:hover { background: var(--blue-600); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-success { background: var(--success); color: #fff; }

.btn-lg { padding: 15px 26px; font-size: var(--t-base); border-radius: var(--r-lg); }
.btn-sm { padding: 8px 13px; font-size: var(--t-xs); border-radius: var(--r-sm); }
.btn-xs { padding: 5px 10px; font-size: var(--t-2xs); border-radius: var(--r-xs); gap: 5px; }
.btn-xs svg, .btn-sm svg { width: 15px; height: 15px; }
.btn-icon { padding: 9px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }

/* ---------------- Badges / status pills ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-weight: 600;
  font-size: var(--t-2xs); line-height: 1; letter-spacing: 0.01em;
  padding: 4px 9px; border-radius: var(--r-full); white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-neutral { background: var(--n-100); color: var(--n-600); }
.badge-success { background: var(--success-bg); color: #0B7A3C; }
.badge-warning { background: var(--warning-bg); color: #9A6206; }
.badge-danger  { background: var(--danger-bg);  color: #B5292E; }
.badge-info    { background: var(--info-bg);    color: var(--blue-700); }
.badge-review  { background: var(--review-bg);  color: var(--violet-600); }
.badge-brand   { background: var(--brand-50);   color: var(--brand-700); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); }

/* commission / risk specialized */
.badge-risk-high { background: var(--danger-bg); color: #B5292E; }
.badge-risk-med  { background: var(--warning-bg); color: #9A6206; }
.badge-risk-low  { background: var(--success-bg); color: #0B7A3C; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-sm);
}
.card-pad { padding: var(--s-6); }
.card-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--border);
}
.card-hd h3 { font-size: var(--t-h4); }
.card-bd { padding: var(--s-6); }
.card-ft { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); }
.card-hover { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--sh-lg); border-color: var(--border-strong); }

/* ---------------- Metric / KPI cards ---------------- */
.metric {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--sh-sm);
  display: flex; flex-direction: column; gap: var(--s-2); position: relative; overflow: hidden;
}
.metric-label { font-size: var(--t-xs); color: var(--text-muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.metric-ico { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none; }
.metric-ico svg { width: 17px; height: 17px; }
.metric-top { display: flex; align-items: center; justify-content: space-between; }
.metric-value { font-family: var(--font-display); font-weight: 600; font-size: 1.85rem; color: var(--text-strong); letter-spacing: -0.02em; line-height: 1.1; }
.metric-sub { font-size: var(--t-xs); color: var(--text-subtle); display: flex; align-items: center; gap: 6px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: var(--t-xs); }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.tbl thead th {
  text-align: left; font-weight: 600; font-size: var(--t-2xs); letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-subtle); padding: 12px 16px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg-subtle);
}
.tbl tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--dur) var(--ease); }
.tbl tbody tr:hover { background: var(--bg-subtle); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-dense tbody td { padding: 9px 14px; }
.tbl-dense thead th { padding: 9px 14px; }
.cell-strong { font-weight: 600; color: var(--text-strong); }
.cell-sub { font-size: var(--t-xs); color: var(--text-subtle); }

/* ---------------- Avatar ---------------- */
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-full); flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: var(--t-xs);
  color: #fff; font-family: var(--font-display); background: var(--ink-700);
}
.avatar-sm { width: 26px; height: 26px; font-size: var(--t-2xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--t-sm); }
.avatar-stack { display: flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--bg-surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.identity { display: flex; align-items: center; gap: 10px; }
.identity .id-name { font-weight: 600; color: var(--text-strong); line-height: 1.2; }
.identity .id-sub { font-size: var(--t-xs); color: var(--text-subtle); }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-size: var(--t-sm); font-weight: 600; color: var(--text-strong); }
.label .req { color: var(--danger); }
.hint { font-size: var(--t-xs); color: var(--text-subtle); }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; font-size: var(--t-sm); color: var(--text-strong);
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.input.err, .select.err { border-color: var(--danger); }
.input.err:focus { box-shadow: 0 0 0 3px rgba(229,72,77,0.2); }
.err-msg { font-size: var(--t-xs); color: var(--danger); display: flex; align-items: center; gap: 5px; }
.textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.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='%236B7888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: 38px; }
.input-group > svg { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--text-subtle); pointer-events: none; }

.checkbox, .radio { display: flex; align-items: flex-start; gap: 10px; font-size: var(--t-sm); color: var(--text); cursor: pointer; line-height: 1.45; }
.checkbox input, .radio input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--brand-500); flex: none; cursor: pointer; }

.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--n-300); border-radius: var(--r-full); transition: background var(--dur) var(--ease); }
.switch .track::before { content: ""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease); box-shadow: var(--sh-xs); }
.switch input:checked + .track { background: var(--brand-500); }
.switch input:checked + .track::before { transform: translateX(17px); }

/* segmented control */
.segmented { display: inline-flex; background: var(--bg-inset); border-radius: var(--r-md); padding: 3px; gap: 2px; }
.segmented button { border: none; background: transparent; padding: 7px 14px; font-size: var(--t-sm); font-weight: 600; color: var(--text-muted); border-radius: var(--r-sm); transition: all var(--dur) var(--ease); }
.segmented button.active { background: var(--bg-surface); color: var(--text-strong); box-shadow: var(--sh-xs); }

/* ---------------- Chips / filters ---------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border-radius: var(--r-full); font-size: var(--t-xs); font-weight: 600;
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  color: var(--text-muted); cursor: pointer; transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--n-400); color: var(--text); }
.chip.active { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }
.chip-count { font-size: var(--t-2xs); padding: 1px 6px; border-radius: var(--r-full); background: var(--bg-inset); color: var(--text-subtle); }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { padding: 12px 4px; margin-right: 18px; font-size: var(--t-sm); font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease); background: none; border-top: none; border-left: none; border-right: none; }
.tab:hover { color: var(--text-strong); }
.tab.active { color: var(--brand-600); border-bottom-color: var(--brand-500); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s var(--ease-out); }

/* ---------------- Accordion ---------------- */
.acc-item { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-surface); margin-bottom: 10px; overflow: hidden; transition: box-shadow var(--dur) var(--ease); }
.acc-item.open { box-shadow: var(--sh-sm); }
.acc-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 18px 20px; background: none; border: none; text-align: left; font-family: var(--font-display); font-weight: 600; font-size: var(--t-lg); color: var(--text-strong); }
.acc-head .chev { transition: transform var(--dur) var(--ease); color: var(--text-subtle); flex: none; }
.acc-item.open .chev { transform: rotate(180deg); color: var(--brand-500); }
.acc-body { max-height: 0; overflow: hidden; transition: max-height 0.3s var(--ease); }
.acc-body-inner { padding: 0 20px 20px; color: var(--text-muted); line-height: 1.65; }

/* ---------------- Alerts ---------------- */
.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--r-md); font-size: var(--t-sm); border: 1px solid; line-height: 1.5; }
.alert svg { width: 19px; height: 19px; flex: none; margin-top: 1px; }
.alert .alert-title { font-weight: 700; }
.alert-info    { background: var(--info-bg);    border-color: #C7D6FF; color: var(--blue-700); }
.alert-success { background: var(--success-bg); border-color: #BCE6CB; color: #0B7A3C; }
.alert-warning { background: var(--warning-bg); border-color: #F1DCA6; color: #9A6206; }
.alert-danger  { background: var(--danger-bg);  border-color: #F4C4C6; color: #B5292E; }

/* ---------------- Toast ---------------- */
.toast-region { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 12px; background: var(--ink-900); color: #fff; padding: 13px 16px; border-radius: var(--r-md); box-shadow: var(--sh-lg); font-size: var(--t-sm); font-weight: 500; min-width: 260px; animation: toastIn 0.3s var(--ease-out); }
.toast svg { width: 18px; height: 18px; color: var(--mint); flex: none; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------------- Tooltip ---------------- */
.tip { position: relative; display: inline-flex; }
.tip[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px); background: var(--ink-900); color: #fff; font-size: var(--t-2xs); font-weight: 500; padding: 6px 9px; border-radius: var(--r-sm); white-space: nowrap; opacity: 0; pointer-events: none; transition: all var(--dur) var(--ease); z-index: 50; }
.tip:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Breadcrumb ---------------- */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: var(--t-xs); color: var(--text-subtle); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--n-300); }
.crumbs .current { color: var(--text); font-weight: 600; }

/* ---------------- Pagination ---------------- */
.pager { display: flex; align-items: center; gap: 5px; }
.pager button { min-width: 34px; height: 34px; padding: 0 8px; border: 1px solid var(--border); background: var(--bg-surface); border-radius: var(--r-sm); font-size: var(--t-sm); font-weight: 600; color: var(--text-muted); }
.pager button:hover:not(:disabled) { border-color: var(--n-400); color: var(--text); }
.pager button.active { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }
.pager button:disabled { opacity: 0.4; cursor: default; }

/* ---------------- Progress ---------------- */
.progress { height: 8px; background: var(--bg-inset); border-radius: var(--r-full); overflow: hidden; }
.progress .bar { height: 100%; background: var(--brand-500); border-radius: var(--r-full); transition: width 0.6s var(--ease-out); }
.progress .bar.bar-blue { background: var(--blue-500); }
.progress .bar.bar-teal { background: var(--teal-500, var(--brand-500)); }
.progress.thin { height: 5px; }

/* ---------------- Empty state ---------------- */
.empty { text-align: center; padding: var(--s-9) var(--s-6); }
.empty .empty-ico { width: 56px; height: 56px; margin: 0 auto var(--s-4); border-radius: var(--r-lg); background: var(--bg-inset); display: grid; place-items: center; color: var(--text-subtle); }
.empty h4 { font-size: var(--t-h4); margin-bottom: 6px; }
.empty p { color: var(--text-muted); font-size: var(--t-sm); max-width: 360px; margin: 0 auto var(--s-5); }

/* ---------------- Skeleton ---------------- */
.skel { background: linear-gradient(90deg, var(--bg-inset) 25%, var(--n-100) 37%, var(--bg-inset) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------------- Copy field / code ---------------- */
.copy-field { display: flex; align-items: center; gap: 8px; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px 4px 4px 14px; }
.copy-field code { font-family: var(--font-mono); font-size: var(--t-xs); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.copy-field .btn { flex: none; }
.code-block { background: var(--ink-900); color: var(--text-onink); border-radius: var(--r-lg); padding: var(--s-5); font-family: var(--font-mono); font-size: var(--t-xs); line-height: 1.7; overflow-x: auto; }
.code-block .c-key { color: #7FE0C0; }
.code-block .c-str { color: #FFC98A; }
.code-block .c-com { color: #6A7A92; }
.code-block .c-fn { color: #8FB4FF; }
.api-key { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: var(--t-xs); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-md); padding: 9px 12px; }
.api-key .key-val { color: var(--text-strong); letter-spacing: 0.02em; flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ---------------- Timeline ---------------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 20px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -26px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg-surface); border: 3px solid var(--brand-500); }
.tl-dot.muted { border-color: var(--n-300); }
.tl-time { font-size: var(--t-2xs); color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; color: var(--text-strong); font-size: var(--t-sm); }

/* ---------------- Modal ---------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,16,32,0.55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 300; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal { background: var(--bg-surface); border-radius: var(--r-xl); box-shadow: var(--sh-xl); width: 100%; max-width: 480px; transform: translateY(12px) scale(0.98); transition: transform var(--dur) var(--ease-out); max-height: 90vh; overflow: auto; }
.modal-overlay.open .modal { transform: none; }
.modal-hd { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: var(--s-6) var(--s-6) var(--s-4); }
.modal-hd h3 { font-size: var(--t-h3); }
.modal-bd { padding: 0 var(--s-6) var(--s-6); }
.modal-ft { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------------- QR placeholder ---------------- */
.qr { width: 96px; height: 96px; border-radius: var(--r-md); background:
  repeating-conic-gradient(var(--ink-900) 0% 25%, #fff 0% 50%) 0 0 / 16px 16px; border: 1px solid var(--border); position: relative; }
.qr::after { content: ""; position: absolute; inset: 32px; background: var(--bg-surface); border-radius: 4px; }

/* ---------------- Divider / misc ---------------- */
.divider { height: 1px; background: var(--border); border: none; margin: var(--s-5) 0; }
.kbd { font-family: var(--font-mono); font-size: var(--t-2xs); background: var(--bg-inset); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: var(--r-xs); padding: 2px 6px; color: var(--text-muted); }

/* ---------------- Charts ---------------- */
.chart { width: 100%; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.chart-legend .lg { display: flex; align-items: center; gap: 7px; font-size: var(--t-xs); color: var(--text-muted); font-weight: 500; }
.chart-legend .lg .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.funnel-row { margin-bottom: 14px; }
.funnel-meta { display: flex; justify-content: space-between; font-size: var(--t-xs); font-weight: 600; color: var(--text); margin-bottom: 6px; }
.funnel-meta .num { color: var(--text-strong); }
.funnel-bar { height: 28px; background: var(--bg-inset); border-radius: var(--r-sm); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: var(--r-sm); transition: width 0.9s var(--ease-out); }

/* ---------------- Animations ---------------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
.reveal { opacity: 0; animation: fadeUp 0.7s var(--ease-out) forwards; }
