/* ==========================================================================
   DESIGN VARIABLES & SYSTEM
   ========================================================================== */
:root {
  --font-title: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Inter', sans-serif;

  --bg-color: #08080f;
  --text-primary: #f8f9fa;
  --text-secondary: #a0aec0;
  
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-border-hover: rgba(255, 255, 255, 0.15);
  --glass-bg-hover: rgba(255, 255, 255, 0.06);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  --accent-color: #7c4dff;
  --accent-glow: rgba(124, 77, 255, 0.3);
  --success-color: #00e676;
  --warning-color: #ffd600;
  --error-color: #ff1744;

  --gradient-title: linear-gradient(135deg, #f8f9fa 30%, #a29bfe 100%);
  --gradient-accent: linear-gradient(135deg, #7c4dff 0%, #18a5e0 100%);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-body);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Ambient glows */
.bg-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  z-index: -1;
  opacity: 0.4;
  pointer-events: none;
}
.bg-glow-1 {
  width: 500px;
  height: 500px;
  background: var(--accent-color);
  top: -100px;
  right: -100px;
}
.bg-glow-2 {
  width: 400px;
  height: 400px;
  background: #0055ff;
  bottom: -100px;
  left: -100px;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px;
  flex-grow: 1;
}

/* Glassmorphism */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 18px;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-icon {
  font-size: 2.2rem;
}

.header-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: var(--gradient-title);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
}

.header-right {
  display: flex;
  gap: 12px;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all 0.3s ease;
}

.btn-primary {
  background: var(--gradient-accent);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124, 77, 255, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--glass-border-hover);
}

.btn-danger {
  color: var(--error-color);
  border-color: rgba(255, 23, 68, 0.2);
}
.btn-danger:hover {
  background: rgba(255, 23, 68, 0.08);
  border-color: rgba(255, 23, 68, 0.4);
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

/* ==========================================================================
   TABS NAVIGATION
   ========================================================================== */
.tool-tabs {
  display: flex;
  padding: 6px;
  gap: 6px;
  margin-bottom: 28px;
}

.tab-btn {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   TOOL WORKSPACE PANELS
   ========================================================================== */
.tab-section {
  display: none;
}
.tab-section.active {
  display: block;
  animation: fadeIn 0.4s ease-out;
}

.tool-card {
  padding: 32px;
}

.tool-card h2 {
  font-family: var(--font-title);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.tool-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ==========================================================================
   UPLOAD ZONE
   ========================================================================== */
.upload-zone {
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.01);
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent-color);
  background: rgba(124, 77, 255, 0.03);
  box-shadow: 0 0 20px rgba(124, 77, 255, 0.1);
}

.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.highlight-text {
  color: #18a5e0;
  font-weight: 600;
  text-decoration: underline;
}

.hidden-input {
  display: none;
}

/* ==========================================================================
   WORKSPACE & WORKSPACE GRID
   ========================================================================== */
.workspace-container {
  animation: fadeIn 0.4s ease-out;
}

.workspace-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--glass-border);
  margin-bottom: 24px;
}

.file-meta-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.workspace-tip {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* Previews Scrollable Grid */
.preview-scroll-container {
  margin-top: 24px;
}
.preview-scroll-container h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 20px;
  padding: 10px 0;
}

/* Page Thumbnail Card */
.preview-card {
  position: relative;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.3s;
}

.preview-card canvas {
  width: 100%;
  height: 140px;
  object-fit: contain;
  background: #111;
  border-radius: 6px;
  margin-bottom: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.page-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Grid Interactive (Delete Mode) */
.grid-interactive .preview-card {
  cursor: pointer;
}
.grid-interactive .preview-card:hover {
  transform: translateY(-2px);
  border-color: var(--glass-border-hover);
}

.grid-interactive .preview-card.delete-selected {
  border-color: var(--error-color);
  background: rgba(255, 23, 68, 0.05);
}
.grid-interactive .preview-card.delete-selected canvas {
  opacity: 0.3;
}
.grid-interactive .preview-card.delete-selected::after {
  content: '❌ Delete';
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* ==========================================================================
   SPLIT / MERGE CONTROLS
   ========================================================================== */
.split-controls {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  padding: 20px;
  border-radius: 14px;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 24px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-group input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s;
}

.input-group input:focus {
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.07);
}

/* ==========================================================================
   FILE LIST CONTAINER (MERGE)
   ========================================================================== */
.file-list-container {
  margin-top: 28px;
  animation: fadeIn 0.4s ease-out;
}

.file-list-container h3 {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  animation: fadeIn 0.3s ease-out;
}

.file-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-item-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.file-item-controls {
  display: flex;
  gap: 8px;
}

.btn-arrow {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all 0.2s;
}
.btn-arrow:hover {
  color: var(--text-primary);
  border-color: var(--glass-border-hover);
  background: rgba(255,255,255,0.06);
}

.btn-remove {
  background: rgba(255, 23, 68, 0.05);
  color: var(--error-color);
  border: 1px solid rgba(255, 23, 68, 0.15);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.btn-remove:hover {
  background: rgba(255, 23, 68, 0.15);
  border-color: rgba(255, 23, 68, 0.30);
}

.btn-action {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

/* ==========================================================================
   AUTH LOADING OVERLAY
   ========================================================================== */
.auth-loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.05);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(12, 11, 20, 0.9);
  border: 1px solid var(--accent-color);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 3000;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   ANIMATIONS & RESPONSIVE
   ========================================================================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.5; }
  50% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.5; }
}

@media (max-width: 680px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .tool-tabs {
    flex-direction: column;
  }
  .split-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .btn {
    width: 100%;
  }
}

/* ==========================================================================
   CANVAS EDITOR & SIGNATURE MODAL
   ========================================================================== */
.editor-canvas-container {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  gap: 16px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--glass-border);
}

.tool-action-btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.tool-action-btn:hover {
  color: var(--text-primary);
  border-color: var(--glass-border-hover);
}
.tool-action-btn.active {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}
.btn-secondary-toolbar {
  margin-left: auto;
}

.canvas-editor-wrapper {
  display: flex;
  justify-content: center;
  overflow: auto;
  background: #121218;
  border-radius: 12px;
  padding: 24px;
  min-height: 450px;
  max-height: 650px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.canvas-overlay-container {
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
}
.canvas-overlay-container canvas {
  display: block;
}

/* Annotation Elements in Editor */
.annotation-el {
  position: absolute;
  border: 1px dashed transparent;
  cursor: move;
  user-select: none;
}
.annotation-el.selected {
  border-color: var(--accent-color);
}

/* Text Element */
.annotation-text-input {
  background: transparent;
  border: none;
  color: #000;
  font-family: Arial, sans-serif;
  font-size: 16px;
  outline: none;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  padding: 2px;
  font-weight: 500;
  line-height: 1.2;
}
.annotation-el.selected::after {
  content: '✎';
  position: absolute;
  top: -16px;
  right: -16px;
  background: var(--accent-color);
  color: white;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Redaction box */
.annotation-redact-box {
  background: #000;
  width: 100%;
  height: 100%;
  opacity: 1;
}

/* Signature image */
.annotation-sig-img {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.annotation-delete-btn {
  position: absolute;
  top: -8px;
  left: -8px;
  background: var(--error-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 9px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  z-index: 10;
}
.annotation-el.selected .annotation-delete-btn {
  display: flex;
}

.editor-page-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--glass-border);
}

#editor-page-indicator {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Modal Popup Styles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  max-width: 500px;
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-card h3 {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
}
.modal-card p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.canvas-sig-wrapper {
  background: #fff;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  justify-content: center;
}
#sig-pad {
  background: #fff;
  cursor: crosshair;
  display: block;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
