/* Workbench — minimal Tailscale-admin-style */

:root {
  --fg: #0f172a;
  --fg-muted: #475569;
  --fg-weak: #64748b;
  --border: #e2e8f0;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --chip-bg: #f1f5f9;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--bg-soft);
  padding: 2px 5px;
  border-radius: 4px;
}
pre { background: var(--bg-soft); padding: 12px; border-radius: var(--radius); overflow-x: auto; }
pre code { background: transparent; padding: 0; }

/* Top navigation */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--fg); }
.brand img { display: block; border-radius: 5px; }
.brand-name { white-space: nowrap; }
.nav-tabs {
  display: flex;
  gap: 4px;
  height: 100%;
  flex: 1;
  min-width: 0;
}
.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.nav-tab:hover { color: var(--fg); text-decoration: none; }
.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.icon { flex-shrink: 0; }
.nav-tab .icon { width: 16px; height: 16px; }
.logout { margin: 0; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-ghost:hover { color: var(--fg); border-color: #cbd5e1; text-decoration: none; }
.btn-ghost.danger { color: var(--danger); border-color: #fecaca; }
.btn-ghost.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn-ghost .icon { width: 14px; height: 14px; }
.btn-icon { padding: 6px 8px; }
.btn-icon .icon { width: 16px; height: 16px; }

/* Keyboard focus rings — visible only for keyboard users */
:focus { outline: none; }
a:focus-visible,
.btn-primary:focus-visible,
.btn-ghost:focus-visible,
.btn-danger:focus-visible,
.brand:focus-visible,
.nav-tab:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius);
}
.toggle input:focus-visible + .track {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.28);
}

/* Page container */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* Wide mode — toggle in top nav makes both the page body and topbar
   stretch edge-to-edge (max-width: none). Useful when you want the
   PDF + CLI in /papers/p/<id> or the multi-tab editor in vault
   browser to actually use the screen instead of being clamped to
   1200px. Toggled per-user globally (localStorage 'platform-wide'). */
html.wide-mode .page,
html.wide-mode .topbar-inner {
  max-width: none;
}
html.wide-mode .page { padding: 18px 16px 32px; }

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.page-header .muted { margin: 0; }
.muted { color: var(--fg-muted); }
.small { font-size: 12px; }
.center { text-align: center; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: white; }

/* Search / count */
.count {
  display: inline-block;
  background: var(--chip-bg);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 12px;
}
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.list-toolbar .count { margin-bottom: 0; }
.filter-input {
  flex: 1;
  max-width: 360px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.filter-input::placeholder { color: var(--fg-weak); }

/* Data table */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg);
}
.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--fg-weak);
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--bg-soft); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .actions form { display: inline; }
.data-table .actions .btn-ghost { padding: 4px 10px; }
.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  display: inline-block;
  background: var(--chip-bg);
  color: var(--fg-muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 4px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.chip-local { background: #e0e7ff; color: #3730a3; }
.chip-link { background: #dcfce7; color: #166534; }

/* Tag chip — clickable filter trigger */
button.chip-tag {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
button.chip-tag:hover {
  background: var(--accent);
  color: white;
}

/* Home page info strip: "访问来源 / Tailscale / LAN" */
.info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 10px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 28px;
  font-size: 12px;
}
.info-bar-bottom { margin-top: 40px; margin-bottom: 0; }
.info-bar > span {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.info-bar .info-label {
  color: var(--fg-weak);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.info-bar code {
  color: var(--fg);
  background: transparent;
  padding: 0;
  font-size: 12px;
}

.header-actions { display: flex; gap: 8px; align-items: flex-start; }

/* Card grid (home sites) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}
.site-card {
  position: relative;
  display: block;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.site-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  color: var(--fg);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.site-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--accent);
}
.site-card-head strong {
  color: var(--fg);
  font-size: 15px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.site-card-body { word-break: break-all; font-size: 12px; }
.site-card-path { font-size: 10px; margin-top: 6px; }
.site-card .chip {
  position: absolute;
  top: 12px;
  right: 12px;
  margin-right: 0;
  font-size: 10px;
  padding: 1px 6px;
}

.icon-card { width: 20px; height: 20px; flex-shrink: 0; }
.icon-row  { width: 18px; height: 18px; flex-shrink: 0; }

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sub section */
.sub-section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-weak);
  margin: 0 0 12px;
}
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 16px; }
.plain-list li:last-child { border-bottom: none; }

/* Empty */
.empty { padding: 48px 0; text-align: center; }

/* Inline hint / collapsible Add form */
.inline-hint { position: relative; }
.inline-hint summary {
  list-style: none;
  cursor: pointer;
}
.inline-hint summary::-webkit-details-marker { display: none; }
.inline-hint[open] .hint-body {
  display: block;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.inline-hint .hint-body { display: none; }
.inline-hint pre { margin: 8px 0; font-size: 12px; }

.inline-form label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--fg-muted);
}
.inline-form input, .inline-form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-top: 4px;
  color: var(--fg);
}
.inline-form textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; }
.inline-form input:focus, .inline-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Login page */
.login-body {
  background: var(--bg-soft);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
}
.login-logo { margin-bottom: 16px; }
.login-logo img { display: inline-block; border-radius: 10px; }
.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}
.login-card .muted { margin: 0 0 24px; font-size: 13px; }
.login-form { text-align: left; }
.login-form label {
  font-size: 12px;
  color: var(--fg-muted);
  display: block;
  margin-bottom: 6px;
}
.login-form input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--fg);
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 38px; }
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--fg-weak);
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
  border-radius: var(--radius);
}
.pw-toggle:hover { color: var(--fg); }
.pw-toggle .icon { width: 16px; height: 16px; }
.pw-toggle .eye-off { display: none; }
.pw-toggle[data-shown="1"] .eye-on { display: none; }
.pw-toggle[data-shown="1"] .eye-off { display: block; }
.login-form .btn-primary {
  width: 100%;
  margin-top: 16px;
  justify-content: center;
}
.form-error { color: var(--danger); font-size: 12px; margin-top: 8px; }

/* Settings blocks */
.setting-block {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 48px;
}
.setting-block:first-of-type { border-top: none; padding-top: 0; }
.setting-head h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
}
.stack-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--fg-muted);
}
.stack-form input {
  display: block;
  width: 100%;
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-top: 4px;
  color: var(--fg);
}
.stack-form input:focus { outline: none; border-color: var(--accent); }

.info-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  row-gap: 8px;
  margin: 0;
}
.info-list dt { color: var(--fg-muted); }
.info-list dd { margin: 0; color: var(--fg); }

/* Flash messages */
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.flash.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Service status */
.service-status {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12); }
.dot.off { background: #94a3b8; }

.btn-danger {
  background: white;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 8px 16px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

/* Toggle switch */
.toggle-form { margin: 0; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle .track {
  width: 36px;
  height: 20px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  transition: background 0.15s;
}
.toggle .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track .thumb { transform: translateX(16px); }
.toggle-label { font-size: 13px; color: var(--fg-muted); }

/* Status pill — non-modal inline indicator (e.g., service restart) */
.status-pill {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.25);
  color: var(--accent);
  font-size: 13px;
}
.status-pill.show { display: inline-flex; }
.status-pill .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37, 99, 235, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: wb-spin 0.9s linear infinite;
}
.status-pill button {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
@keyframes wb-spin { to { transform: rotate(360deg); } }

/* Dialog modals (replaces fragile <details> popovers) */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  width: min(420px, calc(100vw - 32px));
  max-width: 420px;
}
dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
dialog.modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
dialog.modal .modal-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
dialog.modal .modal-close {
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  border-radius: var(--radius);
}
dialog.modal .modal-close:hover { color: var(--fg); }
dialog.modal .modal-body { padding: 16px 18px 18px; }
dialog.modal .modal-body label {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--fg-muted);
}
dialog.modal .modal-body input,
dialog.modal .modal-body textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  margin-top: 4px;
  color: var(--fg);
  background: var(--bg);
}
dialog.modal .modal-body textarea {
  resize: vertical;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
dialog.modal .modal-body input:focus,
dialog.modal .modal-body textarea:focus {
  outline: none;
  border-color: var(--accent);
}
dialog.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
dialog.modal .modal-body label.check-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg);
}
dialog.modal .modal-body label.check-row input { width: auto; margin: 0; }

/* ── Smart-add (single-input "新建元素") ─────────────────────
   The compact dialog has no head bar, no per-type fields, and no
   required typing besides the one textarea. Power overrides hide
   inside <details class="smart-add-more">. */
dialog.modal.modal-compact { width: min(520px, calc(100vw - 32px)); max-width: 520px; }
.smart-add { padding: 18px 18px 16px; }
.smart-add-input-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--bg);
  transition: border-color 0.15s;
}
.smart-add-input-row:focus-within { border-color: var(--accent); }
.smart-add-kind {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  margin-top: 2px;
  user-select: none;
}
.smart-add-kind[data-kind="link"]   { background: #ecfeff; color: #0e7490; }
.smart-add-kind[data-kind="browse"] { background: #dbeafe; color: #1e40af; }
.smart-add-kind[data-kind="serve"]  { background: #dcfce7; color: #166534; }
.smart-add-kind[data-kind="prompt"] { background: #fef3c7; color: #92400e; }
.smart-add textarea#smart-add-text {
  flex: 1 1 auto;
  margin: 0;
  border: 0;
  padding: 0;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  min-height: 22px;
  overflow-y: auto;
  outline: none;
}
.smart-add-hint {
  margin-top: 8px;
  padding-left: 2px;
}
.smart-add-hint kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 10px;
  color: var(--fg-muted);
  background: var(--bg-elev, #f8fafc);
}
.smart-add-more { margin-top: 14px; }
.smart-add-more > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 4px 0;
}
.smart-add-more > summary::-webkit-details-marker { display: none; }
.smart-add-more > summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s;
}
.smart-add-more[open] > summary::before { content: "▾ "; }
.smart-add-more-body {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.smart-add-more-body label { margin-bottom: 10px; }
.smart-add .modal-actions { margin-top: 14px; }

/* Responsive */
@media (max-width: 720px) {
  .topbar-inner { padding: 0 16px; gap: 12px; }
  .nav-tab span { display: none; }
  .nav-tab { padding: 0 8px; }
  .brand-name { display: none; }
  .setting-block { grid-template-columns: 1fr; gap: 16px; }
  .truncate { max-width: 160px; }
  .inline-hint[open] .hint-body { width: min(340px, calc(100vw - 32px)); }
}

/* Dark mode — flips every variable, everything else inherits */
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e2e8f0;
    --fg-muted: #94a3b8;
    --fg-weak: #64748b;
    --border: #1e293b;
    --bg: #0b1220;
    --bg-soft: #111a2c;
    --chip-bg: #1e293b;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
  code { background: var(--bg-soft); }
  .data-table tbody tr:hover { background: #16223a; }
  .chip-local { background: #312e81; color: #c7d2fe; }
  .chip-link { background: #14532d; color: #bbf7d0; }
  .flash.ok { background: #052e1a; color: #86efac; border-color: #14532d; }
  .flash.err { background: #2c0b0e; color: #fca5a5; border-color: #7f1d1d; }
  .btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: #7f1d1d;
  }
  .btn-danger:hover { background: #2c0b0e; border-color: #b91c1c; }
  .btn-ghost.danger { border-color: #7f1d1d; }
  .btn-ghost.danger:hover { background: #2c0b0e; border-color: #b91c1c; }
  .toggle .track { background: #334155; }
  .dot.off { background: #475569; }
  .status-pill {
    background: rgba(96, 165, 250, 0.12);
    border-color: rgba(96, 165, 250, 0.35);
  }
  dialog.modal::backdrop { background: rgba(0, 0, 0, 0.65); }
  .el-icon-img { background: var(--bg-soft); border-color: var(--border); }
  .icon-tile:hover { background: var(--bg-soft); }
  .folder-card { background: var(--bg-soft); }
  .folder-list li:hover { background: rgba(255,255,255,0.04); }
  .cat-row:hover { background: var(--bg-soft); }
}

/* ───── View switcher (top-right of pages with multiple display modes) ───── */
.view-switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}
.view-switcher button {
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.view-switcher button:last-child { border-right: 0; }
.view-switcher button.active {
  background: var(--accent);
  color: white;
}
.view-switcher button:not(.active):hover { background: var(--bg-soft); color: var(--fg); }

/* ───── Element icons (shared by all view modes) ─────
   Every icon uses the SAME box-sized <span> outer wrapper. Content
   (img / svg / emoji / letter) fills 100% of the box, so cards, tiles
   and rows all line up regardless of which kind was rendered.
*/
.el-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg-soft);
  color: white;
  font-weight: 600;
  line-height: 1;
  user-select: none;
  box-sizing: border-box;
}
.el-icon-card { width: 28px;  min-width: 28px;  max-width: 28px;  height: 28px; font-size: 13px; border-radius: 6px; }
.el-icon-tile { width: 56px;  min-width: 56px;  max-width: 56px;  height: 56px; font-size: 24px; border-radius: 14px; }
.el-icon-row  { width: 20px;  min-width: 20px;  max-width: 20px;  height: 20px; font-size: 11px; border-radius: 4px; }

/* Image-based icons (favicon / custom URL): img fills the entire box. */
.el-icon-img {
  background: white;
  border: 1px solid var(--border);
  padding: 0;
}
.el-icon-img img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.el-icon-fallback img { object-fit: cover; opacity: 0.6; }

/* SVG icons (folder / globe): inner svg fills 60% of the box for visual
   parity with favicons that fill 100% — outline icons need breathing room. */
.el-icon-svg svg { width: 60%; height: 60%; display: block; }

/* Emoji: native rendering, no background tint. */
.el-icon-emoji {
  background: transparent;
  color: inherit;
}
.el-icon-card.el-icon-emoji { font-size: 22px; }
.el-icon-tile.el-icon-emoji { font-size: 40px; }
.el-icon-row.el-icon-emoji  { font-size: 16px; }

/* Letter avatars: deterministic colored circle. */
.el-icon-letter { color: white; }

/* ───── Icons grid (Firefox new-tab style) ───── */
.icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.icon-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 6px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  transition: background 0.1s;
}
.icon-tile:hover { background: var(--bg-soft); text-decoration: none; color: var(--fg); }
.icon-tile-label {
  font-size: 12px;
  text-align: center;
  line-height: 1.3;
  word-break: break-all;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ───── Folder cards (Tab Stash style) ───── */
.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.folder-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg);
}
.folder-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  text-decoration: none;
  color: var(--fg);
  font-size: 14px;
}
.folder-head:hover { background: var(--bg-soft); text-decoration: none; color: var(--fg); }
.folder-head .folder-emoji { font-size: 16px; }
.folder-head strong { flex: 1; }
.folder-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: 240px;
  overflow-y: auto;
}
.folder-list li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  text-decoration: none;
  color: var(--fg);
  font-size: 13px;
}
.folder-list li a:hover { background: var(--bg-soft); text-decoration: none; }
.folder-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-list .folder-empty,
.folder-list .folder-more { padding: 6px 14px; }
.loose-elements { margin-top: 32px; }
.loose-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

/* ───── Breadcrumb on /c/<id> ───── */
.breadcrumb {
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 4px;
}
.breadcrumb a {
  color: var(--fg-muted);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb .sep { margin: 0 4px; color: var(--fg-weak); }

/* ───── Filter bar (used on /elements) ───── */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-bar select,
.filter-bar input[type="text"] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}
.filter-bar select:focus,
.filter-bar input:focus { outline: none; border-color: var(--accent); }

/* ───── Categories tree page ───── */
.cat-tree { margin-top: 12px; }
.cat-node { margin-bottom: 4px; }
.cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.cat-row:hover { background: var(--bg-soft); }
.cat-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  text-decoration: none;
  color: var(--fg);
  font-size: 14px;
  min-width: 0;
}
.cat-name strong { font-weight: 600; }
.cat-name:hover { text-decoration: none; color: var(--fg); }
.cat-emoji { font-size: 16px; flex-shrink: 0; }
.cat-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.cat-actions .btn-ghost { padding: 4px 10px; font-size: 12px; }
.cat-children {
  margin-left: 24px;
  margin-top: 4px;
  border-left: 2px solid var(--border);
  padding-left: 12px;
}

/* Usage meter widget — mirrors Claude's `/usage` view layout.
   Used on the home page (compact mode, single 5h bar) and the
   /services/usage-meter detail page (full breakdown). */
.usage-widget {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
}
.usage-widget.compact { padding: 12px 14px; }
.usage-section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.usage-section-head strong { font-size: 14px; }
.usage-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  align-items: center;
  gap: 14px;
  padding: 6px 0;
}
.usage-label { font-size: 13px; line-height: 1.35; }
.usage-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.usage-bar span {
  display: block;
  height: 100%;
  background: #2563eb;
  border-radius: 999px;
  transition: width .25s ease;
}
.usage-pct {
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
  text-align: right;
  min-width: 64px;
}
.usage-empty { padding: 6px 0; }
.usage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.usage-foot .btn-ghost { padding: 4px 8px; }
.usage-widget.compact .usage-row { grid-template-columns: 1fr 1.6fr auto; gap: 10px; }

