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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid #ddd;
  padding: 12px;
  background: #fafafa;
  display: flex;
  flex-direction: column;
}

#sidebar h1 {
  font-size: 16px;
  margin-bottom: 12px;
}

#doc-list {
  list-style: none;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

#me {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #ddd;
}

#me[hidden] {
  display: none;
}

#logout {
  margin-left: auto;
  border: none;
  background: none;
  font-size: 11px;
  color: #888;
  cursor: pointer;
  text-decoration: underline;
}

#logout:hover {
  color: #333;
}

#login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafaee;
  z-index: 10;
}

#login[hidden] {
  display: none;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 280px;
  padding: 24px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 30px #00000014;
}

#login-form h2 {
  font-size: 16px;
}

.login-hint {
  font-size: 12px;
  color: #666;
}

#login-name {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

#login-error {
  font-size: 12px;
  color: #c2352b;
}

#login-form button {
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: #2f7fd1;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#doc-list li {
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  overflow-wrap: anywhere;
}

#doc-list li:hover {
  background: #eee;
}

#doc-list li.active {
  background: #dbe9ff;
  font-weight: 600;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #ddd;
}

#doc-title {
  font-weight: 600;
  font-size: 14px;
}

#status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eee;
  color: #666;
}

#status[data-status='connected'] {
  background: #d9f2dd;
  color: #1a7f37;
}

#presence {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

#history-open {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #fff;
  color: #666;
  cursor: pointer;
}

#history-open:hover {
  background: #eee;
  color: #333;
}

#history {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafaee;
  z-index: 10;
}

#history[hidden] {
  display: none;
}

#history-panel {
  display: flex;
  flex-direction: column;
  width: min(900px, 92vw);
  height: 84vh;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 30px #00000014;
  overflow: hidden;
}

#history-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #ddd;
}

#history-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

#history-play {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #fff;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
}

#history-play:hover {
  background: #eee;
  color: #333;
}

#history-slider {
  flex: 1;
  min-width: 120px;
}

#history-pos {
  font-size: 11px;
  color: #666;
  white-space: nowrap;
}

#history-close {
  border: none;
  background: none;
  font-size: 13px;
  color: #888;
  cursor: pointer;
}

#history-close:hover {
  color: #333;
}

#history-editor {
  flex: 1;
  overflow: hidden;
}

#history-editor .cm-editor {
  height: 100%;
  font-size: 14px;
}

#history-editor .cm-scroller {
  overflow: auto;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  line-height: 1.6;
}

.peer {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 12px;
  color: #fff;
  white-space: nowrap;
}

#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

#editor {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

#preview-toggle {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #fff;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
}

#preview-toggle:hover {
  background: #eee;
  color: #333;
}

#preview-toggle.active {
  background: #dbe9ff;
  border-color: #2f7fd1;
  color: #2f7fd1;
}

#preview {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  border-left: 1px solid #ddd;
  padding: 16px 24px;
  font-size: 14px;
  line-height: 1.6;
}

#preview[hidden] {
  display: none;
}

#preview h1,
#preview h2,
#preview h3 {
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}

#preview p,
#preview ul,
#preview ol,
#preview pre,
#preview blockquote,
#preview table {
  margin: 0.5em 0;
}

#preview ul,
#preview ol {
  padding-left: 1.5em;
}

#preview code {
  background: #f2f2f2;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.9em;
}

#preview pre {
  background: #f7f7f7;
  border: 1px solid #eee;
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
}

#preview pre code {
  background: none;
  padding: 0;
}

#preview blockquote {
  border-left: 3px solid #ddd;
  padding-left: 10px;
  color: #666;
}

#preview table {
  border-collapse: collapse;
}

#preview th,
#preview td {
  border: 1px solid #ddd;
  padding: 4px 10px;
}

#preview pre.mermaid {
  background: none;
  border: none;
  text-align: center;
}

#preview pre.mermaid.mermaid-error {
  border: 1px dashed #c2352b;
  color: #c2352b;
  font-size: 12px;
  text-align: left;
}

#comment-add {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #fff;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
}

#comment-add:hover {
  background: #eee;
  color: #333;
}

#comment-add.nudge {
  animation: comment-nudge 0.3s ease-in-out 2;
  border-color: #c2352b;
  color: #c2352b;
}

@keyframes comment-nudge {
  25% {
    transform: translateX(-2px);
  }
  75% {
    transform: translateX(2px);
  }
}

#comments-panel {
  width: 290px;
  flex-shrink: 0;
  border-left: 1px solid #ddd;
  background: #fafafa;
  display: flex;
  flex-direction: column;
}

#comments-panel[hidden] {
  display: none;
}

#comments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #ddd;
  font-size: 13px;
  font-weight: 600;
}

#comments-filter {
  font-size: 11px;
  font-weight: 400;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}

#comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.comment-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
  font-size: 12px;
}

.comment-card.focused {
  border-color: #e0a82e;
  box-shadow: 0 0 0 2px #f8d47755;
}

.comment-card.resolved {
  opacity: 0.65;
}

.comment-quote {
  font-size: 11px;
  color: #666;
  border-left: 3px solid #f8d477;
  padding-left: 6px;
  margin-bottom: 8px;
  font-style: italic;
  overflow-wrap: anywhere;
}

.comment-entry {
  margin-bottom: 8px;
}

.comment-entry.reply {
  margin-left: 12px;
  padding-left: 8px;
  border-left: 2px solid #eee;
}

.comment-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.comment-head .peer {
  font-size: 10px;
  padding: 1px 8px;
}

.comment-time {
  font-size: 10px;
  color: #999;
  flex: 1;
}

.comment-body {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.comment-mention {
  color: #2f7fd1;
  font-weight: 600;
}

.comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.comment-btn {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  color: #555;
  cursor: pointer;
}

.comment-btn:hover {
  background: #eee;
}

.comment-btn.primary {
  background: #2f7fd1;
  border-color: #2f7fd1;
  color: #fff;
}

.comment-btn.subtle {
  border: none;
  background: none;
  color: #999;
  padding: 1px 4px;
  text-decoration: underline;
}

.comment-btn.subtle:hover {
  color: #333;
  background: none;
}

.comment-compose {
  position: relative;
}

.comment-compose textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}

.comment-reply {
  margin-top: 6px;
}

.comments-empty {
  font-size: 11px;
  color: #999;
  text-align: center;
  padding: 12px 0;
}

.mention-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 14px #00000022;
  z-index: 5;
  max-height: 140px;
  overflow-y: auto;
}

.mention-option {
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.mention-option:hover,
.mention-option.selected {
  background: #dbe9ff;
}

.mdio-comment {
  background: #f8d47740;
  border-bottom: 2px solid #e0a82e88;
  cursor: pointer;
}

.mdio-comment-focused {
  background: #f8d47788;
  border-bottom-color: #e0a82e;
}

#editor .cm-editor {
  height: 100%;
  font-size: 14px;
}

#editor .cm-scroller {
  overflow: auto;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  line-height: 1.6;
}

.mdio-remote-edit {
  background-color: var(--mdio-edit-bg, #88888833);
  border-radius: 2px;
  animation: mdio-edit-fade 2s ease-out forwards;
}

@keyframes mdio-edit-fade {
  0%,
  55% {
    background-color: var(--mdio-edit-bg, #88888833);
  }
  100% {
    background-color: transparent;
  }
}

.mdio-edit-badge {
  display: inline-block;
  font-size: 9px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  line-height: 1;
  padding: 2px 6px;
  margin-right: 4px;
  border-radius: 8px;
  color: #fff;
  vertical-align: text-top;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
  animation: mdio-edit-fade-badge 2s ease-out forwards;
}

@keyframes mdio-edit-fade-badge {
  0%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0.25;
  }
}
