/* Modern, elegant contract generator UI */
:root {
  /* Core colors */
  --bg: linear-gradient(135deg, #0a0e1a 0%, #1a1f2e 100%);
  --bg-solid: #0f1419;
  --card: linear-gradient(145deg, #1a1f2e 0%, #252b3d 100%);
  --card-hover: linear-gradient(145deg, #1e2332 0%, #2a3042 100%);
  --surface: #161b26;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  
  /* Text colors */
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  /* Brand colors */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.1);
  --accent: #06b6d4;
  --accent-hover: #0891b2;
  
  /* Status colors */
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border radius */
  --radius-sm: 0.375rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-solid);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  background: rgba(26, 31, 46, 0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tabs {
  display: flex;
  gap: var(--space-sm);
  background: var(--surface);
  padding: var(--space-xs);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

/* Main content */
.app-main {
  padding: var(--space-2xl);
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.panel.active {
  display: block;
}

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

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
}

.card:hover {
  background: var(--card-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* Form elements */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin: var(--space-md) 0;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.025em;
}

.field input,
.field select {
  background: #1a1f2e;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md);
  color: var(--text);
  font-size: 0.875rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.field select option {
  background: #1a1f2e;
  color: var(--text);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: rgba(59, 130, 246, 0.02);
}

.field input::placeholder {
  color: var(--text-subtle);
}

/* Buttons */
.actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: white;
  box-shadow: var(--shadow);
}

.btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn.danger {
  background: linear-gradient(135deg, var(--error) 0%, #dc2626 100%);
  color: white;
  box-shadow: var(--shadow);
}

.btn.danger:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn:not(.primary):not(.danger) {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn:not(.primary):not(.danger):hover {
  background: var(--card);
  border-color: var(--border-hover);
  color: var(--text);
}

.btn.tiny {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-lg) 0;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

h2 {
  font-size: 1.875rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.75rem;
}

/* Lists */
.list {
  overflow: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

.list-header {
  display: grid;
  grid-template-columns: 80px 1fr 160px 160px 160px;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-lg);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.list-body > div {
  display: grid;
  grid-template-columns: 80px 1fr 160px 160px 160px;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease;
}

.list-body > div:hover {
  background: rgba(255, 255, 255, 0.02);
}

.list-body > div:nth-child(even) {
  background: rgba(255, 255, 255, 0.01);
}

/* Grid layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

.span-2 {
  grid-column: span 2;
}

/* Footer */
.app-footer {
  padding: var(--space-2xl);
  text-align: center;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: var(--space-2xl);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.025em;
}

.badge.ok {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge:not(.ok):not(.error) {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Links */
.link {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

.link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Toast notifications */
.toast {
  position: fixed;
  right: var(--space-lg);
  bottom: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.875rem;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(20px);
  z-index: 1000;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast:not(.err) {
  background: rgba(16, 185, 129, 0.9);
  color: white;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.toast.err {
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Responsive design */
@media (max-width: 1200px) {
  .app-main {
    padding: var(--space-xl);
  }
  
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-header {
    padding: var(--space-md) var(--space-lg);
    flex-direction: column;
    gap: var(--space-md);
  }
  
  .tabs {
    width: 100%;
    overflow-x: auto;
  }
  
  .list-header,
  .list-body > div {
    grid-template-columns: 60px 1fr 120px 120px 100px;
    gap: var(--space-sm);
    padding: var(--space-md);
  }
  
  .actions {
    gap: var(--space-sm);
  }
  
  .btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.8rem;
  }
}

@media (max-width: 640px) {
  .app-main {
    padding: var(--space-lg);
  }
  
  .card {
    padding: var(--space-lg);
    margin: var(--space-md) 0;
  }
  
  .list-header,
  .list-body > div {
    grid-template-columns: 1fr 80px 80px;
    gap: var(--space-xs);
  }
  
  .actions {
    flex-direction: column;
  }
  
  .btn {
    justify-content: center;
  }
}

/* Special elements */
#ocr-raw {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md);
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

#ai-buffer-info {
  background: var(--primary-light);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  font-weight: 500;
}

/* Modal styles */
#ocr-area-modal {
  backdrop-filter: blur(10px);
}

#ocr-area-modal > div {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
}

/* Loading states */
.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Focus styles */
*:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:focus {
  outline-offset: 4px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* Enhanced workflow styles */
.step-header {
  text-align: center;
  margin-bottom: var(--space-2xl);
}

.step-description {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-top: var(--space-sm);
}

.workflow-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.workflow-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.workflow-card:hover {
  background: var(--card-hover);
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.workflow-icon {
  font-size: 2rem;
  margin-bottom: var(--space-md);
  display: block;
}

.workflow-card h3 {
  margin: 0 0 var(--space-md) 0;
  color: var(--text);
  font-size: 1.25rem;
}

.workflow-card p {
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
  line-height: 1.5;
}

.workflow-checklist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.workflow-checklist li {
  padding: var(--space-sm) 0;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.workflow-checklist li:last-child {
  border-bottom: none;
}

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

.card-header h3 {
  margin: 0;
  color: var(--text);
}

.card-header p {
  color: var(--text-muted);
  margin: var(--space-sm) 0 0 0;
}

.progress-indicator {
  background: var(--primary-light);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.next-step-hint {
  background: linear-gradient(135deg, var(--primary-light), rgba(6, 182, 212, 0.1));
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  text-align: center;
  margin-top: var(--space-xl);
}

.next-step-hint p {
  margin: 0 0 var(--space-lg) 0;
  color: var(--text-secondary);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
  margin: 0;
}

.buffer-status {
  background: var(--primary-light);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  font-weight: 500;
  font-size: 0.875rem;
}

.ocr-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md);
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-muted);
}

.success-message {
  background: var(--success-bg);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  text-align: center;
  margin-top: var(--space-xl);
}

.success-message h3 {
  color: var(--success);
  margin: var(--space-md) 0;
}

.success-message p {
  color: var(--text-secondary);
  margin: 0;
}

/* Enhanced tabs */
.tab {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  min-width: 140px;
}

.tab.secondary {
  min-width: auto;
  padding: var(--space-sm) var(--space-md);
}

.tab-number {
  background: var(--primary);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.tab:not(.active) .tab-number {
  background: var(--text-subtle);
}

.tab-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.tab-title {
  font-weight: 500;
  font-size: 0.875rem;
}

.tab-subtitle {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 2px;
}

.tab.active .tab-subtitle {
  color: rgba(255, 255, 255, 0.8);
}

.tab-status {
  font-size: 1rem;
}

/* Field validation styles */
.field input.valid {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.field input.invalid {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.field-feedback {
  font-size: 0.75rem;
  margin-top: var(--space-xs);
  font-weight: 500;
}

.field-feedback.valid {
  color: var(--success);
}

.field-feedback.invalid {
  color: var(--error);
}

.field input.auto-filled {
  background: rgba(16, 185, 129, 0.05);
  border-color: var(--success);
}

/* Preview styles */
.contract-preview {
  margin-top: 2rem;
  display: block !important;
}

.contract-preview-content {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: 'Times New Roman', serif;
  line-height: 1.6;
  color: #333;
  white-space: pre-wrap;
  max-height: 500px;
  overflow-y: auto;
  min-height: 200px;
}

.placeholder-highlight {
  background: var(--success-bg);
  color: var(--success);
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 500;
}

@media (max-width: 900px) {
  .workflow-cards {
    grid-template-columns: 1fr;
  }
  
  .tab {
    flex-direction: column;
    gap: var(--space-xs);
    min-width: 80px;
    padding: var(--space-sm);
  }
  
  .tab-subtitle {
    display: none;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }
}
