/* =========================================
   GSS Sign — CSS Design System
   ========================================= */

:root {
  --bg: #0C0F1A;
  --bg-2: #121626;
  --bg-3: #1A1F35;
  --panel: rgba(20, 26, 48, 0.85);
  --panel-border: rgba(74, 158, 255, 0.15);
  --accent: #4A9EFF;
  --accent-dark: #2B6FD4;
  --accent-deep: #1B4DA8;
  --stamp-blue: #2B4EA8;
  --text: #E8EEFF;
  --text-muted: #7A8BB5;
  --text-dim: #4A5580;
  --success: #34D399;
  --warning: #FBBF24;
  --error: #F87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.35);
  --glow: 0 0 20px rgba(74, 158, 255, 0.25);
  --transition: all 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  /* Keep the app pinned to the viewport so inner panels scroll instead of page content. */
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(74, 158, 255, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 90% 80%, rgba(43, 78, 168, 0.08) 0%, transparent 60%);
}

/* ---- Auth Gate ---- */
.auth-gate {
  position: fixed;
  inset: 0; /* cover everything, including header */
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 18, 0.985);
  z-index: 1000;
  padding: 24px;
  backdrop-filter: blur(10px);
}
.auth-gate.open {
  display: flex;
  animation: fadeIn .25s ease;
}
.auth-gate-card {
  max-width: 460px;
  width: 100%;
  background: rgba(12, 15, 26, 0.96);
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow), var(--glow);
  padding: 28px 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-gate-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(74,158,255,0.12);
  border: 1px solid rgba(74,158,255,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.auth-gate-title {
  font-size: 1.25rem;
  font-weight: 600;
}
.auth-gate-subtitle {
  font-size: .9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.auth-gate-btn {
  margin-top: 6px;
  justify-content: center;
  width: 100%;
}
.auth-gate-btn svg {
  flex-shrink: 0;
}
.auth-gate-footnote {
  font-size: .78rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---- Header ---- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: rgba(12, 15, 26, 0.9);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  z-index: 100;
  flex-shrink: 0;
}

.header-brand { display: flex; align-items: center; gap: 10px; }
.header-logo {
  width: 36px; height: 36px;
  background: rgba(74, 158, 255, 0.1);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(74, 158, 255, 0.25);
}
.header-title { font-size: 1.15rem; letter-spacing: -.02em; color: var(--text); }
.header-title strong { color: var(--accent); }

.header-actions { display: flex; align-items: center; gap: 10px; }
.header-auth { display: flex; align-items: center; gap: 8px; }
.header-auth-user { font-size: 13px; color: var(--text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-auth .btn--ghost { color: var(--text-muted); }
.header-auth .btn--ghost:hover { color: var(--text); }

/* When auth gate is active, hide header actions to avoid pre-auth controls */
body.auth-locked .header-actions {
  visibility: hidden;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-family: inherit; font-size: .85rem; font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--sm { padding: 5px 12px; font-size: .8rem; }
.btn--full { width: 100%; justify-content: center; }
.btn--icon { padding: 6px 10px; font-size: 1.1rem; }

.btn--primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(74, 158, 255, 0.3);
}
.btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(74, 158, 255, 0.45);
}

.btn--outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(74, 158, 255, 0.4);
}
.btn--outline:hover:not(:disabled) {
  background: rgba(74, 158, 255, 0.08);
  border-color: var(--accent);
}
.btn--outline.active {
  background: rgba(74, 158, 255, 0.15);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(74, 158, 255, 0.3);
  animation: pulse-outline 2s infinite;
}

@keyframes pulse-outline {
  0%, 100% { box-shadow: 0 0 12px rgba(74, 158, 255, 0.3); }
  50% { box-shadow: 0 0 20px rgba(74, 158, 255, 0.6); }
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn--ghost:hover:not(:disabled) { background: rgba(255,255,255,0.06); color: var(--text); }

/* ---- Layout ---- */
.app-layout {
  display: none; /* will be enabled by JS after successful auth */
  grid-template-columns: 280px 1fr;
  /* The middle PDF viewer only scrolls when this grid stays constrained by the viewport. */
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Hard lock visuals: nothing from app UI should be visible pre-auth */
body.auth-locked .header {
  display: none !important;
}
body.auth-locked .app-layout {
  display: none !important;
}
body.auth-locked .toast {
  display: none;
}
body.auth-locked .modal-overlay {
  display: none !important;
}

/* ---- Panels ---- */
.panel {
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  backdrop-filter: blur(16px);
  min-height: 0; /* CRITICAL for grid children to allow internal scrolling */
  min-width: 0;
}
.panel--left { border-right: 1px solid var(--panel-border); }
.panel--right { border-left: 1px solid var(--panel-border); }
/* min-height:0 is critical for flex children that need to scroll */
.panel--center { background: rgba(10, 13, 24, 0.7); min-height: 0; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}
.panel-title {
  font-size: .85rem; font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .05em; text-transform: uppercase;
  display: flex; align-items: center; gap: 7px;
}

.panel-body {
  flex: 1; overflow-y: auto; padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(74,158,255,0.2); border-radius: 4px; }

/* ---- Form ---- */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: .78rem; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.form-input {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(74,158,255,0.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit; font-size: .9rem;
  transition: var(--transition);
  width: 100%;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(74,158,255,0.06);
  box-shadow: 0 0 0 3px rgba(74,158,255,0.12);
}
.form-input::placeholder { color: var(--text-dim); }
input[type="date"].form-input::-webkit-calendar-picker-indicator { filter: invert(0.6); }
select.form-input option { background: var(--bg-3); color: var(--text); }

/* ---- Stamp Actions ---- */
.stamp-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.stamp-preview-wrap { animation: fadeSlideUp .3s ease; }
.preview-label {
  font-size: .75rem; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .05em; margin-bottom: 8px; font-weight: 500;
}
.stamp-preview-frame {
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(74,158,255,0.15);
  padding: 12px;
  display: flex; justify-content: center; align-items: center;
  min-height: 80px;
  overflow: hidden;
}
.stamp-preview-frame canvas { max-width: 100%; display: block; }
#stampCanvas { background: #ffffff; }
/* Small preview in left panel — white bg so blue stamp is visible */
.stamp-preview-frame--sm {
  padding: 12px;
  background: #ffffff;
  border: 1px solid rgba(74,158,255,0.3);
}

/* ---- PDF Drop Zone ---- */
.pdf-viewer-wrap {
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  /* Never set a fixed/100% height here: the wrapper must keep internal overflow for PDF scrolling. */
  overflow: auto;
  position: relative;
}
.pdf-viewer-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.pdf-viewer-wrap::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); }
.pdf-viewer-wrap::-webkit-scrollbar-thumb { background: rgba(74,158,255,0.65); border-radius: 999px; }
.pdf-viewer-wrap::-webkit-scrollbar-thumb:hover { background: rgba(74,158,255,0.9); }

.pdf-drop {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px;
  cursor: pointer;
  transition: var(--transition);
}
.pdf-drop.drag-over .pdf-drop-content {
  border-color: var(--accent);
  background: rgba(74,158,255,0.06);
}
.pdf-drop-content {
  border: 2px dashed rgba(74,158,255,0.3);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  transition: var(--transition);
  max-width: 360px; width: 100%;
}
.pdf-drop-content h3 { font-size: 1.1rem; color: var(--text); }
.pdf-drop-content p { color: var(--text-muted); font-size: .875rem; }

/* ---- PDF Page Container ---- */
.pdf-page-container {
  position: relative;
  display: inline-block;
  box-shadow: var(--shadow), 0 0 40px rgba(74,158,255,0.1);
  border-radius: 4px;
  overflow: visible;
}
#pdfCanvas { display: block; border-radius: 4px; }

.stamp-overlay {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;   /* overlay itself transparent to clicks */
}

.placing-cursor {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: crosshair;
  background: rgba(74,158,255,0.04);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 20px;
  pointer-events: all;
}
.placing-cursor span {
  font-size: .8rem; color: var(--accent);
  background: rgba(12,15,26,0.8);
  padding: 5px 12px; border-radius: 20px;
  border: 1px solid rgba(74,158,255,0.3);
  backdrop-filter: blur(8px);
  animation: blink 1.5s infinite;
}
.crosshair {
  position: absolute;
  pointer-events: none;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* Placed stamp on overlay */
.placed-stamp-img {
  position: absolute;
  pointer-events: auto;   /* interactive until the export step locks stamps */
  user-select: none;
  touch-action: none;
  border: 2px dashed transparent;
  border-radius: 3px;
  transition: border-color .15s, box-shadow .15s;
  animation: stampDrop .3s cubic-bezier(.34,1.56,.64,1);
}
.placed-stamp-img:hover {
  border-color: rgba(74,158,255,0.6);
  box-shadow: 0 0 0 3px rgba(74,158,255,0.15);
}
.placed-stamp-img.dragging {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(74,158,255,0.25), 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0.9;
  cursor: grabbing;
  z-index: 10;
}
.placed-stamp-img.locked {
  pointer-events: none;
  border-color: transparent;
  box-shadow: none;
}
.placed-stamp-img .remove-stamp {
  display: none;
  position: absolute; top: -10px; right: -10px;
  background: var(--error); color: #fff;
  border: none; border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 14px; cursor: pointer;
  align-items: center; justify-content: center;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: transform .15s;
  z-index: 11;
}
.placed-stamp-img:hover .remove-stamp { display: flex; }
.placed-stamp-img .remove-stamp:hover { transform: scale(1.2); }
.placed-stamp-img.locked .remove-stamp { display: none !important; }
/* Drag hint tooltip */
.placed-stamp-img .drag-hint {
  display: none;
  position: absolute; bottom: -28px; left: 50%;
  transform: translateX(-50%);
  background: rgba(12,15,26,0.9);
  color: var(--text-muted);
  font-size: .7rem; padding: 3px 8px;
  border-radius: 4px; white-space: nowrap;
  border: 1px solid var(--panel-border);
  pointer-events: none;
}
.placed-stamp-img:hover .drag-hint { display: block; }
.placed-stamp-img.locked .drag-hint { display: none !important; }

@keyframes stampDrop {
  0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ---- Page Nav ---- */
.pdf-nav { display: flex; align-items: center; gap: 8px; }
.page-info { font-size: .82rem; color: var(--text-muted); }

/* ---- Placed stamps bar ---- */
.placed-stamps-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: rgba(74,158,255,0.06);
  border-top: 1px solid var(--panel-border);
  font-size: .8rem; flex-shrink: 0;
}
.placed-label { color: var(--text-muted); white-space: nowrap; }
.placed-list { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.placed-tag {
  background: rgba(74,158,255,0.15);
  color: var(--accent);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: .75rem;
  border: 1px solid rgba(74,158,255,0.25);
}

/* ---- How-to list ---- */
.how-to-list { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.how-to-list li { display: flex; gap: 12px; align-items: flex-start; }
.step-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(74,158,255,0.15);
  border: 1px solid rgba(74,158,255,0.3);
  color: var(--accent); font-size: .75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.step-text { display: flex; flex-direction: column; gap: 2px; }
.step-text strong { font-size: .85rem; color: var(--text); }
.step-text span { font-size: .78rem; color: var(--text-muted); line-height: 1.4; }

/* ---- Info Cards ---- */
.info-card {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
}
.info-card svg { flex-shrink: 0; margin-top: 2px; }
.info-card strong { display: block; margin-bottom: 3px; font-size: .82rem; }
.info-card p { color: var(--text-muted); line-height: 1.4; }
.info-card--blue {
  background: rgba(74,158,255,0.08);
  border: 1px solid rgba(74,158,255,0.2);
  color: var(--accent);
}
.info-card--blue p { color: #7BA8E0; }
.info-card--yellow {
  background: rgba(251,191,36,0.07);
  border: 1px solid rgba(251,191,36,0.2);
  color: var(--warning);
}
.info-card--yellow p { color: #B89040; }

/* ---- PDF Info ---- */
.pdf-info { display: flex; flex-direction: column; gap: 6px; }
.pdf-info-row {
  display: flex; justify-content: space-between;
  font-size: .8rem; padding: 5px 10px;
  background: rgba(255,255,255,0.03); border-radius: 6px;
}
.pdf-info-row span { color: var(--text-muted); }
.pdf-info-row strong { color: var(--text); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Digital Signature ---- */
.signature-wrap { display: flex; flex-direction: column; gap: 8px; }
.signature-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(74,158,255,0.15);
  border-radius: var(--radius-sm);
}
.signature-card .setting-hint { margin-top: -2px; }
.signature-status {
  font-size: .78rem;
  line-height: 1.4;
  color: var(--text-muted);
  padding: 10px 12px;
  background: rgba(12,15,26,0.55);
  border: 1px solid rgba(74,158,255,0.12);
  border-radius: 8px;
}
.signature-status--ready {
  color: #A9D4FF;
  border-color: rgba(74,158,255,0.28);
  background: rgba(74,158,255,0.08);
}
.signature-status--error {
  color: #FFB4B4;
  border-color: rgba(248,113,113,0.25);
  background: rgba(248,113,113,0.08);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(6, 8, 18, 0.75);
  backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; animation: fadeIn .2s ease; }

.modal {
  background: var(--bg-3);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  width: 520px; max-width: 95vw; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow), var(--glow);
  animation: slideUp .25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}
.modal-header h3 { font-size: .95rem; font-weight: 600; }
.modal-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 1.4rem; cursor: pointer; line-height: 1;
  transition: var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 20px; flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--panel-border);
}

/* Settings */
.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-label {
  font-size: .78rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.setting-hint { font-size: .78rem; color: var(--text-dim); line-height: 1.4; }
.setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.file-drop-mini {
  border: 1.5px dashed rgba(74,158,255,0.3);
  border-radius: var(--radius-sm);
  padding: 24px; text-align: center;
  cursor: pointer; transition: var(--transition);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: .8rem;
}
.file-drop-mini:hover {
  border-color: var(--accent);
  background: rgba(74,158,255,0.05);
}

.color-row { display: flex; align-items: center; gap: 10px; }
.color-pick {
  width: 36px; height: 36px; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  background: transparent; padding: 2px;
}
#stampColorHex { font-size: .85rem; color: var(--text-muted); font-family: monospace; }

.stamp-live-preview { display: flex; flex-direction: column; gap: 8px; }
.stamp-preview-frame {
  background: repeating-conic-gradient(rgba(255,255,255,0.03) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(74,158,255,0.15);
  padding: 20px;
  display: flex; justify-content: center; align-items: center;
  min-height: 100px; overflow: hidden;
}
.stamp-preview-frame canvas { max-width: 100%; display: block; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-3);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: .85rem; color: var(--text);
  box-shadow: var(--shadow);
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
  transform: translateY(10px);
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: all; }
.toast.toast--success { border-color: rgba(52,211,153,0.4); color: var(--success); }
.toast.toast--error { border-color: rgba(248,113,113,0.4); color: var(--error); }
.toast.toast--info { border-color: rgba(74,158,255,0.4); color: var(--accent); }

/* ---- Animations ---- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeSlideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Scrollbar global */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); }
::-webkit-scrollbar-thumb { background: rgba(74,158,255,0.35); border-radius: 999px; }
