:root {
  color-scheme: light;
  --app-bg: #ece7dd;
  --surface: #fbfaf7;
  --surface-strong: #ffffff;
  --line: #d3ccc0;
  --line-strong: #afa696;
  --text: #1c1f23;
  --muted: #667085;
  --accent: #1f6feb;
  --accent-strong: #154fb3;
  --danger: #b42318;
  --shadow: 0 12px 35px rgba(20, 24, 31, 0.16);
  --paper-width: 794px;
  --paper-min-height: 1123px;
  --paper-padding: 76px;
  --zoom: 1;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--app-bg);
  color: var(--text);
  font-family: "Segoe UI", Aptos, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"],
input[type="url"],
input[type="search"],
input[type="number"] {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--text);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  cursor: pointer;
  user-select: none;
}

button:hover,
select:hover,
input:hover {
  border-color: var(--line-strong);
}

button:active,
button.active {
  background: #dfeaff;
  border-color: var(--accent);
  color: var(--accent-strong);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: 58px 112px 1fr 30px;
  height: 100%;
  min-width: 1040px;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface-strong);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #1f6feb;
  color: white;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand span:last-child {
  display: block;
  max-width: 680px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 34px;
  padding: 0;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

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

.ribbon {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  background: #f7f4ee;
  border-bottom: 1px solid var(--line);
}

.ribbon-group {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  grid-auto-rows: 32px;
  gap: 6px;
  align-content: start;
  min-width: max-content;
  padding-right: 10px;
  border-right: 1px solid var(--line);
}

.ribbon-group.compact {
  grid-template-columns: repeat(5, 34px);
}

.ribbon-group .group-label {
  grid-column: 1 / -1;
  height: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.ribbon-group select {
  width: 132px;
  padding: 0 8px;
}

.ribbon-group.compact button {
  width: 34px;
  padding: 0;
}

.ribbon-group button {
  white-space: nowrap;
}

.color-control {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  cursor: pointer;
}

.color-control input {
  position: absolute;
  inset: auto 5px 3px 5px;
  width: 22px;
  height: 7px;
  padding: 0;
  border: 0;
}

.workspace {
  display: grid;
  grid-template-columns: 230px 1fr 250px;
  min-height: 0;
}

.sidebar {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.right-sidebar {
  border-right: 0;
  border-left: 1px solid var(--line);
}

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

.ghost-button {
  min-height: 28px;
  padding: 0 8px;
  background: transparent;
}

.outline-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.outline-list button {
  justify-content: flex-start;
  width: 100%;
  min-height: 30px;
  overflow: hidden;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline-level-2 button {
  padding-left: 22px;
}

.outline-level-3 button {
  padding-left: 38px;
}

.panel-block {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.panel-block strong {
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.stats-grid span {
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
}

.segmented button {
  border-radius: 0;
}

.segmented button:first-child {
  border-radius: 6px 0 0 6px;
}

.segmented button:last-child {
  border-radius: 0 6px 6px 0;
}

.document-stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 34px 32px 56px;
  background: var(--app-bg);
}

.page-frame {
  width: calc(var(--paper-width) * var(--zoom));
  min-height: calc(var(--paper-min-height) * var(--zoom));
  margin: 0 auto;
  transform-origin: top center;
}

.paper {
  width: var(--paper-width);
  min-height: var(--paper-min-height);
  padding: var(--paper-padding);
  transform: scale(var(--zoom));
  transform-origin: top left;
  background: white;
  box-shadow: var(--shadow);
  color: #111827;
  font-family: Aptos, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  word-break: break-word;
}

.page-frame.letter {
  --paper-width: 816px;
  --paper-min-height: 1056px;
}

.page-frame.margin-narrow {
  --paper-padding: 48px;
}

.page-frame.margin-normal {
  --paper-padding: 76px;
}

.page-frame.margin-wide {
  --paper-padding: 104px;
}

.paper:empty::before {
  content: "Commencez a ecrire...";
  color: #9aa3b2;
}

.paper h1,
.paper h2,
.paper h3 {
  margin: 0.95em 0 0.35em;
  line-height: 1.18;
}

.paper h1 {
  font-size: 34px;
}

.paper h2 {
  font-size: 25px;
}

.paper h3 {
  font-size: 20px;
}

.paper p {
  margin: 0 0 0.85em;
}

.paper blockquote {
  margin: 1em 0;
  padding: 0.15em 0 0.15em 1em;
  border-left: 4px solid #8aa9d6;
  color: #344054;
}

.paper pre {
  overflow-x: auto;
  padding: 12px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  background: #f2f4f7;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.paper table {
  width: 100%;
  margin: 1em 0;
  border-collapse: collapse;
}

.paper th,
.paper td {
  min-width: 72px;
  padding: 8px;
  border: 1px solid #98a2b3;
  vertical-align: top;
}

.paper th {
  background: #eef4ff;
  font-weight: 700;
}

.paper img {
  max-width: 100%;
  height: auto;
  cursor: pointer;
}

.paper img.selected-media {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.paper hr {
  height: 1px;
  margin: 22px 0;
  border: 0;
  background: #98a2b3;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 0 12px;
  overflow: hidden;
  background: var(--surface-strong);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.statusbar span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar span:first-child {
  flex: 1;
}

.metric {
  display: inline-grid;
  place-items: center;
  min-width: 46px;
  color: var(--muted);
}

.find-panel {
  position: fixed;
  right: 22px;
  bottom: 44px;
  z-index: 20;
  display: grid;
  grid-template-columns: 180px 180px repeat(5, max-content) 52px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.modal {
  width: min(420px, 92vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(16, 24, 40, 0.36);
}

.modal form {
  display: grid;
  gap: 14px;
}

.modal h2 {
  margin: 0;
  font-size: 19px;
}

.modal label {
  display: grid;
  gap: 6px;
}

.modal menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.toast-region {
  position: fixed;
  right: 18px;
  top: 82px;
  z-index: 30;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 360px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.toast.error {
  border-color: #fda29b;
  color: var(--danger);
}

body.theme-dark {
  color-scheme: dark;
  --app-bg: #252525;
  --surface: #1e1f22;
  --surface-strong: #151619;
  --line: #343741;
  --line-strong: #596070;
  --text: #f2f4f7;
  --muted: #a9b1c2;
  --accent: #65a3ff;
  --accent-strong: #8dbbff;
  --shadow: 0 14px 35px rgba(0, 0, 0, 0.38);
}

body.theme-dark .ribbon {
  background: #202225;
}

body.theme-dark .paper {
  background: #fdfdfb;
  color: #111827;
}

body.theme-dark button:active,
body.theme-dark button.active {
  background: #1f3b62;
  color: #cfe2ff;
}

@media print {
  body {
    overflow: visible;
    background: white;
  }

  .titlebar,
  .ribbon,
  .sidebar,
  .statusbar,
  .find-panel,
  .toast-region {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .document-stage,
  .page-frame {
    display: block;
    width: auto;
    height: auto;
    min-height: 0;
    padding: 0;
    overflow: visible;
    background: white;
  }

  .paper {
    width: auto;
    min-height: 0;
    padding: 0;
    transform: none;
    box-shadow: none;
  }
}
