/* ════════════════════════════════════════════════════════════════════════════
   studio-docs.css — "Docs" workstation: a lightweight Word-like editor that
   lives alongside the Canvas workstation. Both stay mounted at once; switching
   apps only toggles visibility, so neither loses its state.
════════════════════════════════════════════════════════════════════════════ */

/* ── App switching: hide the canvas workstation when Docs is active ───────── */
body.mode-docs #menubar,
body.mode-docs #tabs-bar,
body.mode-docs #main        { display: none !important; }
body.mode-docs #bottom-ad-bar { display: none !important; }

#docs-root { display: none; }
body.mode-docs #docs-root {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; overflow: hidden;
  background: #30302f;
}

/* ══ RIBBON ════════════════════════════════════════════════════════════════ */
#docs-ribbon {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  background: #1d1d1d; border-bottom: 1px solid #2a2a2a;
  padding: 5px 8px; min-height: 42px; flex-shrink: 0;
  position: relative; z-index: 30;
}
.docs-grp {
  display: flex; align-items: center; gap: 2px;
  padding: 0 6px; height: 30px;
  border-right: 1px solid #2d2d2d;
}
.docs-grp:last-child { border-right: none; }

.docs-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 28px; height: 28px; padding: 0 7px;
  background: none; border: 1px solid transparent; border-radius: 5px;
  color: #b8b8b8; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .1s, color .1s, border-color .1s;
}
.docs-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.docs-btn.active { background: #24405e; border-color: #2f5a86; color: #8cc3f5; }
.docs-btn.docs-btn-text { font-size: 12px; font-weight: 600; }
.docs-btn i { font-size: 15px; line-height: 1; }
.docs-btn-primary { background: #0d6efd; color: #fff; }
.docs-btn-primary:hover { background: #2a7dff; color: #fff; }

.docs-sel {
  height: 28px; background: #262626; border: 1px solid #383838;
  border-radius: 5px; color: #d4d4d4; font-size: 12px; font-family: inherit;
  padding: 0 6px; cursor: pointer; outline: none;
}
.docs-sel:hover { border-color: #4a4a4a; }
.docs-sel:focus { border-color: #2f5a86; }
#docs-font-family { width: 126px; }
#docs-font-size   { width: 58px; }
#docs-style-sel   { width: 112px; }
#docs-linespacing { width: 46px; }

.docs-color {
  position: relative; display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 30px; height: 28px; border-radius: 5px; cursor: pointer;
  color: #b8b8b8; border: 1px solid transparent;
}
.docs-color:hover { background: rgba(255,255,255,.08); color: #fff; }
.docs-color i { font-size: 14px; line-height: 1; margin-top: -2px; }
.docs-color .docs-color-bar { width: 17px; height: 3px; border-radius: 1px; margin-top: 1px; }
.docs-color input[type=color] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}

.docs-sep-v { width: 1px; height: 22px; background: #2d2d2d; margin: 0 2px; }

/* File menu dropdown (Save as …) */
.docs-menu-wrap { position: relative; }
.docs-dd {
  display: none; position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 210px; background: #262626; border: 1px solid #3a3a3a;
  border-radius: 8px; box-shadow: 0 10px 34px rgba(0,0,0,.6);
  padding: 4px; z-index: 60;
}
.docs-dd.open { display: block; }
.docs-dd-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: 5px; cursor: pointer;
  font-size: 12px; color: #ccc;
}
.docs-dd-item:hover { background: rgba(74,144,217,.16); color: #dcefff; }
.docs-dd-item i { width: 16px; text-align: center; color: #7aa7d4; }
.docs-dd-sep { height: 1px; background: #333; margin: 4px 4px; }
.docs-dd-item .docs-dd-ext { margin-left: auto; font-size: 10px; color: #666; }

/* ══ DOCUMENT TABS ═════════════════════════════════════════════════════════ */
#docs-doctabs {
  display: flex; align-items: flex-end; gap: 2px;
  background: #171717; border-bottom: 1px solid #272727;
  padding: 4px 6px 0; flex-shrink: 0; overflow-x: auto; scrollbar-width: none;
}
#docs-doctabs::-webkit-scrollbar { display: none; }
.docs-tab {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 8px 0 12px; max-width: 200px; min-width: 110px;
  background: #1f1f1f; border: 1px solid #2a2a2a; border-bottom: none;
  border-radius: 7px 7px 0 0; cursor: pointer; flex-shrink: 0;
  color: #888; font-size: 12px; position: relative; transition: background .1s;
}
.docs-tab:hover { background: #262626; }
.docs-tab.active { background: #fff; color: #222; border-color: #d0d0d0; }
.docs-tab .docs-tab-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
  outline: none;
}
.docs-tab .docs-tab-dirty { color: #0d6efd; font-size: 15px; line-height: 0; flex-shrink: 0; }
.docs-tab.active .docs-tab-dirty { color: #0d6efd; }
.docs-tab-close {
  width: 16px; height: 16px; border-radius: 4px; border: none; background: none;
  color: #777; cursor: pointer; font-size: 13px; line-height: 1; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.docs-tab-close:hover { background: rgba(0,0,0,.15); color: #c0392b; }
.docs-tab.active .docs-tab-close { color: #888; }
.docs-tab.active .docs-tab-close:hover { background: #eee; color: #c0392b; }
#docs-tab-add {
  height: 26px; width: 28px; margin: 0 0 2px 4px; flex-shrink: 0;
  background: none; border: none; color: #666; font-size: 18px; cursor: pointer;
  border-radius: 5px; display: flex; align-items: center; justify-content: center;
}
#docs-tab-add:hover { background: #262626; color: #ccc; }

/* ══ STAGE / PAPER ═════════════════════════════════════════════════════════ */
#docs-stage {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  padding: 32px 24px 80px; display: flex; justify-content: center;
}
#docs-pages { width: 100%; display: flex; flex-direction: column; align-items: center; }

.docs-paper {
  background: #fff; color: #111;
  width: 816px;            /* 8.5in @ 96dpi */
  min-height: 1056px;      /* 11in  @ 96dpi */
  padding: 96px;           /* 1in margins */
  box-shadow: 0 2px 16px rgba(0,0,0,.45);
  border-radius: 1px;
  outline: none;
  font-family: 'Calibri', 'Segoe UI', Arial, sans-serif;
  font-size: 11pt; line-height: 1.5;
  user-select: text; cursor: text;
  box-sizing: border-box;
  position: relative;        /* anchor for free-floating images */
}
.docs-paper:focus { box-shadow: 0 2px 16px rgba(0,0,0,.45), 0 0 0 2px rgba(13,110,253,.25); }

/* Default document typography */
.docs-paper p { margin: 0 0 8pt; }
.docs-paper h1 { font-size: 22pt; font-weight: 700; margin: 0 0 10pt; color: #1a1a1a; }
.docs-paper h2 { font-size: 16pt; font-weight: 700; margin: 14pt 0 6pt; color: #2b6cb0; }
.docs-paper h3 { font-size: 13pt; font-weight: 700; margin: 12pt 0 4pt; color: #333; }
.docs-paper h4 { font-size: 12pt; font-weight: 700; margin: 10pt 0 4pt; color: #444; }
.docs-paper blockquote {
  margin: 8pt 0; padding: 4pt 16pt; border-left: 3px solid #cbd5e0; color: #555; font-style: italic;
}
.docs-paper ul, .docs-paper ol { margin: 0 0 8pt; padding-left: 26pt; }
.docs-paper li { margin: 0 0 3pt; }
.docs-paper a { color: #0d6efd; }
.docs-paper img { max-width: 100%; height: auto; }
.docs-paper img.docs-img-sel { outline: 2px solid #0d6efd; outline-offset: 1px; }

/* ── Image placement / wrapping ─────────────────────────────────────────── */
.docs-paper figure.docs-media { margin: 0; padding: 0; display: inline-block; }
.docs-paper figure.docs-media img { display: block; width: 100%; height: auto; }
.docs-paper figure.docs-media figcaption {
  font-size: 9.5pt; color: #555; font-style: italic; text-align: center;
  margin-top: 4px; padding: 0 2px; line-height: 1.35; outline: none;
}
/* Inline (default) — image sits in the text line */
.docs-paper .docs-wrap-inline { vertical-align: bottom; }
/* Wrap: text flows beside the image (Word "Square" wrap) */
.docs-paper .docs-wrap-left   { float: left;  margin: 4px 18px 8px 0;  clear: left; }
.docs-paper .docs-wrap-right  { float: right; margin: 4px 0 8px 18px;  clear: right; }
/* Break text: image on its own centred line */
.docs-paper .docs-wrap-center { display: block; margin: 12px auto; clear: both; text-align: center; }
/* Free float — drag anywhere, sits in front of the text (Word "In Front of Text") */
.docs-paper .docs-wrap-float  { position: absolute; z-index: 6; margin: 0; cursor: move; }
.docs-paper figure.docs-media.docs-img-self,
.docs-paper figure.docs-media.docs-img-self img { outline-offset: 1px; }
.docs-paper figure.docs-media.docs-img-self { outline: 2px solid #0d6efd; }
.docs-paper figure.docs-media.docs-dragging { opacity: .6; }
.docs-paper img.docs-dragging { opacity: .5; }
.docs-paper img { -webkit-user-drag: none; user-drag: none; }
/* Small "linked to canvas" badge sits over the image corner */
.docs-link-badge {
  position: absolute; top: 4px; left: 4px; z-index: 7;
  background: rgba(13,110,253,.92); color: #fff; font-size: 9px; font-weight: 600;
  padding: 2px 6px; border-radius: 10px; display: inline-flex; align-items: center; gap: 3px;
  pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.docs-link-badge i { font-size: 10px; }

/* ── Floating image toolbar ─────────────────────────────────────────────── */
#docs-img-bar {
  display: none; position: absolute; z-index: 45;
  background: #232323; border: 1px solid #3a3a3a; border-radius: 9px;
  box-shadow: 0 8px 26px rgba(0,0,0,.55); padding: 4px; gap: 2px; align-items: center;
}
#docs-img-bar.show { display: flex; }
#docs-img-bar .dib-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 1px solid transparent; border-radius: 6px;
  background: none; color: #bbb; cursor: pointer; font-size: 15px;
}
#docs-img-bar .dib-btn:hover { background: rgba(255,255,255,.09); color: #fff; }
#docs-img-bar .dib-btn.active { background: #24405e; border-color: #2f5a86; color: #8cc3f5; }
#docs-img-bar .dib-btn.dib-danger:hover { background: #3a1e1e; color: #ff8a8a; }
#docs-img-bar .dib-sep { width: 1px; height: 20px; background: #3a3a3a; margin: 0 3px; }
#docs-img-bar .dib-btn.dib-link { color: #8cc3f5; }

/* ── Context menu (right-click an image) ────────────────────────────────── */
#docs-ctx {
  display: none; position: fixed; z-index: 9997; min-width: 196px;
  background: #262626; border: 1px solid #3a3a3a; border-radius: 9px;
  box-shadow: 0 12px 36px rgba(0,0,0,.6); padding: 5px;
}
#docs-ctx.show { display: block; }
#docs-ctx .dctx-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px;
  border-radius: 6px; cursor: pointer; font-size: 12px; color: #ccc;
}
#docs-ctx .dctx-item:hover { background: rgba(74,144,217,.18); color: #eaf4ff; }
#docs-ctx .dctx-item i { width: 16px; text-align: center; color: #7aa7d4; }
#docs-ctx .dctx-item.dctx-accent i { color: #8cc3f5; }
#docs-ctx .dctx-item.dctx-danger { color: #f08a8a; }
#docs-ctx .dctx-item.dctx-danger i { color: #f08a8a; }
#docs-ctx .dctx-sep { height: 1px; background: #343434; margin: 5px 4px; }

/* Drop ghost while dragging a wrapped image to re-anchor it */
#docs-drag-ghost {
  position: fixed; z-index: 9996; pointer-events: none; opacity: .75;
  border: 1px solid #0d6efd; border-radius: 3px; box-shadow: 0 4px 14px rgba(0,0,0,.4);
  max-width: 220px; max-height: 220px;
}
#docs-caret-marker {
  position: fixed; z-index: 9996; width: 2px; background: #0d6efd; pointer-events: none;
  display: none; box-shadow: 0 0 3px rgba(13,110,253,.8);
}
.docs-paper table { border-collapse: collapse; margin: 8pt 0; }
.docs-paper table td, .docs-paper table th {
  border: 1px solid #b0b0b0; padding: 4pt 8pt; min-width: 32px; vertical-align: top;
}
.docs-paper table th { background: #f0f3f7; font-weight: 700; }
.docs-paper hr { border: none; border-top: 1px solid #ccc; margin: 14pt 0; }
.docs-paper .docs-pagebreak {
  border: none; border-top: 2px dashed #c7c7c7; margin: 20pt 0;
  page-break-after: always; break-after: page;
}

/* Simulated page gutter between sheets when more than one is used */
.docs-paper + .docs-paper { margin-top: 24px; }

/* ══ STATUS BAR ════════════════════════════════════════════════════════════ */
#docs-statusbar {
  display: flex; align-items: center; gap: 18px;
  background: #1a1a1a; border-top: 1px solid #272727;
  padding: 4px 16px; flex-shrink: 0; font-size: 11px; color: #777;
  min-height: 28px;
}
#docs-statusbar .docs-status-spacer { flex: 1; }
#docs-zoom-wrap { display: flex; align-items: center; gap: 6px; }
#docs-zoom-range { width: 110px; accent-color: #4a90d9; }
#docs-zoom-val { min-width: 38px; text-align: right; color: #999; }

/* ══ TABLE INSERT GRID PICKER ══════════════════════════════════════════════ */
.docs-table-pop {
  display: none; position: absolute; top: calc(100% + 4px); left: 0;
  background: #262626; border: 1px solid #3a3a3a; border-radius: 8px;
  padding: 10px; z-index: 60; box-shadow: 0 10px 34px rgba(0,0,0,.6);
}
.docs-table-pop.open { display: block; }
.docs-table-grid { display: grid; grid-template-columns: repeat(8, 18px); gap: 3px; }
.docs-table-grid > div {
  width: 18px; height: 18px; border: 1px solid #3f3f3f; border-radius: 2px; background: #1d1d1d;
}
.docs-table-grid > div.on { background: #2f5a86; border-color: #4a90d9; }
.docs-table-pop .docs-table-label { font-size: 11px; color: #aaa; margin-bottom: 7px; text-align: center; }

/* ══ TOAST ═════════════════════════════════════════════════════════════════ */
#docs-toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #222; color: #eee; border: 1px solid #3a3a3a;
  padding: 9px 18px; border-radius: 8px; font-size: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 9999;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#docs-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#docs-toast.err { border-color: #7a2a2a; color: #ffb4b4; }

/* ══ BUSY SPINNER ══════════════════════════════════════════════════════════ */
#docs-busy {
  display: none; position: fixed; inset: 0; z-index: 9998;
  background: rgba(18,18,18,.55); backdrop-filter: blur(2px);
  align-items: center; justify-content: center; flex-direction: column; gap: 14px;
  color: #cfe3f7; font-size: 13px;
}
#docs-busy.show { display: flex; }
#docs-busy .docs-spin {
  width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.15);
  border-top-color: #4a90d9; border-radius: 50%; animation: docsspin .7s linear infinite;
}
@keyframes docsspin { to { transform: rotate(360deg); } }

/* ══ RESPONSIVE ════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .docs-paper { width: 100%; min-height: 70vh; padding: 36px 28px; }
  #docs-stage { padding: 16px 10px 70px; }
}
