:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --ink: #17202a;
  --muted: #637083;
  --line: #d8dee8;
  --panel: #ffffff;
  --accent: #166534;
  --accent-strong: #14532d;
  --danger: #b42318;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1,
h2,
p {
  margin-top: 0;
}

.topbar h1 {
  margin-bottom: 4px;
  font-size: 20px;
  line-height: 1.2;
}

.topbar p,
.status,
.hint,
label,
.commit-date,
.commit-files {
  color: var(--muted);
  font-size: 13px;
}

.actions,
.toolbar,
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: #aeb8c8;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  height: calc(100vh - 77px);
  padding: 18px;
}

.workspace,
.side {
  min-height: 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.toolbar {
  flex-wrap: wrap;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.toolbar button {
  min-width: 42px;
  padding: 0 10px;
}

.editor {
  overflow: auto;
  padding: 38px 46px;
  outline: none;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.62;
  background: #fff;
}

.editor[contenteditable="false"] {
  background: #fcfcfd;
}

.editor article {
  max-width: 820px;
  margin: 0 auto 60px;
}

.editor h1 {
  font-size: 32px;
  line-height: 1.2;
  text-align: center;
}

.editor h2 {
  margin-top: 32px;
  font-size: 24px;
}

.editor img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 18px auto;
}

.side {
  display: grid;
  grid-template-rows: auto minmax(160px, 0.9fr) minmax(180px, 1fr) minmax(140px, 0.55fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 15px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--accent);
}

.hint {
  margin: -2px 0 12px;
  line-height: 1.4;
}

.history-panel,
.comments-panel,
.thread-panel {
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.history,
.comments,
.thread-notes {
  height: calc(100% - 46px);
  overflow: auto;
  padding-right: 4px;
}

.commit {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.commit:first-child {
  border-top: 0;
}

.thread-note {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.thread-note:first-child {
  border-top: 0;
}

.commit-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-weight: 700;
}

.commit-title code {
  color: var(--accent);
}

.commit-message {
  margin-bottom: 4px;
}

.commit-files {
  white-space: pre-wrap;
}

.thread-note-body {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.comment-marker {
  border-bottom: 2px solid #d97706;
  background: #fef3c7;
  cursor: pointer;
  transition: background-color 0.18s ease, box-shadow 0.18s ease;
}

.comment-marker-resolved {
  border-bottom-color: #94a3b8;
  background: #e5e7eb;
}

.comment-marker-active {
  background: #fde68a;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.28);
}

.comment-card {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.comment-card:first-child {
  border-top: 0;
}

.comment-card.is-active {
  margin: 0 -8px;
  padding: 12px 8px;
  border-radius: 7px;
  background: #f8fafc;
}

.comment-card.is-resolved {
  opacity: 0.72;
}

.comment-jump {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  width: 100%;
  height: auto;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
}

.comment-jump:hover {
  border-color: transparent;
}

.comment-status {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.is-resolved .comment-status {
  color: var(--muted);
}

.comment-date {
  color: var(--muted);
  font-size: 12px;
}

.comment-jump q {
  grid-column: 1 / -1;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.comment-note {
  margin: 8px 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.comment-actions {
  display: flex;
  gap: 8px;
}

.comment-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.comment-dialog {
  width: min(460px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
}

.comment-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
}

.comment-dialog h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.comment-quote {
  max-height: 110px;
  overflow: auto;
  margin-bottom: 12px;
  border-left: 3px solid #d97706;
  padding-left: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

@media (max-width: 900px) {
  .topbar,
  .layout {
    display: block;
  }

  .actions {
    margin-top: 12px;
    flex-wrap: wrap;
  }

  .layout {
    height: auto;
    padding: 12px;
  }

  .workspace,
  .side {
    margin-bottom: 12px;
  }

  .side {
    display: block;
  }

  .editor {
    min-height: 68vh;
    padding: 24px 18px;
    font-size: 16px;
  }
}
