/* Cluster Studio — Universal Document Editor */
:root {
  --cs: #0f766e;
  --cs2: #14b8a6;
  --cs-soft: rgba(15,118,110,.1);
  --cs-border: #e2e8f0;
  --cs-bg: #f1f5f9;
  --cs-ink: #0f172a;
}

.cs-app { min-height: calc(100vh - 120px); }

/* Landing — upload only */
.cs-landing {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 160px); padding: 1.5rem;
}
.cs-landing.hidden { display: none; }
.cs-landing-card {
  width: min(560px, 100%);
  text-align: center;
  background: #fff;
  border: 1px solid var(--cs-border);
  border-radius: 18px;
  padding: 2rem 1.75rem 1.5rem;
  box-shadow: 0 16px 48px rgba(15,23,42,.08);
}
.cs-logo-mark {
  width: 56px; height: 56px; margin: 0 auto .85rem;
  border-radius: 16px; color: #fff;
  background: linear-gradient(135deg, #0f766e, #0891b2);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 28px rgba(15,118,110,.35);
}
.cs-logo-mark svg { width: 26px; height: 26px; }
.cs-landing-card h1 {
  font-size: 1.45rem; font-weight: 800; color: var(--cs-ink); margin: 0;
}
.cs-sub {
  display: inline-block; margin: .35rem 0 .75rem;
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--cs); background: var(--cs-soft); padding: 3px 10px; border-radius: 999px;
}
.cs-desc { font-size: 13px; color: #64748b; line-height: 1.5; margin: 0 0 1.25rem; }

.cs-drop {
  border: 2px dashed #99f6e4; border-radius: 14px;
  padding: 1.5rem 1rem; background: #f0fdfa;
  transition: .2s; cursor: pointer;
}
.cs-drop:hover, .cs-drop.drag { border-color: var(--cs); background: #ccfbf1; }
.cs-drop-title { font-size: 14px; font-weight: 700; color: #134e4a; margin: 0 0 .25rem; }
.cs-drop-types { font-size: 11px; color: #64748b; margin: 0 0 .9rem; }
.cs-btn-open, .cs-btn-primary {
  border: none; border-radius: 8px; padding: 9px 16px;
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff; font-size: 12px; font-weight: 700; cursor: pointer;
}
.cs-btn-ghost {
  border: 1px solid var(--cs-border); border-radius: 7px; padding: 7px 12px;
  background: #fff; color: #334155; font-size: 11px; font-weight: 700; cursor: pointer;
}
.cs-flow {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
  margin-top: 1.1rem; font-size: 10px; font-weight: 700; color: #94a3b8;
}

.cs-loading {
  display: none; flex-direction: column; align-items: center; gap: 10px;
  padding: 4rem 1rem;
}
.cs-loading.active { display: flex; }
.cs-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #ccfbf1; border-top-color: var(--cs);
  animation: csSpin .75s linear infinite;
}
@keyframes csSpin { to { transform: rotate(360deg); } }
.cs-progress {
  width: 200px; height: 4px; background: #e2e8f0; border-radius: 4px; overflow: hidden;
}
.cs-progress i {
  display: block; height: 100%; width: 0; background: var(--cs); transition: width .2s;
}
#cs-loading-msg { font-size: 12px; color: #64748b; margin: 0; }

/* Workspace */
.cs-workspace {
  display: none; flex-direction: column;
  height: calc(100vh - 130px); min-height: 480px;
  border: 1px solid var(--cs-border); border-radius: 12px; overflow: hidden;
  background: #fff; box-shadow: 0 8px 28px rgba(15,23,42,.06);
}
.cs-workspace.active { display: flex; }

.cs-topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 10px; border-bottom: 1px solid var(--cs-border);
  background: linear-gradient(180deg, #fff, #f8fafc);
}
.cs-brand-mini { display: flex; flex-direction: column; min-width: 110px; }
.cs-brand-mini strong { font-size: 12px; color: var(--cs); }
#cs-doc-name { font-size: 10px; color: #94a3b8; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cs-tools { display: flex; align-items: center; gap: 2px; flex: 1; flex-wrap: wrap; }
.cs-tool {
  border: none; background: transparent; color: #64748b;
  font-size: 11px; font-weight: 700; padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.cs-tool:hover { background: #f1f5f9; color: #0f172a; }
.cs-tool.active { background: var(--cs); color: #fff; }
.cs-v { width: 1px; height: 18px; background: var(--cs-border); margin: 0 4px; }
.cs-zoom-btn {
  width: 24px; height: 24px; border: 1px solid var(--cs-border); border-radius: 5px;
  background: #fff; font-weight: 700; cursor: pointer;
}
.cs-zoom-label { font-size: 10px; font-weight: 700; color: #475569; min-width: 36px; text-align: center; }
.cs-actions { display: flex; align-items: center; gap: 6px; }
.cs-export-wrap { position: relative; }
.cs-export-menu {
  display: none; position: absolute; right: 0; top: 34px; z-index: 40;
  background: #fff; border: 1px solid var(--cs-border); border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,.12); min-width: 140px; overflow: hidden;
}
.cs-export-menu.open { display: block; }
.cs-export-menu button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 8px 12px; font-size: 11px; font-weight: 600; cursor: pointer; color: #334155;
}
.cs-export-menu button:hover { background: var(--cs-soft); color: var(--cs); }

.cs-body { display: flex; flex: 1; overflow: hidden; }

.cs-left {
  width: 168px; flex-shrink: 0; border-right: 1px solid var(--cs-border);
  background: #f8fafc; display: flex; flex-direction: column;
}
.cs-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 6px; }
.cs-tab {
  border: none; background: transparent; font-size: 10px; font-weight: 700;
  color: #94a3b8; padding: 6px 4px; border-radius: 6px; cursor: pointer;
}
.cs-tab.active { background: #fff; color: var(--cs); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.cs-panel { display: none; flex: 1; overflow: auto; padding: 6px; }
.cs-panel.active { display: block; }
.cs-thumbs { display: flex; flex-direction: column; gap: 6px; }
.cs-thumb {
  border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.06); position: relative;
}
.cs-thumb.active { border-color: var(--cs); }
.cs-thumb canvas, .cs-thumb img { width: 100%; display: block; }
.cs-thumb span {
  position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  font-size: 8px; font-weight: 700; color: #fff; background: rgba(15,23,42,.7);
  padding: 1px 5px; border-radius: 6px;
}
.cs-layers { display: flex; flex-direction: column; gap: 3px; }
.cs-layer {
  display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 6px;
  font-size: 10px; font-weight: 600; color: #475569; cursor: pointer; border: 1px solid transparent;
}
.cs-layer:hover { background: #fff; }
.cs-layer.active { background: var(--cs-soft); border-color: rgba(15,118,110,.25); color: var(--cs); }
.cs-layer.dim { opacity: .45; }
.cs-layer button { border: none; background: transparent; cursor: pointer; font-size: 10px; color: #94a3b8; }
.cs-side-btn {
  width: 100%; border: 1px solid rgba(15,118,110,.25); background: var(--cs-soft);
  color: var(--cs); font-size: 10px; font-weight: 700; padding: 7px; border-radius: 7px;
  cursor: pointer; margin-bottom: 8px;
}
.cs-upload-list { list-style: none; padding: 0; margin: 0; font-size: 10px; color: #64748b; }
.cs-upload-list li { padding: 5px 4px; border-bottom: 1px solid var(--cs-border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-assets { display: flex; flex-wrap: wrap; gap: 6px; }
.cs-asset {
  width: 64px; height: 40px; border: 1px dashed var(--cs-border); border-radius: 6px;
  background: #fff; cursor: grab; overflow: hidden;
}
.cs-asset img { width: 100%; height: 100%; object-fit: contain; }
.cs-hint { font-size: 10px; color: #94a3b8; line-height: 1.4; margin: 0 0 8px; }

.cs-canvas-wrap {
  flex: 1; overflow: auto; padding: 18px;
  background:
    linear-gradient(45deg,#dbe4ec 25%,transparent 25%) 0 0/14px 14px,
    linear-gradient(-45deg,#dbe4ec 25%,transparent 25%) 0 0/14px 14px,
    #e8eef3;
}
.cs-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.cs-page {
  position: relative; background: #fff;
  box-shadow: 0 6px 28px rgba(15,23,42,.14); border-radius: 2px;
}
.cs-page canvas.cs-base { display: block; }
.cs-word-frame {
  width: 100%; min-height: 700px; background: transparent; padding: 0; margin: 0 auto; outline: none;
}
.cs-word-frame .docx-wrapper {
  background: transparent !important; padding: 0 !important;
}
.cs-word-frame section.docx {
  box-shadow: 0 6px 28px rgba(15,23,42,.14) !important;
  margin: 0 auto 24px auto !important;
  background: #fff !important;
}
.cs-text-frame {
  width: min(820px, 100%); min-height: 700px; background: #fff; padding: 40px;
  box-shadow: 0 6px 28px rgba(15,23,42,.14); outline: none;
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.55; white-space: pre-wrap;
}

/* Signature Studio Tabs */
.cs-sig-tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--cs-border); padding-bottom: 4px; }
.cs-sig-tab { border: none; background: transparent; font-size: 12px; font-weight: 700; color: #64748b; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.cs-sig-tab.active { background: var(--cs-soft); color: var(--cs); }
.cs-sig-panel { display: none; margin-bottom: 12px; }
.cs-sig-panel.active { display: block; }
.cs-sig-sub-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.cs-sig-row { margin-top: 8px; margin-bottom: 8px; }
.cs-sig-row select { width: 100%; padding: 6px 8px; border: 1px solid var(--cs-border); border-radius: 6px; font-size: 12px; }
.cs-sig-type-preview { margin-top: 8px; border: 1px solid var(--cs-border); border-radius: 8px; background: #fff; text-align: center; }
.cs-sig-type-preview canvas { display: block; width: 100%; height: 140px; }
.cs-sig-upload-box { border: 2px dashed var(--cs-border); border-radius: 8px; padding: 20px; text-align: center; background: #f8fafc; margin-top: 8px; cursor: pointer; }
.cs-sig-upload-box img { max-height: 120px; max-width: 100%; margin: 0 auto; object-fit: contain; }

.cs-cover, .cs-hits, .cs-overlay, .cs-sel { position: absolute; inset: 0; }
.cs-cover { z-index: 2; pointer-events: none; }
.cs-hits { z-index: 3; pointer-events: none; }
.cs-overlay { z-index: 5; pointer-events: none; }
.cs-sel { z-index: 6; pointer-events: none; }

.cs-hit {
  position: absolute; pointer-events: auto; cursor: text;
  border: 1px solid transparent; border-radius: 1px;
}
.cs-hit:hover { background: rgba(15,118,110,.14); border-color: rgba(15,118,110,.4); }

.cs-cover-block {
  position: absolute; pointer-events: none; background: #fff; box-shadow: 0 0 0 1px #fff;
}

.cs-text {
  position: absolute; pointer-events: auto; cursor: move;
  white-space: pre-wrap; word-break: break-word; line-height: 1.2;
  border: 1px solid transparent; outline: none; background: transparent;
  min-width: 12px; padding: 0 1px;
}
.cs-text:hover { border-color: rgba(15,118,110,.45); }
.cs-text.selected, .cs-text.editing {
  border-color: var(--cs); box-shadow: 0 0 0 2px rgba(15,118,110,.2);
  background: rgba(255,255,255,.92); cursor: text;
}
.cs-text.exporting { border: none !important; box-shadow: none !important; background: transparent !important; }

.cs-ann { position: absolute; pointer-events: auto; cursor: move; }
.cs-hl { mix-blend-mode: multiply; }
.cs-shape { border: 2px solid #ef4444; box-sizing: border-box; }
.cs-sig-obj, .cs-img-obj { overflow: hidden; border: 1px dashed transparent; }
.cs-sig-obj img, .cs-img-obj img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cs-sig-obj.selected, .cs-img-obj.selected { border-color: var(--cs); }

.cs-sel-box { position: absolute; border: 1.5px solid var(--cs); pointer-events: none; box-sizing: border-box; }
.cs-handle {
  position: absolute; width: 8px; height: 8px; background: #fff;
  border: 1.5px solid var(--cs); pointer-events: auto;
}
.cs-handle-nw { left:-4px; top:-4px; cursor:nwse-resize; }
.cs-handle-ne { right:-4px; top:-4px; cursor:nesw-resize; }
.cs-handle-sw { left:-4px; bottom:-4px; cursor:nesw-resize; }
.cs-handle-se { right:-4px; bottom:-4px; cursor:nwse-resize; }
.cs-ghost {
  position: absolute; border: 1.5px dashed var(--cs);
  background: rgba(15,118,110,.1); pointer-events: none; z-index: 20;
}

.cs-right {
  width: 190px; flex-shrink: 0; border-left: 1px solid var(--cs-border);
  padding: 10px; overflow-y: auto; background: #fff;
}
.cs-right h3 {
  font-size: 10px; font-weight: 800; letter-spacing: .7px; text-transform: uppercase;
  color: #94a3b8; margin: 0 0 10px;
}
.cs-right label {
  display: block; font-size: 9px; font-weight: 700; text-transform: uppercase;
  color: #94a3b8; margin-bottom: 3px;
}
.cs-right select, .cs-right input[type=number] {
  width: 100%; padding: 5px 7px; border: 1px solid var(--cs-border); border-radius: 6px;
  font-size: 11px; margin-bottom: 8px; outline: none;
}
.cs-right input[type=color] {
  width: 100%; height: 28px; border: 1px solid var(--cs-border); border-radius: 6px; padding: 1px;
}
.cs-row { display: flex; gap: 8px; margin-bottom: 8px; }
.cs-row > div { flex: 1; }
.cs-chip {
  width: 28px; height: 26px; border: 1px solid var(--cs-border); border-radius: 5px;
  background: #fff; cursor: pointer; font-size: 11px; font-weight: 800; color: #475569;
}
.cs-chip.active { background: var(--cs); color: #fff; border-color: var(--cs); }

.cs-status {
  display: flex; justify-content: space-between; padding: 4px 10px;
  font-size: 10px; color: #94a3b8; border-top: 1px solid var(--cs-border); background: #f8fafc;
}

.cs-modal {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(15,23,42,.45); align-items: center; justify-content: center;
}
.cs-modal.open { display: flex; }
.cs-modal-card {
  background: #fff; border-radius: 12px; padding: 16px; width: min(460px, 92vw);
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.cs-modal-card h3 { margin: 0 0 10px; font-size: 14px; }
#cs-sig-canvas {
  width: 100%; height: 160px; border: 1px solid var(--cs-border); border-radius: 8px;
  background: #fff; cursor: crosshair; touch-action: none;
}
.cs-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

html.dark .cs-landing-card,
html.dark .cs-workspace,
html.dark .cs-topbar,
html.dark .cs-right,
html.dark .cs-export-menu,
html.dark .cs-modal-card { background: #1e293b; border-color: #334155; color: #e2e8f0; }
html.dark .cs-left, html.dark .cs-status { background: #0f172a; border-color: #334155; }
html.dark .cs-landing-card h1 { color: #f1f5f9; }
html.dark .cs-drop { background: #134e4a33; border-color: #334155; }

@media (max-width: 900px) {
  .cs-left, .cs-right { display: none; }
  .cs-workspace { height: calc(100vh - 150px); }
}

/* ── Pro: edit modes ─────────────────────────────────────────────────────── */
.cs-mode {
  min-width: 26px; height: 26px; padding: 0 6px;
  border: 1px solid var(--cs-border); border-radius: 5px;
  background: #fff; color: #64748b; font-size: 10px; font-weight: 800; cursor: pointer;
}
.cs-mode.active { background: var(--cs); color: #fff; border-color: var(--cs); }

/* ── Pro: find bar ───────────────────────────────────────────────────────── */
.cs-find-bar {
  display: none; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 10px; border-bottom: 1px solid var(--cs-border); background: #f8fafc;
}
.cs-find-bar.open { display: flex; }
.cs-find-bar input {
  border: 1px solid var(--cs-border); border-radius: 6px; padding: 5px 8px;
  font-size: 12px; min-width: 120px; outline: none;
}
.cs-find-bar input:focus { border-color: var(--cs); box-shadow: 0 0 0 2px rgba(15,118,110,.15); }
.cs-find-count { font-size: 11px; font-weight: 700; color: #64748b; min-width: 36px; }
.cs-find-hit { outline: 2px solid rgba(245,158,11,.7) !important; }
.cs-find-active { outline: 2px solid #f59e0b !important; background: rgba(254,243,199,.55) !important; }

/* ── Pro: formula / link / comment ───────────────────────────────────────── */
.cs-formula {
  background: rgba(255,255,255,.92); padding: 2px 6px; border-radius: 4px;
  border: 1px solid transparent; cursor: move; color: #0f172a;
}
.cs-formula.inline { display: inline-block; padding: 0 3px; }
.cs-formula.selected { border-color: var(--cs); box-shadow: 0 0 0 2px rgba(15,118,110,.2); }
.cs-formula .katex { font-size: 1em; }
.cs-link {
  border: 1.5px dashed rgba(14,165,233,.7); background: rgba(14,165,233,.08);
  border-radius: 3px; cursor: pointer;
}
.cs-link.selected { border-style: solid; border-color: #0ea5e9; }
.cs-comment {
  background: #fef9c3; border: 1px solid #fde047; border-radius: 6px;
  padding: 6px 8px; color: #713f12; box-shadow: 0 4px 14px rgba(15,23,42,.08);
  white-space: pre-wrap; line-height: 1.35;
}
.cs-comment.selected, .cs-comment[contenteditable="true"] {
  border-color: #eab308; box-shadow: 0 0 0 2px rgba(234,179,8,.25);
}

.cs-prop-block {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--cs-border);
}
.cs-input {
  width: 100%; padding: 5px 7px; border: 1px solid var(--cs-border); border-radius: 6px;
  font-size: 11px; outline: none; box-sizing: border-box;
}
.cs-asset-chip {
  display: block; width: 100%; text-align: left; margin-top: 6px;
  border: 1px solid var(--cs-border); border-radius: 6px; padding: 6px 8px;
  background: #fff; font-size: 11px; cursor: pointer; color: #334155;
}
.cs-asset-chip:hover { border-color: var(--cs); background: var(--cs-soft); }

.cs-hf {
  font-size: 11px; color: #64748b; border-bottom: 1px solid #e2e8f0;
  padding-bottom: 6px; margin-bottom: 12px;
}
.cs-hf-footer {
  border-bottom: none; border-top: 1px solid #e2e8f0;
  padding-top: 8px; margin-top: 18px; margin-bottom: 0;
}

/* ── Pro: equation modal ─────────────────────────────────────────────────── */
.cs-eq-card { width: min(640px, 94vw); max-height: 90vh; overflow: auto; }
.cs-eq-sub { margin: 0 0 10px; font-size: 12px; color: #64748b; line-height: 1.4; }
.cs-eq-palette {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px;
  max-height: 140px; overflow: auto; padding: 6px;
  background: #f8fafc; border: 1px solid var(--cs-border); border-radius: 8px;
}
.cs-eq-palette button {
  border: 1px solid var(--cs-border); border-radius: 5px; background: #fff;
  padding: 3px 7px; font-size: 12px; cursor: pointer; color: #334155;
}
.cs-eq-palette button:hover { border-color: var(--cs); background: #ecfdf5; }
.cs-eq-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cs-eq-row select {
  border: 1px solid var(--cs-border); border-radius: 6px; padding: 4px 8px; font-size: 12px;
}
.cs-eq-latex {
  width: 100%; box-sizing: border-box; border: 1px solid var(--cs-border); border-radius: 8px;
  padding: 8px; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  resize: vertical; margin-bottom: 8px; outline: none;
}
.cs-eq-latex:focus { border-color: var(--cs); box-shadow: 0 0 0 2px rgba(15,118,110,.15); }
.cs-eq-preview {
  min-height: 64px; padding: 14px; border: 1px dashed #99f6e4; border-radius: 8px;
  background: #f0fdfa; display: flex; align-items: center; justify-content: center;
  overflow: auto; margin-bottom: 4px;
}

html.dark .cs-find-bar,
html.dark .cs-eq-palette,
html.dark .cs-eq-preview { background: #0f172a; border-color: #334155; }
html.dark .cs-mode,
html.dark .cs-asset-chip,
html.dark .cs-eq-palette button { background: #1e293b; border-color: #334155; color: #e2e8f0; }
html.dark .cs-formula { background: rgba(30,41,59,.92); color: #f1f5f9; }
html.dark .cs-comment { background: #422006; border-color: #a16207; color: #fef3c7; }
