:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1a1a2e;
  --muted: #8b949e;
  --accent: #4f8cff;
  --border: #e1e4e8;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft Yahei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.nav-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.nav-header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-tab:disabled {
  opacity: 1;
}

.nav-tab:hover:not(:disabled) {
  color: var(--text);
  background: var(--bg);
}

.nav-tab:active:not(:disabled) {
  transform: scale(.96);
}

.nav-tab.active {
  color: var(--accent);
  background: rgba(79,140,255,.08);
  cursor: default;
}

.nav-sub-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
}

.nav-sub-tab {
  padding: 4px 12px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.nav-sub-tab:hover:not(.active) {
  color: var(--text);
}

.nav-sub-tab:active:not(.active) {
  transform: scale(.96);
}

.nav-sub-tab.active {
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.nav-header-right {
  display: flex;
  align-items: center;
}

.card-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: all .2s;
}

.card-count.filtering {
  color: var(--accent);
  background: rgba(79,140,255,.08);
  border-color: rgba(79,140,255,.25);
}

.nav-main {
  margin: 0 auto;
  padding: 16px 16px 24px;
  min-height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 769px) {
  .nav-main {
    column-count: 2;
    column-gap: 12px;
    display: block;
    margin-right: 244px;
  }
}

@media (min-width: 1100px) {
  .nav-main {
    column-count: 3;
  }
}

@media (min-width: 1500px) {
  .nav-main {
    column-count: 4;
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 20px;
  color: var(--muted);
  text-align: center;
  grid-column: 1 / -1;
  column-span: all;
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-hint { font-size: 13px; line-height: 1.8; }

.bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  break-inside: avoid;
  margin-bottom: 10px;
  position: relative;
  transition: box-shadow .2s;
  animation: bubbleIn .25s ease-out;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.bubble.dragging {
  opacity: .25;
  border: 2px dashed var(--border);
  background: transparent;
  box-shadow: none;
}

.drag-clone {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: .92;
  transform: rotate(1.5deg) scale(1.03);
  box-shadow: 0 12px 40px rgba(0,0,0,.18), 0 0 0 1px rgba(79,140,255,.3);
  border-radius: var(--radius);
  transition: none;
}

.drag-gap {
  background: rgba(79,140,255,.08);
  border: 2px dashed rgba(79,140,255,.35);
  border-radius: var(--radius);
  margin-bottom: 10px;
  break-inside: avoid;
  transition: height .15s ease, opacity .15s ease;
  overflow: hidden;
}

.drag-gap.card-gap {
  height: 40px;
}

.drag-gap.link-gap {
  height: 34px;
  margin-top: 4px;
  margin-bottom: 4px;
  border-radius: 10px;
}

.bubble-card-drag {
  color: var(--muted);
  font-size: 16px;
  cursor: grab;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
  padding: 4px 2px;
  margin: -4px -2px;
}

.bubble:hover .bubble-card-drag { opacity: .5; }
.bubble-card-drag:hover { opacity: 1 !important; }
.bubble-card-drag:active { cursor: grabbing; }

.bubble-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.bubble-note {
  flex: 1;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.bubble-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .2s;
  flex-shrink: 0;
}

.bubble:hover .bubble-actions { opacity: 1; }

.bubble-action-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.bubble-action-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.bubble-edit-pin,
.bubble-edit-delete {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
}

.bubble-edit-pin:hover {
  color: var(--accent);
  border-color: rgba(79,140,255,.35);
  background: rgba(79,140,255,.06);
}

.bubble-edit-pin.pinned {
  color: var(--accent);
  border-color: rgba(79,140,255,.35);
  background: rgba(79,140,255,.08);
}

.bubble-edit-delete:hover {
  background: #fff0f0;
  color: #e74c3c;
  border-color: rgba(231,76,60,.35);
}

.bubble-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  background: var(--bg);
  transition: background .15s, box-shadow .15s, opacity .15s;
  min-width: 0;
}

.bubble-link a {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.bubble-link:hover {
  background: rgba(79,140,255,.06);
  box-shadow: 0 1px 4px rgba(79,140,255,.1);
}

.bubble-link.dragging {
  opacity: .25;
  border: 1px dashed var(--border);
  background: transparent;
  box-shadow: none;
}

.link-drag-clone {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: .92;
  transform: rotate(1deg) scale(1.03);
  box-shadow: 0 8px 24px rgba(0,0,0,.15), 0 0 0 1px rgba(79,140,255,.3);
  border-radius: 10px;
  background: var(--bg);
  transition: none;
}

.bubble-link-drag {
  color: var(--muted);
  font-size: 14px;
  cursor: grab;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.bubble.editing .bubble-link-drag {
  opacity: .5;
  pointer-events: auto;
}

.bubble.editing .bubble-link-drag:hover { opacity: 1 !important; }
.bubble.editing .bubble-link-drag:active { cursor: grabbing; }

.bubble-link-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bubble-link-icon img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.bubble-link-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.bubble-link-arrow {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 11px;
}

.bubble-time {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  opacity: .7;
}

.bubble-edit-area {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.bubble-edit-area.show { display: block; }

.bubble-edit-area textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 40px;
  transition: border-color .2s;
}

.bubble-edit-area textarea:focus { border-color: var(--accent); }

.bubble-edit-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-edit-link-item {
  display: flex;
  gap: 6px;
  align-items: center;
  transition: opacity .15s;
}

.edit-link-drag {
  color: var(--muted);
  font-size: 14px;
  cursor: grab;
  opacity: .5;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
  transition: opacity .15s;
}

.edit-link-drag:hover { opacity: 1; }
.edit-link-drag:active { cursor: grabbing; }

.bubble-edit-link-item.dragging {
  opacity: .25;
}

.edit-link-drag-clone {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: .92;
  transform: rotate(1deg) scale(1.03);
  box-shadow: 0 8px 24px rgba(0,0,0,.15), 0 0 0 1px rgba(79,140,255,.3);
  border-radius: 6px;
  background: var(--panel);
  padding: 4px 8px;
  transition: none;
}

.edit-drag-gap {
  background: rgba(79,140,255,.08);
  border: 2px dashed rgba(79,140,255,.35);
  border-radius: 6px;
  height: 34px;
  transition: height .15s ease, opacity .15s ease;
}

.bubble-edit-link-item input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  min-width: 0;
  transition: border-color .2s;
}

.bubble-edit-link-item input:focus { border-color: var(--accent); }

.bubble-edit-link-item .name-input { flex: 0 0 80px; }

.bubble-edit-link-remove {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bubble-edit-link-remove:hover { background: #fff0f0; color: #e74c3c; }

.bubble-edit-add-link {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  margin-top: 4px;
  transition: all .2s;
}

.bubble-edit-add-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.bubble-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

.bubble-edit-actions button {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}

.bubble-edit-cancel {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border) !important;
}

.bubble-edit-cancel:hover { background: var(--border); }

.bubble-edit-save {
  background: var(--accent);
  color: #fff;
}

.bubble-edit-save:hover { background: #3d7be8; }

.composer {
  position: fixed;
  top: 52px;
  right: 12px;
  bottom: 12px;
  width: 220px;
  z-index: 100;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 16px rgba(0,0,0,.06);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  border-left: 3px solid transparent;
}

.composer:hover {
  border-left-color: var(--accent);
}

.composer.searching {
  border-color: rgba(79,140,255,.25);
  border-left-color: var(--accent);
  box-shadow: 0 2px 16px rgba(0,0,0,.06), 0 0 0 1px rgba(79,140,255,.1);
}

.composer.resizing {
  border-left-color: var(--accent);
  user-select: none;
}

.composer-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
  min-height: 0;
}

.input-row {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
  min-height: 0;
}

.input-row textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 60px;
  line-height: 1.5;
  transition: border-color .2s, box-shadow .2s;
}

.input-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.1);
}

.input-row textarea::placeholder { color: var(--muted); }

.send-btn {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  transition: background .2s, transform .15s;
}

.send-btn:hover { background: #3d7be8; transform: scale(1.02); }

.send-btn:active { transform: scale(.97); }

.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: var(--text);
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
  .nav-header { padding: 0 12px; }
  .nav-tabs { display: none; }
  .nav-sub-tabs { font-size: 11px; }
  .nav-sub-tab { padding: 3px 10px; }
  .nav-main { padding: 12px 12px 100px; margin-right: 0; }

  .composer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    border-radius: 0;
    border-top: 1px solid var(--border);
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .composer-inner { gap: 0; }

  .input-row {
    flex-direction: row;
    align-items: flex-end;
  }

  .input-row textarea {
    min-height: 40px;
    max-height: 100px;
    border-radius: 20px;
    padding: 9px 14px;
  }

  .send-btn {
    width: 40px;
    border-radius: 50%;
    font-size: 0;
    gap: 0;
  }
}
