/* ============================================================
   ReaDI — base + component primitives (COSS UI style)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4, h5 { font-family: var(--font-heading); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
svg { display: block; width: 16px; height: 16px; flex: none; }
::selection { background: rgba(59, 130, 246, 0.22); }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 4px; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid var(--background); }
*::-webkit-scrollbar-thumb:hover { background: var(--muted-foreground); }

/* ---------- type helpers ---------- */
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 19px; }
.text-2xl { font-size: 24px; letter-spacing: -0.02em; }
.text-3xl { font-size: 30px; letter-spacing: -0.025em; }
.text-4xl { font-size: 38px; letter-spacing: -0.03em; }
.muted { color: var(--muted-foreground); }
.mono { font-family: var(--font-mono); font-feature-settings: "zero"; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-foreground); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout utils ---------- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.gap-5 { gap: 20px; } .gap-6 { gap: 24px; } .gap-8 { gap: 32px; }
.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mt-6{margin-top:24px}.mt-8{margin-top:32px}
.mb-1{margin-bottom:4px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mb-6{margin-bottom:24px}
.w-full{width:100%}
.grid { display: grid; }

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
  user-select: none;
}
.btn:active { transform: translateY(0.5px); }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.btn-primary { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, var(--background)); }

.btn-secondary { background: var(--card); color: var(--foreground); border-color: var(--border); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--secondary); }

.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--secondary); }

.btn-outline { background: transparent; border-color: var(--input); color: var(--foreground); }
.btn-outline:hover { background: var(--secondary); }

.btn-destructive { background: var(--destructive); color: #fff; }
.btn-destructive:hover { filter: brightness(.94); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; height: 30px; }
.btn-block { width: 100%; }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 500; line-height: 1;
  border: 1px solid var(--border);
  background: var(--secondary); color: var(--foreground);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-soft { border-color: transparent; }
.badge-success { color: var(--success-foreground); background: var(--success-soft); border-color: transparent; }
.badge-warning { color: var(--warning-foreground); background: var(--warning-soft); border-color: transparent; }
.badge-info { color: var(--info-foreground); background: var(--info-soft); border-color: transparent; }
.badge-destructive { color: var(--destructive-foreground); background: var(--destructive-soft); border-color: transparent; }
.badge-violet { color: var(--violet-700); background: var(--violet-soft); border-color: transparent; }
.dark .badge-violet { color: var(--color-violet-500); }
.badge-neutral { color: var(--muted-foreground); background: var(--secondary); border-color: transparent; }
.badge-outline { background: transparent; }

/* ---------- Card ---------- */
.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 18px; }
.card-hd { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-bd { padding: 18px; }
.card-ft { padding: 14px 18px; border-top: 1px solid var(--border); }
.card-hover { transition: border-color .15s, box-shadow .15s, transform .15s; cursor: pointer; }
.card-hover:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* ---------- Input / form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted-foreground); }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px;
  background: var(--background); color: var(--foreground);
  border: 1px solid var(--input); border-radius: 8px;
  font-size: 13px; transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 92px; padding: 9px 11px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 28%, transparent); }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }
.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='%23737373' stroke-width='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 9px center; padding-right: 30px; }
.input-group { position: relative; }
.input-group .input { padding-left: 34px; }
.input-group svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted-foreground); pointer-events: none; }

.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--input); transition: background .18s; flex: none; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .18s; }
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(16px); }

.check { width: 18px; height: 18px; border: 1px solid var(--input); border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer; transition: background .15s, border-color .15s; }
.check.on { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.check svg { width: 13px; height: 13px; opacity: 0; }
.check.on svg { opacity: 1; color: var(--primary-foreground); }

/* ---------- Avatar ---------- */
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; flex: none; background: var(--color-neutral-500); user-select: none; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }
.avatar-xl { width: 64px; height: 64px; font-size: 22px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--card); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th { text-align: left; font-weight: 500; color: var(--muted-foreground); font-size: 12px; padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .12s; }
.table-hover tbody tr:hover { background: var(--secondary); cursor: pointer; }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab { position: relative; padding: 9px 12px; font-size: 13px; font-weight: 500; color: var(--muted-foreground); border-radius: 8px 8px 0 0; transition: color .15s, background .15s; white-space: nowrap; }
.tab:hover { color: var(--foreground); background: var(--secondary); }
.tab.active { color: var(--foreground); }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--primary); border-radius: 2px 2px 0 0; }
.tab .count { margin-left: 6px; font-size: 11px; color: var(--muted-foreground); background: var(--secondary); padding: 1px 6px; border-radius: 999px; }
.segmented { display: inline-flex; background: var(--secondary); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented .seg { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; font-size: 12.5px; font-weight: 500; border-radius: 7px; color: var(--muted-foreground); transition: all .15s; white-space: nowrap; }
.segmented .seg svg { width: 14px; height: 14px; }
.segmented .seg.active { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-xs); }

/* ---------- Misc primitives ---------- */
.divider { height: 1px; background: var(--border); border: none; }
.kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 4px; font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); background: var(--secondary); border: 1px solid var(--border); border-radius: 5px; }
.dot-sep { color: var(--border-strong); }
.icon-box { width: 36px; height: 36px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--secondary); color: var(--foreground); }
.icon-box svg { width: 18px; height: 18px; }
.icon-box.sm { width: 28px; height: 28px; border-radius: 7px; } .icon-box.sm svg { width: 15px; height: 15px; }
.icon-box.tint-info { background: var(--info-soft); color: var(--info-foreground); }
.icon-box.tint-success { background: var(--success-soft); color: var(--success-foreground); }
.icon-box.tint-warning { background: var(--warning-soft); color: var(--warning-foreground); }
.icon-box.tint-violet { background: var(--violet-soft); color: var(--violet-700); }
.dark .icon-box.tint-violet { color: var(--color-violet-500); }

.progress { height: 6px; border-radius: 999px; background: var(--secondary); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }
.progress.info > span { background: var(--info); }

.meter-ring { --p: 0; --sz: 48px; width: var(--sz); height: var(--sz); border-radius: 50%; background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--p) * 1%), var(--secondary) 0); display: grid; place-items: center; }
.meter-ring::after { content: ""; width: calc(var(--sz) - 11px); height: calc(var(--sz) - 11px); border-radius: 50%; background: var(--card); }
.meter-ring .meter-val { position: absolute; font-size: 12px; font-weight: 600; }

/* empty state */
.empty { text-align: center; padding: 44px 24px; }
.empty .icon-box { margin: 0 auto 14px; width: 46px; height: 46px; }

/* tooltip */
.tip { position: relative; }
.tip[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%) translateY(3px); background: var(--color-neutral-900); color: #fff; font-size: 11.5px; font-weight: 500; padding: 5px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .14s, transform .14s; z-index: 60; box-shadow: var(--shadow-md); }
.dark .tip[data-tip]::after { background: var(--color-neutral-700); }
.tip[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* confidence flag chip */
.conf { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.conf .bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; }
.conf .bars i { width: 3px; border-radius: 1px; background: currentColor; opacity: .28; }
.conf .bars i:nth-child(1){height:4px} .conf .bars i:nth-child(2){height:7px} .conf .bars i:nth-child(3){height:11px}
.conf-high { color: var(--success-foreground); background: var(--success-soft); }
.conf-high .bars i { opacity: 1; }
.conf-medium { color: var(--warning-foreground); background: var(--warning-soft); }
.conf-medium .bars i:nth-child(1),.conf-medium .bars i:nth-child(2){opacity:1}
.conf-low { color: var(--destructive-foreground); background: var(--destructive-soft); }
.conf-low .bars i:nth-child(1){opacity:1}

/* skeleton shimmer */
.skel { background: linear-gradient(90deg, var(--secondary) 25%, var(--accent) 37%, var(--secondary) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0%{background-position:100% 0} 100%{background-position:-100% 0} }

/* typing dots */
.typing { display: inline-flex; gap: 3px; align-items: center; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted-foreground); animation: typing 1.2s infinite; }
.typing i:nth-child(2){animation-delay:.15s} .typing i:nth-child(3){animation-delay:.3s}
@keyframes typing { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-3px);opacity:1} }

.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
