:root{
  --primary: #2d5a3d;
  --primary-dark: #1e3a2a;
  --accent: #10b981;
  --text: #0f172a;
  --muted: #64748b;
  --bg: #f8fafc;
  --white: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 8px 24px rgba(0,0,0,0.08);
  --radius: 14px;
}

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial; color: var(--text); background: var(--bg); }

.topbar{
  height: 64px;
  display:flex;
  align-items:center;
  padding: 0 16px;
  gap: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--white);
  box-shadow: var(--shadow);
}
.brand{ font-weight: 800; letter-spacing: .3px; }
.spacer{ flex:1; }
.context{ opacity:.95; }

.layout{
  display:grid;
  grid-template-columns: 360px 1fr;
  grid-auto-rows: 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 64px);
}

.explorer{
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  min-width: 280px;
}
.explorer-header{
  display:flex; align-items:center; gap:8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.explorer-title{ font-weight: 700; }
.crumb{
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}
.explorer-list{ padding: 6px 8px; overflow:auto; }
.row{
  display:flex; align-items:center; gap:10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.row:hover{ background:#f1f5f9; }
.row .name{ flex:1; }
.row .size{ color: var(--muted); font-size: 12px; }
.folder{ color: var(--primary-dark); font-weight: 700; }
.file{ color: #0b3b2e; }

.viewer{
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  overflow: hidden;
}
.toolbar{
  display:flex; gap:10px; padding: 12px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.btn{
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white; border:none; border-radius: 10px; padding:10px 14px; font-weight:600; cursor:pointer;
  box-shadow: 0 4px 12px rgba(45,90,61,.25);
}
.btn:hover{ filter:brightness(1.05); transform: translateY(-1px); }
.btn.success{ background: linear-gradient(135deg, var(--accent), #059669); }
.btn.warn{ background: linear-gradient(135deg, #f59e0b, #d97706); }
.ghost{
  background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius:10px; cursor:pointer;
}
.ghost:hover{ background:#f1f5f9; }

.pdf-stage{ position:relative; display:flex; align-items:center; justify-content:center; height:100%; }
#pdfCanvas{ max-width: 100%; height: auto; display:none; }
.nofile{ color: var(--muted); }

@media (max-width: 1024px){
  .layout{ grid-template-columns: 1fr; grid-auto-rows: auto 1fr; }
  .explorer{ min-height: 260px; }
}


/* ===== Account Dropdown ===== */
.account-dropdown-container{ position:relative; }
.account-btn{
  display:flex; align-items:center; gap:8px; padding:8px 10px;
  background: rgba(255,255,255,0.1); color:#fff; border:none; border-radius:9999px; cursor:pointer;
}
.account-btn:hover{ background: rgba(255,255,255,0.18); }
.account-avatar,.dropdown-avatar{
  width:28px; height:28px; border-radius:9999px; background:#86efac; border:2px solid rgba(0,0,0,0.08);
}
.dropdown-icon{ opacity:.9; }
.dropdown-menu{
  position:absolute; right:0; top:44px; width:220px; background:#fff; border:1px solid var(--border);
  border-radius:14px; box-shadow: var(--shadow); overflow:hidden; z-index: 20;
}
.dropdown-menu.hidden{ display:none; }
.dropdown-header{
  display:flex; align-items:center; gap:10px; padding:12px; background:#f8fafc; border-bottom:1px solid var(--border);
}
.dropdown-item{
  display:block; padding:10px 12px; text-decoration:none; color:var(--text); font-weight:600;
}
.dropdown-item:hover{ background:#f1f5f9; }

/* ===== PDF Card / Stage improvements ===== */
.pdf-stage{ position:relative; display:flex; align-items:stretch; justify-content:center; height:100%; padding: 12px; overflow:auto; }
.pdf-card{
  background: #ffffff; border:1px solid var(--border); border-radius:16px; box-shadow: var(--shadow);
  width:100%; height:100%; display:flex; align-items:center; justify-content:center; overflow:auto; padding: 12px;
}
#pdfCanvas{ display:none; max-width:100%; height:auto; box-shadow: 0 2px 20px rgba(0,0,0,.06); border: 1px solid #e5e7eb; border-radius: 8px; }
.nofile{ color: var(--muted); }

/* Make explorer+viewer cards have consistent inner spacing */
.explorer, .viewer { background:#fff; }


/* --- Scroll/position fix: start at top, normal scrolling --- */
.pdf-stage {
  overflow: hidden;            /* outer container doesn't scroll */
  justify-content: center;     /* keep horizontal centering */
  align-items: stretch;
}

.pdf-card {
  align-items: flex-start;     /* top-align canvas */
  justify-content: center;     /* center horizontally */
  overflow: auto;              /* only the card scrolls */
  scroll-behavior: auto;
}

/* Make sure canvas is block-level and doesn't shift baseline */
#pdfCanvas { display: block; }


/* ===== Multi-page viewer ===== */
.pdf-pages{
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.pdf-page-canvas{
  display: block;
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 20px rgba(0,0,0,.06);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
/* Basic layout */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; color: #111; }

.topbar {
  height: 56px; background: #0f172a; color: #fff; display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
}
.topbar .title { font-weight: 600; }
.topbar .spacer { flex: 1; }

.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 56px); }

.sidebar {
  border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; min-width: 280px;
}
.folder-path { font-size: 13px; padding: 12px; background: #f8fafc; border-bottom: 1px solid #e5e7eb; }
.toolbar { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid #eef2f7; }
.toolbar button {
  padding: 6px 10px; border: 1px solid #e5e7eb; border-radius: 8px;  cursor: pointer; font-size: 13px;
}
.explorer { overflow: auto; flex: 1; }
.explorer .row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #f1f5f9; }
.explorer .row:hover { background: #f8fafc; }
.explorer .row.folder .name { cursor: pointer; }
.explorer .row .name { flex: 1 1 auto; min-width: 0; }
.explorer .row .size { opacity: .65; }
.explorer .row .actions { margin-left: auto; display: flex; gap: 6px; }
.explorer .row .actions button {
  border: 1px solid #e5e7eb; background: #fff; border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 12px;
}

.viewer { display: flex; flex-direction: column; overflow: hidden; }
.viewer-toolbar {
  display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid #eef2f7; background: #fff;
}
.viewer-toolbar button {
  padding: 6px 10px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px;
}

.pdf-container {
  position: relative;
  overflow-x: hidden; /* no horizontal scroll */
  overflow-y: auto;
  padding: 12px;
  height: calc(100% - 52px); /* toolbar height */
  display: flex;
  flex-direction: column;
  align-items: center; /* center pages */
  gap: 20px;
}

/* Field overlays */
.field-overlay { border-radius: 4px; }
.signature-field { font-weight: 400; }

/* Modal shell */
.kp-modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center; z-index: 999999;
}
.kp-modal {
  background: #fff; border-radius: 12px; padding: 16px; width: min(560px, 92vw);
  box-shadow: 0 12px 30px rgba(0,0,0,.25); font-size: 14px;
}
.kp-modal h3 { margin: 0 0 8px; font-size: 16px; }
.kp-modal p { margin: 6px 0 12px; white-space: pre-line; }
.kp-modal .row { display:flex; gap:10px; align-items:center; margin-top:8px; }
.kp-modal input[type="text"] { flex:1; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(0,0,0,0.2); }
.kp-modal .actions { display:flex; gap:8px; justify-content:flex-end; margin-top:14px; }
.kp-modal button {
  border: 1px solid rgba(0,0,0,0.2); border-radius: 8px; background:#f6f6f6; padding: 6px 12px; cursor:pointer;
}

/* Message */
.nofile { padding: 16px; color: #64748b; }

/* IMPORTANT: hide legacy single-canvas to prevent double preview */
#pdfCanvas { display: none !important; }

/* Toolbar text labels fix */
.toolbar .btn{display:inline-flex;gap:.5rem;white-space:nowrap;}


/* === Ensure toolbar button labels never disappear === */
.toolbar .btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap !important;
  text-indent: 0 !important;
  font-size: inherit !important;
  overflow: visible !important;
  flex: 0 0 auto !important;
  min-width: max-content;
}
.toolbar .btn * { font-size: inherit !important; }


.toolbar .btn .label{display:inline !important}
.toolbar .btn .icon{line-height:1}


/* === Toolbar text visibility hardening === */
.toolbar .btn {
  display:inline-flex;
  align-items:center;
  gap:.5rem;
  white-space:nowrap !important;
  text-indent:0 !important;
  font-size:inherit !important;
  overflow:visible !important;
  min-width:max-content;
}
.toolbar .btn .label{display:inline !important}

/* === BEGIN: Explorer row layout & icon buttons (patched) === */
.explorer .row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  flex-wrap: nowrap;
}
.explorer .row .name {
  flex: 1 1 auto;          /* take all remaining space */
  min-width: 0;
  overflow: visible;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* Hide size column entirely */
.explorer .row .size { display: none !important; }

.explorer .row .actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-left: 12px;
}
.explorer .row .actions .icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, #e5e7eb);
  background: #fff;
  border-radius: 8px;
  padding: 0;
  line-height: 1;
  font-size: 16px;
  cursor: pointer;
}
.explorer .row .actions .icon-btn:hover { background: #f1f5f9; }
.explorer .row .actions .icon-btn.danger { border-color: #fecaca; }
/* === END: Explorer row layout & icon buttons (patched) === */

/* === Overlay hardening (opaque + above canvas) === */
.pdf-page-wrapper { position: relative; }

.field-overlay{
  background: #fff !important;          /* no translucency */
  opacity: 1 !important;
  z-index: 20 !important;
  box-sizing: border-box !important;
  border: 1px solid rgba(0,0,0,.28) !important;
}


/* === Overlay calibration (global trim) === */
.field-overlay{
  line-height: 1.05 !important;
  padding: 2px 4px !important;
}
.field-overlay[type="checkbox"]{
  width: 14px !important;
  height: 14px !important;
  padding: 0 !important;
}

