:root {
  --bg-color: #0f172a;
  --surface-color: rgba(30, 41, 59, 0.7);
  --surface-border: rgba(255, 255, 255, 0.1);
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: 
    radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.15), transparent 25%);
  background-attachment: fixed;
}

.glass-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.logo img {
  object-fit: contain;
}

.nav-links {
  display: flex;
  gap: 1rem;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-btn:hover, .nav-btn.active {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

#app-container {
  flex: 1;
  padding: 2rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.view-section {
  width: 100%;
  max-width: 1200px;
  display: none;
  animation: fadeIn 0.4s ease forwards;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.glass-card {
  background: var(--surface-color);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.login-card {
  max-width: 400px;
  margin: 10vh auto 0;
  text-align: center;
}

.login-card h2 { margin-bottom: 0.5rem; }
.login-card p { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.9rem; }

.input-group {
  display: flex;
  flex-direction: column;
  text-align: left;
  margin-bottom: 1.5rem;
}

.input-group label {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

input[type="text"], input[type="file"], input[type="number"], input[type="password"] {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
  font-size: 1rem;
}

input:focus {
  border-color: var(--primary);
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-size: 1rem;
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.15); }

.btn-text {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  font-weight: 600;
}
.btn-text:hover { opacity: 0.8; }

.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.hidden { display: none !important; }
.error-msg { color: var(--danger); margin-top: 1rem; font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }

/* Document Multi-Page Enhancements */
.document-container {
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(0,0,0,0.5);
  padding: 2rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  border: 1px solid var(--surface-border);
  box-shadow: inset 0 2px 15px rgba(0,0,0,0.5);
}

.document-container.miniature {
  max-height: 500px;
  padding: 1rem;
}

.document-container.modal-doc {
  max-height: 70vh;
  margin-bottom: 0;
}

.multi-page-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: 100%;
}

.pdf-page-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.8);
  background: #fff;
  width: 100%;
  max-width: 900px;
}

.pdf-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.page-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 5;
}

.interactive-pdf .page-overlay {
  cursor: crosshair;
}

/* Signature Styles */
.signature-wrapper {
  position: absolute;
  z-index: 10;
  transition: border-color 0.2s;
  display: flex;
  flex-direction: column;
  border: 2px dashed var(--primary);
  border-radius: 4px;
  overflow: hidden;
}

.signature-wrapper.error {
  border-color: var(--danger);
  animation: shake 0.4s ease-in-out;
}

.signature-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.2);
  color: var(--primary);
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 4px;
}

.signature-placeholder:hover {
  background: rgba(59, 130, 246, 0.4);
  color: #fff;
}

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

.signature-modal-content {
  max-width: 600px;
}

.pad-container {
  width: 100%;
  height: 300px;
  background: #ffffff;
  border: 2px dashed var(--surface-border);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.05);
  position: relative;
}

.alignment-line {
  position: absolute;
  bottom: 25%;
  left: 5%;
  right: 5%;
  height: 2px;
  background-color: rgba(0, 0, 0, 0.15);
  pointer-events: none;
  z-index: 1;
  border-radius: 2px;
}

#main-signature-pad {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  position: relative;
  z-index: 2;
  background: transparent;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
  75% { transform: translateX(-10px); }
}

/* Admin Tabs & Layout */
.admin-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.5);
  padding: 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
  flex-wrap: wrap;
}

.admin-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.admin-tab-btn.active, .admin-tab-btn:hover {
  background: var(--surface-color);
  color: var(--text-main);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.admin-tab-content {
  animation: fadeIn 0.3s ease;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface-color);
  backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}

.stat-card p { font-size: 2rem; font-weight: 700; color: var(--primary); }

.file-drop-area {
  border: 2px dashed var(--surface-border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  position: relative;
  background: rgba(15, 23, 42, 0.3);
  transition: border-color 0.2s;
  overflow: hidden;
}
.file-drop-area:hover { border-color: var(--primary); }
.file-drop-area input[type="file"] {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}

.batch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* Resizable Box */
.draggable-box {
  position: absolute;
  border: 2px solid var(--primary);
  background: rgba(59, 130, 246, 0.4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: bold;
  border-radius: 4px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  resize: both;
  overflow: hidden;
  cursor: move;
  pointer-events: auto;
  min-width: 50px;
  min-height: 30px;
}

/* List Styles & Search */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 400px;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding-left: 2.5rem;
  margin: 0;
}

.contract-list {
  display: flex; flex-direction: column; gap: 1rem;
}

.contract-item {
  display: flex; justify-content: space-between; align-items: center;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--surface-border);
  padding: 1rem; border-radius: 8px;
  transition: all 0.3s ease;
}
.contract-item:hover { transform: translateY(-2px); background: rgba(30, 41, 59, 0.8); }

.contract-item.fade-out { opacity: 0; transform: translateX(-20px); }

.contract-info { display: flex; flex-direction: column; gap: 0.25rem; }
.contract-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-icon {
  background: transparent; border: none; font-size: 1.25rem;
  cursor: pointer; padding: 0.25rem; border-radius: 4px;
  transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255, 255, 255, 0.1); }

.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-primary { color: var(--primary) !important; }

.status-badge {
  padding: 0.25rem 0.5rem; border-radius: 99px;
  font-size: 0.75rem; font-weight: 600;
}
.status-pending { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.status-signed { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }

/* File System (OPFS) Viewer */
.fs-browser {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 1rem;
  font-family: monospace;
  font-size: 0.95rem;
}
.fs-list {
  padding-left: 1.5rem;
  border-left: 1px dashed var(--surface-border);
  margin-left: 0.5rem;
  margin-top: 0.5rem;
}
.fs-file-item {
  padding: 0.4rem 0;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.fs-file-item:last-child { border-bottom: none; }

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(8px);
  display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content {
  background: var(--bg-color); padding: 2rem; border-radius: var(--radius);
  max-width: 1000px; width: 95%; max-height: 95vh; overflow-y: auto;
  position: relative;
  border: 1px solid var(--surface-border);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.close-modal {
  position: absolute; top: 1rem; right: 1rem; font-size: 1.5rem;
  cursor: pointer; color: var(--text-muted); z-index: 10;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(0,0,0,0.5);
  transition: color 0.2s, background 0.2s;
}
.close-modal:hover { color: #fff; background: rgba(255,255,255,0.2); }

.action-bar { display: flex; gap: 1rem; margin-top: 1.5rem; }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast { background: var(--surface-color); backdrop-filter: blur(10px); padding: 12px 20px; border-radius: 8px; color: white; animation: slideIn 0.3s; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3); }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.toast.fade-out { animation: fadeOut 0.3s forwards; }
@keyframes fadeOut { to { opacity: 0; transform: translateY(10px); } }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255,255,255,0.1);
  transition: .4s;
  border: 1px solid var(--surface-border);
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-muted);
  transition: .4s;
}
input:checked + .slider {
  background-color: var(--primary);
  border-color: var(--primary);
}
input:checked + .slider:before {
  transform: translateX(22px);
  background-color: white;
}
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr; }
  .action-bar { flex-direction: column; }
  .admin-header-bar { flex-direction: column; align-items: flex-start; }
  .contract-item { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .contract-actions { width: 100%; justify-content: flex-end; }
}

.document-container::-webkit-scrollbar { width: 10px; }
.document-container::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 8px; }
.document-container::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 8px; }
.document-container::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }