:root {
  --bg: #14181c;
  --bg-elevated: #1c2228;
  --surface: #f3f5f4;
  --ink: #1a1f24;
  --ink-muted: #5a6570;
  --accent: #2f6f5e;
  --accent-hover: #265a4c;
  --danger: #9b3b3b;
  --border: #d7ddd9;
  --radius: 10px;
  --font-sans: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Songti SC", Georgia, "STSong", serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #243038 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1e2a28 0%, transparent 50%),
    var(--bg);
  line-height: 1.55;
  overflow-x: hidden;
}

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

a:hover {
  text-decoration: underline;
}

.shell {
  max-width: 1100px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.shell-embed {
  max-width: min(1400px, 100%);
  height: 100vh;
  height: 100dvh;
  padding-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.shell-embed .topbar {
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.panel-embed {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  overflow: hidden;
}

.tools-embed-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.65rem;
  flex-shrink: 0;
}

.tools-embed-frame {
  flex: 1;
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  color: #e8eeea;
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.25rem;
  min-width: 0;
}

.module-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.module-nav a {
  color: #c9d5cf;
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
}

.module-nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.module-nav a.active {
  background: rgba(89, 168, 140, 0.25);
  color: #9ed9c2;
}

.portal-hero h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 0.4rem;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 1.25rem;
}

.module-card {
  display: block;
  padding: 1.15rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.module-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-2px);
  color: inherit;
}

.module-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.45rem;
}

.module-card h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 0;
}

.module-card p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.module-badge {
  font-size: 0.72rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: #dfeaE4;
  color: #2f4f44;
}

.portal-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.link-section {
  margin-bottom: 1.5rem;
}

.link-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.link-section-head h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0;
}

.link-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.link-list li {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
  border-top: 1px solid var(--border);
}

.link-list li:first-child {
  border-top: none;
}

.link-main {
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.link-main:hover {
  text-decoration: none;
}

.link-main strong {
  color: var(--ink);
}

.link-url {
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}

.link-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-shrink: 0;
}

.link-actions a,
.link-actions button {
  background: none;
  border: none;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.link-actions a:hover,
.link-actions button:hover {
  color: var(--accent);
}

.btn.ghost-ink {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.btn.ghost-ink:hover {
  background: #e8ece9;
  color: var(--ink);
}

.nav-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  align-items: center;
  flex-shrink: 0;
}

.nav-more {
  position: relative;
}

.nav-more-toggle::after {
  content: "▾";
  margin-left: 0.25rem;
  font-size: 0.75em;
  opacity: 0.85;
}

.nav-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 10.5rem;
  padding: 0.35rem;
  background: #1a2420;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-more-menu[hidden] {
  display: none;
}

.nav-more-menu a,
.nav-more-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #e7eeea;
  font: inherit;
  font-size: 0.88rem;
  padding: 0.5rem 0.65rem;
  border-radius: 7px;
  text-decoration: none;
  cursor: pointer;
}

.nav-more-menu a:hover,
.nav-more-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-more-menu form {
  margin: 0;
}

.nav-more-sep {
  height: 1px;
  margin: 0.25rem 0.35rem;
  background: rgba(255, 255, 255, 0.12);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #c9d5cf;
  white-space: nowrap;
}

.badge.unlocked {
  border-color: rgba(89, 168, 140, 0.55);
  color: #9ed9c2;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.4rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  max-width: 100%;
  min-width: 0;
}

.panel h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.7rem;
  margin: 0 0 0.4rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.lead {
  color: var(--ink-muted);
  margin: 0 0 1.25rem;
}

/* —— 登录页：居中窄卡片，避免输入框横贯整屏 —— */
.shell-login {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 1.25rem;
  padding-bottom: 2rem;
}

.shell-login .topbar {
  display: none;
}

.panel-login {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 1.4rem;
}

.login-layout {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.login-brand {
  text-align: center;
}

.login-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.login-brand h1 {
  margin: 0 0 0.35rem;
  font-size: 1.85rem;
  text-align: center;
}

.login-brand .lead {
  margin: 0;
  font-size: 0.92rem;
}

.login-quote-box {
  margin: 0;
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.login-quote {
  margin: 0;
  min-height: 2.8em;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.login-quote.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.login-form .form-row {
  margin-bottom: 0.85rem;
}

.login-form .form-row input {
  max-width: 100%;
}

.login-actions {
  margin-top: 0.35rem;
}

.login-submit {
  width: 100%;
  padding: 0.7rem 1rem;
  font-weight: 600;
}

.login-policy {
  margin: 0.15rem 0 0;
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.login-policy summary {
  cursor: pointer;
  list-style: none;
  color: var(--ink-muted);
  user-select: none;
}

.login-policy summary::-webkit-details-marker {
  display: none;
}

.login-policy summary::before {
  content: "▸ ";
  color: var(--accent);
}

.login-policy[open] summary::before {
  content: "▾ ";
}

.login-policy p {
  margin: 0.55rem 0 0;
  line-height: 1.5;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.messages li {
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  background: #e7efeb;
  color: var(--ink);
}

.messages li.error {
  background: #f3e2e2;
  color: #6d2c2c;
}

.messages li.success {
  background: #dff0e8;
}

.messages li.info {
  background: #e3eaf1;
}

.form-row {
  margin-bottom: 1rem;
}

.form-row label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.form-row input[type="text"],
.form-row input[type="password"],
.form-row input[type="username"],
.form-row textarea,
.form-row input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.form-row textarea {
  resize: vertical;
  min-height: 220px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
}

.helptext,
.form-row .helptext {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.errorlist {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: #fff;
}

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: #e8ece9;
  color: var(--ink);
}

.btn.danger {
  background: var(--danger);
}

.btn.ghost {
  background: transparent;
  color: #d7e0db;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.1rem;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
}

.search-form input {
  flex: 1;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.note-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.note-list li {
  border-top: 1px solid var(--border);
}

.note-list li:first-child {
  border-top: none;
}

.note-list a.note-link {
  display: block;
  padding: 0.95rem 0.15rem;
  color: inherit;
  text-decoration: none;
}

.note-list a.note-link:hover {
  background: rgba(47, 111, 94, 0.06);
}

.note-title {
  font-weight: 600;
  margin: 0 0 0.2rem;
}

.note-meta {
  font-size: 0.82rem;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.vault-note {
  max-width: 100%;
  min-width: 0;
}

.vault-note-body {
  max-width: 100%;
  min-width: 0;
}

.category-pill {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #dfeaE4;
  color: #2f4f44;
  font-size: 0.75rem;
}

.attach-pill {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #e8eef4;
  color: #3a4f66;
  font-size: 0.75rem;
}

.prose {
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  min-width: 0;
  font-size: 1rem;
  line-height: 1.7;
  margin-top: 1.25rem;
  color: var(--ink);
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.4em 0 0.5em;
}

.prose h1 { font-size: 1.45rem; }
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.1rem; }

.prose p {
  margin: 0 0 0.9em;
}

.prose ul,
.prose ol {
  margin: 0 0 0.9em;
  padding-left: 1.4em;
}

.prose li {
  margin: 0.25em 0;
}

.prose li > p {
  margin: 0.2em 0;
}

.prose blockquote {
  margin: 0 0 0.9em;
  padding: 0.35em 0 0.35em 0.9em;
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
}

.prose code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: #e7eeea;
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.prose pre {
  margin: 0 0 1em;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  background: #1a1f24;
  color: #e8eeea;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.prose pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.prose .table-wrap {
  margin: 0 0 1em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow-x: visible;
}

.prose table {
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* 首列为序号时仅占用内容宽度，其余列分配剩余空间 */
.prose table.has-index-col th:first-child,
.prose table.has-index-col td:first-child {
  width: 1%;
  white-space: nowrap;
  text-align: center;
  vertical-align: top;
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}

.prose th,
.prose td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.prose th {
  background: #e7eeea;
  font-weight: 600;
}

.prose tbody tr:nth-child(even) td {
  background: #f7faf8;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75em 0 1em;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.media-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 0.25rem 0 1rem;
}

.media-btn {
  cursor: pointer;
}

.file-panel {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.file-panel h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-list li {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}

.file-list li:first-child {
  border-top: none;
}

.file-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-info a {
  display: block;
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
}

.empty-files {
  color: var(--ink-muted);
  border-top: none !important;
}

.layout-with-aside {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.aside-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin: 0 0 0.55rem;
}

.aside-title + .template-nav {
  margin-top: 0;
}

.category-aside .aside-title:not(:first-child) {
  margin-top: 1.35rem;
}

.category-nav,
.template-nav {
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem;
}

.category-nav a,
.template-nav a,
.pill-link {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
}

.template-nav a {
  display: block;
}

.category-nav a:hover,
.template-nav a:hover,
.pill-link:hover {
  background: #e7eeea;
  text-decoration: none;
}

.category-nav a.active,
.pill-link.active {
  background: #dfeaE4;
  color: #2f4f44;
  font-weight: 600;
}

.category-nav .count {
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.filter-hint {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.template-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 1rem;
}

.pill-link {
  border: 1px solid var(--border);
  background: #fff;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.editor-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
}

.draft-status {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin: 0.5rem 0 1rem;
  min-height: 420px;
}

.editor-pane,
.preview-pane {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  overflow: hidden;
}

.pane-label {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #f3f6f4;
}

.editor-pane textarea {
  flex: 1;
  width: 100%;
  border: none !important;
  border-radius: 0 !important;
  resize: vertical;
  min-height: 360px;
  padding: 0.85rem 0.9rem !important;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

.preview-pane .prose {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 0.85rem 0.9rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #e7eeea;
}

.ua-cell {
  max-width: 220px;
  word-break: break-all;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.fail-pill {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #f3e2e2;
  color: #6d2c2c;
  font-size: 0.75rem;
}

/* Pygments / codehilite */
.prose .highlight {
  margin: 0 0 1em;
  border-radius: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  background: #1a1f24;
}

.prose .highlight pre {
  margin: 0;
  background: transparent;
  border-radius: 0;
}

.prose .highlight .hll { background-color: #49483e }
.prose .highlight .c { color: #75715e } /* Comment */
.prose .highlight .k { color: #66d9ef } /* Keyword */
.prose .highlight .n { color: #f8f8f2 }
.prose .highlight .o { color: #f92672 }
.prose .highlight .s { color: #e6db74 } /* String */
.prose .highlight .m { color: #ae81ff } /* Number */
.prose .highlight .na { color: #a6e22e }
.prose .highlight .nb { color: #f8f8f2 }
.prose .highlight .nc { color: #a6e22e }
.prose .highlight .nf { color: #a6e22e }
.prose .highlight .nn { color: #f8f8f2 }
.prose .highlight .nt { color: #f92672 }
.prose .highlight .nv { color: #f8f8f2 }
.prose .highlight .ow { color: #f92672 }
.prose .highlight .p { color: #f8f8f2 }
.prose .highlight .err { color: #f8f8f2 }

@media (max-width: 900px) {
  .layout-with-aside {
    grid-template-columns: 1fr;
  }

  .editor-split {
    grid-template-columns: 1fr;
  }
}

.warn-box {
  background: #fff6e8;
  border: 1px solid #ebd2a6;
  color: #6a4b1b;
  padding: 0.8rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.empty {
  color: var(--ink-muted);
  padding: 1.5rem 0;
}

.portal-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.35rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
  color: var(--ink-muted);
  background: #fff;
}

.status-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa5a0;
}

.status-chip.online .dot { background: #2f9b6a; }
.status-chip.online { color: #1f6b48; border-color: #b7e0cb; background: #eef8f2; }
.status-chip.offline .dot { background: #c45c5c; }
.status-chip.offline { color: #8a3535; border-color: #ecc4c4; background: #fbf0f0; }

.module-badge.ok { background: #dff3e8; color: #1f6b48; }
.module-badge.off { background: #f3e2e2; color: #8a3535; }

.dash-section { margin: 1.1rem 0 1.4rem; }

.dash-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.dash-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  background: #fff;
  min-height: 160px;
}

.dash-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.dash-panel-head h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin: 0;
}

.dash-panel-head a {
  font-size: 0.82rem;
}

.dash-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dash-list li {
  padding: 0.45rem 0;
  border-top: 1px solid var(--border);
}

.dash-list li:first-child { border-top: none; }

.dash-list a {
  display: block;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.dash-list a:hover { color: var(--accent); }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.stat {
  text-align: center;
  padding: 0.55rem 0.35rem;
  border-radius: 8px;
  background: #f3f6f4;
}

.stat strong {
  display: block;
  font-size: 1.25rem;
  font-family: var(--font-display);
}

.stat strong.warn { color: var(--danger); }

.stat span {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.empty-guide {
  padding: 1rem 0.15rem;
  color: var(--ink-muted);
}

.empty-guide p { margin: 0 0 0.75rem; }

.empty-guide .btn { margin-right: 0.4rem; margin-bottom: 0.4rem; }

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.22);
  color: #d7e0db;
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

html[data-theme="dark"] {
  --surface: #1c2421;
  --ink: #e8eeea;
  --ink-muted: #9aaca3;
  --border: #314038;
  --bg: #0d1210;
  --bg-elevated: #151c19;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(1000px 500px at 10% -10%, #1a2a24 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #15201c 0%, transparent 50%),
    var(--bg);
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .dash-panel,
html[data-theme="dark"] .link-list,
html[data-theme="dark"] .editor-pane,
html[data-theme="dark"] .preview-pane,
html[data-theme="dark"] .status-chip,
html[data-theme="dark"] .tool-group {
  background: var(--surface);
  color: var(--ink);
}

html[data-theme="dark"] .login-quote-box {
  background: color-mix(in srgb, var(--accent) 14%, #121916);
}

html[data-theme="dark"] .panel-login {
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] .form-row input,
html[data-theme="dark"] .form-row textarea,
html[data-theme="dark"] .search-form input {
  background: #121916;
  color: var(--ink);
  border-color: var(--border);
}

html[data-theme="dark"] .btn.secondary,
html[data-theme="dark"] .btn.ghost-ink {
  color: var(--ink);
  border-color: var(--border);
}

html[data-theme="dark"] .stat { background: #151d19; }
html[data-theme="dark"] .warn-box { background: #2a2418; border-color: #5a4a28; color: #e6d3a2; }
html[data-theme="dark"] .module-card { background: #1a221e; }
html[data-theme="dark"] .category-nav a:hover,
html[data-theme="dark"] .template-nav a:hover,
html[data-theme="dark"] .pill-link:hover { background: #243029; }
html[data-theme="dark"] .category-nav a.active,
html[data-theme="dark"] .pill-link.active { background: #2a3d34; color: #b7dec9; }

html[data-theme="dark"] .data-table th {
  background: #243029;
  color: #d7e6de;
  border-color: var(--border);
}

html[data-theme="dark"] .data-table td {
  color: var(--ink);
  border-color: var(--border);
}

html[data-theme="dark"] .data-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

html[data-theme="dark"] .ua-cell {
  color: var(--ink-muted);
}

html[data-theme="dark"] .prose th {
  background: #243029;
  color: #d7e6de;
}

html[data-theme="dark"] .tools-embed-frame {
  background: #121916;
  border-color: var(--border);
}


@media (max-width: 900px) {
  .dash-columns { grid-template-columns: 1fr; }
  .portal-hero { flex-direction: column; }
}

@media (max-width: 640px) {
  .shell {
    padding: 1rem 0.85rem 2rem;
  }

  .panel h1 {
    font-size: 1.35rem;
  }

  .note-meta {
    line-height: 1.5;
  }

  .prose table {
    font-size: 0.82rem;
  }

  .prose th,
  .prose td {
    padding: 0.4rem 0.5rem;
  }

  .prose pre,
  .prose .highlight {
    font-size: 0.82rem;
  }

  .shell-login {
    justify-content: flex-start;
    padding-top: 0.5rem;
  }

  .panel {
    padding: 1.15rem 1rem;
  }

  .panel-login {
    padding: 1.35rem 1.1rem 1.15rem;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .nav-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .nav-toggle { display: inline-flex; }

  .module-nav {
    display: none;
    width: 100%;
    flex-direction: column;
  }

  .module-nav.open { display: flex; }

  body.has-mobile-tabs .shell {
    padding-bottom: 4.5rem;
  }

  .mobile-tabs {
    display: flex;
  }

  .shell-embed ~ .mobile-tabs,
  body:has(.shell-embed) .mobile-tabs {
    display: none;
  }

  body:has(.shell-embed).has-mobile-tabs .shell {
    padding-bottom: 0;
  }
}

/* Mobile bottom tabs */
.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--panel, #fff);
  border-top: 1px solid var(--border, #e4e0d8);
  padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
  justify-content: space-around;
  gap: 0.25rem;
}
.mobile-tabs a {
  flex: 1;
  text-align: center;
  padding: 0.55rem 0.25rem;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--muted, #6b6560);
  border-radius: 8px;
}
.mobile-tabs a.active {
  color: var(--ink, #1c1917);
  background: var(--chip, #f0ebe3);
  font-weight: 600;
}

/* Command palette */
.command-palette {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 16, 12, 0.45);
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 1rem 1rem;
}
.command-palette.open {
  display: flex;
}
.command-palette-dialog {
  width: min(520px, 100%);
  background: var(--panel, #fff);
  border: 1px solid var(--border, #e4e0d8);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(20, 16, 12, 0.25);
  overflow: hidden;
}
.command-palette-dialog input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border, #e4e0d8);
  padding: 0.9rem 1rem;
  font: inherit;
  background: transparent;
  color: inherit;
  outline: none;
}
#command-palette-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  max-height: 320px;
  overflow: auto;
}
#command-palette-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}
#command-palette-list li.active,
#command-palette-list li:hover {
  background: var(--chip, #f0ebe3);
}
#command-palette-list .cmd-hint,
#command-palette-list .empty {
  color: var(--muted, #6b6560);
  font-size: 0.85rem;
}
.command-palette-hint {
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted, #6b6560);
}

.tag-pill {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  margin-right: 0.25rem;
  border-radius: 999px;
  background: var(--chip, #f0ebe3);
  font-size: 0.78rem;
  color: var(--muted, #6b6560);
}
.search-form-enhanced {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.search-form-enhanced select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border, #e4e0d8);
  background: var(--panel, #fff);
  color: inherit;
}
.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
