/* H2Learn — shared components */

/* === Button === */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  font-size: var(--t-base);
  font-weight: 500;
  line-height: 1;
  border-radius: var(--r-2);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  transition: background 120ms, border-color 120ms, transform 80ms;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.primary:hover { background: #2a261c; border-color: #2a261c; }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: var(--t-sm); }
.btn.xs { padding: 3px 8px; font-size: var(--t-xs); border-radius: var(--r-1); }
.btn.lg { padding: 13px 22px; font-size: var(--t-md); }
.btn.icon { width: 32px; height: 32px; padding: 0; justify-content: center; }
.btn.icon.sm { width: 26px; height: 26px; }
.btn.warm { background: var(--warm); color: #fff; border-color: var(--warm); }
.btn.warm:hover { background: #a84620; border-color: #a84620; }

/* === Chip / pill === */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-size: var(--t-xs);
  font-weight: 500;
  line-height: 1.2;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.solid { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warm { background: var(--warm-soft); color: var(--warm); border-color: transparent; }
.chip.moss { background: var(--moss-soft); color: var(--moss); border-color: transparent; }
.chip.outline { background: transparent; }
.chip.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; }
.chip.lg { font-size: var(--t-sm); padding: 5px 12px; }
.chip.xs { font-size: 10.5px; padding: 2px 7px; }

/* relationship chips */
.chip.rel-similar    { background: rgba(26,77,110,0.10); color: var(--e-similar); border-color: transparent; }
.chip.rel-comp       { background: rgba(194,86,42,0.10); color: var(--e-comp); border-color: transparent; }
.chip.rel-antidup    { background: rgba(176,58,46,0.10); color: var(--e-antidup); border-color: transparent; }
.chip.rel-bridge     { background: rgba(138,110,46,0.12); color: var(--e-bridge); border-color: transparent; }
.chip.rel-method     { background: rgba(91,95,184,0.10); color: var(--e-method); border-color: transparent; }
.chip.rel-uncertain  { background: rgba(138,74,140,0.10); color: var(--e-uncertain); border-color: transparent; }
.chip.rel-needoffer  { background: rgba(42,138,110,0.10); color: var(--e-needoffer); border-color: transparent; }

/* === Card === */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-4);
  padding: var(--s-5);
}
.card.tight { padding: var(--s-4); }
.card.elevated { background: var(--surface-2); box-shadow: var(--shadow-2); }
.card.flat { background: transparent; border-color: transparent; padding: 0; }
.card.bordered { border-color: var(--line-2); }
.card-title { font-size: var(--t-md); font-weight: 600; margin: 0; letter-spacing: -0.005em; }
.card-sub   { font-size: var(--t-sm); color: var(--ink-3); margin-top: 2px; }
.card-section { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); }
.card-section:first-child { border-top: 0; }

/* === Avatar === */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: var(--t-sm);
  border: 1px solid var(--surface-2);
  flex-shrink: 0;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10.5px; }
.avatar.lg { width: 56px; height: 56px; font-size: var(--t-md); }
.avatar.xl { width: 88px; height: 88px; font-size: var(--t-xl); }

/* === Badge / score === */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--r-1);
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.high   { background: var(--moss-soft); color: var(--moss); border-color: transparent; }
.badge.med    { background: rgba(184,149,52,0.16); color: #7a611f; border-color: transparent; }
.badge.low    { background: rgba(176,58,46,0.10); color: var(--e-antidup); border-color: transparent; }
.badge.curated { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* === Progress / signal bar === */
.bar {
  position: relative;
  height: 6px;
  background: var(--surface-3);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.bar > .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 600ms cubic-bezier(.2,.8,.2,1);
}
.bar.thin { height: 3px; }
.bar.thick { height: 10px; }
.bar > .fill.warm { background: var(--warm); }
.bar > .fill.moss { background: var(--moss); }
.bar > .fill.alert { background: var(--e-antidup); }

/* === Score ring (donut) === */
.score-ring { position: relative; display: inline-flex; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .num {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  letter-spacing: -0.02em;
}
.score-ring .num small { font-family: var(--font-sans); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); margin-top: 2px;}

/* === Field === */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 500; }
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: var(--t-base);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  color: var(--ink);
  transition: border-color 120ms, box-shadow 120ms;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input.search {
  padding-left: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2398927f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='M21 21l-4.35-4.35'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
}

/* === Toggle / switch === */
.switch {
  position: relative;
  width: 32px; height: 18px;
  background: var(--line-2);
  border-radius: var(--r-pill);
  transition: background 160ms;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 160ms;
  box-shadow: var(--shadow-1);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(14px); }

/* === Segmented control === */
.segmented {
  display: inline-flex;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 2px;
  gap: 0;
}
.segmented > button {
  padding: 5px 12px;
  font-size: var(--t-sm);
  border-radius: var(--r-1);
  color: var(--ink-2);
  font-weight: 500;
}
.segmented > button.on { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow-1); }
.segmented > button:hover:not(.on) { color: var(--ink); }

/* === Tab bar === */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--line);
}
.tabs > button {
  padding: 10px 16px;
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs > button.on { color: var(--ink); border-color: var(--ink); }
.tabs > button:hover { color: var(--ink-2); }

/* === Drawer === */
.drawer {
  background: var(--surface-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer-head { padding: var(--s-5); border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.drawer-foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); background: var(--surface); }

/* === Divider === */
.divider { height: 1px; background: var(--line); margin: var(--s-4) 0; }
.divider.dashed { background: none; border-top: 1px dashed var(--line-2); }

/* === Tooltip / kbd === */
.kbd {
  display: inline-flex; align-items: center;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  border-bottom-width: 2px;
}

/* === Empty state === */
.empty {
  text-align: center;
  padding: var(--s-9) var(--s-6);
  color: var(--ink-3);
}
.empty .emoji-art {
  font-family: var(--font-display);
  font-size: 56px;
  color: var(--line-2);
  letter-spacing: -0.04em;
  margin-bottom: var(--s-3);
}

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

/* === KPI === */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-family: var(--font-display); font-size: var(--t-3xl); line-height: 1; letter-spacing: -0.02em; }
.kpi .l { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); }
.kpi .delta { font-size: var(--t-sm); color: var(--moss); }

/* === App shell === */
.appshell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: var(--s-5) var(--s-3);
  display: flex; flex-direction: column;
  gap: var(--s-4);
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 var(--s-3) var(--s-3);
  border-bottom: 1px solid var(--line);
}
.sidebar .brand .mark {
  width: 32px; height: 32px;
  background: var(--ink); color: var(--surface);
  border-radius: var(--r-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: -0.04em;
}
.sidebar .brand .name { font-weight: 600; letter-spacing: -0.01em; line-height: 1.1;}
.sidebar .brand .sub  { font-size: 10.5px; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group .group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); padding: 0 var(--s-3); margin-bottom: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px var(--s-3);
  border-radius: var(--r-2);
  font-size: var(--t-sm);
  color: var(--ink-2);
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.on { background: var(--ink); color: var(--surface); }
.nav-item .icon { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.85; }
.nav-item .count { margin-left: auto; font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nav-item.on .count { color: var(--surface); opacity: 0.6; }

.workspace { display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.workspace-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-4) var(--s-7);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.workspace-head h1 {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 400;
  margin: 0;
  letter-spacing: -0.015em;
}
.workspace-head .crumbs { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin-bottom: 2px; }
.workspace-body { flex: 1; padding: var(--s-7); overflow-x: hidden; }

/* === Section heading === */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--s-4); }
.section-head h2 { font-family: var(--font-display); font-size: var(--t-2xl); font-weight: 400; margin: 0; letter-spacing: -0.015em; }
.section-head .desc { font-size: var(--t-sm); color: var(--ink-3); margin-top: 2px; }

/* === Subtle hr label === */
.label-hr { display: flex; align-items: center; gap: 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); }
.label-hr::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* === Notice / banner === */
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px;
  border-radius: var(--r-3);
  background: var(--accent-soft);
  border: 1px solid transparent;
  font-size: var(--t-sm);
  color: var(--accent);
}
.notice.alert { background: rgba(176,58,46,0.08); color: var(--e-antidup); }
.notice.warm  { background: var(--warm-soft); color: var(--warm); }

/* === Hover lift === */
.lift { transition: transform 180ms, box-shadow 180ms, border-color 180ms; }
.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); border-color: var(--line-2); }

/* === Grid utilities === */
.grid { display: grid; gap: var(--s-4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }
.col-span-5 { grid-column: span 5; }
.col-span-6 { grid-column: span 6; }
.col-span-7 { grid-column: span 7; }
.col-span-8 { grid-column: span 8; }
.col-span-9 { grid-column: span 9; }

@media (max-width: 1100px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* === graph canvas surface === */
.canvas-bg {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(26,77,110,0.05), transparent 50%),
    radial-gradient(ellipse at 75% 75%, rgba(194,86,42,0.04), transparent 50%),
    radial-gradient(ellipse at 50% 50%, var(--surface), var(--bg));
  position: relative;
}
.canvas-bg::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle, rgba(22,20,15,0.05) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  opacity: 0.6;
}

/* pulse for recommended/anti-dup */
@keyframes pulse-glow {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.55; }
}
.pulse-glow { animation: pulse-glow 2.4s ease-in-out infinite; }
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* fade-in */
@keyframes fade-up { 0% { opacity: 0; transform: translateY(6px); } 100% { opacity: 1; transform: none; } }
.fade-up { animation: fade-up 320ms cubic-bezier(.2,.8,.2,1) both; }
