/* ================================================================
   PDF Editor — styles.css
   8px grid · Inter typeface · day/night themes
   ================================================================ */

:root{
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-6: 48px;
  --space-8: 64px;

  --radius-btn: 8px;
  --radius-panel: 12px;
  --radius-input: 6px;

  --header-h: 60px;
  --toolbar-h: 52px;
  --statusbar-h: 32px;

  --transition: 0.3s ease;
}

/* ---------- Day theme ---------- */
.theme-day{
  --primary: #4F46E5;
  --primary-hover: #3F35D6;
  --secondary: #0E9D63;
  --bg: #F6F5FC;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --text: #181529;
  --text-muted: #6D6889;
  --border: #E5E2F4;
  --shadow: 0 1px 3px rgba(24,21,41,0.08);
  --shadow-lg: 0 10px 30px rgba(24,21,41,0.12);
  --canvas-bg: #EFEDF9;
  --danger: #DC3B34;
}

/* ---------- Night theme ---------- */
.theme-night{
  --primary: #7C74FF;
  --primary-hover: #948CFF;
  --secondary: #37D999;
  --bg: #0E0D18;
  --surface: #17152A;
  --surface-raised: #1B1930;
  --text: #F2F0FB;
  --text-muted: #948FB2;
  --border: #2C2946;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
  --canvas-bg: #0A0913;
  --danger: #F16863;
}

*{ box-sizing: border-box; }

/* The `hidden` attribute must always win over any component's own `display` rule below */
[hidden]{ display: none !important; }

html,body{
  margin:0; padding:0; height:100%;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  overflow: hidden;
}

button{ font-family: inherit; }

::selection{ background: var(--primary); color: #fff; }

/* ================= HEADER ================= */
.app-header{
  height: var(--header-h);
  display:flex; align-items:center; justify-content:space-between;
  padding: 0 var(--space-3);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
  position: relative; z-index: 40;
}
.header-left, .header-right{ display:flex; align-items:center; gap: var(--space-2); }
.logo{ display:flex; align-items:center; gap: var(--space-1); }
.logo-mark{
  width:30px;height:30px;border-radius:9px;
  background:linear-gradient(150deg,var(--primary),#8B7CFF);
  color:#fff;display:flex;align-items:center;justify-content:center;
  font-weight:800;font-size:14px;flex:none;
  box-shadow:0 6px 14px -4px rgba(79,70,229,.4);
}
.logo-text{ font-weight:600; font-size:13.5px; white-space:nowrap; }
.logo-text strong{ font-weight:800; color: var(--primary); }

.header-center{ display:flex; flex-direction:column; align-items:center; line-height:1.25; }
#file-name{ font-weight:600; font-size:13.5px; }
.file-meta{ font-size:11.5px; color: var(--text-muted); }

/* ================= BUTTONS ================= */
.btn{
  display:inline-flex; align-items:center; gap:8px;
  height:38px; padding: 0 14px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-weight: 600;
  cursor:pointer;
  transition: all 0.15s ease;
}
.btn i{ width:16px; height:16px; }
.btn:hover{ background: var(--border); }
.btn:disabled{ opacity:.4; cursor:not-allowed; }
.btn-primary{
  background: var(--primary); border-color: var(--primary); color:#fff;
}
.btn-primary:hover:not(:disabled){ background: var(--primary-hover); }
.btn-ghost{ background: transparent; }
.btn-lg{ height:46px; padding:0 22px; font-size:14.5px; border-radius:10px; }

.icon-btn{
  width:36px; height:36px;
  display:flex; align-items:center; justify-content:center;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  background: transparent; color: var(--text);
  cursor:pointer; transition: all 0.15s ease;
}
.icon-btn i{ width:17px; height:17px; }
.icon-btn:hover{ background: var(--surface); border-color: var(--border); }
.icon-btn:disabled{ opacity:.35; cursor:not-allowed; }
.icon-btn.is-active{ background: var(--primary); color:#fff; }
.icon-btn.is-danger:hover{ color: var(--danger); border-color: var(--danger); }
.icon-btn.small{ width:28px; height:28px; }
.icon-btn.small i{ width:14px; height:14px; }

/* ================= TOOLBAR ================= */
.toolbar{
  height: var(--toolbar-h);
  display:flex; align-items:center; gap: var(--space-1);
  padding: 0 var(--space-2);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x:auto;
  transition: background var(--transition), border-color var(--transition);
}
.toolbar-group{ display:flex; align-items:center; gap:4px; flex-shrink:0; }
.toolbar-divider{ width:1px; height:26px; background: var(--border); margin:0 var(--space-1); flex-shrink:0; }
.toolbar-spacer{ flex:1; }

.tool-btn{
  display:flex; align-items:center; gap:6px;
  height:36px; padding:0 12px;
  border-radius: var(--radius-btn);
  border:1px solid transparent;
  background: transparent; color: var(--text-muted);
  font-size:13px; font-weight:600; cursor:pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.tool-btn i{ width:16px; height:16px; }
.tool-btn:hover{ background: var(--border); color: var(--text); }
.tool-btn.is-active{ background: var(--primary); color:#fff; }

.view-group{ display:flex; align-items:center; gap:2px; }
.zoom-label{
  min-width:52px; text-align:center; font-size:12.5px; font-weight:600;
  background:transparent; border:none; color: var(--text); cursor:pointer;
  height:36px;
}
.page-nav{ display:flex; align-items:center; gap:6px; font-size:12.5px; font-weight:600; }
#page-indicator{ min-width:52px; text-align:center; }

/* ================= WORKSPACE ================= */
.workspace{
  display:flex;
  height: calc(100vh - var(--header-h) - var(--toolbar-h) - var(--statusbar-h));
}

.thumb-rail{
  width:168px; flex-shrink:0;
  background: var(--surface);
  border-right:1px solid var(--border);
  display:flex; flex-direction:column;
  transition: margin-left var(--transition), background var(--transition), border-color var(--transition);
}
.thumb-rail.is-hidden{ margin-left:-168px; }
.thumb-rail-header{
  padding: var(--space-2); font-size:11.5px; font-weight:700;
  text-transform:uppercase; letter-spacing:.06em; color: var(--text-muted);
  border-bottom:1px solid var(--border);
}
.thumb-list{ overflow-y:auto; padding: var(--space-1); display:flex; flex-direction:column; gap: var(--space-1); }
.thumb-item{
  border-radius: var(--radius-input);
  border:2px solid transparent;
  padding:6px; cursor:pointer;
  background: var(--surface-raised);
  transition: border-color .15s ease;
}
.thumb-item.is-active{ border-color: var(--primary); }
.thumb-item canvas{ width:100%; display:block; border-radius:3px; box-shadow: var(--shadow); background:#fff; }
.thumb-item .thumb-label{ font-size:10.5px; text-align:center; margin-top:4px; color: var(--text-muted); display:flex; justify-content:center; align-items:center; gap:6px; }
.thumb-item .thumb-actions{ display:flex; justify-content:center; gap:2px; margin-top:2px; }
.thumb-item .thumb-actions button{ width:20px; height:20px; }
.thumb-item .thumb-actions button i{ width:11px; height:11px; }

.canvas-container{
  flex:1; overflow:auto; background: var(--canvas-bg);
  display:flex; align-items:flex-start; justify-content:center;
  padding: var(--space-4);
  transition: background var(--transition);
}
.page-stage{
  position:relative; background:#fff;
  box-shadow: var(--shadow-lg);
  flex-shrink:0;
}
#pdf-canvas{ display:block; }
.overlay-layer{
  position:absolute; top:0; left:0; right:0; bottom:0;
  pointer-events: none; /* let clicks on empty space fall through to the canvas below */
}

.properties-panel{
  width:264px; flex-shrink:0;
  background: var(--surface);
  border-left:1px solid var(--border);
  display:flex; flex-direction:column;
  transition: margin-right var(--transition), background var(--transition), border-color var(--transition);
}
.properties-panel.is-hidden{ margin-right:-264px; }
.panel-header{
  height:44px; display:flex; align-items:center; justify-content:space-between;
  padding: 0 var(--space-2); border-bottom:1px solid var(--border);
  font-size:12.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em;
  color: var(--text-muted);
}
.panel-body{ padding: var(--space-2); overflow-y:auto; display:flex; flex-direction:column; gap: var(--space-2); }
.panel-empty{ font-size:12.5px; color: var(--text-muted); line-height:1.6; }

.field{ display:flex; flex-direction:column; gap:6px; }
.field label{ font-size:11.5px; font-weight:600; color: var(--text-muted); }
.field select, .field input[type=number], .field textarea{
  width:100%; padding:8px 10px; border-radius: var(--radius-input);
  border:1px solid var(--border); background: var(--surface-raised); color: var(--text);
  font-size:13px; font-family:inherit;
}
.field textarea{ resize:vertical; min-height:64px; }
.field input[type=color]{ width:100%; height:36px; border-radius:var(--radius-input); border:1px solid var(--border); background:var(--surface-raised); cursor:pointer; padding:2px; }

.format-row{ display:flex; gap:6px; }
.format-row .icon-btn{ flex:1; border:1px solid var(--border); }
.format-row .icon-btn.is-active{ background: var(--primary); color:#fff; border-color: var(--primary); }

.btn-block{ width:100%; justify-content:center; }

/* ================= DROPZONE / EMPTY STATE ================= */
.dropzone{
  position:fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--primary) 10%, transparent), transparent 45%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--secondary) 10%, transparent), transparent 45%),
    var(--bg);
  z-index: 30;
  transition: background var(--transition);
}
.dropzone.is-dragover .dropzone-inner{ border-color: var(--primary); background: var(--surface); }
.dropzone-inner{
  max-width:480px; text-align:center; padding: var(--space-8) var(--space-4);
  border:2px dashed var(--border); border-radius: 20px;
  transition: all .2s ease;
}
.dropzone-icon{
  width:64px; height:64px; margin: 0 auto var(--space-2);
  border-radius:16px; background: var(--surface);
  display:flex; align-items:center; justify-content:center;
  color: var(--primary);
}
.dropzone-icon i{ width:28px; height:28px; }
.dropzone h1{ font-size:24px; margin: 0 0 var(--space-1); font-weight:800; }
.dropzone p{ font-size:14px; color: var(--text-muted); line-height:1.6; margin: 0 0 var(--space-3); }
.dropzone-hint{ display:block; margin-top: var(--space-2); font-size:11.5px; color: var(--text-muted); }

/* ================= STATUS BAR ================= */
.status-bar{
  height: var(--statusbar-h);
  display:flex; align-items:center; justify-content:space-between;
  padding: 0 var(--space-2);
  background: var(--surface-raised);
  border-top:1px solid var(--border);
  font-size:11.5px; color: var(--text-muted);
  transition: background var(--transition), border-color var(--transition);
}

/* ================= OVERLAY TEXT ELEMENTS ================= */
.pdf-el{
  position:absolute;
  cursor: grab;
  outline: 1px dashed transparent;
  min-width: 20px; min-height: 14px;
  pointer-events: auto;
}
.pdf-el:hover{ outline-color: color-mix(in srgb, var(--primary) 55%, transparent); }
.pdf-el.is-selected{ outline: 1.5px solid var(--primary); }
.pdf-el.is-whiteout{ background: #fff; }
.pdf-el.is-dragging{ cursor: grabbing; }
/* Keep the "grabbing" hand showing everywhere on screen during a fast drag, even if the
   pointer momentarily slips outside the element's own box while the mouse button is held. */
body.is-dragging-element, body.is-dragging-element *{ cursor: grabbing !important; }
.pdf-el .el-text{
  width:100%; height:100%;
  outline:none; border:none; background:transparent;
  white-space: pre-wrap; word-break: break-word;
  overflow:hidden;
  line-height:1.15;
}
.pdf-el .el-text[contenteditable=true]{ cursor:text; }
.handle{
  position:absolute; width:9px; height:9px; background:#fff;
  border:1.5px solid var(--primary); border-radius:2px;
  display:none;
}
.pdf-el.is-selected .handle{ display:block; }
.handle.nw{ left:-5px; top:-5px; cursor: nwse-resize; }
.handle.ne{ right:-5px; top:-5px; cursor: nesw-resize; }
.handle.sw{ left:-5px; bottom:-5px; cursor: nesw-resize; }
.handle.se{ right:-5px; bottom:-5px; cursor: nwse-resize; }

.marquee{
  position:absolute;
  border: 1.5px dashed var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  pointer-events: none;
}

/* ================= TOASTS ================= */
.toast-stack{
  position:fixed; right:20px; bottom:52px; z-index:100;
  display:flex; flex-direction:column; gap:8px; align-items:flex-end;
}
.toast{
  background: var(--surface-raised); color: var(--text);
  border:1px solid var(--border); box-shadow: var(--shadow-lg);
  padding:10px 14px; border-radius: var(--radius-btn);
  font-size:13px; font-weight:600; display:flex; align-items:center; gap:8px;
  animation: toast-in .2s ease;
}
.toast.is-error{ border-color: var(--danger); color: var(--danger); }
.toast.is-success i{ color: var(--secondary); }
@keyframes toast-in{ from{ opacity:0; transform: translateY(8px);} to{opacity:1; transform:none;} }

/* ================= LOADING ================= */
.loading-overlay{
  position:fixed; inset:0; z-index:200;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(3px);
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px;
}
.spinner{
  width:34px; height:34px; border-radius:50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }
#loading-text{ font-size:13px; font-weight:600; color: var(--text-muted); }

/* ================= RESPONSIVE ================= */
@media (max-width: 1024px){
  .thumb-rail{ position:absolute; z-index:20; height: calc(100vh - var(--header-h) - var(--toolbar-h) - var(--statusbar-h)); box-shadow: var(--shadow-lg); }
  .thumb-rail.is-hidden{ margin-left:-168px; }
  .properties-panel{ position:absolute; right:0; z-index:20; height: calc(100vh - var(--header-h) - var(--toolbar-h) - var(--statusbar-h)); box-shadow: var(--shadow-lg); }
}
@media (max-width: 768px){
  .logo-text{ display:none; }
  .header-center{ display:none !important; }
  .toolbar .tool-btn span{ display:none; }
  .btn span{ display:none; }
}
@media (max-width: 480px){
  .toolbar-group.page-nav span, .zoom-label{ font-size:11px; }
}
