:root {
  color-scheme: light;
  --background: #f2f5f4;
  --surface: #ffffff;
  --surface-muted: #e9efec;
  --text: #17211d;
  --muted: #63716b;
  --border: #d4ddd9;
  --primary: #176b52;
  --primary-strong: #0f5943;
  --primary-soft: #dceee7;
  --accent: #c77918;
  --shadow: 0 8px 22px rgba(20, 39, 31, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #111715;
  --surface: #19211e;
  --surface-muted: #222d29;
  --text: #edf3f0;
  --muted: #a7b5af;
  --border: #35413c;
  --primary: #55b493;
  --primary-strong: #74c7aa;
  --primary-soft: #233f35;
  --accent: #e5a244;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input { font: inherit; letter-spacing: 0; }
button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 66px minmax(0, 1fr);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 250px minmax(260px, 680px) minmax(180px, 1fr);
  align-items: center;
  gap: 22px;
  min-height: 66px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
}

.brand-mark img { display: block; width: 100%; height: 100%; }

.brand-copy { min-width: 0; display: grid; gap: 1px; }
.brand-copy strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.brand-copy small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.search-wrap {
  position: relative;
  min-width: 0;
  width: 100%;
}

.search-wrap input {
  min-width: 0;
  width: 100%;
  height: 42px;
  padding: 0 44px 0 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--text);
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.search-wrap input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
  outline: none;
}

.search-wrap input::placeholder { color: var(--muted); }
.search-icon { position: absolute; top: 50%; left: 14px; color: var(--muted); transform: translateY(-50%); }
.search-icon svg { display: block; width: 18px; height: 18px; }

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.icon-button:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }
.icon-button svg { width: 18px; height: 18px; }
.clear-search { position: absolute; top: 50%; right: 2px; width: 38px; height: 38px; border: 0; background: transparent; transform: translateY(-50%); }

.top-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.access-badge {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.access-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.workspace {
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 66px;
  height: calc(100vh - 66px);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.category-nav { display: grid; gap: 5px; }
.nav-label { padding: 14px 10px 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.nav-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 750; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item em { min-width: 24px; color: inherit; font-size: 11px; font-style: normal; text-align: right; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 10px 4px;
  color: var(--muted);
  font-size: 10px;
}
.sidebar-footer svg { width: 16px; height: 16px; color: var(--primary); }

.main-content {
  min-width: 0;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 32px 34px 56px;
}

.page-heading { margin-bottom: 26px; }
.page-heading h1 { margin: 0; font-size: 26px; line-height: 1.25; }
.page-heading p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }

.content-section { margin-top: 30px; }
.content-section > header { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.content-section h2 { margin: 0; font-size: 15px; }
.content-section > header span { min-width: 24px; padding: 2px 6px; border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: 10px; text-align: center; }

.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 11px;
}

.bookmark-card {
  min-width: 0;
  height: 82px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 11px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(20, 39, 31, 0.03);
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}
.bookmark-card:hover { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); box-shadow: var(--shadow); transform: translateY(-2px); }
.bookmark-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 15px;
  font-weight: 800;
}
.bookmark-copy { min-width: 0; display: grid; gap: 5px; }
.bookmark-copy strong,
.bookmark-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-copy strong { font-size: 13px; }
.bookmark-copy span { color: var(--muted); font-size: 11px; }
.external-icon { color: var(--muted); opacity: 0.65; }
.external-icon svg { width: 16px; height: 16px; }
.bookmark-card:hover .external-icon { color: var(--primary); opacity: 1; }

.boot-state,
.empty-state,
.error-state {
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}
.boot-state p,
.empty-state p { margin: 0; }
.empty-state svg,
.error-state > svg { width: 28px; height: 28px; }
.boot-spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 700ms linear infinite; }
.error-state h1 { margin: 0; color: var(--text); font-size: 19px; }
.error-state button { height: 38px; display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }
.error-state button svg { width: 16px; height: 16px; }

.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 50; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 200px minmax(220px, 1fr) auto; gap: 14px; padding: 0 16px; }
  .workspace { grid-template-columns: 205px minmax(0, 1fr); }
  .main-content { padding: 26px 22px 48px; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-rows: auto minmax(0, 1fr); }
  .topbar { position: sticky; min-height: 116px; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 54px 50px; column-gap: 14px; row-gap: 0; padding: 6px 12px; }
  .search-wrap { grid-column: 1 / -1; grid-row: 2; }
  .access-badge { display: none; }
  .workspace { display: block; }
  .sidebar { position: sticky; top: 116px; z-index: 10; width: 100%; height: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow: hidden; }
  .category-nav { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; }
  .nav-label,
  .sidebar-footer { display: none; }
  .nav-item { width: auto; min-width: max-content; grid-template-columns: 18px auto auto; padding: 8px 11px; }
  .main-content { padding: 24px 14px 42px; }
  .page-heading { margin-bottom: 20px; }
  .page-heading h1 { font-size: 22px; }
  .content-section { margin-top: 25px; }
}

@media (max-width: 460px) {
  .brand-mark { width: 35px; height: 35px; flex-basis: 35px; }
  .brand-copy strong { font-size: 14px; }
  .bookmark-grid { grid-template-columns: 1fr; }
  .bookmark-card { height: 78px; }
}

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