:root {
  --primary-color: #673ab7;
  --primary-dark: #5e35b1;
  color-scheme: light dark;
  font-family: "Roboto", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--md-sys-color-background, #fdfbff);
  color: var(--md-sys-color-on-background, #1c1b1f);
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(246, 244, 255, 0.9) 0%, #ffffff 60%);
}

.admin-only {
  display: none;
}

/* Navbar Styling */
.navbar {
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.navbar .container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 600;
  color: var(--primary-color);
  text-decoration: none;
}

.logo-icon {
  font-size: 28px;
}

.nav-menu {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-link {
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  color: #666;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 15px;
}

.nav-link:hover {
  background: #f5f5f5;
  color: var(--primary-color);
}

.nav-link.active {
  background: var(--primary-color);
  color: white;
}

/* Navigation Dropdown */
.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  color: #666;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 15px;
  cursor: pointer;
  background: none;
  border: none;
}

.nav-dropdown-toggle:hover {
  background: #f5f5f5;
  color: var(--primary-color);
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s;
  z-index: 1000;
}

.nav-dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-dropdown-item {
  display: block;
  padding: 12px 16px;
  color: #333;
  text-decoration: none;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
}

.nav-dropdown-item:first-child {
  border-radius: 12px 12px 0 0;
}

.nav-dropdown-item:last-child {
  border-radius: 0 0 12px 12px;
}

.nav-dropdown-item:hover {
  background: #f5f5f5;
}

/* Profile Dropdown */
.profile-dropdown {
  position: relative;
  display: inline-block;
}

.profile-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  cursor: pointer;
  font-weight: 500;
  color: #333;
  transition: all 0.2s;
}

.profile-button:hover {
  background: #e8e8e8;
  border-color: var(--primary-color);
}

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

.profile-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 200px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s;
  z-index: 1000;
}

.profile-dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.profile-dropdown-item {
  display: block;
  padding: 12px 16px;
  color: #333;
  text-decoration: none;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
}

.profile-dropdown-item:first-child {
  border-radius: 12px 12px 0 0;
}

.profile-dropdown-item:last-child {
  border-radius: 0 0 12px 12px;
}

.profile-dropdown-item:hover {
  background: #f5f5f5;
}

.profile-dropdown-divider {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  display: grid;
  gap: 2rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.headline {
  font-size: clamp(2rem, 3vw, 2.5rem);
  font-weight: 600;
  margin: 0;
}

.upload-card,
.documents-card,
.document-detail-card,
.history-card {
  border-radius: 28px;
  padding: 2rem;
  background-color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 20px rgba(69, 90, 100, 0.08);
  backdrop-filter: blur(16px);
}

.card-title {
  font-size: 1.5rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.file-input {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.select-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: rgba(28, 27, 31, 0.85);
}

.select-field {
  appearance: none;
  border: 1px solid rgba(103, 80, 164, 0.3);
  border-radius: 16px;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  background-color: rgba(255, 255, 255, 0.9);
  color: inherit;
}

.select-field:focus {
  outline: 2px solid rgba(103, 80, 164, 0.6);
  outline-offset: 2px;
}

.document-list {
  display: grid;
  gap: 1rem;
}

.document-item {
  padding: 1rem 1.25rem;
  border-radius: 20px;
  background-color: rgba(243, 237, 255, 0.7);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 2px solid transparent;
  cursor: pointer;
}

.document-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(102, 84, 187, 0.1);
}

.document-item.active {
  border-color: rgba(103, 80, 164, 0.5);
  box-shadow: 0 0 0 4px rgba(103, 80, 164, 0.15);
}

.document-name {
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.document-meta {
  font-size: 0.85rem;
  color: rgba(28, 27, 31, 0.65);
}

.status-chip {
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4f378b;
  background-color: rgba(79, 55, 139, 0.12);
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: rgba(28, 27, 31, 0.6);
  font-size: 0.95rem;
}

.schema-card {
  border-radius: 28px;
  padding: 2rem;
  background-color: rgba(236, 240, 255, 0.85);
  box-shadow: 0 2px 20px rgba(79, 55, 139, 0.06);
}

.history-card {
  background-color: rgba(243, 240, 255, 0.92);
}

.history-table-wrapper {
  overflow-x: auto;
  border-radius: 20px;
  border: 1px solid rgba(103, 80, 164, 0.2);
  background-color: rgba(255, 255, 255, 0.9);
}

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

.history-table th,
.history-table td {
  padding: 0.9rem 1rem;
  text-align: left;
  font-size: 0.95rem;
  border-bottom: 1px solid rgba(103, 80, 164, 0.1);
}

.history-table tr:hover {
  background-color: rgba(103, 80, 164, 0.08);
  cursor: pointer;
}

.history-empty {
  text-align: center;
  padding: 1.5rem;
  color: rgba(28, 27, 31, 0.6);
}

.document-detail-card {
  background-color: rgba(250, 248, 255, 0.92);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 1.4fr;
  gap: 1.5rem;
  align-items: flex-start;
}

.preview-panel {
  position: sticky;
  top: 2rem;
}

.preview-frame {
  width: 100%;
  min-height: 420px;
  border: 1px solid rgba(103, 80, 164, 0.25);
  border-radius: 20px;
  background-color: rgba(255, 255, 255, 0.9);
}

.analysis-panel {
  display: grid;
  gap: 1.5rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.detail-filename {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.detail-meta {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(28, 27, 31, 0.65);
}

.detail-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: rgba(28, 27, 31, 0.75);
}

.detail-label {
  width: 140px;
  font-weight: 600;
}

.detail-block {
  display: grid;
  gap: 0.75rem;
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-output {
  width: 100%;
  min-height: 160px;
  border-radius: 16px;
  border: 1px solid rgba(103, 80, 164, 0.2);
  background-color: rgba(255, 255, 255, 0.9);
  padding: 1rem;
  font-family: "Roboto Mono", monospace;
  font-size: 0.9rem;
  resize: vertical;
}

.ocr-results-list,
.schema-assignment-list,
.classification-list {
  display: grid;
  gap: 1rem;
}

.ocr-result-card,
.schema-assignment-card,
.classification-card {
  padding: 1rem;
  border-radius: 18px;
  background-color: rgba(233, 230, 251, 0.7);
  border: 1px solid rgba(103, 80, 164, 0.2);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.result-header span {
  font-size: 0.85rem;
  color: rgba(28, 27, 31, 0.6);
}

.result-preview {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: rgba(28, 27, 31, 0.75);
  line-height: 1.4;
}

.assignment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.assignment-values {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 0.75rem;
  border-radius: 12px;
  overflow-x: auto;
}

.classification-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.classification-header span {
  font-size: 0.85rem;
  color: rgba(28, 27, 31, 0.6);
}

.classification-body {
  margin-top: 0.6rem;
  font-size: 0.9rem;
  color: rgba(28, 27, 31, 0.75);
  display: grid;
  gap: 0.4rem;
}

.classification-fields,
.classification-schema {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(28, 27, 31, 0.7);
}

.ghost-button {
  border: 1px solid rgba(103, 80, 164, 0.3);
  background: transparent;
  color: #6750a4;
  border-radius: 16px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.ghost-button:hover {
  background-color: rgba(103, 80, 164, 0.08);
}

.schema-apply {
  margin-top: 2rem;
  display: grid;
  gap: 1rem;
}

.schema-apply-fields {
  display: grid;
  gap: 1rem;
}

.schema-apply-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.schema-apply-hint {
  margin: 0;
  color: rgba(28, 27, 31, 0.65);
}

.schema-apply-field {
  display: grid;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(103, 80, 164, 0.2);
  background-color: rgba(255, 255, 255, 0.9);
}

.schema-apply-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.schema-field-help {
  font-size: 0.8rem;
  color: rgba(28, 27, 31, 0.6);
}

.schema-field-input {
  border: 1px solid rgba(103, 80, 164, 0.25);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  font-family: inherit;
}

.schema-field-input:focus {
  outline: 2px solid rgba(103, 80, 164, 0.5);
  outline-offset: 2px;
}

.schema-suggestion {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(103, 80, 164, 0.9);
  background-color: rgba(103, 80, 164, 0.1);
  padding: 0.75rem 1rem;
  border-radius: 16px;
}

.schema-form {
  display: grid;
  gap: 1rem;
}

.schema-field-group {
  display: grid;
  gap: 0.75rem;
  border: 1px dashed rgba(79, 55, 139, 0.3);
  padding: 1rem;
  border-radius: 20px;
}

.schema-fields {
  display: grid;
  gap: 1rem;
}

.schema-empty {
  padding: 1rem;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  text-align: center;
  color: rgba(28, 27, 31, 0.55);
}

.actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.link {
  color: #6750a4;
  text-decoration: none;
  font-weight: 500;
}

.link:hover,
.link:focus {
  text-decoration: underline;
}

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

  .preview-panel {
    position: static;
  }
}

@media (max-width: 768px) {
  .navbar .container {
    padding: 0 16px;
  }
  
  .nav-menu {
    gap: 4px;
  }
  
  .nav-link {
    padding: 6px 12px;
    font-size: 14px;
  }
  
  .nav-brand {
    font-size: 18px;
    gap: 8px;
  }
  
  .logo-icon {
    font-size: 24px;
  }
  
  .container {
    padding: 16px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 1rem;
    gap: 1rem;
  }

  .document-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .schema-apply-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .navbar .container {
    height: 56px;
  }
  
  .nav-menu {
    gap: 2px;
    flex-wrap: wrap;
  }
  
  .nav-link {
    padding: 4px 8px;
    font-size: 13px;
  }
  
  .headline {
    font-size: 1.75rem;
  }
  
  .card-title {
    font-size: 1.25rem;
  }
}

/* Profile Dropdown Active State */
.profile-dropdown.active .profile-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
  animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #333;
}

.modal-close {
  background: none;
  border: none;
  font-size: 32px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
  line-height: 1;
}

.modal-close:hover {
  background: #f5f5f5;
  color: #333;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

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

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(103, 58, 183, 0.1);
}

.form-group small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #666;
}

.status-message {
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}

.status-message.success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #4caf50;
  display: block;
}

.status-message.error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #f44336;
  display: block;
}

.status-message.info {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #2196f3;
  display: block;
}

/* Button Styles */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: inherit;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(103, 58, 183, 0.3);
}

.btn-secondary {
  background: #f5f5f5;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

.btn-danger {
  background: #f44336;
  color: white;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* API Key Item Styles */
.api-key-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  margin-bottom: 12px;
  transition: all 0.2s;
}

.api-key-item:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(103, 58, 183, 0.1);
}

/* Mobile Responsive for Modals */
@media (max-width: 640px) {
  .modal-content {
    width: 95%;
    max-height: 95vh;
  }
  
  .modal-header {
    padding: 20px 16px 12px;
  }
  
  .modal-header h2 {
    font-size: 20px;
  }
  
  .modal-body {
    padding: 16px;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .modal-footer .btn {
    width: 100%;
  }
  
  .api-key-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .api-key-item > div:last-child {
    width: 100%;
    display: flex;
    gap: 8px;
  }
  
  .api-key-item > div:last-child button {
    flex: 1;
  }
}
