/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #3498db;
  --primary-dark: #2980b9;
  --secondary-color: #2ecc71;
  --danger-color: #e74c3c;
  --warning-color: #f39c12;
  --dark-color: #2c3e50;
  --light-color: #ecf0f1;
  --gray-color: #95a5a6;
  --white: #ffffff;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --border-radius: 8px;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--light-color);
  color: var(--dark-color);
  line-height: 1.6;
}

/* Layout */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-wrapper {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 20px;
  margin-left: 250px;
}

/* Navigation */
.sidebar {
  width: 250px;
  background: var(--dark-color);
  color: var(--white);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  text-align: center;
}

.sidebar-header h2 {
  font-size: 1.5rem;
  margin-bottom: 5px;
}

.sidebar-header span {
  font-size: 0.8rem;
  color: var(--gray-color);
}

.nav-menu {
  list-style: none;
  padding: 20px 0;
}

.nav-menu li a {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  color: var(--white);
  text-decoration: none;
  transition: background 0.3s;
}

.nav-menu li a:hover,
.nav-menu li a.active {
  background: var(--primary-color);
}

.nav-menu li a i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
}

/* Cards */
.card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

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

.card-header h3 {
  font-size: 1.2rem;
}

.card-body {
  padding: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  text-decoration: none;
}

.btn i {
  margin-right: 8px;
}

.btn-primary {
  background: var(--primary-color);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-color);
  color: var(--white);
}

.btn-secondary:hover {
  background: #7f8c8d;
}

.btn-success {
  background: var(--secondary-color);
  color: var(--white);
}

.btn-success:hover {
  background: #27ae60;
}

.btn-danger {
  background: var(--danger-color);
  color: var(--white);
}

.btn-danger:hover {
  background: #c0392b;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 15px 30px;
  font-size: 1.1rem;
}

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

.btn-group {
  display: flex;
  gap: 10px;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: var(--border-radius);
  font-size: 1rem;
  transition: border-color 0.3s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
}

.form-control:disabled {
  background: var(--light-color);
  cursor: not-allowed;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--light-color);
}

.table th {
  background: var(--light-color);
  font-weight: 600;
}

.table tbody tr:hover {
  background: #f8f9fa;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-draft {
  background: var(--warning-color);
  color: var(--white);
}

.badge-processing {
  background: var(--primary-color);
  color: var(--white);
}

.badge-completed {
  background: var(--secondary-color);
  color: var(--white);
}

/* Login Page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-color), var(--dark-color));
}

.login-card {
  background: var(--white);
  padding: 40px;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  text-align: center;
  margin-bottom: 30px;
  color: var(--dark-color);
}

.login-card .form-group {
  margin-bottom: 20px;
}

.login-card .btn {
  width: 100%;
  margin-top: 10px;
}

/* Alerts */
.alert {
  padding: 15px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-danger {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.alert-info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-color);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--light-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* PDF Editor */
.editor-container {
  display: grid;
  grid-template-columns: 300px 1fr 250px;
  gap: 20px;
  height: calc(100vh - 100px);
}

.editor-sidebar {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.editor-sidebar-header {
  padding: 15px;
  border-bottom: 1px solid var(--light-color);
  font-weight: 600;
}

.editor-sidebar-content {
  padding: 15px;
}

.pdf-viewer-container {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.pdf-toolbar {
  padding: 10px 15px;
  border-bottom: 1px solid var(--light-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pdf-toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pdf-canvas-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #888;
  padding: 20px;
}

.pdf-canvas-container {
  position: relative;
  margin: 0 auto;
  background: var(--white);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

#pdfCanvas {
  display: block;
}

/* Draggable Fields */
.field-list {
  list-style: none;
}

.field-item {
  padding: 10px 15px;
  margin-bottom: 8px;
  background: var(--light-color);
  border-radius: var(--border-radius);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.2s;
}

.field-item:hover {
  background: #dfe6e9;
}

.field-item.csv-field {
  border-left: 4px solid var(--primary-color);
}

.field-item.common-field {
  border-left: 4px solid var(--secondary-color);
}

.field-item.signature-field {
  border-left: 4px solid var(--warning-color);
}

.field-item i {
  color: var(--gray-color);
}

/* Positioned Field */
.positioned-field {
  position: absolute;
  background: rgba(52, 152, 219, 0.2);
  border: 2px solid var(--primary-color);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--dark-color);
  user-select: none;
}

.positioned-field.common {
  background: rgba(46, 204, 113, 0.2);
  border-color: var(--secondary-color);
}

.positioned-field.signature {
  background: rgba(243, 156, 18, 0.2);
  border-color: var(--warning-color);
}

.positioned-field.mark {
  background: rgba(255, 255, 255, 0.9);
  border-color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
}

.positioned-field.selected {
  border-color: var(--danger-color);
  border-width: 3px;
}

.positioned-field .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--primary-color);
  border-radius: 50%;
}

.positioned-field .resize-handle.se {
  right: -5px;
  bottom: -5px;
  cursor: se-resize;
}

.positioned-field .delete-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  background: var(--danger-color);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: none;
}

.positioned-field:hover .delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Field Properties Panel */
.properties-panel {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.properties-header {
  padding: 15px;
  border-bottom: 1px solid var(--light-color);
  font-weight: 600;
}

.properties-content {
  padding: 15px;
}

.property-row {
  margin-bottom: 15px;
}

.property-row label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.9rem;
  color: var(--gray-color);
}

.property-row input,
.property-row select {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  font-size: 1.5rem;
  color: var(--white);
}

.stat-icon.primary {
  background: var(--primary-color);
}

.stat-icon.success {
  background: var(--secondary-color);
}

.stat-icon.warning {
  background: var(--warning-color);
}

.stat-icon.danger {
  background: var(--danger-color);
}

.stat-info h4 {
  font-size: 1.8rem;
  margin-bottom: 5px;
}

.stat-info p {
  color: var(--gray-color);
  font-size: 0.9rem;
}

/* File Upload Zone */
.upload-zone {
  border: 2px dashed var(--gray-color);
  border-radius: var(--border-radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary-color);
  background: rgba(52, 152, 219, 0.05);
}

.upload-zone i {
  font-size: 3rem;
  color: var(--gray-color);
  margin-bottom: 15px;
}

.upload-zone p {
  color: var(--gray-color);
  margin-bottom: 10px;
}

.upload-zone input[type="file"] {
  display: none;
}

/* Progress Bar */
.progress {
  height: 20px;
  background: var(--light-color);
  border-radius: 10px;
  overflow: hidden;
  margin: 20px 0;
}

.progress-bar {
  height: 100%;
  background: var(--primary-color);
  transition: width 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 0.8rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-color);
}

.empty-state i {
  font-size: 4rem;
  margin-bottom: 20px;
  opacity: 0.5;
}

.empty-state h3 {
  margin-bottom: 10px;
}

/* Signature Grid */
.signatures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.signature-card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.signature-preview {
  height: 100px;
  background: var(--light-color);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

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

.signature-info {
  padding: 15px;
}

.signature-info h4 {
  font-size: 0.9rem;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signature-info p {
  font-size: 0.8rem;
  color: var(--gray-color);
}

.signature-actions {
  padding: 0 15px 15px;
  display: flex;
  gap: 10px;
}

/* Responsive */
@media (max-width: 1200px) {
  .editor-container {
    grid-template-columns: 250px 1fr 200px;
  }
}

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    z-index: 100;
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .editor-container {
    grid-template-columns: 1fr;
    height: auto;
  }

  .editor-sidebar,
  .properties-panel {
    display: none;
  }
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .table-responsive {
    font-size: 0.9rem;
  }
}

/* Common Field Add Form */
.add-common-field {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.add-common-field input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.add-common-field button {
  padding: 8px 15px;
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: var(--white);
  animation: spin 1s ease-in-out infinite;
}

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

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-content {
  background: var(--white);
  padding: 30px 50px;
  border-radius: var(--border-radius);
  text-align: center;
}

.loading-content .spinner {
  width: 40px;
  height: 40px;
  border-color: var(--light-color);
  border-top-color: var(--primary-color);
  margin-bottom: 15px;
}

/* Actions dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  background-color: var(--white);
  min-width: 160px;
  box-shadow: var(--shadow);
  border-radius: var(--border-radius);
  z-index: 1;
}

.dropdown-content a {
  color: var(--dark-color);
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: var(--light-color);
}

.dropdown:hover .dropdown-content {
  display: block;
}

/* User info in header */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.user-details {
  flex: 1;
  overflow: hidden;
}

.user-details .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-details .email {
  font-size: 0.75rem;
  color: var(--gray-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
