/* =========================================================
   HAIF UI — Advanced App CSS (drop-in replacement)
   - Keeps your existing class names working
   - Adds modern tokens, subtle gradients, better spacing,
     improved PDF editor/signing UX, and stronger responsive behavior
========================================================= */

/* ---------- Theme tokens ---------- */
:root{
  /* Surfaces */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfcff;
  --panel: #0f1a30;

  /* Text */
  --text: #0b0f19;
  --muted: #667085;
  --muted-2: rgba(17,24,39,.62);

  /* Lines */
  --line: rgba(15,23,42,.10);
  --line-2: rgba(15,23,42,.14);

  /* Brand */
  --primary: #0b57d0;
  --primary2:#0a4db9;
  --primary-ghost: rgba(11,87,208,.10);

  /* Status */
  --ok: #188038;
  --warn: #b54708;
  --bad: #d93025;

  /* Shadow + radius */
  --radius: 18px;
  --radius-lg: 22px;

  --shadow-sm: 0 8px 18px rgba(2,6,23,.08);
  --shadow:    0 16px 40px rgba(2,6,23,.12);
  --shadow-2:  0 10px 24px rgba(2,6,23,.10);

  /* Layout */
  --sidebar-w: 280px;
  --sidebar-w-collapsed: 88px;
  --topbar-h: 60px;

  /* PDF */
  --pdf-bg: #f2f4fb;
  --pdf-page-shadow: 0 14px 28px rgba(2,6,23,.12);
  --pdf-page-radius: 16px;

  /* Motion */
  --ease: cubic-bezier(.2,.8,.2,1);
  --t-fast: 120ms;
  --t: 180ms;
}

/* Optional dark theme hook (if you ever want it) */
[data-theme="dark"]{
  --bg:#0b1220;
  --surface:#0f1a30;
  --surface-2:#0b1427;
  --text:#eaf1ff;
  --muted:rgba(234,241,255,.66);
  --muted-2:rgba(234,241,255,.56);
  --line:rgba(255,255,255,.10);
  --line-2:rgba(255,255,255,.14);
  --pdf-bg:#0b1427;
  --pdf-page-shadow:0 18px 40px rgba(0,0,0,.35);
}

/* ---------- Base reset ---------- */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(11,87,208,.07), transparent 60%),
    radial-gradient(900px 500px at 85% 0%, rgba(24,128,56,.05), transparent 55%),
    var(--bg);
  color:var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a{color:inherit}
img{max-width:100%;display:block}
svg{width:20px;height:20px}
.truncate{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* Better focus styles */
:focus-visible{
  outline: 3px solid rgba(11,87,208,.22);
  outline-offset: 2px;
  border-radius: 12px;
}

/* ---------- Layout ---------- */
.app{display:flex;min-height:100vh}

/* ---------- Sidebar ---------- */
.sidebar{
  width:var(--sidebar-w);
  background:
    radial-gradient(800px 420px at 20% 0%, rgba(255,255,255,.08), transparent 55%),
    linear-gradient(180deg,#0b1220 0%, #0f1a30 100%);
  color:#e6edf8;
  border-right:1px solid rgba(255,255,255,.08);
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:14px;
  position:sticky;
  top:0;
  height:100vh;
  z-index:60;
}

/* Brand block */
.brand{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 10px;
  border-radius:16px;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  box-shadow: 0 10px 22px rgba(0,0,0,.10);
}
.brand-logo{
  width:44px;
  height:44px;
  object-fit:contain;
  background:rgba(255,255,255,.07);
  border-radius:14px;
  padding:6px;
}
.brand-text{display:flex;flex-direction:column;min-width:0}
.brand-name{font-weight:1000;letter-spacing:.25px;line-height:1.05}
.brand-sub{
  font-size:12px;
  color:rgba(230,237,248,.72);
  margin-top:2px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis
}

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  text-decoration:none;
  font-weight:800;
  transition:
    transform var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    filter var(--t-fast) var(--ease);
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover{
  background:#f2f6ff;
  border-color:rgba(11,87,208,.18);
  box-shadow: 0 10px 22px rgba(2,6,23,.08);
}
.btn:active{transform:translateY(1px);box-shadow:none}
.btn:disabled{
  opacity:.55;
  cursor:not-allowed;
  box-shadow:none;
}

.btn.primary{
  background:
    radial-gradient(600px 220px at 30% 0%, rgba(255,255,255,.22), transparent 55%),
    linear-gradient(180deg,var(--primary) 0%, var(--primary2) 100%);
  border-color:rgba(255,255,255,.16);
  color:#fff;
  box-shadow:0 16px 32px rgba(11,87,208,.28);
}
.btn.primary:hover{filter:brightness(1.03)}
.btn.primary:active{filter:brightness(.98)}

/* Sidebar new doc button (kept compatible) */
.btn-newdoc{
  border-color:rgba(255,255,255,.12);
  background:rgba(255,255,255,.06);
  color:#fff;
}
.btn-newdoc:hover{background:rgba(255,255,255,.10)}
.btn-newdoc .btn-ico{font-size:18px;font-weight:1000;line-height:1}
.btn-newdoc .btn-label{white-space:nowrap}

/* Icon button */
.icon-btn{
  border:none;background:transparent;cursor:pointer;
  width:44px;height:44px;border-radius:14px;
  display:inline-flex;align-items:center;justify-content:center;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.icon-btn:hover{background:var(--primary-ghost)}
.icon-btn:active{transform:translateY(1px)}

/* Hamburger */
.hamburger{
  width:18px;height:2px;background:#111827;position:relative;border-radius:999px;
}
.hamburger::before,.hamburger::after{
  content:"";
  position:absolute;left:0;width:18px;height:2px;background:#111827;border-radius:999px;
}
.hamburger::before{top:-6px}
.hamburger::after{top:6px}

/* ---------- Nav ---------- */
.nav{display:flex;flex-direction:column;gap:8px}
.nav a{
  display:flex;align-items:center;gap:12px;
  text-decoration:none;
  padding:10px 12px;
  border-radius:14px;
  color:#e6edf8;
  background:transparent;
  border:1px solid transparent;
  transition:
    background var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}
.nav a:hover{
  background:rgba(255,255,255,.06);
  border-color:rgba(255,255,255,.08);
}
.nav a.active{
  background:rgba(11,87,208,.22);
  border-color:rgba(11,87,208,.38);
}
.nav-ico{
  display:inline-flex;
  width:36px;height:36px;
  align-items:center;justify-content:center;
  border-radius:12px;
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.07);
  flex:0 0 auto;
}
.nav-ico svg{width:20px;height:20px;opacity:.95}
.nav-label{font-weight:900;white-space:nowrap}

/* Sidebar footer */
.sidebar-footer{
  margin-top:auto;
  display:flex;
  flex-direction:column;
  gap:10px;
  padding-top:10px;
  border-top:1px solid rgba(255,255,255,.10);
}
.user-mini{
  display:flex;gap:10px;align-items:center;
  padding:10px 12px;border-radius:14px;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08)
}
.user-dot{
  width:10px;height:10px;border-radius:999px;
  background:linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.55));
  box-shadow: 0 6px 14px rgba(255,255,255,.08);
}
.user-text{min-width:0}
.user-name{font-weight:1000;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-email{font-size:12px;color:rgba(230,237,248,.70);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.logout-link{
  display:flex;align-items:center;gap:12px;
  padding:10px 12px;border-radius:14px;text-decoration:none;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  color:#fff;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.logout-link:hover{background:rgba(255,255,255,.09)}
.logout-link:active{transform:translateY(1px)}

/* Collapsed sidebar */
.sidebar.collapsed{
  width:var(--sidebar-w-collapsed);
  padding:14px 10px;
}
.sidebar.collapsed .brand-text,
.sidebar.collapsed .btn-label,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .user-text{display:none}
.sidebar.collapsed .brand{justify-content:center;padding:10px}
.sidebar.collapsed .brand-logo{width:46px;height:46px}
.sidebar.collapsed .btn-newdoc{justify-content:center}
.sidebar.collapsed .btn-newdoc .btn-ico{margin:0}
.sidebar.collapsed .user-mini{justify-content:center}
.sidebar.collapsed .logout-link{justify-content:center}
.sidebar.collapsed .nav a{justify-content:center;padding:10px}
.sidebar.collapsed .nav-ico{width:44px;height:44px;border-radius:14px}

/* ---------- Main / Topbar ---------- */
.main{flex:1;display:flex;flex-direction:column;min-width:0}
.topbar{
  height:var(--topbar-h);
  display:flex;align-items:center;gap:12px;
  padding:0 14px;
  border-bottom:1px solid rgba(15,23,42,.08);
  background:rgba(246,247,251,.72);
  backdrop-filter:saturate(170%) blur(12px);
  position:sticky;top:0;z-index:30;
}
.topbar-title{font-weight:1000}
.topbar-spacer{flex:1}
.content{
  padding:16px;
  max-width:1280px;
  width:100%;
  margin:0 auto;
  min-width:0;
}

/* ---------- Cards ---------- */
.card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow-2);
  padding:16px;
}
.card.soft{
  background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,255,255,.86));
}

/* Alerts */
.alert{
  padding:10px 12px;
  border-radius:14px;
  background:#fff2f2;
  border:1px solid #ffd5d5;
  margin:12px 0;
  font-weight:800;
}
.alert.success{background:#eefcf3;border-color:#b7f0c8}
.alert.warn{background:#fff7ed;border-color:#fed7aa}

/* ---------- Forms ---------- */
label{display:block;font-weight:1000;margin-top:12px;margin-bottom:6px}
input,select,textarea{
  width:100%;
  padding:10px 12px;
  border:1px solid var(--line-2);
  border-radius:14px;
  outline:none;
  font-size:14px;
  background:#fff;
  transition: box-shadow var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
input::placeholder,textarea::placeholder{color:rgba(102,112,133,.75)}
input:focus,select:focus,textarea:focus{
  border-color:rgba(11,87,208,.35);
  box-shadow:0 0 0 4px rgba(11,87,208,.14);
}
textarea{min-height:110px;resize:vertical}

/* ---------- Typography utils ---------- */
.muted{color:var(--muted)}
.mt{margin-top:14px}
.m0{margin:0}
.row{display:flex;align-items:center;gap:10px}
.row.between{justify-content:space-between}
.row.gap{gap:12px}

/* ---------- Badges ---------- */
.badge{
  display:inline-flex;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:rgba(15,23,42,.03);
  font-size:12px;
  font-weight:1000;
}
.badge.ok{background:rgba(24,128,56,.10);border-color:rgba(24,128,56,.22);color:#0f5a2a}
.badge.bad{background:rgba(217,48,37,.10);border-color:rgba(217,48,37,.22);color:#8f1f18}
.badge.info{background:rgba(11,87,208,.10);border-color:rgba(11,87,208,.22);color:#0b3f96}

/* Aliases used in some views */
.badge.danger{background:rgba(217,48,37,.10);border-color:rgba(217,48,37,.22);color:#8f1f18}
.badge.soft{background:rgba(15,23,42,.03);border-color:var(--line);color:rgba(17,24,39,.70)}

/* ---------- Tables ---------- */
.table-wrap{overflow:auto}
.table{
  width:100%;
  border-collapse:collapse;
  min-width:820px;
  background:var(--surface);
  border-radius:16px;
  overflow:hidden;
}
.table th,.table td{
  padding:12px 10px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align:middle
}
.table th{
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:rgba(17,24,39,.68);
  font-weight:1000;
  background:rgba(15,23,42,.02);
}
.table tr:hover td{background:rgba(11,87,208,.04)}

/* ---------- Tabs / chips ---------- */
.tabs{display:flex;gap:10px;flex-wrap:wrap}
.tab{
  text-decoration:none;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid var(--line);
  background:#fff;
  font-weight:1000;
  font-size:13px;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tab.active,.tab:hover{
  background:#eef3ff;
  border-color:rgba(11,87,208,.28);
}
.chips{display:flex;gap:8px;flex-wrap:wrap}
.chip{
  border:1px solid var(--line);
  background:#fff;
  border-radius:999px;
  padding:8px 12px;
  cursor:pointer;
  font-weight:1000;
  font-size:13px;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.chip:hover{background:#eef3ff}
.chip:active{transform:translateY(1px)}
.chip.primary{background:#eef3ff;border-color:rgba(11,87,208,.28)}

/* ---------- Simple spinner ---------- */
@keyframes spin{to{transform:rotate(360deg)}}
.spinner{
  width:18px;height:18px;border-radius:999px;
  border:3px solid rgba(11,87,208,.18);
  border-top-color:rgba(11,87,208,.95);
  animation:spin .7s linear infinite;
}

/* =========================================================
   PREPARE + SIGN PDF UI
========================================================= */

/* Layout: prepare editor */
.prepare{
  display:grid;
  grid-template-columns: 340px 1fr;
  gap:14px;
  align-items:start;
}

/* Elements list */
.elements{display:grid;grid-template-columns:1fr;gap:10px}
.btn.elem{
  justify-content:flex-start;
  padding:12px 12px;
  border-radius:16px;
  font-weight:1000;
  letter-spacing:.2px;
}
.btn.elem:hover{background:#f3f7ff}
.btn.elem.active-tool{
  border-color:rgba(11,87,208,.35);
  box-shadow:0 0 0 4px rgba(11,87,208,.12);
  background:rgba(11,87,208,.08);
}

/* PDF card */
.pdf-card{padding:0;overflow:hidden}
.pdf-toolbar{
  padding:12px 14px;
  border-bottom:1px solid var(--line);
  background:
    radial-gradient(700px 220px at 25% 0%, rgba(11,87,208,.10), transparent 55%),
    var(--surface-2);
}

/* PDF root */
.pdf-root{
  position:relative;
  width:100%;
  height:calc(100vh - 220px);
  overflow:auto;
  padding:14px;
  background:var(--pdf-bg);
  border-radius:0 0 var(--radius) var(--radius);
  scroll-behavior:smooth;
}

/* Scrollbars (WebKit) */
.pdf-root::-webkit-scrollbar{width:10px;height:10px}
.pdf-root::-webkit-scrollbar-thumb{
  background:rgba(15,23,42,.18);
  border-radius:999px;
  border:2px solid rgba(255,255,255,.65);
}
.pdf-root::-webkit-scrollbar-thumb:hover{background:rgba(15,23,42,.26)}
.pdf-root::-webkit-scrollbar-track{background:transparent}

/* PDF page wrap + canvas */
.pdf-page{
  position:relative;
  margin:0 auto 14px;
  background:#fff;
  box-shadow:var(--pdf-page-shadow);
  border-radius:var(--pdf-page-radius);
  overflow:hidden;
  border:1px solid rgba(15,23,42,.06);
}
.pdf-canvas{display:block}
.overlay{position:absolute;inset:0}

/* ---------- Fields (editor + signer) ---------- */
.field{
  position:absolute;
  border:2px solid rgba(11,87,208,.86);
  border-radius:14px;
  background:rgba(11,87,208,.08);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:6px 10px;
  font-size:12px;
  font-weight:1000;
  user-select:none;
  touch-action:none;
  cursor:pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    box-shadow var(--t-fast) var(--ease),
    outline-color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}
.field:hover{
  box-shadow:0 14px 28px rgba(11,87,208,.14);
  transform: translateY(-1px);
}
.field:active{transform: translateY(0)}
.field.selected{
  outline:3px solid rgba(11,87,208,.24);
  box-shadow:0 0 0 4px rgba(11,87,208,.10);
}
.field.filled{
  border-color:rgba(24,128,56,.92);
  background:rgba(24,128,56,.10);
}

/* Field label (editor) */
.field-label{
  pointer-events:none;
  text-shadow: 0 1px 0 rgba(255,255,255,.65);
}

/* Resize handles (editor) — corners */
.resize-handle{
  position:absolute;
  width:18px;height:18px;
  border-radius:10px;
  background: rgba(11,87,208,.98);
  border:2px solid #fff;
  box-shadow: 0 10px 22px rgba(2,6,23,.16);
  z-index: 9999;
  pointer-events: auto;
}
.resize-handle.tl{left:-9px;top:-9px;cursor:nwse-resize}
.resize-handle.tr{right:-9px;top:-9px;cursor:nesw-resize}
.resize-handle.bl{left:-9px;bottom:-9px;cursor:nesw-resize}
.resize-handle.br{right:-9px;bottom:-9px;cursor:nwse-resize}

/* If you need a smaller single-handle style for signer pages, scope it there.
   IMPORTANT: do NOT apply to prepare editor fields. */
:is(.signer, .recipient-sign, #signerRoot, #recipientSignRoot, #signRoot) .field .resize-handle{
  width:14px;height:14px;border-radius:8px;
}

/* Nudge arrows (bottom-right inside field) */
.field .nudge-tools{
  position:absolute;
  right:6px;
  bottom:6px;
  display:grid;
  grid-template-columns:repeat(2, 30px);
  grid-template-rows:repeat(2, 30px);
  gap:6px;
  z-index:8;
  pointer-events:auto;
}

.nudge-btn{
  width:30px;height:30px;
  border:1px solid rgba(15,23,42,.12);
  background:#fff;
  border-radius:12px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:0 10px 22px rgba(17,24,39,.12);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nudge-btn svg{width:18px;height:18px}
.nudge-btn:hover{background:#f3f7ff}
.nudge-btn:active{transform:translateY(1px)}

/* iPad/tablet: slightly bigger for fingers */
@media (max-width: 1024px){
  .field .nudge-tools{ grid-template-columns:repeat(2, 34px); grid-template-rows:repeat(2, 34px); }
  .nudge-btn{ width:34px; height:34px; border-radius:13px; }
  .nudge-btn svg{ width:20px; height:20px; }
}

/* ---------- Mini tools on field (Prepare page) ---------- */
.field .mini-tools{
  display:none;
  position:absolute;
  top:-14px;
  right:-14px;
  gap:6px;
  z-index:10000;
  pointer-events:auto;
}
.field.selected .mini-tools,
.field.show-tools .mini-tools{
  display:flex;
}

/* Shared mini button style (also used by preset actions elsewhere) */
.mini-btn{
  border:1px solid rgba(15,23,42,.12);
  background:#fff;
  border-radius:999px;
  font-weight:1000;
  font-size:12px;
  padding:6px 10px;
  cursor:pointer;
  box-shadow:0 10px 22px rgba(17,24,39,.12);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mini-btn:hover{background:#f3f7ff}
.mini-btn:active{transform:translateY(1px)}

/* Signer preview content */
.field .field-content{
  width:100%;
  height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}
.field .field-preview-img{
  max-width:100%;
  max-height:100%;
  object-fit:contain;
  pointer-events:none;
  transform-origin:center center;
}
.field .field-preview-text{
  width:100%;
  text-align:center;
  line-height:1.1;
  pointer-events:none;
  user-select:none;
  font-weight:1000;
  transform-origin:center center;
}

/* ---------- Modal ---------- */
.modal{
  position:fixed;inset:0;
  background:rgba(2,6,23,.56);
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:90;
}
.modal.open{display:flex}
.modal-card{
  width:min(760px,100%);
  background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(255,255,255,.94));
  border-radius:var(--radius-lg);
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  padding:16px;
}
.modal-card .tabs{margin-top:12px}

/* Color grids (signer) */
.color-grid{display:grid;grid-template-columns:repeat(4,34px);gap:10px}
.color-dot{
  width:34px;height:34px;border-radius:999px;
  border:1px solid rgba(0,0,0,.14);
  cursor:pointer;padding:0;
  box-shadow: 0 6px 14px rgba(2,6,23,.10);
  transition: transform var(--t-fast) var(--ease), filter var(--t-fast) var(--ease);
}
.color-dot:hover{transform:translateY(-1px)}
.color-dot:active{transform:translateY(0)}

/* Signature pad wrap */
.sig-wrap{
  width:100%;
  height:240px;
  border:1px solid rgba(15,23,42,.14);
  border-radius:16px;
  overflow:hidden;
  background:#fff;
  touch-action:none;
  box-shadow: inset 0 1px 0 rgba(15,23,42,.04);
}
#sigCanvas{
  width:100%;
  height:100%;
  display:block;
  background:#fff;
  touch-action:none;
  pointer-events:auto;
  cursor:crosshair;
}

/* ---------- Sidebar overlay (mobile) ---------- */
.sidebar-overlay{
  position:fixed;inset:0;
  background:rgba(2,6,23,.45);
  z-index:55;
  display:none;
}
.sidebar-overlay.show{display:block}

/* ---------- Filters (kept compatible) ---------- */
.filters{
  display:grid;
  grid-template-columns: 1.2fr .8fr 1fr auto auto;
  gap:10px;
  align-items:end;
}

/* Links */
.link{text-decoration:none;color:var(--primary);font-weight:1000}
.link:hover{text-decoration:underline}

/* =========================================================
   Responsive
========================================================= */
@media (max-width: 980px){
  .prepare{grid-template-columns:1fr}
  .content{padding:12px}
  .filters{grid-template-columns:1fr}

  .sidebar{
    position:fixed;
    left:-320px;
    top:0;
    height:100vh;
    width:var(--sidebar-w);
    transition:left var(--t) var(--ease);
  }
  .sidebar.open{left:0}
  .sidebar.collapsed{width:var(--sidebar-w)} /* don't collapse on mobile */

  .pdf-root{height:calc(100vh - 240px)}
}

/* =========================================================
   Small polish utilities
========================================================= */
hr{
  border:none;
  border-top:1px solid var(--line);
  margin:14px 0;
}
.actions{display:flex;gap:10px;flex-wrap:wrap}

/* =========================================================
   Dashboard — Stats tiles (3D + compact + iPad responsive)
   - Works with: <div class="grid stats-grid"> and .stat .stat-link
========================================================= */

.stats-grid{
  display:grid;
  grid-template-columns:repeat(5, minmax(160px, 1fr));
  gap:12px;
  align-items:stretch;
}

.stat{
  position:relative;
  display:flex;
  gap:12px;
  align-items:center;
  padding:14px 14px;
  border-radius:18px;
  border:1px solid rgba(15,23,42,.10);
  text-decoration:none;
  background:
    radial-gradient(500px 220px at 20% 0%, rgba(255,255,255,.75), rgba(255,255,255,.0) 55%),
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,255,255,.90));
  box-shadow:
    0 12px 26px rgba(2,6,23,.10),
    inset 0 1px 0 rgba(255,255,255,.9);
  transform: translateZ(0);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, filter 140ms ease;
  min-height:76px;
}

.stat:hover{
  transform: translateY(-2px);
  border-color: rgba(11,87,208,.22);
  box-shadow:
    0 18px 34px rgba(2,6,23,.14),
    inset 0 1px 0 rgba(255,255,255,.92);
}
.stat:active{transform: translateY(-1px); box-shadow: 0 10px 18px rgba(2,6,23,.10);}

.stat-ico{
  width:44px;height:44px;
  border-radius:16px;
  display:flex;align-items:center;justify-content:center;
  color:#0b57d0;
  background:
    radial-gradient(380px 160px at 25% 0%, rgba(255,255,255,.55), rgba(255,255,255,0) 55%),
    linear-gradient(180deg, rgba(11,87,208,.14), rgba(11,87,208,.08));
  border:1px solid rgba(11,87,208,.20);
  box-shadow:
    0 12px 22px rgba(11,87,208,.16),
    inset 0 1px 0 rgba(255,255,255,.75);
}
.stat-ico svg{width:22px;height:22px}

.stat-body{min-width:0}
.stat-title{
  font-weight:1000;
  font-size:12px;
  color: rgba(17,24,39,.70);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.stat-num{
  margin-top:4px;
  font-weight:1000;
  font-size:22px;
  line-height:1;
  color:#0b0f19;
}

/* Flavor per tile */
.stat-completed .stat-ico{
  color:#188038;
  border-color:rgba(24,128,56,.22);
  background:linear-gradient(180deg, rgba(24,128,56,.14), rgba(24,128,56,.08));
}
.stat-expiring .stat-ico{
  color:#b54708;
  border-color:rgba(181,71,8,.22);
  background:linear-gradient(180deg, rgba(181,71,8,.14), rgba(181,71,8,.08));
}
.stat-draft .stat-ico{
  color:#111827;
  border-color:rgba(17,24,39,.18);
  background:linear-gradient(180deg, rgba(17,24,39,.10), rgba(17,24,39,.06));
}
.stat-waiting .stat-ico{ color:#0b57d0; }

/* iPad + tablets: smaller tiles + wrap nicely */
@media (max-width: 1024px){
  .stats-grid{grid-template-columns:repeat(3, minmax(160px, 1fr)); gap:10px;}
  .stat{padding:12px; min-height:70px; border-radius:16px;}
  .stat-ico{width:40px;height:40px;border-radius:14px}
  .stat-num{font-size:20px}
}
@media (max-width: 820px){
  .stats-grid{grid-template-columns:repeat(2, minmax(160px, 1fr));}
}
@media (max-width: 420px){
  .stats-grid{grid-template-columns:1fr;}
}

/* Saved elements list look */
#savedElementsPanel .btn.elem{
  justify-content:space-between;
}
#savedElementsPanel .saved-meta{
  font-size:11px;
  opacity:.7;
  font-weight:900;
  margin-left:10px;
}
