/* ── EDITOR LAYOUT ── */
    body { overflow: hidden; height: 100vh; display: flex; flex-direction: column; }

    .editor-wrap {
      flex: 1;
      display: flex;
      overflow: hidden;
      position: relative;
    }

    /* ── TOOLBAR (left side) ── */
    .editor-toolbar {
      width: 120px;
      background: var(--bg-card);
      border-right: 0.5px solid var(--border);
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 12px 0;
      gap: 4px;
      z-index: 10;
      flex-shrink: 0;
    }

    .tool-btn {
      width: 100%; height: 46px;
      border-radius: var(--radius-sm);
      background: transparent;
      border: none;
      display: flex; align-items: center; justify-content: flex-start;
      padding: 0 10px;
      gap: 0;
      cursor: pointer;
      transition: var(--transition);
      position: relative;
      font-size: 20px;
      color: #7a6e64;
    }
    .tool-btn-label {
      font-size: 12px;
      font-weight: 500;
      color: #7a6e64;
      white-space: nowrap;
      order: -1;
      width: 80px;
      text-align: left;
      flex-shrink: 0;
    }
    .tool-btn:hover .tool-btn-label,
    .tool-btn.active .tool-btn-label {
      color: inherit;
    }
    .tool-btn svg { width: 20px; height: 20px; }
    .tool-btn:hover { background: var(--bg); color: var(--text); }
    .tool-btn.active { background: var(--text); color: var(--bg) !important; }
    .tool-btn.active svg { stroke: var(--bg) !important; fill: none; }
    .tool-btn.locked { opacity: 0.5; cursor: not-allowed; }
    .tool-btn.locked:hover { background: transparent; }

    /* Per-tool icon colors (default/hover state) */
    #tool-select svg      { stroke: #7a6e64; }
    #tool-highlight svg   { fill: #c8870a; stroke: #c8870a; }
    #tool-text svg        { stroke: #2e7d8a; }
    #tool-pen svg         { stroke: #6d4fc2; }
    #tool-sticky svg      { stroke: #e67e22; }
    #tool-eraser svg      { stroke: #27ae60; }
    #tool-rectangle svg   { stroke: #c0392b; }
    #tool-circle svg      { stroke: #e91e8c; }
    #tool-arrow svg       { stroke: #1565c0; }
    #tool-image svg       { stroke: #00796b; }
    #tool-signature svg   { stroke: #5c3d99; }
    #tool-redact svg      { fill: #c0392b; stroke: none; }

    .tool-btn-tooltip { display: none; }

    .toolbar-sep {
      width: 28px; height: 0.5px;
      background: var(--border);
      margin: 6px 0;
      flex-shrink: 0;
    }

    .toolbar-pro-badge {
      font-size: 8px;
      font-weight: 600;
      color: var(--accent);
      position: absolute;
      top: 4px; right: 4px;
      background: var(--accent-light);
      padding: 1px 4px;
      border-radius: 4px;
      line-height: 1.4;
    }

    /* ── OPTIONS PANEL (right side) ── */
    .editor-options {
      width: 220px;
      background: var(--bg-card);
      border-left: 0.5px solid var(--border);
      padding: 16px;
      overflow-y: auto;
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .options-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--text);
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 4px;
    }

    .option-group { display: flex; flex-direction: column; gap: 8px; }

    .option-group label {
      font-size: 13px;
      font-weight: 500;
      color: var(--text);
    }

    .color-row {
      display: flex; gap: 6px; flex-wrap: wrap;
    }

    .color-swatch {
      width: 22px; height: 22px;
      border-radius: 50%;
      cursor: pointer;
      border: 2px solid transparent;
      transition: var(--transition);
      flex-shrink: 0;
    }
    .color-swatch.active { border-color: var(--text); }
    .color-swatch:hover { transform: scale(1.15); }

    .option-slider {
      width: 100%;
      accent-color: var(--accent);
    }

    .option-select-sm {
      width: 100%; padding: 6px 10px;
      border-radius: var(--radius-sm);
      border: 0.5px solid var(--border);
      background: var(--bg);
      font-size: 13px;
      color: var(--text);
      font-family: var(--font);
    }

    .option-input-sm {
      width: 100%; padding: 6px 10px;
      border-radius: var(--radius-sm);
      border: 0.5px solid var(--border);
      background: var(--bg);
      font-size: 13px;
      color: var(--text);
      font-family: var(--font);
    }
    .option-input-sm:focus { border-color: var(--accent); }

    /* Signature pad in options */
    .sig-pad-wrap {
      background: var(--bg);
      border: 0.5px solid var(--border);
      border-radius: var(--radius-sm);
      overflow: hidden;
      position: relative;
    }
    .sig-pad-wrap canvas {
      display: block;
      cursor: crosshair;
      touch-action: none;
    }
    .sig-pad-clear {
      font-size: 11px;
      color: var(--text-muted);
      background: none;
      border: none;
      cursor: pointer;
      padding: 4px 0;
      text-align: left;
      transition: var(--transition);
    }
    .sig-pad-clear:hover { color: #c0392b; }

    .sig-tabs {
      display: flex; gap: 0;
      border: 0.5px solid var(--border);
      border-radius: var(--radius-sm);
      overflow: hidden;
      margin-bottom: 8px;
    }
    .sig-tab {
      flex: 1; padding: 6px 0;
      font-size: 12px; text-align: center;
      cursor: pointer; background: var(--bg);
      color: var(--text-muted);
      border: none;
      font-family: var(--font);
      transition: var(--transition);
    }
    .sig-tab.active { background: var(--text); color: var(--bg); }

    /* ── CANVAS AREA (center) ── */
    .editor-canvas-area {
      flex: 1;
      overflow: auto;
      background: #e8e4de;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20px;
      gap: 16px;
      position: relative;
    }

    .page-wrap {
      position: relative;
      box-shadow: 0 4px 20px rgba(31,26,21,0.18);
      flex-shrink: 0;
      background: white;
      margin-bottom: 9px;
    }

    .page-wrap canvas.pdf-canvas {
      display: block;
    }

    .page-wrap canvas.annotation-canvas {
      position: absolute;
      top: 0; left: 0;
      pointer-events: all;
    }

    /* ── TOP BAR ── */
    .editor-topbar {
      display: flex; align-items: center; justify-content: space-between;
      padding: 0 16px; height: 48px;
      background: var(--bg);
      border-bottom: 0.5px solid var(--border);
      flex-shrink: 0;
      gap: 12px;
    }

    .topbar-left { display: flex; align-items: center; gap: 12px; }
    .topbar-right { display: flex; align-items: center; gap: 8px; }

    .topbar-filename {
      font-size: 13px;
      font-weight: 500;
      color: var(--text);
      max-width: 200px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .topbar-pages {
      font-size: 12px;
      color: var(--text-muted);
    }

    .topbar-btn {
      padding: 6px 14px;
      border-radius: var(--radius-sm);
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      transition: var(--transition);
      font-family: var(--font);
    }

    .topbar-btn.outline {
      background: transparent;
      border: 0.5px solid var(--border);
      color: var(--text-muted);
    }
    .topbar-btn.outline:hover { border-color: var(--border-hover); color: var(--text); background: var(--bg-card); }

    .topbar-btn.primary {
      background: var(--accent);
      border: none;
      color: var(--bg);
    }
    .topbar-btn.primary:hover { background: #a8681f; }
    .topbar-btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }

    .topbar-btn.danger {
      background: transparent;
      border: 0.5px solid #f5c6c6;
      color: #c0392b;
    }
    .topbar-btn.danger:hover { background: #fdf2f2; }

    .topbar-zoom {
      display: flex; align-items: center; gap: 4px;
    }
    .topbar-zoom button {
      width: 28px; height: 28px;
      border-radius: var(--radius-sm);
      background: var(--bg-card);
      border: 0.5px solid var(--border);
      font-size: 16px;
      color: var(--text);
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      transition: var(--transition);
      font-family: var(--font);
    }
    .topbar-zoom button:hover { background: #ebe7e1; }
    .topbar-zoom span {
      font-size: 12px;
      color: var(--text-muted);
      min-width: 36px;
      text-align: center;
    }

    /* page nav */
    .page-nav {
      display: flex; align-items: center; gap: 6px;
    }
    .page-nav button {
      width: 28px; height: 28px;
      border-radius: var(--radius-sm);
      background: var(--bg-card);
      border: 0.5px solid var(--border);
      font-size: 14px;
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      transition: var(--transition);
      color: var(--text);
    }
    .page-nav button:hover { background: #ebe7e1; }
    .page-nav button:disabled { opacity: 0.3; cursor: not-allowed; }

    /* ── UPLOAD OVERLAY (shown before file is loaded) ── */
    .upload-overlay {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 20;
      background: #e8e4de;
    }

    .upload-overlay-card {
      background: var(--bg);
      border: 1.5px dashed var(--border-hover);
      border-radius: var(--radius-xl);
      padding: 56px 48px;
      text-align: center;
      max-width: 440px;
      width: 100%;
      cursor: pointer;
      transition: var(--transition);
    }
    .upload-overlay-card:hover, .upload-overlay-card.dragover {
      border-color: var(--accent);
      background: var(--accent-light);
    }
    .upload-overlay-icon { font-size: 48px; margin-bottom: 16px; }
    .upload-overlay-title { font-size: 20px; font-weight: 500; margin-bottom: 8px; }
    .upload-overlay-sub { font-size: 14px; color: var(--text-muted); margin-bottom: 6px; }
    .upload-overlay-limit { font-size: 12px; color: var(--text-light); }
    .upload-overlay-sub span { color: var(--accent); font-weight: 500; }

    /* ── TIER BADGE in topbar ── */
    .tier-badge {
      font-size: 11px; font-weight: 500;
      padding: 3px 9px; border-radius: 10px;
    }
    .tier-badge.guest { background: var(--bg-card); color: var(--text-muted); border: 0.5px solid var(--border); }
    .tier-badge.free { background: #e8f5e9; color: #388e3c; }
    .tier-badge.pro { background: var(--accent-light); color: var(--accent); }

    /* ── SAVE PROGRESS OVERLAY ── */
    .save-overlay {
      position: fixed; inset: 0;
      background: rgba(31,26,21,0.4);
      z-index: 300;
      display: none;
      align-items: center;
      justify-content: center;
    }
    .save-overlay.show { display: flex; }
    .save-overlay-card {
      background: var(--bg);
      border-radius: var(--radius-lg);
      padding: 32px 40px;
      text-align: center;
      min-width: 260px;
    }
    .save-overlay-title { font-size: 16px; font-weight: 500; margin-bottom: 12px; }
    .save-progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
    .save-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; width: 0%; transition: width 0.3s ease; }

    /* ── ERROR TOAST ── */
    .editor-toast {
      position: fixed;
      bottom: 24px; left: 50%;
      transform: translateX(-50%) translateY(80px);
      background: var(--bg-dark);
      color: var(--bg);
      font-size: 13px;
      padding: 10px 20px;
      border-radius: var(--radius-md);
      z-index: 400;
      transition: transform 0.25s ease;
      white-space: nowrap;
      max-width: 90vw;
      white-space: normal;
      text-align: center;
    }
    .editor-toast.show { transform: translateX(-50%) translateY(0); }
    .editor-toast.error { background: #c0392b; }
    .editor-toast.success { background: #27ae60; }

    /* ── LOCKED TOOL MODAL ── */
    .lock-modal {
      position: fixed; inset: 0;
      background: rgba(31,26,21,0.5);
      z-index: 300;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }
    .lock-modal.show { display: flex; }
    .lock-modal-card {
      background: var(--bg);
      border-radius: var(--radius-lg);
      padding: 32px 28px;
      max-width: 380px;
      width: 100%;
      text-align: center;
    }
    .lock-modal-icon { font-size: 36px; margin-bottom: 12px; }
    .lock-modal-title { font-size: 18px; font-weight: 500; margin-bottom: 8px; }
    .lock-modal-desc { font-size: 14px; color: var(--text-muted); margin-bottom: 24px; line-height: 1.6; }
    .lock-modal-actions { display: flex; gap: 10px; justify-content: center; }

    /* ── WATERMARK NOTICE ── */
    .watermark-notice {
      background: var(--accent-light);
      border: 0.5px solid var(--accent);
      border-radius: var(--radius-sm);
      padding: 8px 14px;
      font-size: 12px;
      color: var(--text);
      text-align: center;
    }
    .watermark-notice a { color: var(--accent); font-weight: 500; }

    /* ── UNDO/REDO count ── */
    .undo-count {
      font-size: 10px;
      position: absolute;
      bottom: 3px; right: 3px;
      color: var(--text-light);
    }

    .pdf-text-layer {
      position: absolute;
      top: 0;
      left: 0;
      overflow: hidden;
      line-height: 1;
    }
    .pdf-text-layer span {
      color: transparent;
      position: absolute;
      white-space: pre;
      cursor: text;
      transform-origin: 0% 0%;
    }
    .pdf-text-layer span::selection {
      background: rgba(30, 136, 229, 0.5);
      color: transparent;
    }

    /* ── RESPONSIVE ── */
    @media (max-width: 768px) {
      .editor-options { display: none; }
      .editor-options.mobile-open { display: flex; position: fixed; right: 0; top: 0; bottom: 0; z-index: 50; box-shadow: var(--shadow-md); }
      .topbar-filename { max-width: 120px; }
    }
    @media (max-width: 480px) {
      .editor-toolbar { width: 52px; }
      .tool-btn { width: 40px; height: 40px; font-size: 18px; }
    }