/* ════════════════════════════════════════════════════════════════
   BASE · reset + body + typography utilities
═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  font-family: var(--ff-sans);
  font-size: var(--fs-13);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; }

/* typography */
.mono, .num { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; letter-spacing: -.005em; }
.serif { font-family: var(--ff-serif); }
.eyebrow { font-size: var(--fs-10); text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
h1 { font-size: var(--fs-24); }
h2 { font-size: var(--fs-20); }
h3 { font-size: var(--fs-15); }
h4 { font-size: var(--fs-13); }
p  { margin: 0; }

/* utility colors */
.t-good { color: var(--good) !important; }
.t-warn { color: var(--warn) !important; }
.t-bad  { color: var(--bad)  !important; }
.t-info { color: var(--info) !important; }
.t-dim  { color: var(--dim)  !important; }
.t-muted{ color: var(--muted)!important; }

/* layout helpers */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.col { display: flex; flex-direction: column; }
.spc { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-6); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-6); }

/* premium scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--line-3); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--line-3); border-color: var(--bg); }

/* selection */
::selection { background: var(--accent-soft); color: var(--text); }

/* focus ring */
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--sh-glow);
  border-radius: var(--r-md);
}

/* icon system */
.i {
  width: 16px; height: 16px;
  display: inline-block; vertical-align: -3px;
  color: currentColor; flex-shrink: 0;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .18s cubic-bezier(.21,.61,.35,1);
}
.i-xs { width: 12px; height: 12px; vertical-align: -2px; }
.i-sm { width: 14px; height: 14px; vertical-align: -2px; }
.i-md { width: 18px; height: 18px; vertical-align: -4px; }
.i-lg { width: 22px; height: 22px; vertical-align: -5px; }
.i-xl { width: 28px; height: 28px; }
.i-2xl { width: 36px; height: 36px; }

.i-tint {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--info-soft); color: var(--info);
  transition: all .2s ease;
  flex-shrink: 0;
}
.i-tint.good { background: var(--good-soft); color: var(--good); }
.i-tint.warn { background: var(--warn-soft); color: var(--warn); }
.i-tint.bad  { background: var(--bad-soft);  color: var(--bad); }
.i-tint.plum { background: var(--plum-soft); color: var(--plum); }
.i-tint.accent { background: var(--accent-soft); color: var(--accent); }
.i-tint.lg { width: 42px; height: 42px; border-radius: 11px; }
.i-tint.lg .i { width: 20px; height: 20px; }
.i-tint:hover { transform: translateY(-1px); box-shadow: var(--sh-1); }

/* keyboard chip */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 20px; padding: 0 5px;
  background: var(--surface); border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: var(--r-sm); font-family: var(--ff-mono);
  font-size: 10.5px; color: var(--dim);
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

/* delta chip with icon */
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-11); font-weight: 600; padding: 2px 8px; border-radius: var(--r-md); font-variant-numeric: tabular-nums; }
.delta.up   { color: var(--good); background: var(--good-soft); }
.delta.dn   { color: var(--bad);  background: var(--bad-soft); }
.delta.flat { color: var(--dim);  background: var(--line); }
.delta .i { width: 11px; height: 11px; vertical-align: -1px; }

/* pills / status / state */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-full); font-size: var(--fs-11); font-weight: 600; border: 1px solid; }
.pill .i { width: 11px; height: 11px; }
.pill.good { color: var(--good); border-color: var(--good-line); background: var(--good-soft); }
.pill.warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-soft); }
.pill.bad  { color: var(--bad);  border-color: var(--bad-line);  background: var(--bad-soft); }
.pill.info { color: var(--info); border-color: var(--info-line); background: var(--info-soft); }
.pill.plum { color: var(--plum); border-color: var(--plum-line); background: var(--plum-soft); }
.pill.dim  { color: var(--dim);  border-color: var(--line-2);    background: var(--surface-2); }

/* priority tag */
.pri { font-family: var(--ff-mono); font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-sm); letter-spacing: .04em; display: inline-flex; align-items: center; gap: 3px; }
.pri.p1 { background: var(--bad-soft);  color: var(--bad); }
.pri.p2 { background: var(--warn-soft); color: var(--warn); }
.pri.p3 { background: var(--info-soft); color: var(--info); }

/* state chip for actions */
.state { font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-sm); text-transform: uppercase; letter-spacing: .05em; border: 1px solid var(--line-2); color: var(--dim); font-family: var(--ff-mono); }
.state.open      { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.state.snoozed   { color: var(--plum);   border-color: var(--plum-line);   background: var(--plum-soft); }
.state.escalated { color: var(--bad);    border-color: var(--bad-line);    background: var(--bad-soft); }
.state.done      { color: var(--good);   border-color: var(--good-line);   background: var(--good-soft); }

/* avatar */
.av { width: 24px; height: 24px; border-radius: 50%; background: linear-gradient(135deg, #4338ca, #7c3aed); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 10px; flex-shrink: 0; box-shadow: 0 2px 6px -1px rgba(67,56,202,.3); }
.av.sm { width: 18px; height: 18px; font-size: 9px; }
.av.lg { width: 36px; height: 36px; font-size: 13px; }

/* live pulse */
.live {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-11); color: var(--good); font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
}
.live::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 var(--ring-accent);
  animation: p-pulse-ring 1.8s infinite;
}
.live.warn { color: var(--warn); }
.live.warn::before { background: var(--warn); box-shadow: 0 0 0 0 var(--ring-warn); }
.live.bad  { color: var(--bad); }
.live.bad::before { background: var(--bad); box-shadow: 0 0 0 0 var(--ring-bad); }

/* AI sparkle wrapper */
.ai-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--plum); font-size: var(--fs-11); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.ai-tag .i { animation: p-sparkle 2.4s ease-in-out infinite; transform-origin: center; }

/* button */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: var(--r-md); font-size: var(--fs-12); font-weight: 500; border: 1px solid var(--line-2); color: var(--text); background: var(--surface-2); cursor: pointer; transition: all .15s; }
.btn:hover { background: var(--surface-3); border-color: var(--line-3); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 4px 10px -3px rgba(13,148,136,.4); }
.btn.primary:hover { background: var(--accent-strong); box-shadow: 0 6px 14px -3px rgba(13,148,136,.5); }
.btn.sm { padding: 5px 10px; font-size: var(--fs-11); }
.btn.icon-only { padding: 7px; width: 32px; height: 32px; }
.btn .i { width: 14px; height: 14px; vertical-align: -2px; }

.load-error {
  margin-top: 14px;
  color: var(--bad);
  font-size: 11px;
  text-align: left;
}

/* ════════════════════════════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════════════════════════ */
@keyframes p-fade-up   { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes p-fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes p-scale-in  { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes p-pulse-dot { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(.88); } }
@keyframes p-pulse-ring {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes p-draw   { from { stroke-dashoffset: 2000; } to { stroke-dashoffset: 0; } }
@keyframes p-grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes p-grow-y { from { height: 0; } }
@keyframes p-bar-w  { from { width: 0; } }
@keyframes p-spin   { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes p-float  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes p-sparkle{
  0%,100% { transform: scale(1) rotate(0); opacity: .9; }
  50%     { transform: scale(1.15) rotate(8deg); opacity: 1; }
}
@keyframes p-shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.anim-fade-up { animation: p-fade-up .55s cubic-bezier(.21,.61,.35,1) backwards; }
.anim-fade-in { animation: p-fade-in .4s ease-out backwards; }
.anim-scale-in { animation: p-scale-in .35s cubic-bezier(.21,.61,.35,1) backwards; }
.anim-float { animation: p-float 3s ease-in-out infinite; }
.anim-spin  { animation: p-spin 1.4s linear infinite; }
.anim-sparkle { animation: p-sparkle 2.4s ease-in-out infinite; transform-origin: center; }

/* stagger via --i */
.stagger > * { animation: p-fade-up .55s cubic-bezier(.21,.61,.35,1) backwards; animation-delay: calc(var(--i, 0) * 70ms); }
.stagger > *:nth-child(1) { --i: 0; } .stagger > *:nth-child(2) { --i: 1; }
.stagger > *:nth-child(3) { --i: 2; } .stagger > *:nth-child(4) { --i: 3; }
.stagger > *:nth-child(5) { --i: 4; } .stagger > *:nth-child(6) { --i: 5; }
.stagger > *:nth-child(7) { --i: 6; } .stagger > *:nth-child(8) { --i: 7; }
.stagger > *:nth-child(9) { --i: 8; } .stagger > *:nth-child(10) { --i: 9; }
.stagger > *:nth-child(11) { --i: 10; } .stagger > *:nth-child(12) { --i: 11; }
.stagger > *:nth-child(13) { --i: 12; } .stagger > *:nth-child(14) { --i: 13; }
.stagger > *:nth-child(15) { --i: 14; } .stagger > *:nth-child(16) { --i: 15; }
.stagger > *:nth-child(17) { --i: 16; } .stagger > *:nth-child(18) { --i: 17; }

/* sparkline draw on load */
.spark-anim path, .spark-anim polyline {
  stroke-dasharray: 2000; stroke-dashoffset: 2000;
  animation: p-draw 1.4s cubic-bezier(.21,.61,.35,1) forwards;
  animation-delay: .25s;
}
/* bar grow on load */
.bar-grow { transform-origin: left center; animation: p-grow-x .9s cubic-bezier(.21,.61,.35,1) backwards; animation-delay: .15s; }
.bar-grow-y { transform-origin: bottom; animation: p-grow-y .8s cubic-bezier(.21,.61,.35,1) backwards; }

/* card hover lift */
.card-hover { transition: transform .2s cubic-bezier(.21,.61,.35,1), box-shadow .2s ease, border-color .2s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--sh-3); }

/* skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: p-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--r-sm);
}

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