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

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  margin: 0; 
  color: #1a202c; 
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

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

.loading-spinner {
  background: white;
  padding: 32px 48px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: #475569;
  font-size: 0.95rem;
  font-weight: 500;
}

/* Button loading state */
button.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

button.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Header */
.app-header { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  padding: 16px 24px; 
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 { 
  margin: 0; 
  font-size: 1.75rem; 
  font-weight: 700;
}

.app-header h1 a {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.header-actions button { 
  font-size: 0.875rem;
  padding: 8px 16px;
}

/* Main Layout */
.app-main { 
  display: flex; 
  max-width: 1400px;
  margin: 24px auto;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  min-height: calc(100vh - 120px);
}

/* Sidebar */
.sidebar { 
  width: 220px; 
  background: #f8fafc;
  border-right: 1px solid #e2e8f0; 
  padding: 20px 12px; 
  display: flex; 
  flex-direction: column; 
  gap: 6px;
}

.nav-btn { 
  padding: 12px 16px; 
  border: 0; 
  background: transparent; 
  text-align: left; 
  border-radius: 8px; 
  cursor: pointer;
  font-weight: 500;
  color: #475569;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

.nav-btn:hover { 
  background: #e0e7ff;
  color: #4f46e5;
  transform: translateX(4px);
}

.nav-btn.active { 
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Content Area */
.content { 
  flex: 1; 
  padding: 24px 32px; 
  overflow: auto;
  background: #ffffff;
}

.view { 
  display: none; 
}

.view.active { 
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* View Header */
.view-header { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-header h2 {
  font-size: 1.875rem;
  font-weight: 700;
  color: #1a202c;
  margin: 0;
}

.view-header > div {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.view-header input { 
  padding: 10px 16px; 
  border: 2px solid #e2e8f0; 
  border-radius: 8px;
  font-size: 0.95rem;
  min-width: 200px;
  transition: all 0.2s ease;
}

.view-header input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Sheep Table */
.sheep-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.sheep-table thead {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.sheep-table th {
  padding: 16px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s ease;
}

.sheep-table th:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sheep-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: all 0.2s ease;
}

.sheep-table tbody tr.sheep-row {
  cursor: pointer;
}

.sheep-table tbody tr:hover {
  background: #f8fafc;
}

.sheep-table tbody tr.sheep-row:hover {
  background: #ede9fe;
}

.sheep-table tbody tr:last-child {
  border-bottom: none;
}

.sheep-table td {
  padding: 14px 12px;
  font-size: 0.925rem;
  color: #334155;
}

.sheep-table td:first-child {
  font-weight: 600;
  color: #1e293b;
}

/* List & Cards */
.list { 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
}

.card { 
  background: white; 
  padding: 18px 20px; 
  border-radius: 12px; 
  border: 1px solid #e2e8f0; 
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
  border-color: #cbd5e1;
}

.card .meta { 
  display: flex; 
  gap: 12px; 
  align-items: center;
  flex: 1;
}

.card-actions { 
  display: flex; 
  gap: 8px; 
}

/* Buttons */
button { 
  padding: 10px 18px; 
  border-radius: 8px; 
  border: 2px solid transparent;
  background: #f1f5f9;
  color: #475569;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  white-space: nowrap;
}

button:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

button:active {
  transform: translateY(0);
}

button.primary { 
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white; 
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

button.primary:hover {
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
  transform: translateY(-2px);
}

/* Modal */
.modal { 
  position: fixed; 
  inset: 0; 
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex; 
  align-items: center; 
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal.hidden { 
  display: none; 
}

.modal-content { 
  background: white; 
  padding: 28px 32px; 
  border-radius: 16px; 
  width: 720px; 
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content h3 {
  margin: 0 0 20px 0;
  font-size: 1.5rem;
  color: #1a202c;
}

.modal-close { 
  position: absolute; 
  right: 16px; 
  top: 16px; 
  border: 0; 
  background: #f1f5f9;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.25rem; 
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* Form Elements */
.form-row { 
  display: flex; 
  gap: 12px; 
  margin-bottom: 16px;
  align-items: center;
}

.form-row label { 
  width: 140px; 
  font-weight: 600;
  color: #475569;
  font-size: 0.925rem;
}

.form-row input, 
.form-row select, 
.form-row textarea { 
  flex: 1; 
  padding: 10px 14px; 
  border: 2px solid #e2e8f0; 
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

.form-row input:focus, 
.form-row select:focus, 
.form-row textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-row textarea {
  resize: vertical;
  min-height: 80px;
}

/* Pedigree */
.pedigree { 
  background: white; 
  padding: 20px; 
  border-radius: 12px; 
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.pedigree .line { 
  padding: 8px 0;
  font-size: 0.95rem;
  color: #334155;
}

.pedigree .line strong {
  color: #1e293b;
}

.pedigree-card {
  transition: all 0.2s ease;
}

.pedigree-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* Settings Panel */
.settings-panel {
  background: #f8fafc;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.settings-panel p {
  margin: 0;
  color: #64748b;
  line-height: 1.6;
}

/* Mobile Navigation Toggle */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  font-size: 1.5rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .app-main {
    margin: 16px;
    min-height: calc(100vh - 100px);
  }
  
  .content {
    padding: 20px 24px;
  }
  
  .sidebar {
    width: 200px;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 12px 16px;
  }
  
  .app-header h1 {
    font-size: 1.35rem;
  }
  
  .header-actions span {
    font-size: 0.8rem !important;
    margin-right: 8px !important;
  }
  
  .header-actions button {
    padding: 7px 14px;
    font-size: 0.85rem;
  }
  
  .app-main {
    flex-direction: column;
    margin: 12px;
    border-radius: 12px;
  }
  
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    flex-direction: row;
    overflow-x: auto;
    padding: 12px;
    gap: 8px;
  }
  
  .nav-btn {
    white-space: nowrap;
    padding: 10px 16px;
  }
  
  .nav-btn:hover {
    transform: translateX(0);
  }
  
  .content {
    padding: 16px;
  }
  
  .view-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .view-header h2 {
    font-size: 1.5rem;
  }
  
  .view-header > div {
    width: 100%;
  }
  
  .view-header input {
    width: 100%;
  }
  
  .sheep-table {
    font-size: 0.875rem;
  }
  
  .sheep-table th,
  .sheep-table td {
    padding: 10px 8px;
  }
  
  .card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .card-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .modal-content {
    padding: 20px;
    border-radius: 12px;
  }
  
  .form-row {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .form-row label {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .app-header {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  
  .app-header h1 {
    font-size: 1.15rem;
  }
  
  .header-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  
  .header-actions span {
    font-size: 0.75rem !important;
    margin-right: 6px !important;
  }
  
  .header-actions button {
    padding: 6px 10px;
    font-size: 0.75rem;
  }
  
  .app-main {
    margin: 8px;
  }
  
  .content {
    padding: 12px;
  }
  
  .view-header h2 {
    font-size: 1.25rem;
  }
  
  button {
    padding: 8px 14px;
    font-size: 0.85rem;
  }
  
  .sheep-table {
    display: block;
    overflow-x: auto;
  }
}

/* Authentication Screen */
.auth-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.auth-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 48px;
  max-width: 420px;
  width: 100%;
}

.auth-form h2 {
  margin: 0 0 24px 0;
  font-size: 1.5rem;
  color: #1a202c;
}

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

.auth-form .form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #2d3748;
  font-size: 0.9rem;
}

.auth-form .form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.auth-form .form-group input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.auth-form .form-group small {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: #718096;
}

.auth-form button[type="submit"] {
  width: 100%;
  margin-top: 8px;
}

.auth-switch {
  text-align: center;
  margin-top: 24px;
  color: #718096;
  font-size: 0.9rem;
}

.auth-switch a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.error-message {
  background: #fed7d7;
  color: #c53030;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  display: none;
}

.error-message:not(:empty) {
  display: block;
}

@media (max-width: 480px) {
  .auth-container {
    padding: 32px 24px;
  }
}
