:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #102a43;
  --muted: #52606d;
  --line: #d9e2ec;
  --brand: #0f3d57;
  --brand-strong: #083246;
  --accent: #d9a441;
  --danger: #b83232;
  --shadow: 0 14px 28px rgba(15, 61, 87, 0.08);
  --radius: 14px;
  --ribbon-bg: #f0f3f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Trebuchet MS", "Gill Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(15,61,87,.12), transparent),
    radial-gradient(900px 320px at 100% 0%, rgba(217,164,65,.12), transparent),
    var(--bg);
}

.bg-shape { position: fixed; z-index: -1; border-radius: 999px; filter: blur(12px); opacity: .2; }
.bg-shape-a { width: 280px; height: 280px; background: #0f3d57; top: 72px; right: -90px; }
.bg-shape-b { width: 180px; height: 180px; background: #d9a441; bottom: 90px; left: -60px; }

.uploader-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(15,61,87,.12), transparent),
    radial-gradient(900px 320px at 100% 0%, rgba(217,164,65,.12), transparent),
    var(--bg);
}
.uploader-screen[hidden] { display: none; }
.uploader-full { width: min(760px, 96vw); }
.brand-upload { margin-bottom: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.uploader { padding: 20px; animation: rise 320ms ease; }
.uploader h2 { margin: 0; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 72px; height: 72px; object-fit: contain; border-radius: 10px;
}
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(145deg, var(--brand), var(--brand-strong));
  color: #fff; display: grid; place-items: center; font-weight: 700; letter-spacing: .6px;
}
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); }
.hint { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }

.dropzone {
  margin-top: 12px;
  border: 1px dashed var(--brand);
  border-radius: 12px;
  display: grid; place-items: center;
  padding: 34px 16px;
  background: #f8fbfd;
  cursor: pointer;
  text-align: center;
  transition: border-color 180ms, background-color 180ms, transform 180ms;
}
.dropzone:hover, .dropzone.dragging {
  border-color: var(--accent); background: #fffaf0; transform: translateY(-1px);
}
.dropzone input { display: none; }
/* =========== EDITOR SHELL =========== */
.editor-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}
.editor-shell[hidden] { display: none !important; }

.ribbon-tabbar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--brand);
  padding: 0 8px;
}
.ribbon-tabbar .ribbon-logo {
  margin-left: auto;
  height: 26px;
  width: auto;
  object-fit: contain;
  padding: 2px 10px;
  opacity: .85;
  pointer-events: none;
}
.ribbon-tab {
  border: none;
  border-radius: 0;
  padding: 7px 18px;
  background: transparent;
  color: rgba(255,255,255,.7);
  font-weight: 600;
  font-size: .86rem;
  cursor: pointer;
  transition: background 120ms, color 120ms;
  border-bottom: 2px solid transparent;
}
.ribbon-tab:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
}
.ribbon-tab.active {
  background: var(--ribbon-bg);
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.ribbon-strip {
  background: var(--ribbon-bg);
  border-bottom: 1px solid var(--line);
  min-height: 78px;
}

.ribbon-panel {
  display: none;
  padding: 4px 8px;
  gap: 0;
  align-items: stretch;
}
.ribbon-panel.active {
  display: flex;
  flex-wrap: wrap;
}

.ribbon-group {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding: 0 10px;
}
.ribbon-group:last-child { border-right: none; }

.ribbon-group-body {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  padding: 2px 0;
}

.ribbon-group-label {
  text-align: center;
  font-size: .7rem;
  color: var(--muted);
  padding: 1px 0 3px;
  border-top: 1px solid rgba(0,0,0,.04);
  letter-spacing: .2px;
}
/* =========== RIBBON BUTTONS =========== */
.ribbon-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 3px;
  padding: 3px 7px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  transition: background 100ms, border-color 100ms;
}
.ribbon-btn:hover {
  background: rgba(15,61,87,.07);
  border-color: var(--line);
}
.ribbon-btn.primary { background: var(--brand); color: #fff; }
.ribbon-btn.primary:hover { background: var(--brand-strong); }
.ribbon-btn.danger { color: var(--danger); }
.ribbon-btn.active-mode {
  background: #fff7e7;
  border-color: var(--accent);
  color: #6e4a13;
}

.ribbon-btn-large {
  flex-direction: column;
  padding: 5px 10px;
  font-size: .74rem;
  text-align: center;
  min-width: 52px;
}
.ribbon-btn-large .ribbon-icon { font-size: 1.25rem; }
.ribbon-icon { font-size: .95rem; line-height: 1; }

.ribbon-fmt {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  padding: 0;
  font-size: .86rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
}

.rg-font {
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}
.ribbon-font-row {
  display: flex;
  align-items: center;
  gap: 3px;
}
.ribbon-select {
  min-width: 115px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 5px;
  font-size: .82rem;
  background: #fff;
}
.ribbon-size {
  width: 44px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 5px;
  font-size: .82rem;
  text-align: center;
  background: #fff;
}
.ribbon-color {
  width: 26px; height: 26px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px;
  cursor: pointer;
  background: #fff;
}

.ribbon-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--muted);
  font-size: .8rem;
  background: #fff;
}

.ribbon-file-label { cursor: pointer; }
.ribbon-file-label input { display: none; }

.ribbon-mini-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }

.ribbon-zoom-label { font-size: .8rem; color: var(--muted); }
.ribbon-zoom-range { width: 110px; accent-color: var(--brand); }
.ribbon-zoom-val { font-size: .8rem; color: var(--muted); min-width: 34px; }
/* =========== DOCUMENT AREA =========== */
.editor-main {
  padding: 16px;
  overflow: auto;
  background:
    linear-gradient(180deg, #f6f9fc, #edf2f7),
    repeating-linear-gradient(90deg, rgba(15,61,87,.03) 0 24px, transparent 24px 48px);
}

.page-stage {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

#mainCanvas {
  display: block;
  border-radius: 3px;
  border: 1px solid #dbe5ef;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.text-layer, .overlay-layer {
  position: absolute;
  inset: 0;
}
.text-layer { z-index: 2; }
.overlay-layer { z-index: 3; pointer-events: none; }

.pdf-text-item {
  position: absolute;
  box-sizing: border-box;
  border: 1px solid rgba(115,129,146,.15);
  border-radius: 2px;
  background: #ffffff;
  min-width: 4px;
  padding: 0 1px;
  outline: none;
  white-space: pre;
  overflow: hidden;
  cursor: text;
  line-height: 1;
  transition: border-color 120ms, box-shadow 120ms;
}
.pdf-text-item:hover {
  border-color: rgba(15,61,87,.35);
  box-shadow: 0 0 0 1px rgba(15,61,87,.08);
}
.pdf-text-item.selected,
.pdf-text-item:focus {
  border-color: rgba(217,164,65,.85);
  background: #fffef8;
  box-shadow: 0 0 0 2px rgba(217,164,65,.18);
  overflow: visible;
  z-index: 5;
}
.pdf-text-item.deleted {
  opacity: .24;
  text-decoration: line-through;
}

.overlay-item {
  position: absolute;
  border: 1px solid transparent;
  user-select: none;
  pointer-events: auto;
}
.overlay-item.selected {
  border-color: rgba(217,164,65,.95);
  box-shadow: 0 0 0 2px rgba(217,164,65,.2);
}

.overlay-text {
  width: 100%; height: 100%;
  min-width: 40px; min-height: 22px;
  padding: 2px 4px;
  outline: none;
  white-space: pre-wrap;
  background: rgba(255,255,255,.9);
  overflow: hidden;
}

.overlay-item img {
  width: 100%; height: 100%;
  display: block; object-fit: fill;
}

.shape-box { width: 100%; height: 100%; box-sizing: border-box; }
.shape-box.ellipse { border-radius: 50%; }
.shape-box.line {
  position: relative;
  background: transparent !important;
  border: none !important;
}
.shape-box.line::after {
  content: "";
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 0;
  border-top: var(--line-width, 2px) solid var(--line-color, #d9a441);
}

.resize-handle {
  position: absolute; right: -6px; bottom: -6px;
  width: 11px; height: 11px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--brand);
  cursor: nwse-resize;
}

.editor-status {
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  background: #f7fafc;
  color: var(--muted);
  font-size: .8rem;
}

.toast {
  position: fixed; bottom: 18px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #0f3d57; color: #fff;
  padding: 10px 14px; border-radius: 10px;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms, transform 200ms;
  z-index: 100;
}
.toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

input[type="range"] { accent-color: var(--brand); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .ribbon-panel { flex-wrap: wrap; }
  .ribbon-group { border-right: none; border-bottom: 1px solid var(--line); padding: 4px 6px; }
  .ribbon-group:last-child { border-bottom: none; }
}

/* =========== LOADING OVERLAY =========== */
.loading-overlay {
  position: fixed; inset: 0;
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(3px);
}
.loading-overlay[hidden] { display: none; }
.loading-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  animation: rise .25s ease-out;
}
.loading-box p {
  margin: 14px 0 0;
  font-size: .95rem;
  color: var(--text);
}
.loading-spinner {
  width: 38px; height: 38px;
  margin: 0 auto;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }