/* PodpisujPDF Web - Modern Material 3 Styling */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-focus: rgba(37, 99, 235, 0.2);
  --on-primary: #ffffff;

  --secondary: #0284c7;
  --secondary-hover: #0369a1;

  --success: #16a34a;
  --success-hover: #15803d;
  --success-light: #f0fdf4;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-variant: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #3b82f6;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* App Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

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

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.badge-web {
  font-size: 0.65rem;
  background: #dbeafe;
  color: #1e40af;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  min-height: 40px;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-outline:hover:not(:disabled) {
  background: var(--surface-variant);
  border-color: #cbd5e1;
}

.btn-subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-subtle:hover:not(:disabled) {
  background: var(--surface-variant);
  color: var(--text-primary);
}

.btn-danger {
  color: var(--danger);
  border-color: #fca5a5;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-light);
  border-color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
  min-height: 48px;
  border-radius: var(--radius-lg);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.775rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
}
.btn-sm:hover {
  background: var(--surface-variant);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
}
.dot-active {
  background: var(--success);
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.8);
}
.dot-inactive {
  background: #94a3b8;
}

.badge-counter {
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Workspace */
.main-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Doc Toolbar */
.doc-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  z-index: 20;
}

.doc-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 320px;
}

.doc-filename {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-tag {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.pagination-controls, .zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-indicator, .zoom-level {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 4px;
}

/* Viewer Container */
.viewer-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: auto;
  padding: 20px;
  background: #cbd5e1;
}

/* Empty State */
.empty-state {
  width: 100%;
  max-width: 580px;
  padding: 20px;
}

.hero-card {
  background: var(--surface);
  padding: 40px 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  border: 1px solid var(--border);
}

.hero-icon-wrapper {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px auto;
}

.hero-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.hero-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.features-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
}

.feature-pill {
  font-size: 0.75rem;
  background: var(--surface-variant);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

/* PDF Stage & Canvas */
.pdf-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  min-height: 100%;
}

.canvas-wrapper {
  position: relative;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  margin-bottom: 80px; /* Space for bottom bar */
  user-select: none;
  touch-action: pan-x pan-y;
}

#pdf-render-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Signature Box Overlay */
.signature-box {
  position: absolute;
  top: 80%;
  left: 58%;
  width: 36%;
  height: 10%;
  border: 2px dashed #2563eb;
  background: rgba(37, 99, 235, 0.12);
  border-radius: 6px;
  cursor: grab;
  touch-action: none; /* Pointer drag control */
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  z-index: 10;
  transition: border-color 0.15s, background-color 0.15s;
}

.signature-box:hover, .signature-box.active {
  border-color: #1d4ed8;
  background: rgba(37, 99, 235, 0.2);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.signature-box.dragging {
  cursor: grabbing;
  opacity: 0.85;
}

.signature-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px;
  background: rgba(37, 99, 235, 0.85);
  color: #fff;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  pointer-events: none;
}

.signature-box-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  pointer-events: none;
}

.signature-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #1d4ed8;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
  padding: 4px;
  gap: 2px;
}

.signature-preview-img {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
}

.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 18px;
  height: 18px;
  background: #2563eb;
  border: 2px solid #fff;
  border-radius: var(--radius-full);
  cursor: se-resize;
  touch-action: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  z-index: 15;
}

/* Quick Templates Bar */
.quick-templates-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  position: sticky;
  bottom: 64px;
  z-index: 25;
}

.templates-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.quick-templates-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.template-chip {
  background: var(--surface-variant);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}
.template-chip:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

/* Bottom Action Bar */
.bottom-action-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
}

.action-buttons-group {
  display: flex;
  gap: 12px;
  max-width: 680px;
  margin: 0 auto;
}

.action-btn {
  flex: 1;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-signature-card {
  max-width: 620px;
}

.modal-history-card {
  max-width: 640px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-close-modal:hover {
  background: var(--surface-variant);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-variant);
}

.justify-center {
  justify-content: center;
}

/* Signature Pad Canvas */
.signature-canvas-wrapper {
  position: relative;
  background: #ffffff;
  border: 2px dashed #94a3b8;
  border-radius: var(--radius-md);
  height: 240px;
  overflow: hidden;
  touch-action: none; /* CRITICAL for smooth touch drawing */
}

#signature-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.canvas-guide-line {
  position: absolute;
  bottom: 45px;
  left: 20px;
  right: 20px;
  border-bottom: 1px solid #e2e8f0;
  pointer-events: none;
  text-align: center;
}

.canvas-guide-line span {
  font-size: 0.75rem;
  color: #94a3b8;
  background: #fff;
  padding: 0 10px;
  position: relative;
  top: 8px;
}

.signature-tools {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.color-options, .stroke-options {
  display: flex;
  gap: 6px;
}

.color-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s;
}
.color-btn.active {
  border-color: #3b82f6;
  transform: scale(1.15);
}

.stroke-btn {
  background: var(--surface-variant);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 0.75rem;
  cursor: pointer;
}
.stroke-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Forms & Inputs */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-group input, .form-group select {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.password-input-wrapper input {
  width: 100%;
  padding-right: 40px;
}
.btn-toggle-pwd {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
}

.checkbox-group {
  margin-top: 4px;
}
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-secondary);
}
.checkbox-label input {
  margin-top: 2px;
}

.info-callout {
  background: #eff6ff;
  border-left: 4px solid var(--primary);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  color: #1e3a8a;
  font-size: 0.825rem;
}
.info-callout p {
  margin-top: 2px;
  color: #1e40af;
}

.progress-box, .error-box, .success-box, .test-result-box {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin-top: 14px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-box {
  background: #eff6ff;
  color: #1d4ed8;
}
.error-box {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.success-box {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}
.test-result-box {
  background: var(--surface-variant);
  border: 1px solid var(--border);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.file-summary-box {
  background: var(--surface-variant);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.file-summary-details {
  display: flex;
  flex-direction: column;
}
.file-summary-details .name {
  font-weight: 600;
  font-size: 0.85rem;
}
.file-summary-details .size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Templates & History Lists */
.templates-list, .history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.template-item, .history-item {
  background: var(--surface-variant);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s, background-color 0.15s;
}

.template-item:hover, .history-item:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.template-info, .history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.item-title {
  font-weight: 600;
  font-size: 0.875rem;
}
.item-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-template-box {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.add-template-box h4 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.input-with-button {
  display: flex;
  gap: 8px;
}
.input-with-button input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-empty {
  text-align: center;
  padding: 30px 16px;
  color: var(--text-muted);
}
.history-empty p {
  margin-top: 10px;
  font-size: 0.875rem;
}

/* Success Modal */
.success-icon-wrapper {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: #dcfce7;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
}

.success-actions-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.text-center {
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastIn 0.25s ease-out;
  max-width: 90%;
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 15px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .brand-subtitle {
    display: none;
  }
  .btn-text {
    display: none;
  }
  .doc-toolbar {
    padding: 6px 10px;
  }
  .quick-templates-bar {
    bottom: 72px;
  }
}
