:root {
  color-scheme: light;
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --page-bg: #f4f6f8;
  --surface-primary: #ffffff;
  --surface-secondary: #f8fafc;
  --surface-tertiary: #f1f5f9;
  --surface-hover: #eef3f8;
  --surface-active: #eaf2ff;

  --border-primary: #dce2e8;
  --border-secondary: #e8edf2;
  --border-strong: #c8d0da;
  --border-active: #8fb4f5;

  --text-primary: #111827;
  --text-secondary: #475569;
  --text-muted: #7b8794;
  --text-soft: #98a3af;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eaf2ff;
  --success: #22a65a;
  --success-soft: #eaf8ef;

  --shadow-soft: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px rgba(15, 23, 42, .035);
  --shadow-card-hover: 0 12px 28px rgba(15, 23, 42, .07);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 14px;

  --font-xs: 12px;
  --font-sm: 13px;
  --font-md: 15px;
  --font-lg: 18px;
  --font-xl: 22px;
  --font-2xl: clamp(26px, 2vw, 32px);

  --layout-width: 1440px;
  --transition-fast: 150ms cubic-bezier(.2, .7, .2, 1);
  --transition-base: 220ms cubic-bezier(.2, .7, .2, 1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #090c10;
  --surface-primary: #0f141a;
  --surface-secondary: #131920;
  --surface-tertiary: #171f27;
  --surface-hover: #18212a;
  --surface-active: #1b2530;

  --border-primary: #27303a;
  --border-secondary: #1d252d;
  --border-strong: #35414d;
  --border-active: #536273;

  --text-primary: #edf1f5;
  --text-secondary: #a5afb9;
  --text-muted: #69747f;
  --text-soft: #59636e;

  --accent: #d5dbe2;
  --accent-hover: #ffffff;
  --accent-soft: #1c232b;
  --success: #45c878;
  --success-soft: #10261a;

  --shadow-soft: 0 1px 2px rgba(0, 0, 0, .18);
  --shadow-card-hover: 0 12px 28px rgba(0, 0, 0, .22);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--font-md);
  line-height: 1.58;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition-base), color var(--transition-base);
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--text-primary);
  color: var(--surface-primary);
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 12px; }

.app-shell {
  width: min(calc(100% - 32px), var(--layout-width));
  margin: 16px auto;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  background: var(--surface-primary);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: background-color var(--transition-base), border-color var(--transition-base);
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-secondary);
}

.identity, .topbar-actions, .infra-state, .theme-toggle { display: flex; align-items: center; }
.identity { gap: 12px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -.04em;
}
.identity-copy { display: grid; min-width: 0; }
.identity-copy strong { font-size: 16px; letter-spacing: -.01em; }
.identity-copy span { color: var(--text-muted); font-size: var(--font-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { gap: 8px; }
.infra-state, .theme-toggle {
  min-height: 38px;
  padding: 0 12px;
  gap: 8px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  color: var(--text-secondary);
}
.infra-state { font-size: var(--font-xs); }
.infra-state strong { color: var(--text-primary); font-weight: 650; }
.status-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); flex: 0 0 auto; }
.theme-toggle { cursor: pointer; transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast); }
.theme-toggle:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle:focus-visible, .filter-button:focus-visible, .project-open:focus-visible, .empty-state button:focus-visible, .project-search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-icon { font-size: 15px; }
.theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-icon-moon { display: block; }
.theme-label { font-size: var(--font-xs); font-weight: 650; }

main { padding: 16px; background: var(--surface-secondary); }
.overview-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--surface-primary);
  overflow: hidden;
}
.metric { min-width: 0; padding: 16px 18px; border-right: 1px solid var(--border-secondary); }
.metric:last-child { border-right: 0; }
.metric-label, .metric small { display: block; color: var(--text-muted); font-size: var(--font-xs); }
.metric strong { min-height: 27px; display: flex; align-items: center; gap: 8px; margin: 3px 0 1px; font-size: var(--font-lg); letter-spacing: -.02em; }

.projects-section, .system-panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--surface-primary);
}
.section-heading, .panel-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; }
.eyebrow { margin: 0 0 3px; color: var(--text-muted); font-size: var(--font-xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.section-heading h1, .panel-heading h2 { margin: 0; font-size: var(--font-2xl); letter-spacing: -.035em; line-height: 1.15; }
.section-heading p:not(.eyebrow), .panel-heading span { margin: 5px 0 0; color: var(--text-muted); font-size: var(--font-sm); }
.result-summary { display: flex; align-items: baseline; gap: 5px; color: var(--text-muted); font-size: var(--font-xs); white-space: nowrap; }
.result-summary strong { color: var(--text-primary); font-size: var(--font-lg); }

.project-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 14px;
  padding: 5px;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
}
.filter-list { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.filter-list::-webkit-scrollbar { display: none; }
.filter-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-xs);
  font-weight: 560;
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}
.filter-button:hover { color: var(--text-primary); background: var(--surface-hover); }
.filter-button.is-active { color: var(--accent); border-color: var(--border-active); background: var(--surface-active); }

.project-search {
  width: min(340px, 36vw);
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: var(--surface-primary);
  color: var(--text-muted);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}
.project-search svg { flex: 0 0 auto; font-size: 14px; }
.project-search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text-primary); font-size: var(--font-xs); }
.project-search input::placeholder { color: var(--text-soft); }
kbd { min-width: 20px; padding: 1px 5px; border: 1px solid var(--border-primary); border-bottom-color: var(--border-strong); border-radius: 4px; background: var(--surface-secondary); color: var(--text-muted); font: 10px/1.6 var(--font-sans); text-align: center; }

.project-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.project-card {
  min-width: 0;
  min-height: 278px;
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--surface-primary);
  transition: transform var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}
.project-card:hover { transform: translateY(-1px); border-color: var(--border-strong); background: var(--surface-secondary); box-shadow: var(--shadow-card-hover); }
.project-card-topline, .project-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.project-icon { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--border-secondary); border-radius: var(--radius-md); background: var(--surface-secondary); color: var(--accent); }
.project-icon svg { width: 20px; height: 20px; }
.project-state { display: flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: var(--font-xs); }
.project-copy { margin-top: 14px; }
.project-copy h2 { margin: 0; font-size: 17px; letter-spacing: -.018em; }
.project-copy p { display: -webkit-box; min-height: 62px; margin: 7px 0 0; overflow: hidden; color: var(--text-secondary); font-size: var(--font-xs); -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.project-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 16px; }
.project-tags span { padding: 4px 7px; border: 1px solid var(--border-secondary); border-radius: 5px; background: var(--surface-secondary); color: var(--text-secondary); font-size: 11px; line-height: 1.25; }
.project-card-footer { margin-top: auto; padding-top: 13px; border-top: 1px solid var(--border-secondary); }
.project-meta { min-width: 0; display: grid; }
.project-meta strong { color: var(--text-secondary); font-size: var(--font-xs); font-weight: 600; }
.project-meta span { overflow: hidden; color: var(--text-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.project-open { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid var(--border-primary); border-radius: var(--radius-sm); color: var(--text-secondary); font-size: var(--font-xs); font-weight: 620; text-decoration: none; opacity: .8; transition: color var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast), opacity var(--transition-fast); }
.project-open svg { width: 13px; height: 13px; transition: transform var(--transition-fast); }
.project-card:hover .project-open { opacity: 1; }
.project-open:hover { color: var(--accent); border-color: var(--border-active); background: var(--surface-active); }
.project-open:hover svg { transform: translate(1px, -1px); }

.empty-state { display: grid; place-items: center; gap: 5px; padding: 60px 20px; border: 1px dashed var(--border-primary); border-radius: var(--radius-md); color: var(--text-muted); text-align: center; }
.empty-state strong { color: var(--text-primary); }
.empty-state button { margin-top: 8px; padding: 7px 10px; border: 1px solid var(--border-primary); border-radius: var(--radius-sm); background: var(--surface-secondary); color: var(--text-primary); cursor: pointer; }

.panel-heading { align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--border-secondary); }
.panel-heading h2 { font-size: var(--font-lg); }
.system-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.system-metric { padding: 14px 16px 4px; border-right: 1px solid var(--border-secondary); }
.system-metric:last-child { border-right: 0; }
.system-metric > span, .system-metric > small { display: block; color: var(--text-muted); font-size: var(--font-xs); }
.system-metric strong { display: block; margin-top: 2px; font-size: var(--font-xl); letter-spacing: -.025em; }
.system-metric .metric-good { margin-top: 1px; color: var(--success); }
.sparkline { height: 30px; display: flex; align-items: end; gap: 3px; margin-top: 8px; }
.sparkline i { width: 100%; height: var(--h); border-radius: 2px 2px 0 0; background: color-mix(in srgb, var(--accent) 55%, transparent); opacity: .75; }

.footer {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border-secondary);
  color: var(--text-muted);
  font-size: var(--font-xs);
}
.footer-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.footer-identity > span { white-space: nowrap; }
.footer-identity a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.social-links { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.social-links a { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 9px; border: 1px solid transparent; border-radius: var(--radius-sm); transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast); }
.social-links a:hover { border-color: var(--border-primary); background: var(--surface-secondary); }
.social-links svg { width: 15px; height: 15px; }
.footer a { color: var(--text-secondary); text-decoration: none; }
.footer a:hover { color: var(--accent); }

@media (min-width: 1320px) {
  .project-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-toolbar { align-items: stretch; flex-direction: column; }
  .project-search { width: 100%; }
  .system-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .system-metric:nth-child(2) { border-right: 0; }
  .system-metric:nth-child(-n+2) { border-bottom: 1px solid var(--border-secondary); }
}

@media (max-width: 720px) {
  .app-shell { width: min(calc(100% - 16px), var(--layout-width)); margin: 8px auto; border-radius: var(--radius-lg); }
  .topbar { min-height: 64px; padding: 10px 12px; }
  .identity-copy span, .infra-label, .theme-label { display: none; }
  .infra-state, .theme-toggle { padding: 0 10px; }
  main { padding: 8px; }
  .overview-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border-secondary); }
  .projects-section, .system-panel { margin-top: 8px; padding: 12px; }
  .section-heading { align-items: flex-start; }
  .section-heading p:not(.eyebrow), .panel-heading > span { display: none; }
  .project-grid { grid-template-columns: 1fr; }
  .project-card { min-height: 250px; }
  .footer { grid-template-columns: 1fr; min-height: auto; padding: 12px; }
  .social-links { justify-content: flex-start; flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .infra-state strong { display: none; }
  .section-heading { display: block; }
  .result-summary { margin-top: 8px; }
  .filter-button { padding-inline: 9px; }
  .system-grid { grid-template-columns: 1fr; }
  .system-metric { border-right: 0; border-bottom: 1px solid var(--border-secondary); }
  .system-metric:last-child { border-bottom: 0; }
}

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