:root {
  color-scheme: light;
  --app-height: 100dvh;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-muted: #eef2ee;
  --surface-strong: #e8eee7;
  --ink: #17201b;
  --muted: #637168;
  --border: #d8e0d8;
  --primary: #245d4f;
  --primary-strong: #153c34;
  --primary-soft: #e3f1ec;
  --accent: #315f9c;
  --danger: #a33b36;
  --danger-soft: #f9e7e5;
  --success: #23724f;
  --warning: #7b5b1e;
  --warning-soft: #fff3d4;
  --shadow: 0 8px 28px rgba(26, 43, 35, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(49, 95, 156, 0.26);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--border);
  background: rgba(247, 248, 245, 0.92);
  backdrop-filter: blur(12px);
}

.brand-lockup,
.top-actions,
.user-chip,
.note-meta,
.note-actions,
.history-item-head,
.notify-item-head,
.status-line {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 2px solid var(--primary);
  border-radius: 8px;
  background:
    linear-gradient(var(--primary), var(--primary)) 8px 10px / 14px 2px no-repeat,
    linear-gradient(var(--primary), var(--primary)) 8px 16px / 10px 2px no-repeat,
    var(--surface);
}

.brand-name {
  color: var(--ink);
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.main-layout {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 4vw, 32px) 42px;
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  align-items: start;
}

.intro-panel,
.auth-panel,
.editor-panel,
.side-panel,
.diff-panel,
.profile-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro-panel {
  padding: clamp(22px, 5vw, 42px);
}

.intro-panel h1,
.auth-panel h2,
.editor-panel h1,
.side-panel h2,
.diff-panel h2,
.profile-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.intro-panel h1 {
  max-width: 720px;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.05;
}

.intro-copy {
  max-width: 660px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.58;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 28px;
}

.feature-pill {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.feature-pill strong {
  display: block;
  font-size: 14px;
}

.feature-pill span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.auth-panel,
.profile-panel,
.side-panel,
.diff-panel {
  padding: 16px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 16px 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.tab-btn {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.tab-btn.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(23, 32, 27, 0.08);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  padding: 10px 12px;
}

.field textarea {
  min-height: 420px;
  resize: vertical;
  line-height: 1.58;
}

.helper,
.muted {
  color: var(--muted);
}

.helper {
  font-size: 13px;
  line-height: 1.4;
}

.error,
.banner {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.4;
}

.error {
  border: 1px solid #efc8c4;
  background: var(--danger-soft);
  color: var(--danger);
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #ead698;
  background: var(--warning-soft);
  color: var(--warning);
}

.btn {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 760;
}

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

.btn.secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink);
}

.btn.secondary:hover {
  background: var(--surface-muted);
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
}

.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.52;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 18px;
  align-items: start;
}

.editor-panel {
  min-width: 0;
  padding: 16px;
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.editor-title {
  display: grid;
  gap: 8px;
}

.editor-title h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
}

.note-meta {
  flex-wrap: wrap;
  gap: 8px;
}

.note-meta span,
.status-pill {
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 13px;
}

.status-pill.is-live {
  border-color: #b9d9ca;
  color: var(--success);
  background: #eaf5ef;
}

.status-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
}

.note-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.editor-field {
  min-width: 0;
}

.editor-host {
  min-width: 0;
  overflow: visible;
}

.editor-host .sun-editor {
  overflow: visible;
  border-color: var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-family: inherit;
}

.editor-host .sun-editor .se-toolbar {
  position: relative;
  flex: 0 0 auto;
  z-index: 12;
  outline: 0;
  background: var(--surface-muted);
}

.editor-host .sun-editor .se-container {
  overflow: visible;
}

.editor-host .sun-editor .se-list-layer,
.editor-host .sun-editor .se-selector-table,
.editor-host .sun-editor .se-submenu,
.editor-host .sun-editor .se-menu-container,
.editor-host .sun-editor .se-dialog {
  z-index: 120;
}

.editor-host .sun-editor .se-dialog {
  position: fixed;
}

.editor-host .sun-editor .se-wrapper {
  background: var(--surface);
}

.editor-host .sun-editor-editable {
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.58;
}

.editor-host .sun-editor-editable img {
  max-width: 100%;
  height: auto;
}

.side-stack {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.profile-panel,
.notifications-list,
.history-list {
  display: grid;
  gap: 10px;
}

.push-settings {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.push-settings h3,
.push-settings p {
  margin: 0;
}

.push-settings h3 {
  font-size: 15px;
}

.push-settings p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(17, 25, 21, 0.34);
}

.account-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 141;
  display: grid;
  grid-template-rows: auto;
  align-content: start;
  gap: 18px;
  width: min(430px, calc(100vw - 18px));
  overflow: auto;
  padding: 18px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: -12px 0 32px rgba(23, 32, 27, 0.14);
}

.changes-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 141;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(860px, calc(100vw - 18px));
  overflow: hidden;
  padding: 18px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: -12px 0 32px rgba(23, 32, 27, 0.14);
}

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

.drawer-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.changes-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 14px;
}

.changes-history,
.changes-diff {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.changes-history h3,
.changes-diff h3 {
  margin: 0;
  font-size: 18px;
}

.changes-history .history-list {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.changes-diff .diff-box {
  flex: 1 1 auto;
  max-height: none;
}

.drawer-user {
  max-width: none;
  border-radius: 8px;
}

.drawer-section {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.drawer-section h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.drawer-section .push-settings {
  padding-top: 0;
  border-top: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  font-size: 18px;
}

.user-chip {
  max-width: 320px;
  gap: 9px;
  min-height: 42px;
  padding: 6px 8px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 800;
}

.user-copy {
  min-width: 0;
  display: grid;
}

.user-copy strong,
.user-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-copy strong {
  font-size: 13px;
}

.user-copy span {
  color: var(--muted);
  font-size: 12px;
}

.history-item,
.notify-item {
  width: 100%;
  min-height: 86px;
  display: grid;
  gap: 6px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.history-item {
  cursor: pointer;
}

.history-item:hover,
.history-item.is-active {
  border-color: var(--accent);
  background: #f2f6fb;
}

.history-item-head,
.notify-item-head {
  justify-content: space-between;
  gap: 8px;
}

.history-item strong,
.notify-item strong {
  font-size: 14px;
}

.history-item time,
.notify-item time,
.history-item span,
.notify-item p {
  color: var(--muted);
  font-size: 12px;
}

.notify-item.is-unread {
  border-color: #b9d9ca;
  background: #eff8f3;
}

.diff-panel {
  margin-top: 18px;
}

.diff-box {
  overflow: auto;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101713;
  color: #edf7f0;
  font: 13px/1.48 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.diff-line {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  min-height: 25px;
  padding: 3px 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line.added {
  background: rgba(56, 159, 108, 0.22);
}

.diff-line.removed {
  background: rgba(184, 67, 63, 0.25);
}

.diff-token {
  border-radius: 4px;
}

.diff-token.added {
  background: rgba(78, 199, 132, 0.36);
  color: #f4fff7;
}

.diff-token.removed {
  background: rgba(255, 118, 107, 0.34);
  color: #fff1ef;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.status-line {
  min-height: 28px;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 28px));
}

.toast {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

.quick-image-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

body.editor-fullscreen {
  overflow: hidden;
}

body.editor-fullscreen .app-shell {
  height: var(--app-height);
  min-height: var(--app-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.editor-fullscreen .topbar {
  position: relative;
  flex: 0 0 auto;
  z-index: 20;
}

body.editor-fullscreen .main-layout {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body.editor-fullscreen .workspace {
  display: block;
  height: 100%;
  min-height: 0;
}

body.editor-fullscreen .editor-panel {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px clamp(10px, 3vw, 18px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.editor-fullscreen .editor-head {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

body.editor-fullscreen .editor-title {
  gap: 6px;
}

body.editor-fullscreen .editor-title h1 {
  font-size: clamp(22px, 3vw, 30px);
}

body.editor-fullscreen .editor-field {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.editor-fullscreen .editor-host {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

body.editor-fullscreen .editor-host .sun-editor {
  flex: 1 1 auto;
  height: 100% !important;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.editor-fullscreen .editor-host .sun-editor .se-container {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.editor-fullscreen .editor-host .sun-editor .se-toolbar {
  position: sticky;
  top: 0;
  z-index: 80;
  max-height: min(168px, 36vh);
  max-height: min(168px, calc(var(--app-height) * 0.36));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.changes-open .editor-host .sun-editor .se-toolbar,
body.menu-open .editor-host .sun-editor .se-toolbar {
  display: none !important;
}

body.editor-fullscreen .editor-host .sun-editor .se-wrapper {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
  overflow: hidden;
}

body.editor-fullscreen .editor-host .sun-editor .se-wrapper-inner {
  height: 100% !important;
  min-height: 0 !important;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.editor-fullscreen .editor-host .sun-editor-editable img {
  max-width: 100%;
}

body.editor-fullscreen .note-image-row {
  margin: 0 0 12px;
}

body.editor-fullscreen .side-stack,
body.editor-fullscreen .diff-panel {
  display: none;
}

@media (max-width: 940px) {
  .auth-layout,
  .workspace {
    grid-template-columns: 1fr;
  }

  .feature-row {
    grid-template-columns: 1fr;
  }

  .editor-head,
  .banner {
    align-items: stretch;
    flex-direction: column;
  }

  .note-actions {
    justify-content: stretch;
  }

  .note-actions .btn,
  .banner .btn {
    flex: 1 1 150px;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: center;
    flex-direction: row;
    min-height: 58px;
    padding: 10px 12px;
  }

  .top-actions {
    width: auto;
    justify-content: flex-end;
  }

  .brand-name {
    font-size: 16px;
  }

  .main-layout {
    padding: 14px 10px 32px;
  }

  .editor-panel,
  .side-panel,
  .diff-panel {
    padding: 12px;
  }

  .editor-title h1 {
    font-size: 24px;
  }

  .field textarea {
    min-height: 360px;
  }

  .editor-host .sun-editor {
    border-radius: 6px;
  }

  .editor-host .sun-editor .se-toolbar {
    padding: 4px;
  }

  .editor-host .sun-editor .se-btn {
    min-width: 40px;
    min-height: 40px;
    margin: 2px !important;
  }

  .editor-host .sun-editor .se-btn-select {
    min-width: 92px;
  }

  .editor-host .sun-editor .se-list-layer,
  .editor-host .sun-editor .se-selector-table,
  .editor-host .sun-editor .se-submenu {
    max-width: calc(100vw - 28px);
  }

  .editor-host .sun-editor .se-list-layer.se-list-font-family,
  .editor-host .sun-editor .se-list-layer.se-list-font-size,
  .editor-host .sun-editor .se-list-layer.se-list-format {
    max-height: min(360px, 58dvh);
    overflow-y: auto;
  }

  body.editor-fullscreen.editor-is-editing .topbar {
    display: none;
  }

  body.editor-fullscreen.editor-is-editing .editor-head {
    display: none;
  }

  body.editor-fullscreen.editor-is-editing .editor-panel {
    padding-top: 0;
  }

  body.editor-fullscreen.editor-is-editing .field label,
  body.editor-fullscreen.editor-is-editing #draftState {
    display: none;
  }

  body.editor-fullscreen.editor-is-editing .editor-host .sun-editor .se-toolbar {
    border-bottom: 1px solid var(--border);
    max-height: min(150px, calc(var(--app-height) * 0.42));
  }

  .account-drawer {
    width: 100vw;
    padding: 14px;
  }

  .changes-drawer {
    width: 100vw;
    padding: 14px;
  }

  .changes-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(150px, 32dvh) minmax(0, 1fr);
    gap: 12px;
  }

  body.editor-fullscreen .main-layout {
    padding: 0;
  }

  body.editor-fullscreen .editor-panel {
    padding: 8px;
  }

  body.editor-fullscreen .editor-head {
    gap: 8px;
  }

  body.editor-fullscreen .editor-title h1 {
    font-size: 20px;
  }

  body.editor-fullscreen .note-meta {
    gap: 5px;
  }

  body.editor-fullscreen .note-meta span {
    min-height: 24px;
    padding: 3px 6px;
    font-size: 12px;
  }
}
