:root {
  --bg: #0f0f11;
  --bg-soft: #17171b;
  --bg-card: #1c1c21;
  --bg-hover: #23232a;
  --border: #2a2a33;
  --border-strong: #3a3a46;
  --fg: #ebe8e1;
  --fg-muted: #9a968d;
  --fg-dim: #6a6760;
  --accent: #f5a524;
  --accent-soft: rgba(245, 165, 36, 0.12);
  --accent-line: rgba(245, 165, 36, 0.4);
  --danger: #e5484d;
  --success: #46a758;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--mono); }

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg);
  text-decoration: none;
}
.topbar .brand .dot { color: var(--accent); }
.topbar .brand-icon { display: block; flex: 0 0 auto; }
.topbar .nav {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}
.topbar .nav a {
  color: var(--fg-muted);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
}
.topbar .nav a:hover { background: var(--bg-hover); color: var(--fg); text-decoration: none; }
.topbar .nav a.active { color: var(--accent); background: var(--accent-soft); }
.topbar .spacer { flex: 1; }
.topbar .user {
  font-size: 12px;
  color: var(--fg-muted);
  font-family: var(--mono);
}
.topbar .user .role {
  color: var(--accent);
  margin-left: 6px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.page-header .subtitle {
  color: var(--fg-muted);
  font-size: 13px;
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.search-bar input[type="search"] {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
}
.search-bar input[type="search"]:focus {
  outline: none;
  border-color: var(--accent-line);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  gap: 14px;
  align-items: stretch;
}
/* card-wrap is the positioning context for the kebab; make it stretch to
   the row height so the inner card fills it. */
.card-wrap { display: flex; }
.card-wrap > .card { flex: 1; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.12s ease, transform 0.12s ease;
  text-decoration: none;
  color: var(--fg);
}
.card:hover {
  border-color: var(--accent-line);
  text-decoration: none;
  transform: translateY(-1px);
}
.card .thumb {
  position: relative;
  height: 100px;
  border-radius: 6px;
  background: linear-gradient(135deg, #26262e 0%, #1c1c22 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  color: var(--accent);
  font-size: 28px;
  font-weight: 600;
  overflow: hidden;
}
.card .thumb-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
}
.card .thumb-letter { display: none; }
.card .thumb.thumb-fallback .thumb-letter { display: inline; }
.card .thumb.thumb-fallback { /* image removed by onerror */ }
.card .title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
}
.card .meta {
  color: var(--fg-muted);
  font-size: 12px;
  font-family: var(--mono);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}
.card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  /* Pin tags to the bottom so cards with shorter titles still align. */
  margin-top: auto;
}
.tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}
.tag.visibility-private { color: var(--fg-dim); }
.tag.visibility-shared { color: #a78bfa; border-color: rgba(167, 139, 250, 0.3); }
.tag.visibility-public { color: var(--success); border-color: rgba(70, 167, 88, 0.3); }

/* Package kind — MD (drop) vs HTML (explainer). Distinct from visibility
   colours so the two stack readably. */
.tag.kind-md {
  color: #7cc4ff;
  border-color: rgba(124, 196, 255, 0.4);
  background: rgba(124, 196, 255, 0.08);
  font-weight: 600;
  letter-spacing: 0.06em;
}
.tag.kind-html {
  color: #c4f47c;
  border-color: rgba(196, 244, 124, 0.4);
  background: rgba(196, 244, 124, 0.08);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--fg-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty h2 {
  color: var(--fg);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent-line); background: var(--bg-hover); text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1306;
  font-weight: 600;
}
.btn-primary:hover { background: #ffb84a; border-color: #ffb84a; color: #1a1306; }
.btn-danger {
  color: var(--danger);
  border-color: rgba(229, 72, 77, 0.3);
}
.btn-ghost { background: transparent; }

/* Compact icon button used by inline row/card actions (delete, etc.).
   Appears on hover for the grid card, always-on for the list row so
   it's reachable on touch. */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 80ms ease, border-color 80ms ease, background 80ms ease;
}
.btn-icon:hover { color: var(--fg); border-color: var(--border-strong); }
.btn-icon-danger:hover {
  color: var(--danger);
  border-color: rgba(229, 72, 77, 0.4);
  background: rgba(229, 72, 77, 0.08);
}

/* Grid card: position the delete form on top of the card. The form is a
   sibling of <a class="card"> (forms can't legally be nested inside <a>)
   so we use card-wrap as the positioning context. */
.card-wrap { position: relative; }
.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  margin: 0;
  z-index: 2;
  opacity: 0;
  transition: opacity 100ms ease;
}
.card-wrap:hover .card-actions,
.card-actions:focus-within { opacity: 1; }
/* On touch devices there's no hover — keep it visible. */
@media (hover: none) {
  .card-actions { opacity: 0.7; }
}

/* List row actions: keep the cell narrow so it doesn't push everything
   else around. The td gets onclick=stopPropagation so clicking the
   button doesn't trigger the row navigation. */
.list-table .actions-col { width: 44px; padding: 6px 10px; text-align: right; }
.row-actions { margin: 0; display: inline-block; }

.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(245, 165, 36, 0.08), transparent);
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.auth-card .brand-mark {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.auth-card p {
  color: var(--fg-muted);
  margin: 0 0 20px;
}
.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input[type="email"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
  margin-bottom: 12px;
  box-sizing: border-box;
}
.auth-card input[type="text"]:focus,
.auth-card input[type="password"]:focus,
.auth-card input[type="email"]:focus {
  outline: none; border-color: var(--accent-line);
}
.auth-card .full { width: 100%; justify-content: center; }
.auth-card .error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

.viewer-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 54px);
  transition: grid-template-columns 180ms ease;
}
.viewer-layout.sidebar-collapsed {
  grid-template-columns: 32px 1fr;
}
.viewer-sidebar {
  position: relative;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 18px 16px;
  overflow-y: auto;
  max-height: calc(100vh - 54px);
}
.viewer-layout.sidebar-collapsed .viewer-sidebar {
  padding: 18px 0;
  overflow: hidden;
}
.viewer-layout.sidebar-collapsed .viewer-sidebar > *:not(.sidebar-toggle) {
  display: none;
}
.sidebar-toggle {
  position: absolute;
  top: 14px;
  right: 8px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-muted);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.sidebar-toggle:hover {
  color: var(--accent);
  border-color: var(--accent-line);
}
.viewer-layout.sidebar-collapsed .sidebar-toggle {
  right: 50%;
  transform: translateX(50%);
}
.viewer-sidebar h2 {
  font-size: 12px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 16px 0 6px;
  font-weight: 500;
}
.viewer-sidebar h2:first-child { margin-top: 0; }
.viewer-sidebar .pkg-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
}
.viewer-sidebar .pkg-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-muted);
  margin-bottom: 14px;
}
.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.file-list li a {
  display: block;
  padding: 4px 6px;
  border-radius: 4px;
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}
.file-list li a:hover { background: var(--bg-hover); color: var(--fg); text-decoration: none; }
.file-list li a.active { color: var(--accent); background: var(--accent-soft); }

.viewer-main {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.viewer-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-muted);
}
.viewer-frame {
  flex: 1;
  border: 0;
  background: var(--bg);
  color-scheme: dark;
  width: 100%;
}
.md-panel {
  padding: 24px;
  max-width: 780px;
  margin: 0 auto;
  overflow-y: auto;
}
.md-panel pre {
  background: var(--bg-card);
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
}
.md-panel code {
  background: var(--bg-soft);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg-soft);
  color: var(--fg-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.table tr:last-child td { border-bottom: 0; }
.table .mono { font-family: var(--mono); font-size: 12px; color: var(--fg-muted); }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
}
.panel h2 {
  font-size: 15px;
  margin: 0 0 14px;
  font-weight: 600;
}
.panel p.dim {
  color: var(--fg-muted);
  font-size: 13px;
  margin: 0 0 14px;
}

form.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
form.inline input, form.inline select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 13px;
}
form.inline input:focus, form.inline select:focus {
  outline: none; border-color: var(--accent-line);
}

/* Themed select — strip native chrome, apply our own chevron, match input look. */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%239a968d' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 7px;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 30px 8px 10px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.2;
}
select:hover { border-color: var(--border-strong); }
select:focus {
  outline: none;
  border-color: var(--accent-line);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23f5a524' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
/* Inside option list — best-effort across browsers (Firefox respects, Chrome/Safari mostly don't). */
select option {
  background: var(--bg-card);
  color: var(--fg);
}

label.field-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  margin-right: 4px;
  display: block;
}

/* Stack: vertical form column with consistent spacing. */
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack > .field-label { margin: 6px 0 -2px; }

/* Field: themed input/select that fills its container. */
.field {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 13px;
  box-sizing: border-box;
}
.field:focus { outline: none; border-color: var(--accent-line); }
select.field {
  /* keep the chevron aware of full width */
  padding-right: 32px;
}

.kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-soft);
  color: var(--fg-muted);
}

.banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--fg);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  margin-bottom: 18px;
}
.banner .label {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
  display: block;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  color: var(--fg-muted);
  background: var(--bg-card);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}
.drop-zone input[type="file"] { display: none; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

.footer {
  margin-top: auto;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  text-align: center;
}

/* ---- Yawasa landing + portal ----------------------------------------- */

.splash-body {
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  font-family: var(--sans);
}

.splash-header {
  display: flex;
  justify-content: flex-end;
  padding: 20px 24px;
}

.splash-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.yawasa-logo {
  font-family: "Silkscreen", "JetBrains Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: clamp(3.5rem, 13vw, 9rem);
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-align: center;
  user-select: none;
  text-shadow:
    2px 2px 0 rgba(245, 165, 36, 0.18),
    -1px -1px 0 rgba(245, 165, 36, 0.18);
}

.splash-footer {
  text-align: center;
  padding: 24px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.18em;
}

.burger-wrap { position: relative; }
.burger {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 18px;
  font-family: var(--mono);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.burger:hover { color: var(--fg); border-color: var(--border-strong); }
.burger:focus { outline: none; border-color: var(--accent-line); }
.burger-menu {
  position: absolute;
  top: 48px;
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px;
  display: none;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
.burger-menu.show { display: flex; flex-direction: column; gap: 1px; }
.burger-menu a,
.burger-menu button {
  display: block;
  padding: 9px 12px;
  color: var(--fg);
  text-decoration: none;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--sans);
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
}
.burger-menu a:hover,
.burger-menu button:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: var(--accent);
}

.portal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
}
.portal-brand {
  font-family: "Silkscreen", "JetBrains Mono", ui-monospace, monospace;
  font-weight: 700;
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 0.05em;
}
.portal-main {
  flex: 1;
  padding: 56px 32px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}
.portal-greeting {
  font-size: 26px;
  color: var(--fg);
  margin-bottom: 32px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.portal-greeting .dim { color: var(--fg-muted); font-weight: 400; }

.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.service-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: var(--fg);
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.service-tile:hover {
  border-color: var(--accent-line);
  text-decoration: none;
  transform: translateY(-1px);
}
.service-tile-icon {
  width: 28px;
  height: 28px;
  margin-bottom: 8px;
  color: var(--accent);
}
.service-tile-title { font-weight: 600; font-size: 15px; }
.service-tile-desc { color: var(--fg-muted); font-size: 12px; line-height: 1.5; }

.site-footer {
  margin-top: auto;
  padding: 28px 32px 36px;
  border-top: 1px solid var(--border);
  background: rgba(14, 17, 22, 0.6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
}
.site-footer .left { display: flex; align-items: center; gap: 10px; }
.site-footer .left .mark {
  width: 18px;
  height: 18px;
  border: 1px solid var(--accent-line);
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 9px;
  font-weight: 600;
}
.site-footer .copy { color: var(--fg-dim); }
.site-footer .copy strong { color: var(--fg); font-weight: 600; }
.site-footer .right { color: var(--fg-muted); font-size: 10px; }
@media (max-width: 600px) {
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    padding: 22px 18px 28px;
  }
}

.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 11px;
  text-decoration: none;
  cursor: pointer;
}
.tag-pill:hover { color: var(--fg); border-color: var(--border-strong); text-decoration: none; }
.tag-pill.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.tag-pill-count {
  font-size: 10px;
  color: var(--fg-dim);
  font-weight: 500;
}
.tag-pill.active .tag-pill-count { color: var(--accent); opacity: 0.7; }

.tag-link {
  cursor: pointer;
  text-decoration: none;
}
.tag-link:hover {
  border-color: var(--accent-line);
  color: var(--accent);
}

.layout-toggle { display: inline-flex; gap: 4px; }

/* Multi-select checkboxes + sticky action bar */
.multiselect-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-card);
  cursor: pointer;
  position: relative;
  margin: 0;
  flex: 0 0 18px;
}
.multiselect-cb:hover { border-color: var(--accent-line); }
.multiselect-cb:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.multiselect-cb:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
/* Indeterminate state — horizontal bar instead of checkmark. Browsers
   don't trigger :checked when :indeterminate, so this overrides the empty
   state and replaces (via the more specific selector ordering below). */
.multiselect-cb:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}
.multiselect-cb:indeterminate::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--bg);
  border: none;
  transform: none;
  width: auto;
}
.card-wrap > .multiselect-cb {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  /* Don't set background here — equal specificity to :checked / :indeterminate
     would override the amber-fill of the selected state. The base rule
     already gives an unchecked checkbox its bg-card chip. */
  box-shadow: 0 0 0 2px var(--bg-card);
}
/* Checkbox column — header AND body, identical widths. */
.list-table th.multiselect-cb-col,
.list-table td.multiselect-cb-cell {
  width: 36px;
  min-width: 36px;
  padding: 8px 6px 8px 12px;
  text-align: left;
}
/* Icon column — class on both header and body for matched widths. */
.list-table th.icon-col,
.list-table td.icon-col {
  width: 32px;
  min-width: 32px;
  padding-right: 4px;
}

/* Page-header select-all wrapper (grid view). */
.multiselect-all-label {
  display: inline-flex;
  align-items: center;
  margin-right: 12px;
}
.list-row.selected,
.card-wrap.selected > .card {
  border-color: var(--accent);
  background: rgba(245, 165, 36, 0.05);
}

.multiselect-bar {
  position: sticky;
  top: 54px; /* below topbar */
  z-index: 30;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.multiselect-bar.show { display: flex; }
.multiselect-summary {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  padding-right: 6px;
}

/* Kebab trigger button */
.kebab {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kebab:hover { background: var(--bg-hover); color: var(--fg); border-color: var(--border); }
.kebab:focus { outline: none; border-color: var(--accent-line); }
.card-wrap { position: relative; }
.card-wrap > .kebab,
.card .kebab {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}
.card { position: relative; }

/* Menu popover */
.kebab-menu {
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  padding: 4px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.kebab-menu button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.kebab-menu button:hover { background: var(--bg-hover); }
.kebab-menu button.danger { color: var(--danger); }
.kebab-menu button.danger:hover { background: rgba(229, 72, 77, 0.1); }
.kebab-sep {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.list-table { width: 100%; }
.list-table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  padding: 8px 10px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  white-space: nowrap;
}
.list-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.list-table td.title-col { white-space: normal; min-width: 240px; }
.list-row { transition: background 80ms ease; }
.list-row:hover { background: var(--bg-hover); }
.list-row td.title-col { color: var(--fg); }
.list-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
  border-radius: 3px;
}

.tabs { display: flex; gap: 6px; }
.tab {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}
.tab:hover { color: var(--fg); background: var(--bg-hover); text-decoration: none; }
.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  margin: 2px 4px 2px 0;
}
.chip .x {
  cursor: pointer;
  color: var(--fg-muted);
  font-weight: bold;
  background: none;
  border: none;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.chip .x:hover { color: var(--danger); }

.typeahead { position: relative; }
.typeahead-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}
.typeahead-results.show { display: block; }
.typeahead-result {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.typeahead-result:last-child { border-bottom: none; }
.typeahead-result:hover, .typeahead-result.focused {
  background: var(--bg-hover);
  color: var(--accent);
}
.typeahead-result .role-tag {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-dim);
  margin-left: 6px;
}

/* ---- Folders --------------------------------------------------------- */

.folder-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.folder-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  flex-wrap: wrap;
}
.breadcrumb-link {
  color: var(--fg-muted);
  padding: 2px 4px;
  border-radius: 4px;
}
.breadcrumb-link:hover {
  color: var(--accent);
  background: var(--bg-hover);
  text-decoration: none;
}
.breadcrumb-current {
  color: var(--fg);
  padding: 2px 4px;
}
.breadcrumb-sep {
  color: var(--fg-dim);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.folder-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px 14px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.folder-card:hover {
  border-color: var(--accent-line);
  transform: translateY(-1px);
  text-decoration: none;
}
.folder-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}
.folder-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.folder-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.005em;
  word-break: break-word;
}
.folder-shared {
  font-family: var(--mono);
  color: var(--fg-muted);
}
.folder-kebab {
  position: absolute;
  top: 6px;
  right: 6px;
}
.folder-card-unpublished {
  border-style: dashed;
  border-color: var(--accent-line);
  background: linear-gradient(180deg, rgba(245, 165, 36, 0.04), var(--bg-card));
}
.folder-card-unpublished .folder-icon { color: var(--accent); }
.folder-card-unpublished .folder-name::after {
  content: " · drafts";
  color: var(--fg-dim);
  font-weight: 400;
  font-size: 11px;
  font-family: var(--mono);
}

/* ---- Modal (folder picker, share, etc.) ----------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  animation: modal-fade 120ms ease-out;
}
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-title {
  font-size: 14px;
  font-weight: 600;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--bg-soft);
}

/* ---- Folder picker (used inside modal) ------------------------------ */

.folder-picker {
  display: flex;
  flex-direction: column;
}
.folder-picker-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.folder-picker-row {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 8px 12px;
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.folder-picker-row:last-child { border-bottom: none; }
.folder-picker-row:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

/* ---- Share modal chips ---------------------------------------------- */

.share-typeahead .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
  margin-bottom: 8px;
}
.share-typeahead .typeahead-results {
  position: static;
  margin-top: 4px;
}
