:root {
  /* Apple/Google системная палитра */
  --primary: #007AFF;
  --primary-hover: #0062CC;
  --primary-light: #E8F4FF;
  --primary-glow: rgba(0, 122, 255, 0.15);
  
  --secondary: #8E8E93;
  --success: #34C759;
  --error: #FF3B30;
  --warning: #FF9500;
  
  --background: #F2F2F7;
  --surface: #FFFFFF;
  
  --text: #1C1C1E;
  --text-secondary: #8E8E93;
  --text-tertiary: #C7C7CC;
  
  --border: #C6C6C8;
  --border-light: #E5E5EA;
  
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
  
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; }

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

/* Header */
.header {
  background: var(--surface);
  padding: 14px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(20px);
  background: rgba(255, 255, 255, 0.8);
}

.header-title {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* Main */
.main {
  flex: 1;
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* Buttons */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { 
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { 
  background: var(--border-light);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { 
  background: var(--background);
  border-color: var(--border);
}

.btn-full { width: 100%; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 10px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  border: none;
  cursor: pointer;
}
.btn-icon:hover { 
  background: var(--primary);
  color: white;
  transform: scale(1.05);
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-add-log {
  margin-top: 4px;
}

.btn-danger {
  background: var(--error);
  color: white;
}
.btn-danger:hover { background: #D73027; }

/* Emulations List */
.emulations-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.emulation-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: var(--transition);
  border: 1px solid transparent;
}
.emulation-item:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.emulation-info {
  flex: 1;
  min-width: 0;
}

.emulation-name {
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* State badges */
.state-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.state-new { background: var(--primary-light); color: var(--primary); }
.state-active { background: #E8F5E9; color: var(--success); }
.state-completed { background: #FFF3E0; color: var(--warning); }
.state-paused { background: var(--border-light); color: var(--text-secondary); }
.state-disabled { background: #F5F5F5; color: var(--text-tertiary); }

.emulation-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Skeleton Loading */
.skeleton-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.skeleton-item::before {
  content: '';
  display: block;
  height: 20px;
  background: linear-gradient(90deg, var(--border-light) 25%, var(--background) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 1;
}
.modal-header h3 { 
  font-weight: 600; 
  font-size: 1.1rem;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: var(--transition);
}
.modal-close:hover { 
  background: var(--background); 
  color: var(--text);
}

/* Form */
.form { padding: 20px; }
.form-label {
  display: block;
  margin-bottom: 18px;
}
.form-label > span {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}
.form-label > span .required {
  color: var(--error);
  font-weight: 600;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition);
  background: var(--surface);
  color: var(--text);
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}
.form-input:disabled,
.form-input[readonly] {
  background: var(--background);
  color: var(--text-secondary);
  cursor: default;
  opacity: 1;
  font-family: monospace;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}

textarea.form-input { 
  min-height: 80px; 
  resize: vertical; 
  font-family: inherit;
}

select.form-input {
  appearance: none;
  background-image: url("image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* Error Log List */
.error-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.error-log-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.error-log-row .form-input {
  flex: 1;
  min-width: 0;
}

.btn-remove-log {
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--border-light);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
  border: none;
  cursor: pointer;
}
.btn-remove-log:hover:not(:disabled) {
  background: var(--error);
  color: white;
}
.btn-remove-log:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-remove-log svg { width: 14px; height: 14px; }

/* Radio Group */
.radio-group {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  user-select: none;
}
.radio-option:hover { background: var(--background); }
.radio-option input {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.hidden { display: none !important; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-hover);
  z-index: 200;
  animation: slideUpToast 0.3s ease forwards;
  max-width: 90%;
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warning { background: var(--warning); color: var(--text); }
.toast.hidden { 
  animation: slideDownToast 0.2s ease forwards; 
}

@keyframes slideUpToast {
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
@keyframes slideDownToast {
  to { transform: translateX(-50%) translateY(20px); opacity: 0; }
}

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

/* Responsive */
@media (max-width: 480px) {
  .emulation-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .emulation-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 12px;
  }
  .radio-group {
    flex-direction: column;
    gap: 8px;
  }
  .modal-content {
    margin: 10px;
    max-height: calc(100vh - 20px);
  }
  .form-actions {
    flex-direction: column-reverse;
  }
  .form-actions .btn {
    width: 100%;
  }
}

/* Focus visible for accessibility */
.btn:focus-visible,
.form-input:focus-visible,
.modal-close:focus-visible,
.radio-option:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}