/* ============================================================
   Base — reset, typography, common primitives
   ============================================================ */

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

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  font-weight: 400;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-feature-settings: 'cv11', 'ss03';
  font-feature-settings: 'cv11', 'ss03';
  font-variant-ligatures: contextual;
  min-height: 100vh;
  overflow: hidden;
  transition: background var(--t-base), color var(--t-base);
}

/* ---------- Typography base ---------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
h1 { font-size: var(--fs-24); line-height: 1.25; letter-spacing: -0.015em; }
h2 { font-size: var(--fs-18); line-height: 1.3; }
h3 { font-size: var(--fs-15); line-height: 1.35; }
h4 { font-size: var(--fs-13); line-height: 1.35; font-weight: 600; }

p { color: var(--text-2); }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }

code, pre, .mono {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  font-feature-settings: 'liga' 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* ---------- Focus ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-2);
}

/* ============================================================
   Primitive components
   ============================================================ */

/* ----- Card ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.card:hover { border-color: var(--border-strong); }

.card-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.card-title { font-size: var(--fs-13); font-weight: 600; color: var(--text); }
.card-body { padding: var(--sp-5); }

/* ----- Badges ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  height: 20px;
  border-radius: var(--r-2);
  font-size: var(--fs-11);
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  line-height: 1;
}
.badge--mono { font-family: var(--font-mono); font-weight: 500; }
.badge--primary  { background: var(--accent-100);    color: var(--accent);   border-color: transparent; }
.badge--success  { background: var(--success-100);   color: var(--success);  border-color: transparent; }
.badge--warning  { background: var(--warning-100);   color: var(--warning);  border-color: transparent; }
.badge--danger   { background: var(--danger-100);    color: var(--danger);   border-color: transparent; }
.badge--highlight { background: var(--highlight-100); color: var(--highlight); border-color: transparent; }
.badge--muted    { background: var(--bg-2);          color: var(--text-3);   border-color: transparent; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 32px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-2);
  font-size: var(--fs-13);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: all var(--t-fast);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { background: var(--bg-active); }
.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn--sm { height: 26px; padding: 0 var(--sp-2); font-size: var(--fs-12); }
.btn--icon { width: 32px; padding: 0; }
.btn--icon.btn--sm { width: 26px; }

.btn svg { width: 14px; height: 14px; }

/* ----- Inputs ----- */
.input {
  height: 32px;
  padding: 0 var(--sp-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  color: var(--text);
  font-size: var(--fs-13);
  transition: border-color var(--t-fast), background var(--t-fast);
  width: 100%;
}
.input:focus-visible { border-color: var(--accent); outline: none; }
.input::placeholder { color: var(--text-4); }
textarea.input { height: auto; padding: var(--sp-2) var(--sp-3); line-height: 1.5; resize: vertical; }
select.input { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23818896' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

/* ----- Labels ----- */
.label {
  display: block;
  font-size: var(--fs-11);
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-1);
}

/* ----- Dividers ----- */
.hr {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: var(--sp-4) 0;
}

/* ----- Empty state ----- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  color: var(--text-3);
  gap: var(--sp-3);
  min-height: 220px;
}
.empty svg { width: 28px; height: 28px; color: var(--text-4); }
.empty-title { font-size: var(--fs-14); font-weight: 600; color: var(--text-2); }
.empty-hint  { font-size: var(--fs-13); color: var(--text-3); max-width: 420px; }
.empty-hint code { background: var(--surface-sunken); padding: 2px 6px; border-radius: var(--r-1); color: var(--text-2); }

/* ----- Avatar ----- */
.avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--r-pill);
  background: var(--accent-100);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-11);
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0;
}
.avatar--md { width: 28px; height: 28px; font-size: var(--fs-12); }
.avatar--lg { width: 36px; height: 36px; font-size: var(--fs-13); }

/* ----- Stack utilities ----- */
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row--sm { gap: var(--sp-1); }
.row--lg { gap: var(--sp-3); }
.col { display: flex; flex-direction: column; gap: var(--sp-2); }
.col--lg { gap: var(--sp-4); }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ----- Icons ----- */
.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke-width: 1.75;
}
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 18px; height: 18px; }

/* ----- Dot ----- */
.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--text-4);
  flex-shrink: 0;
}
.dot--success  { background: var(--success); }
.dot--warning  { background: var(--warning); }
.dot--danger   { background: var(--danger); }
.dot--accent   { background: var(--accent); }
.dot--highlight { background: var(--highlight); }

/* ----- Kbd ----- */
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  min-width: 18px;
  height: 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-1);
  line-height: 1;
}

/* ----- Skeleton ----- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 0%, var(--bg-hover) 50%, var(--bg-3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-2);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
