/* —— Themes (Konto → Wygląd / localStorage panel-ekranow-theme) —— */
:root,
html[data-theme="zielony"] {
  color-scheme: light;
  --ink: #1c1917;
  --ink-muted: #57534e;
  --ink-rgb: 28, 25, 23;
  --paper: #fffcf7;
  --desk: #e7e0d6;
  --desk-deep: #d6cdc0;
  --panel: #faf7f2;
  --line: #d4cbc0;
  --accent: #0f5c4c;
  --accent-hover: #0a463a;
  --accent-soft: #d8ebe5;
  --accent-mid: #1a7a64;
  --accent-warm: #c4a35a;
  --accent-rgb: 15, 92, 76;
  --glow: rgba(var(--accent-rgb), 0.14);
  --surface: #ffffff;
  --surface-elevated: #fffefb;
  --surface-muted: rgba(255, 255, 255, 0.72);
  --btn-on-accent: #f7fffc;
  --shadow: 0 1px 2px rgba(var(--ink-rgb), 0.06), 0 12px 32px rgba(var(--ink-rgb), 0.1);
  --radius: 8px;
  --font-ui: "Source Sans 3", system-ui, sans-serif;
  --font-doc: Literata, Georgia, "Times New Roman", serif;
  --shell-max: 960px;
  --shell-pad: 1.5rem 1rem 2.75rem;
  --shell-gap: 1.15rem;
  --card-pad: 1.15rem 1.25rem 1.25rem;
  --card-radius: 14px;
}

html[data-theme="niebieski"] {
  color-scheme: light;
  --ink: #1a2332;
  --ink-muted: #5a6578;
  --ink-rgb: 26, 35, 50;
  --paper: #f7f9fc;
  --desk: #e4e9f0;
  --desk-deep: #d2dae5;
  --panel: #f3f6fa;
  --line: #c5cedb;
  --accent: #1e4d7b;
  --accent-hover: #163a5c;
  --accent-soft: #d6e4f2;
  --accent-mid: #2f6dad;
  --accent-warm: #7a9ab8;
  --accent-rgb: 30, 77, 123;
  --glow: rgba(var(--accent-rgb), 0.14);
  --surface: #ffffff;
  --surface-elevated: #fbfdff;
  --surface-muted: rgba(255, 255, 255, 0.75);
  --btn-on-accent: #f5f9fc;
  --shadow: 0 1px 2px rgba(var(--ink-rgb), 0.06), 0 12px 32px rgba(var(--ink-rgb), 0.1);
}

html[data-theme="grafit"] {
  color-scheme: light;
  --ink: #1f2328;
  --ink-muted: #5c636c;
  --ink-rgb: 31, 35, 40;
  --paper: #f6f7f8;
  --desk: #e5e7ea;
  --desk-deep: #d4d7db;
  --panel: #f2f3f5;
  --line: #c8ccd1;
  --accent: #3f4a56;
  --accent-hover: #2c343d;
  --accent-soft: #e1e5e9;
  --accent-mid: #5a6674;
  --accent-warm: #8b949e;
  --accent-rgb: 63, 74, 86;
  --glow: rgba(var(--accent-rgb), 0.12);
  --surface: #ffffff;
  --surface-elevated: #fafbfc;
  --surface-muted: rgba(255, 255, 255, 0.72);
  --btn-on-accent: #f7f8f9;
  --shadow: 0 1px 2px rgba(var(--ink-rgb), 0.06), 0 12px 32px rgba(var(--ink-rgb), 0.1);
}

html[data-theme="bursztyn"] {
  color-scheme: light;
  --ink: #2a2118;
  --ink-muted: #6b5b4a;
  --ink-rgb: 42, 33, 24;
  --paper: #fbf7f1;
  --desk: #ebe3d6;
  --desk-deep: #dccfbc;
  --panel: #f7f1e8;
  --line: #d4c4ae;
  --accent: #8b5a2b;
  --accent-hover: #6f4520;
  --accent-soft: #efe0cc;
  --accent-mid: #b07a3d;
  --accent-warm: #c9a06a;
  --accent-rgb: 139, 90, 43;
  --glow: rgba(var(--accent-rgb), 0.14);
  --surface: #ffffff;
  --surface-elevated: #fffdf9;
  --surface-muted: rgba(255, 255, 255, 0.72);
  --btn-on-accent: #fffaf3;
  --shadow: 0 1px 2px rgba(var(--ink-rgb), 0.06), 0 12px 32px rgba(var(--ink-rgb), 0.1);
}

html[data-theme="ciemny"] {
  color-scheme: dark;
  --ink: #eceae7;
  --ink-muted: #a8a29e;
  --ink-rgb: 236, 234, 231;
  --paper: #1c1917;
  --desk: #161412;
  --desk-deep: #0f0e0c;
  --panel: #221f1c;
  --line: #3f3a35;
  --accent: #3d9b7f;
  --accent-hover: #2f7d66;
  --accent-soft: rgba(61, 155, 127, 0.22);
  --accent-mid: #4db396;
  --accent-warm: #b8954e;
  --accent-rgb: 61, 155, 127;
  --glow: rgba(var(--accent-rgb), 0.16);
  --surface: #2a2622;
  --surface-elevated: #312c27;
  --surface-muted: rgba(42, 38, 34, 0.85);
  --btn-on-accent: #f7fffc;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--desk);
}

/* Shared panel chrome (Konto, Strony, Biblioteka, Archiwum, auth) */
.panel-page {
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 100%;
  height: auto;
  background:
    radial-gradient(ellipse 70% 45% at 8% 0%, var(--glow), transparent 55%),
    linear-gradient(180deg, var(--desk) 0%, var(--desk-deep) 100%);
}

.panel-app,
.account-app,
.sites-app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.app-legal {
  padding: 0 1rem 1.15rem;
  text-align: center;
}

.app-legal p {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

.panel-main,
.account-main,
.sites-main {
  width: min(var(--shell-max), 100%);
  margin: 0 auto;
  padding: var(--shell-pad);
  display: grid;
  gap: var(--shell-gap);
  align-content: start;
}

body.sites-page {
  --shell-max: 1400px;
}

/* Editor shell: lock viewport and scroll inside .workspace */
body:has(> .app) {
  height: 100%;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100%;
  min-height: 100%;
}

.body-row {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
  overflow: hidden;
}

/* —— File list —— */
.files-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.files-header h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.files-header-actions {
  display: flex;
  gap: 0.2rem;
}

.btn-sm {
  padding: 0.15rem 0.55rem;
  font-size: 1.1rem;
  line-height: 1.2;
  min-width: 2rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.file-list:empty::after {
  content: "Brak zapisanych plików";
  display: block;
  padding: 0.75rem 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-style: italic;
}

.file-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem;
  align-items: stretch;
  margin-bottom: 0.25rem;
  position: relative;
}

.file-item-with-assign {
  grid-template-areas:
    "open actions"
    "assign assign";
}

.file-item-with-assign .file-item-open {
  grid-area: open;
}

.file-item-with-assign .file-item-actions {
  grid-area: actions;
}

.file-item-assign {
  grid-area: assign;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0 0.5rem 0.4rem 3.35rem;
  position: relative;
}

.file-item-pages {
  font-size: 0.72rem;
  color: var(--ink-muted);
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-pages-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.35rem;
  margin-top: 0.28rem;
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.file-item-pages-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-right: 0.1rem;
}

.file-page-chip {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-page-chip-empty {
  border-color: rgba(180, 83, 9, 0.35);
  background: rgba(251, 191, 36, 0.18);
  color: #92400e;
  font-weight: 600;
}

.file-item-pages-row.has-pages .file-item-pages-label {
  color: var(--accent);
}

.file-item-assign.has-pages .file-item-pages {
  color: var(--accent);
  font-weight: 600;
}

.file-item-assign-toggle {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.3;
}

.file-item-assign-toggle:hover,
.file-item-assign.is-open .file-item-assign-toggle {
  border-color: rgba(var(--accent-rgb), 0.35);
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.06);
}

.file-item-assign-panel {
  position: absolute;
  z-index: 8;
  left: 3.35rem;
  right: 0.5rem;
  top: calc(100% - 0.15rem);
  display: grid;
  gap: 0.35rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffefb;
  box-shadow: 0 8px 24px rgba(var(--ink-rgb), 0.12);
}

.file-item-assign-hint {
  margin: 0 0 0.15rem;
  font-size: 0.7rem;
  color: var(--ink-muted);
  line-height: 1.35;
}

.file-item-assign-option {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.3;
}

.file-item-assign-option input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.file-item-assign-option em {
  font-style: normal;
  color: var(--ink-muted);
  font-size: 0.75rem;
}

.page-assign-options {
  display: grid;
  gap: 0.45rem;
  margin: 0.35rem 0 0.75rem;
  max-height: min(50vh, 18rem);
  overflow: auto;
}

.page-assign-option {
  padding: 0.35rem 0.15rem;
}

.file-item-open {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: 0.55rem;
  align-items: flex-start;
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
  min-width: 0;
}

.file-item-open:hover,
.file-item:hover .file-item-open {
  background: rgba(var(--accent-rgb), 0.08);
}

.file-item.active .file-item-open {
  background: var(--accent-soft);
}

.file-thumb {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 6px;
  background: rgba(var(--ink-rgb), 0.06);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  overflow: hidden;
  flex-shrink: 0;
}

.file-thumb[data-type="pdf"] {
  background: #fde8e8;
  color: #9f1239;
  border-color: #f0c4c8;
}

.file-thumb[data-type="word"] {
  background: #e0ecff;
  color: #1e40af;
  border-color: #bfdbfe;
}

.file-thumb[data-type="excel"] {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}

.file-thumb[data-type="file"] {
  background: #f3f0ea;
  color: var(--ink-muted);
}

.file-thumb[data-type="image"] {
  padding: 0;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-item-main {
  min-width: 0;
}

.file-item-title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.file-item-title {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  margin-top: 0.35rem;
  padding-right: 0.1rem;
}

.file-item-download,
.file-item-archive,
.file-item-restore,
.file-item-rename,
.file-item-delete {
  border: none;
  border-radius: 6px;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.file-item-download,
.file-item-archive,
.file-item-restore,
.file-item-rename {
  background: rgba(var(--ink-rgb), 0.07);
  color: var(--ink);
}

.file-item-download:hover,
.file-item-archive:hover,
.file-item-restore:hover,
.file-item-rename:hover {
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent);
}

.file-item-delete {
  background: #dc2626;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 600;
}

.file-item-delete:hover {
  background: #b91c1c;
  color: #fff;
}

.list-preview {
  border-top: 1px solid var(--line);
  padding: 0.55rem 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.list-preview[hidden] {
  display: none !important;
}

.list-preview-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.list-preview-body {
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
}

.list-preview-body img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.list-preview-body iframe {
  width: 100%;
  height: 140px;
  border: none;
  display: block;
}

.list-preview-body .preview-fallback {
  display: grid;
  place-items: center;
  height: 140px;
  font-size: 0.85rem;
  color: var(--ink-muted);
  padding: 0.75rem;
  text-align: center;
}

.media-view {
  width: min(210mm, 100%);
  margin: 0 auto;
  min-height: 70vh;
  position: relative;
}

/* Word: full workspace width so page(s) can center in the viewport */
.media-view:has(.media-frame-word) {
  width: 100%;
  max-width: none;
}

.media-view[hidden] {
  display: none !important;
}

.media-view .rotate-controls {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  z-index: 5;
  display: flex;
  gap: 0.3rem;
  opacity: 0.4;
  transition: opacity 0.2s ease;
}

.media-view:hover .rotate-controls,
.media-view .rotate-controls:focus-within,
.media-view .rotate-controls:hover {
  opacity: 1;
}

.media-view .rotate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 254, 251, 0.95);
  color: var(--ink-muted);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.media-view .rotate-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.media-view .rotate-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.media-frame.page-rotated {
  transform-origin: center center;
  transition: transform 0.2s ease;
  overflow: visible;
}

.media-frame {
  background: var(--paper);
  box-shadow: var(--shadow);
  border-radius: 2px;
  overflow: hidden;
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-frame-word,
.media-frame-excel {
  display: block;
  overflow: auto;
  background: #fff;
  padding: 1rem;
}

/* Word: match desk / wrapper gray to document page background; center page(s) */
.media-frame-word {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--docx-page-bg, #fff);
  box-shadow: none;
  padding: 0;
}

.workspace:has(.media-frame-word) {
  background: var(--docx-page-bg, #fff);
}

.docx-preview-host,
.excel-preview {
  width: 100%;
  overflow: auto;
}

.docx-preview-host {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  background: var(--docx-page-bg, #fff);
  min-height: 100%;
}

/* docx-preview injects gray .docx-preview-wrapper — page color + centered pages */
.docx-preview-wrapper {
  background: var(--docx-page-bg, #fff) !important;
  padding: 1.25rem !important;
  padding-bottom: 0 !important;
  width: 100%;
  box-sizing: border-box;
  min-height: 100%;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: safe center;
}

.docx-preview-wrapper > section.docx-preview {
  box-shadow: none;
  background: var(--docx-page-bg, #fff);
  margin-bottom: 1.25rem !important;
  margin-left: auto;
  margin-right: auto;
  flex-shrink: 0;
}

.docx-preview-wrapper > section.docx-preview:last-child {
  margin-bottom: 0 !important;
}

.excel-preview table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.85rem;
}

.excel-preview td,
.excel-preview th {
  border: 1px solid #d4cbc0;
  padding: 0.35rem 0.55rem;
}

.file-placeholder {
  text-align: center;
  padding: 2rem 1.5rem;
  display: grid;
  gap: 0.65rem;
  justify-items: center;
}

.file-placeholder-title {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.file-placeholder-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.word-fallback {
  padding: 1rem 1.25rem;
  max-width: 720px;
  margin: 0 auto;
}

.media-image {
  max-width: 100%;
  max-height: 85vh;
  display: block;
  object-fit: contain;
}

.media-video {
  max-width: 100%;
  max-height: 85vh;
  width: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.video-player--panel {
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.video-player-bar {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  background: #111;
}

.video-player-loop {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: #d6d3d1;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.video-player-loop.is-on {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.16);
}

.media-pdf {
  width: 100%;
  height: min(85vh, 1000px);
  min-height: 70vh;
  border: none;
  display: block;
  background: #fff;
}

.app.media-mode .ribbon {
  opacity: 0.45;
  pointer-events: none;
}

.app.media-mode .doc-title {
  pointer-events: none;
}

/* —— Top bar —— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 0.65rem 1rem;
  padding: 0.6rem 1.1rem;
  background: linear-gradient(180deg, var(--surface-elevated) 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--line);
}

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

.brand-text {
  min-width: 0;
  display: grid;
  gap: 0.05rem;
}

.brand-name {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
  line-height: 1.2;
}

.brand .view-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 4px;
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-mid) 55%, var(--accent-warm) 100%);
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.doc-title {
  border: none;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  min-width: 0;
  width: min(420px, 100%);
}

.doc-title:hover,
.doc-title:focus {
  background: rgba(var(--accent-rgb), 0.06);
  outline: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 0.3rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.topbar-actions::-webkit-scrollbar {
  height: 4px;
}

.topbar-actions::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

.topbar-actions [hidden] {
  display: none !important;
}

.save-status {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-right: 0.35rem;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.save-status.visible {
  opacity: 1;
}

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.topbar-actions .btn {
  flex: 0 0 auto;
  box-sizing: border-box;
  height: 2.05rem;
  min-height: 2.05rem;
  max-height: 2.05rem;
  padding: 0 0.62rem;
  font-size: 0.84rem;
  line-height: 1;
  white-space: nowrap;
  border-width: 1px;
  box-shadow: none;
}

.topbar-actions .btn[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--btn-on-accent);
  box-shadow: none;
}

.topbar-actions .btn[aria-current="page"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--btn-on-accent);
}

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

.btn-ghost:hover {
  background: rgba(var(--ink-rgb), 0.06);
}

.btn-primary {
  background: var(--accent);
  color: var(--btn-on-accent);
}

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

.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #b91c1c;
}

.btn-danger:hover {
  background: #b91c1c;
  color: #fff;
}

/* Compact action buttons in lists / row actions (alias: btn-small) */
.btn-sm-text,
.btn-small {
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  min-height: 2rem;
}

/* —— Modal / confirm (shared UIConfirm + page modals) —— */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(var(--ink-rgb), 0.42);
}

.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, var(--surface-elevated) 0%, var(--panel) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.3rem 1.25rem 1.2rem;
}

.modal-card > h3 {
  position: sticky;
  top: -1.3rem;
  z-index: 2;
  margin: 0 0 1rem;
  padding-top: 0.2rem;
  padding-bottom: 0.45rem;
  font-family: Literata, Georgia, serif;
  font-size: 1.35rem;
  background: var(--surface-elevated);
}

.modal-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.modal-hint a {
  color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.35rem;
}

.modal-card > .modal-actions:last-child,
.modal-card form > .modal-actions:last-child {
  position: sticky;
  bottom: -1.2rem;
  z-index: 2;
  padding-top: 0.65rem;
  padding-bottom: 0.15rem;
  background: var(--panel);
}

.modal-actions-right {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.confirm-modal {
  z-index: 50;
}

.confirm-message {
  margin: 0 0 1.1rem;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.45;
  white-space: pre-line;
}

.confirm-input-wrap {
  display: block;
  margin: 0 0 0.85rem;
}

.confirm-input-wrap[hidden] {
  display: none;
}

.confirm-modal .auth-error {
  margin: 0 0 0.85rem;
}

/* —— Ribbon —— */
.ribbon {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.ribbon-group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.ribbon-divider {
  width: 1px;
  height: 1.6rem;
  background: var(--line);
  margin: 0 0.35rem;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}

.tool:hover {
  background: rgba(var(--accent-rgb), 0.1);
}

.tool.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool b,
.tool i,
.tool u,
.tool s {
  font-family: Georgia, serif;
  font-size: 0.95rem;
}

.select {
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 0.45rem;
  max-width: 10.5rem;
  cursor: pointer;
}

.select:focus {
  outline: 2px solid rgba(var(--accent-rgb), 0.35);
  outline-offset: 1px;
}

.select-sm {
  max-width: 4.2rem;
}

.color-tool {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  cursor: pointer;
}

.color-tool:hover {
  background: rgba(var(--accent-rgb), 0.1);
}

.color-label {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
  pointer-events: none;
}

.color-tool.highlight .color-label {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 1px;
  font-size: 0.78rem;
  font-weight: 700;
}

.color-tool input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
  padding: 0;
}

/* —— Workspace / page —— */
.workspace {
  overflow: auto;
  background:
    radial-gradient(ellipse at top, rgba(255, 255, 255, 0.45), transparent 55%),
    linear-gradient(180deg, var(--desk) 0%, var(--desk-deep) 100%);
  padding: 2rem 1rem 3rem;
}

.page-stack {
  display: flex;
  justify-content: center;
}

.page {
  width: min(210mm, 100%);
  min-height: 297mm;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  border-radius: 2px;
  padding: 22mm 20mm;
  font-family: var(--font-doc);
  font-size: 16px;
  line-height: 1.65;
  outline: none;
  overflow-wrap: break-word;
}

.page:focus {
  box-shadow: var(--shadow), 0 0 0 1px rgba(var(--accent-rgb), 0.2);
}

.page h1,
.page h2,
.page h3 {
  line-height: 1.25;
  margin: 0 0 0.6em;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page h1 {
  font-size: 2rem;
}

.page h2 {
  font-size: 1.5rem;
}

.page h3 {
  font-size: 1.2rem;
}

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

.page blockquote {
  margin: 0.85em 0;
  padding: 0.35em 0 0.35em 1em;
  border-left: 3px solid var(--accent);
  color: var(--ink-muted);
  font-style: italic;
}

.page pre {
  font-family: "Courier New", Courier, monospace;
  background: rgba(var(--ink-rgb), 0.05);
  padding: 0.75em 1em;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.9em;
}

.page ul,
.page ol {
  margin: 0 0 0.85em;
  padding-left: 1.4em;
}

.page a {
  color: var(--accent);
}

.page hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.4em 0;
}

.page img {
  max-width: 100%;
  height: auto;
}

/* —— Status —— */
.statusbar {
  display: flex;
  gap: 1.25rem;
  padding: 0.4rem 1.1rem;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* —— Print —— */
@media print {
  body {
    background: white;
    overflow: visible;
  }

  .topbar,
  .ribbon,
  .statusbar,
  .files-panel,
  .rotate-controls {
    display: none !important;
  }

  .body-row {
    display: block;
  }

  .workspace {
    padding: 0;
    overflow: visible;
    background: white;
  }

  .media-view {
    width: 100%;
  }

  .media-frame {
    box-shadow: none;
    min-height: auto;
  }

  .media-pdf {
    height: 100vh;
    min-height: 100vh;
  }

  .page {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
  }

  .page:focus {
    box-shadow: none;
  }
}

@media (max-width: 860px) {
  .body-row {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .files-panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 180px;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    padding: 1rem 0.6rem 2rem;
  }

  .page {
    padding: 16mm 12mm;
    min-height: 70vh;
  }
}
