:root {
  --bg: #f5f5f5;
  --card: #ffffff;
  --border: #e8e8e8;
  --text: #1a1a1a;
  --sub: #757575;
  --hint: #bdbdbd;
  --accent: #111111;
  --accent-soft: #f0f0f0;
  --accent-strong: #0f172a;
  --blue: #2563eb;
  --danger: #d32f2f;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 6px 18px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
}

.app-shell {
  display: flex;
  flex: 1;
  width: 100%;
  min-height: 100vh;
  min-height: 0;
  flex-direction: column;
}

.page {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.page.active {
  display: flex;
}

.node-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.node-summary {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: none;
  background: none;
  text-align: left;
  padding: 0;
  min-width: 0;
  cursor: pointer;
}

.node-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-subtitle {
  font-size: 12px;
  color: var(--sub);
  line-height: 1.4;
}

.node-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-bar-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.icon-btn,
.btn,
.nav-btn,
.term-key,
.fab,
.term-tab {
  border: none;
  cursor: pointer;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: transparent;
  color: var(--sub);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover,
.icon-btn:active {
  background: var(--accent-soft);
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent-strong);
  color: #ffffff;
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--text);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid #f2f2f2;
}

.list-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #f6f6f6;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.list-icon.folder {
  background: #eef2ff;
  color: #1d4ed8;
}

.list-icon.file {
  background: #f4f4f5;
}

.list-icon.link {
  background: #f5f3ff;
  color: #7c3aed;
}

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

.list-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-main-btn {
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.list-action {
  flex-shrink: 0;
}

.empty-state {
  margin: 20px 16px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--sub);
  line-height: 1.6;
}

.fab-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  background: linear-gradient(transparent, var(--bg) 26%);
  flex-shrink: 0;
}

.fab {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.fab-primary {
  background: var(--accent-strong);
  color: #ffffff;
}

.fab-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.editor-meta {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-area {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px 22px;
  background: var(--card);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.term-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.term-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--sub);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.term-tab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.term-tab.active {
  background: #e8eefc;
  color: #1d4ed8;
}

.term-tab-close {
  color: currentColor;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.72;
}

.term-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #111111;
}

.term-box {
  position: absolute;
  inset: 0;
  display: none;
}

.term-box.active {
  display: block;
}

.term-box .xterm,
.term-box .xterm-screen {
  height: 100%;
}

.term-box .xterm-viewport {
  overflow-y: auto !important;
}

.term-keys {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--card);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.term-key {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.bottom-nav {
  display: flex;
  height: 60px;
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.bottom-nav.hidden {
  display: none;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  color: var(--sub);
  font-size: 11px;
}

.nav-btn.active {
  color: var(--text);
}

.sheet-bg,
.dialog-bg {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  background: rgba(15, 23, 42, 0.32);
}

.sheet-bg.show,
.dialog-bg.show {
  display: flex;
}

.sheet {
  width: 100%;
  max-height: 72vh;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h3 {
  flex: 1;
  margin: 0;
  font-size: 16px;
}

.sheet-body {
  overflow-y: auto;
  padding: 8px 0;
}

.sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 18px;
  background: none;
  border: none;
  text-align: left;
  font-size: 14px;
  color: var(--text);
}

.sheet-row-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--sub);
}

.dialog-bg {
  align-items: center;
  padding: 18px;
}

.dialog {
  width: min(360px, 100%);
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.dialog h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.dialog p {
  margin: 0 0 12px;
  color: var(--sub);
  line-height: 1.5;
}

.dialog input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  outline: none;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: #111111;
  color: #ffffff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
}

.lucide {
  width: 18px;
  height: 18px;
  stroke-width: 2.1;
}

@media (min-width: 900px) {
  body {
    background: #ececec;
  }

  .app-shell {
    max-width: 1180px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
    background: var(--bg);
  }

  .fab-row {
    justify-content: flex-start;
  }

  .fab {
    flex: 0 0 auto;
    min-width: 180px;
  }
}
