/* N-Cloud — Swiss minimalist (light)
   Design system: neutral, gridded, single accent. */

:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F5F5F5;
  --ink: #0A0A0A;
  --text: #171717;
  --text-2: #525252;
  --text-3: #A3A3A3;
  --line: #EAEAEA;
  --line-2: #D4D4D4;
  --accent: #0066FF;
  --accent-soft: rgba(0, 102, 255, 0.08);
  --ok: #16A34A;
  --warn: #D97706;
  --danger: #DC2626;
  --shadow-pop: 0 8px 32px rgba(10, 10, 10, 0.08);
  --shadow-hover: 0 1px 2px rgba(0, 0, 0, 0.04);

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Consolas, monospace;

  --sidebar-w: 240px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button:disabled, .btn:disabled { cursor: not-allowed; opacity: 0.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--ink) !important;
  box-shadow: none !important;
}

.hidden { display: none !important; }
#spaceCards, #spaceSwitchMenu { display: none !important; }

.muted { color: var(--text-2); }
small.muted, .muted small { color: var(--text-3); }

/* ============== Typography helpers ============== */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 14px; line-height: 1.4; }
p { margin: 0; }

.eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ============== Buttons ============== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink); }
.btn.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn.primary:hover:not(:disabled) { background: #222; border-color: #222; }
.btn.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--line-2);
}
.btn.danger:hover:not(:disabled) { background: #FEF2F2; border-color: var(--danger); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

/* ============== Tags / pills ============== */
.tag, .pill, .role-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.tag.green { color: var(--ok); border-color: rgba(22, 163, 74, 0.3); background: rgba(22, 163, 74, 0.06); }
.tag.red { color: var(--danger); border-color: rgba(220, 38, 38, 0.3); background: rgba(220, 38, 38, 0.05); }
.tag.blue { color: var(--accent); border-color: rgba(0, 102, 255, 0.3); background: var(--accent-soft); }
.role-badge { font-family: var(--font); }

/* ============== Brand ============== */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .mark {
  width: 24px;
  height: 24px;
  background: var(--ink);
  color: #fff;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}
.brand-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-3);
  margin: 0;
  letter-spacing: 0.02em;
}

/* ============== Login screen ============== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  padding: 48px 24px;
  overflow: auto;
}
.login-screen.hidden { display: none; }

.login-brand,
.login-panel {
  width: 100%;
  max-width: 480px;
}

.login-brand {
  margin-bottom: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.login-copy h1 {
  font-size: 44px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}
.login-copy p {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 440px;
}
.login-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.login-metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.login-metric strong {
  font-size: 13px;
  color: var(--ink);
  font-weight: 600;
}
.login-metric span {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.form-title h2 {
  font-size: 16px;
  margin-bottom: 4px;
}
.form-title p {
  font-size: 13px;
  color: var(--text-2);
}

/* ============== Forms ============== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.field input,
.field select,
.field textarea,
input[type="search"],
input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: 13px;
  transition: border-color 0.12s;
}
.field textarea, textarea { min-height: 120px; padding: 10px 12px; line-height: 1.6; resize: vertical; height: auto; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--text-3); }
.field input::placeholder, textarea::placeholder { color: var(--text-3); }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.field-row {
  display: flex;
  gap: 8px;
}
.field-row input { min-width: 0; }
.field-row .btn {
  flex: 0 0 auto;
  height: 36px;
}
.check-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
}
.check-field input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}
.field-error {
  color: var(--danger);
  font-size: 11px;
  margin-top: 2px;
  min-height: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid .field.wide { grid-column: 1 / -1; }
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ============== App shell ============== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  position: relative;
  transition: background 0.12s, color 0.12s;
}
.nav button svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active {
  background: var(--surface-2);
  color: var(--ink);
}
.nav button.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--ink);
}

.project-switcher {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.project-switcher-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.project-switcher-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.project-switcher #projectSelect { display: none; }
.project-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
}
.tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  border: 0;
  cursor: pointer;
}
.tree-item:hover { background: var(--surface-2); color: var(--ink); }
.tree-item.active {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 500;
}
.tree-item .tag { flex-shrink: 0; }
#projectLink { font-size: 11px; color: var(--text-3); }

.storage {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.storage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.storage-head span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.storage-head strong {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  font-weight: 500;
}
.bar {
  height: 2px;
  background: var(--line);
  border-radius: 1px;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--ink);
  border-radius: 1px;
}
#sidebarStorageHint { font-size: 11px; color: var(--text-3); }

/* Main */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(0, 480px) auto;
  gap: 24px;
  align-items: center;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-title h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
}
.page-title p {
  font-size: 12px;
  color: var(--text-3);
  margin: 2px 0 0;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search svg {
  position: absolute;
  left: 12px;
  width: 14px;
  height: 14px;
  stroke: var(--text-3);
  stroke-width: 1.6;
  fill: none;
  pointer-events: none;
}
.search input {
  height: 36px;
  padding: 0 12px 0 36px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  width: 100%;
}
.search input:hover { background: #EEEEEE; }
.search input:focus { background: var(--surface); border-color: var(--ink); }

.search-panel {
  margin: 16px 32px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  position: sticky;
  top: calc(var(--topbar-h) + 12px);
  z-index: 9;
}
.search-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.search-panel-head strong {
  font-size: 14px;
  font-weight: 600;
}
.search-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}
.search-section {
  min-width: 0;
  background: var(--surface);
  padding: 14px;
}
.search-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.search-section-title strong {
  color: var(--text-3);
  font-weight: 500;
}
.search-result {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 10px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.search-result:hover,
.search-result:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.search-result span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result small {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

/* Content area */
.content {
  flex: 1;
  padding: 16px 24px 32px;
  min-width: 0;
}

.project-header { display: none; }
.stats { display: none; }

.switch-notice {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--r-md);
  font-size: 12px;
  margin-bottom: 16px;
}
.switch-notice.visible { display: inline-flex; }

/* Views */
.view { display: none; }
.view.active { display: block; }

/* ============== Workspaces (Files + Shares) ============== */
.workspace {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
.panel-head-tools { display: flex; gap: 8px; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
  min-width: 0;
}
.crumbs strong {
  color: var(--ink);
  font-weight: 600;
}
.crumbs span:not(strong) { color: var(--text-3); }

.folder-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.folder-bar button {
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  border: 1px solid transparent;
}
.folder-bar button:hover { background: var(--surface-2); color: var(--ink); }
.folder-bar button.active {
  background: var(--ink);
  color: #fff;
  font-weight: 500;
}
.folder-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: 2px;
}
.folder-actions .btn { height: 26px; padding: 0 8px; font-size: 11px; }

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}
.table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr { transition: background 0.1s; cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.selected { background: var(--accent-soft); }
.table tbody tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

.file-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
}
.file-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-2);
  flex-shrink: 0;
  text-transform: uppercase;
}

.drive-grid { display: none; }

.pagination {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
}
.pagination .actions { margin: 0; }
.pagination .btn { height: 28px; font-size: 12px; padding: 0 10px; }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  display: none;
}
.empty-state.active { display: block; }
.empty-state strong {
  display: block;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 4px;
}
.empty-state .muted { font-size: 13px; }

/* Side panel (files / shares right column) */
.side-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
}
.side-panel .preview {
  width: 56px;
  height: 56px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.side-panel .preview span { font-size: 22px; }

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--line);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.detail-row span { color: var(--text-3); font-size: 12px; }
.detail-row strong { color: var(--ink); font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }
.detail-actions { justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
.detail-actions .btn { flex: 0 0 auto; }
.file-detail-empty {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}
.file-detail-empty strong { color: var(--ink); font-weight: 500; font-size: 13px; }

/* Activity / recommendations */
.activity {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.audit-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.audit-item:last-child { border-bottom: 0; }
.audit-item strong {
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
}

/* ============== Knowledge ============== */
.kb-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  gap: 24px;
  align-items: start;
}
.doc-tree {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
}
.doc-tree-head h3 {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}
.kb-list { display: flex; flex-direction: column; gap: 2px; }
.kb-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
}
.kb-item strong {
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
}
.kb-item .muted { font-size: 11px; color: var(--text-3); }
.kb-item.active { background: var(--surface-2); }

.editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.editor-title {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.editor-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.editor-title-row input {
  flex: 1;
  height: auto;
  padding: 0;
  background: transparent;
  border: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.editor-title-row input:focus { outline: 0; border: 0; }
.doc-actions { display: flex; gap: 6px; }
.doc-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
  flex-wrap: wrap;
}
.doc-meta { display: flex; align-items: center; gap: 6px; }
.doc-state-line { display: flex; align-items: center; gap: 8px; }

.editor-toolbar { display: flex; align-items: center; }
.segmented {
  display: inline-flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
}
.segmented button {
  padding: 8px 12px;
  background: transparent;
  font-size: 13px;
  color: var(--text-3);
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s;
}
.segmented button.active {
  color: var(--ink);
  font-weight: 500;
  border-bottom-color: var(--ink);
}

.editor-body {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  background: var(--surface);
}
.editor.previewing .editor-body { display: none; }
.preview-doc { display: none; }
.preview-doc.active { display: block; }
.preview-doc, .markdown-body {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}
.preview-doc h1, .markdown-body h1 { font-size: 28px; margin: 24px 0 12px; }
.preview-doc h2, .markdown-body h2 { font-size: 20px; margin: 24px 0 12px; }
.preview-doc h3, .markdown-body h3 { font-size: 16px; margin: 20px 0 8px; }
.preview-doc p, .markdown-body p { margin: 12px 0; }
.preview-doc ul, .preview-doc ol, .markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 12px 0; }
.preview-doc code, .markdown-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}
.preview-doc pre, .markdown-body pre {
  background: var(--surface-2);
  padding: 16px;
  border-radius: var(--r-md);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
}

.outline {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  font-size: 12px;
}
.outline a {
  display: block;
  color: var(--text-2);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.outline a:hover { color: var(--ink); }
.outline-section-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 16px 0 8px;
}

/* ============== Shares ============== */
.share-toolbar {
  display: grid;
  grid-template-columns: 1fr 160px 160px;
  gap: 8px;
  margin-bottom: 16px;
}
.share-list-head {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr 80px;
  gap: 12px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 500;
}
.share-list { display: flex; flex-direction: column; }
.share-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr 80px;
  gap: 12px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  align-items: center;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.share-row:hover { background: var(--surface-2); }
.share-row.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.share-row > span:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
}
.share-row > span:first-child .file-icon { flex-shrink: 0; }
.share-row .muted { font-family: var(--mono); font-size: 11px; }

.share-detail-panel { gap: 12px; }
.share-detail-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ============== Admin ============== */
.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
.admin-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.section-title h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 16px;
}
.admin-segmented {
  margin-bottom: 16px;
  flex-shrink: 0;
}
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
}
.metric .label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.metric .value {
  font-size: 36px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-feature-settings: "tnum";
  line-height: 1.1;
}
.config-actions { display: flex; gap: 8px; }
.system-health {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--surface) 90%, var(--accent-soft));
}
.system-health > div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}
.system-health .muted { font-size: 12px; }

.admin-toolbar {
  display: grid;
  grid-template-columns: 1fr 160px 160px;
  gap: 8px;
  margin-bottom: 16px;
}
.admin-table tbody td .btn { margin-right: 4px; }
.audit { position: sticky; top: calc(var(--topbar-h) + 24px); }
.audit-head { margin-bottom: 8px; }
.audit-tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

/* ============== Modals ============== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.4);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-pop);
}
.modal.large { max-width: 720px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.modal-head h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}
.modal-head .muted { font-size: 12px; }

/* Login tabs inside admin login modal */
.login-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}
.login-tab {
  padding: 10px 14px;
  background: transparent;
  font-size: 13px;
  color: var(--text-3);
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
}
.login-tab.active {
  color: var(--ink);
  font-weight: 500;
  border-bottom-color: var(--ink);
}
.form { display: none; }
.form.active { display: flex; flex-direction: column; gap: 16px; }

/* Version list */
.version-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
}
.version-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.version-item strong { font-size: 13px; }
.version-item .markdown-body {
  max-height: 200px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.version-actions { justify-content: flex-start; }

/* Preview modal */
.preview-body {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: 16px;
  max-height: 70vh;
  overflow: auto;
}
.preview-empty {
  text-align: center;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.preview-empty strong { color: var(--ink); font-size: 14px; }

/* Danger modal */
.danger-copy {
  background: rgba(220, 38, 38, 0.05);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--danger);
}
.danger-copy strong { font-size: 13px; }
.danger-copy span { font-size: 12px; color: var(--text-2); }

/* ============== Share public page ============== */
.share-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.share-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.share-content h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}
.share-content .actions { justify-content: flex-start; margin-top: 12px; }

/* ============== Toast ============== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 24px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: var(--shadow-pop);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============== Responsive ============== */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .kb-layout { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .side-panel, .doc-tree, .outline, .audit { position: static; max-height: none; }
  .search-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav button.active::before { display: none; }
  .project-switcher, .storage { width: 100%; border-top: 1px solid var(--line); padding-top: 12px; }
  .topbar { grid-template-columns: 1fr; height: auto; padding: 12px 16px; }
  .search-panel { margin: 12px 16px 0; position: static; }
  .search-panel-head { align-items: flex-start; flex-direction: column; }
  .search-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .login-screen { padding: 24px 16px; }
  .login-copy h1 { font-size: 32px; }
  .share-toolbar, .admin-toolbar { grid-template-columns: 1fr; }
  .share-list-head, .share-row { grid-template-columns: 1fr; gap: 4px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Non-visual UX fixes: keep existing style, improve layout behavior. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.table-wrap .table {
  min-width: 720px;
}
.role-menu-wrap {
  position: relative;
  display: inline-flex;
}
.role-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 172px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  display: none;
}
.role-menu.active {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.role-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13px;
}
.role-menu button:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.role-menu button:last-child { color: var(--danger); }

@media (max-width: 720px) {
  .table-wrap { margin-inline: -16px; padding-inline: 16px; }
  .table-wrap .table { min-width: 680px; }
  .role-menu-wrap { width: 100%; }
  .role-menu-wrap > .btn { width: 100%; }
  .role-menu { left: 0; right: auto; width: min(240px, 100%); }
  .top-actions { align-items: stretch; }
}

/* Mobile usability pass: preserve current visual style while improving touch layout. */
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }
  .btn,
  .nav button,
  .segmented button,
  .role-menu button,
  .folder-bar button,
  .share-row { min-height: 40px; }

  .sidebar { align-items: stretch; }
  .sidebar > .brand { width: 100%; }
  .nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .nav button {
    justify-content: flex-start;
    height: 42px;
  }
  .project-list {
    max-height: 180px;
  }
  .tree-item {
    min-height: 40px;
    padding: 8px 10px;
  }

  .topbar {
    gap: 12px;
  }
  .page-title h1 {
    font-size: 18px;
  }
  .page-title p {
    line-height: 1.4;
  }
  .search input {
    height: 40px;
  }
  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    justify-content: stretch;
  }
  .top-actions > .role-badge,
  .top-actions > .pill,
  .top-actions > .role-menu-wrap,
  .top-actions > .btn {
    width: 100%;
  }
  .top-actions > .role-badge,
  .top-actions > .pill {
    justify-content: center;
  }
  .top-actions > .role-menu-wrap,
  .top-actions > .btn.primary {
    grid-column: 1 / -1;
  }

  .panel-head,
  .section-title,
  .system-health,
  .modal-head,
  .editor-title-row,
  .doc-meta-row {
    align-items: stretch;
    flex-direction: column;
  }
  .panel-head-tools,
  .config-actions,
  .doc-actions,
  .actions,
  .detail-actions,
  .version-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .panel-head-tools .btn,
  .config-actions .btn,
  .doc-actions .btn,
  .actions .btn,
  .detail-actions .btn,
  .version-actions .btn {
    width: 100%;
  }

  .folder-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 10px;
  }
  .folder-bar button {
    flex: 0 0 auto;
  }
  .folder-actions {
    display: none;
  }

  .side-panel .preview {
    width: 48px;
    height: 48px;
    font-size: 16px;
  }
  .detail-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .detail-row strong {
    max-width: 100%;
    text-align: left;
  }

  .editor-title-row input {
    width: 100%;
    font-size: 24px;
    line-height: 1.2;
  }
  .doc-meta,
  .doc-state-line {
    flex-wrap: wrap;
  }
  .editor-body {
    min-height: 360px;
  }
  .preview-doc.active,
  .markdown-body {
    overflow-wrap: anywhere;
  }
  .outline a {
    padding: 10px 0;
  }

  .share-toolbar,
  .admin-toolbar,
  .audit-tools {
    gap: 10px;
  }
  .share-row {
    padding: 12px 10px;
  }
  .share-row > span {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .share-row .muted {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .metric {
    padding: 12px 0;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }
  .pagination .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  .pagination .btn {
    width: 100%;
    height: 36px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 12px;
  }
  .modal {
    max-height: min(92vh, 760px);
    overflow: auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .modal.large {
    max-width: 100%;
  }
  .field-row {
    flex-wrap: wrap;
  }
  .field-row input {
    flex: 1 1 180px;
  }
  .field-row .btn {
    flex: 1 1 auto;
  }
  .login-metrics {
    gap: 12px;
  }
  .toast {
    width: calc(100% - 32px);
    text-align: center;
  }
}

@media (max-width: 420px) {
  .nav { grid-template-columns: 1fr; }
  .top-actions { grid-template-columns: 1fr; }
  .login-metrics { grid-template-columns: 1fr; }
  .table-wrap .table { min-width: 620px; }
}

/* Mobile card tables */
@media (max-width: 720px) {
  .table-wrap {
    margin-inline: 0;
    padding-inline: 0;
    overflow: visible;
  }
  .table-wrap .table {
    min-width: 0;
  }
  .table,
  .table thead,
  .table tbody,
  .table tr,
  .table td {
    display: block;
    width: 100%;
  }
  .table thead {
    display: none;
  }
  .table tbody tr {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    cursor: default;
  }
  .table tbody tr + tr {
    margin-top: 10px;
  }
  .table tbody tr:hover {
    background: var(--surface);
  }
  .table tbody tr.selected {
    background: var(--accent-soft);
  }
  .table tbody tr.selected td:first-child {
    box-shadow: none;
  }
  .table tbody td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  .table tbody td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }
  .table tbody td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-size: 12px;
    line-height: 1.8;
  }
  .table tbody td[colspan] {
    display: block;
  }
  .table tbody td[colspan]::before {
    content: none;
  }
  .table tbody td[data-label="名称"],
  .table tbody td[data-label="文件"],
  .table tbody td[data-label="项目空间"],
  .table tbody td[data-label="账号"] {
    grid-template-columns: 1fr;
    gap: 6px;
    padding-top: 0;
  }
  .table tbody td[data-label="名称"]::before,
  .table tbody td[data-label="文件"]::before,
  .table tbody td[data-label="项目空间"]::before,
  .table tbody td[data-label="账号"]::before {
    content: none;
  }
  .table tbody td[data-label="操作"] {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .table tbody td[data-label="操作"]::before {
    content: none;
  }
  .table tbody td[data-label="操作"] .btn {
    width: 100%;
    margin: 0 0 6px;
  }
  .table tbody td[data-label="操作"] .btn:last-child {
    margin-bottom: 0;
  }
  .file-cell {
    align-items: flex-start;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 420px) {
  .table-wrap .table { min-width: 0; }
  .table tbody td {
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 10px;
  }
}
