:root {
  --bg-app: #f3f5f8;
  --bg-sidebar: #1e293b;
  --text-sidebar: #e2e8f0;
  --text-sidebar-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e2e8f0;
  --paper-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid #0f172a;
}

.sidebar-header {
  padding: 18px 16px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #fff;
}

.brand-logo {
  font-size: 20px;
}

.sidebar-section-label {
  padding: 8px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-sidebar-muted);
  font-weight: 600;
}

.doc-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s ease;
  color: #cbd5e1;
}

.doc-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.doc-item.active {
  background-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.doc-item-main {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.doc-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.doc-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.doc-online-pill {
  font-size: 11px;
  background: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
}

.doc-item.active .doc-online-pill {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.doc-delete-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  padding: 0 4px;
  border-radius: 4px;
}

.doc-item:hover .doc-delete-btn {
  opacity: 1;
}

.doc-delete-btn:hover {
  color: #f87171;
  background: rgba(0, 0, 0, 0.2);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Main Area */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.topbar {
  height: 60px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.doc-title-input {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  background: transparent;
  width: 240px;
  transition: border-color 0.15s, background 0.15s;
}

.doc-title-input:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.doc-title-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.status-badge.connected {
  background: #ecfdf5;
  color: #047857;
}

.status-badge.disconnected {
  background: #fef2f2;
  color: #b91c1c;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.status-dot.offline {
  background: #ef4444;
}

.save-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.online-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.online-count-badge {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.online-users-list {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 3px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #e2e8f0;
  font-size: 12px;
  color: #1e293b;
}

.user-chip.is-self {
  cursor: pointer;
  border-color: #cbd5e1;
}

.user-chip.is-self:hover {
  background: #f1f5f9;
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Editor Workspace */
.editor-workspace {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px 32px;
}

.editor-paper {
  width: 100%;
  max-width: 900px;
  background: var(--paper-bg);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 150px);
  border: 1px solid var(--border);
}

.ql-toolbar.ql-snow {
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
  background: #f8fafc;
  border-radius: 12px 12px 0 0;
  padding: 10px 16px !important;
  position: sticky;
  top: 0;
  z-index: 10;
}

.ql-container.ql-snow {
  border: none !important;
  font-size: 16px;
  flex: 1;
  font-family: inherit;
}

.ql-editor {
  padding: 32px 48px !important;
  min-height: 520px;
  line-height: 1.75;
  color: #1e293b;
}

/* Quill Cursors Multi-user Styling */
.ql-cursors {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.ql-cursor {
  position: absolute;
}

.ql-cursor.hidden {
  display: none;
}

.ql-cursor-selections {
  position: absolute;
  top: 0;
  left: 0;
}

.ql-cursor-selection-block {
  position: absolute;
  opacity: 0.25;
}

.ql-cursor-caret-container {
  position: absolute;
  width: 2px;
}

.ql-cursor-caret {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
}

.ql-cursor-flag {
  position: absolute;
  bottom: 100%;
  left: -1px;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px 4px 4px 0;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 20;
}

.ql-cursor-flag-flap {
  display: none;
}

/* Statusbar */
.statusbar {
  height: 32px;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: #0f172a;
  color: #fff;
}

.btn-accent:hover {
  background: #334155;
}

.btn-outline {
  background: #fff;
  border-color: #cbd5e1;
  color: #334155;
}

.btn-outline:hover {
  background: #f8fafc;
}

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

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.modal-card.modal-lg {
  max-width: 560px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #64748b;
}

.modal-body {
  padding: 20px;
}

.modal-desc {
  font-size: 14px;
  color: #334155;
  line-height: 1.6;
  margin-bottom: 14px;
}

.modal-footer {
  padding: 12px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
}

.color-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.selected {
  border-color: #0f172a;
  transform: scale(1.15);
}

.lan-url-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.lan-url-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.lan-tag {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  background: #e2e8f0;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.lan-code {
  flex: 1;
  font-family: Consolas, monospace;
  font-size: 13px;
  color: var(--primary);
  word-break: break-all;
}

.lan-tip {
  font-size: 12px;
  color: #475569;
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
}
