* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, 'Noto Sans SC', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  min-height: 100vh;
  padding: 20px;
}

header {
  background: white;
  border-radius: 12px;
  padding: 2em;
  margin-bottom: 2em;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

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

.header-content > div {
  flex: 1;
  text-align: center;
}

.lang-toggle {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  font-weight: 500;
  transition: all 0.3s;
  white-space: nowrap;
}

.lang-toggle:hover {
  background: #5568d3;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.lang-toggle:active {
  transform: translateY(0);
}

h1 {
  color: #667eea;
  margin-bottom: 0.5em;
  font-size: 2em;
}

.subtitle {
  color: #666;
  font-size: 1.1em;
}

main {
  background: white;
  border-radius: 12px;
  padding: 2em;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  margin-bottom: 2em;
}

.search-panel {
  margin-bottom: 2em;
}

.search-group {
  display: flex;
  gap: 10px;
  margin-bottom: 1em;
}

input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1em;
  transition: border-color 0.3s;
}

input:focus {
  outline: none;
  border-color: #667eea;
}

.btn-primary {
  padding: 12px 24px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.3s;
  font-weight: 500;
}

.btn-primary:hover {
  background: #5568d3;
}

.btn-secondary {
  padding: 12px 24px;
  background: #e0e0e0;
  color: #333;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.3s;
  font-weight: 500;
}

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

.btn-export {
  padding: 12px 24px;
  background: #4caf50;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 500;
  margin-left: 10px;
}

.btn-export:hover {
  background: #45a049;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.info-badge {
  background: #f0f7ff;
  border-left: 4px solid #667eea;
  padding: 12px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #555;
}

.tabs-container {
  margin-bottom: 1.5em;
}

.tabs-container h3 {
  color: #667eea;
  margin-bottom: 0.8em;
  font-size: 1.1em;
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.type-tab, .property-tab {
  padding: 10px 20px;
  background: #f5f5f5;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 0.95em;
  font-weight: 500;
}

.type-tab:hover, .property-tab:hover {
  background: #e8eeff;
  border-color: #667eea;
}

.type-tab.active, .property-tab.active {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.results-container {
  margin-top: 1.5em;
}

.result-count {
  margin-bottom: 1em;
  padding: 10px;
  background: #f0f7ff;
  border-radius: 6px;
  color: #667eea;
  font-weight: 500;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1em;
  min-width: 800px;
}

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

th {
  padding: 14px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 0.9em;
}

td {
  padding: 12px 10px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.9em;
}

tr:hover {
  background: #f8f9fa;
}

tbody tr:nth-child(even) {
  background: #fafbfc;
}

tbody tr:nth-child(even):hover {
  background: #f0f2f5;
}

.loading, .no-data {
  text-align: center;
  padding: 3em 2em;
  color: #666;
  font-size: 1.1em;
}

.no-data {
  background: #fff3cd;
  border-radius: 8px;
  color: #856404;
}

footer {
  text-align: center;
  color: white;
  padding: 1em;
}

footer a {
  color: white;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,0.5);
  transition: border-bottom-color 0.3s;
}

footer a:hover {
  border-bottom-color: white;
}

/* 表格内链接样式 */
table a {
  color: #667eea;
  text-decoration: none;
  font-weight: 500;
}

table a:hover {
  text-decoration: underline;
}

.material-link {
  color: #667eea;
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.material-link:hover {
  color: #5568d3;
  text-decoration: underline;
}

.material-link:active {
  color: #4557c2;
}

/* V2 Features: Expandable Rows, Composition, Data Notes */
.data-note {
  background: #e3f2fd;
  border-left: 4px solid #2196f3;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #1565c0;
}

.composition {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-weight: 500;
  color: #333;
}

.poscar-icon {
  font-size: 1.3em;
  cursor: help;
  transition: transform 0.2s;
  display: inline-block;
}

.poscar-icon:hover {
  transform: scale(1.2);
}

.data-meta {
  font-size: 0.85em;
  color: #666;
  font-weight: normal;
}

.chart-indicator {
  display: inline-block;
  padding: 2px 8px;
  background: #e8f4fd;
  color: #0066cc;
  border-radius: 4px;
  font-size: 0.9em;
  font-weight: 500;
}

/* Expandable Row System */
.expand-cell {
  width: 30px;
  text-align: center;
  padding: 4px !important;
}

.expand-btn {
  background: transparent;
  border: none;
  font-size: 0.9em;
  cursor: pointer;
  color: #667eea;
  padding: 2px 6px;
  transition: transform 0.2s;
}

.expand-btn:hover {
  transform: scale(1.2);
}

.expanded-row {
  background: #f8f9fa;
  position: relative;
  z-index: 10;
}

.expanded-row.hidden {
  display: none;
}

.expanded-content {
  padding: 16px;
  border-top: 2px solid #e0e0e0;
}

.expanded-selectors {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 12px;
  background: #f0f4ff;
  border-radius: 6px;
  border: 1px solid #d0d7e5;
}

.expanded-selectors .selector-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.expanded-selectors label {
  font-weight: 600;
  color: #555;
  font-size: 0.9em;
  white-space: nowrap;
}

.expanded-selectors select {
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
  font-size: 0.9em;
  cursor: pointer;
  min-width: 120px;
}

.expanded-selectors select:hover {
  border-color: #667eea;
}

.expanded-selectors select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.sub-table {
  width: 100%;
  background: white;
  border-radius: 4px;
  overflow: visible;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: relative;
  z-index: 10;
}

.sub-table th {
  background: #667eea;
  color: white;
  padding: 8px;
  font-size: 0.9em;
}

.sub-table td {
  padding: 8px;
  font-size: 0.9em;
  border-bottom: 1px solid #eee;
}

/* Lattice Parameters Dropdown */
.lattice-cell {
  position: relative;
  z-index: 1;
}

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

.point-group {
  font-weight: 600;
  color: #333;
}

.lattice-expand, .sites-expand {
  background: #667eea;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.85em;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  min-width: 24px;
}

.lattice-expand:hover, .sites-expand:hover {
  background: #5568d3;
  transform: scale(1.05);
}

.lattice-details {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  padding: 12px;
  z-index: 1000;
  min-width: 150px;
  margin-top: 4px;
}

.lattice-details.hidden {
  display: none;
}

.lattice-details div {
  padding: 4px 0;
  font-size: 0.9em;
  color: #333;
}

/* Elastic Constants Matrix */
.elastic-cell {
  position: relative;
  z-index: 1;
}

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

.matrix-expand {
  background: transparent;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  padding: 2px 6px;
  transition: transform 0.2s;
}

.matrix-expand:hover {
  transform: scale(1.2);
}

.matrix-details {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border: 2px solid #667eea;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  padding: 16px;
  z-index: 1001;
  margin-top: 8px;
}

.matrix-details.hidden {
  display: none;
}

.cij-matrix {
  border-collapse: separate;
  border-spacing: 0;
}

.cij-matrix td {
  border: 1px solid #ddd;
  padding: 6px 10px;
  text-align: center;
  font-size: 0.85em;
  font-family: 'Courier New', monospace;
  background: #f8f9fa;
}

.cij-matrix tr:first-child td {
  background: #e3f2fd;
}

.cij-matrix td:first-child {
  background: #e3f2fd;
}

/* Interstitial Sites */
.interstitial-cell {
  position: relative;
  z-index: 1;
}

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

/* Stacking Fault Types */
.stacking-cell {
  position: relative;
  z-index: 1;
}

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

.sites-expand {
  background: #667eea;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 0.8em;
  cursor: pointer;
  transition: background 0.2s;
}

.sites-expand:hover {
  background: #5568d3;
}

.sites-details {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  padding: 12px;
  z-index: 1000;
  min-width: 200px;
  margin-top: 4px;
}

.sites-details.hidden {
  display: none;
}

.sites-details div {
  padding: 4px 0;
  font-size: 0.9em;
  color: #333;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  overflow: auto;
}

.modal-content {
  background-color: white;
  margin: 2% auto;
  padding: 0;
  border-radius: 12px;
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease-out;
}

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

.modal-close {
  color: #aaa;
  float: right;
  font-size: 32px;
  font-weight: bold;
  padding: 10px 20px;
  cursor: pointer;
  transition: color 0.3s;
}

.modal-close:hover,
.modal-close:focus {
  color: #667eea;
}

/* Export Modal */
.export-modal {
  max-width: 650px;
  padding: 25px;
}

.export-modal h2 {
  color: #2c3e50;
  margin: 0 0 25px 0;
  padding: 0;
  font-size: 1.5em;
  font-weight: 600;
}

.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.export-section {
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-icon {
  font-size: 1.2em;
}

.section-header h3 {
  color: #2c3e50;
  margin: 0;
  font-size: 1em;
  font-weight: 600;
}

.format-options, .range-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-card {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid #e1e8ed;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.radio-card:hover {
  border-color: #667eea;
  background: #f8f9ff;
}

.radio-card input {
  margin: 0;
  margin-right: 10px;
  cursor: pointer;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.radio-card input:checked + .radio-content strong {
  color: #667eea;
}

.radio-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.radio-content strong {
  font-size: 0.95em;
  color: #2c3e50;
}

.radio-content small {
  font-size: 0.8em;
  color: #7f8c8d;
}

.props-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.checkbox-card {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid #e1e8ed;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.checkbox-card:hover {
  border-color: #667eea;
  background: #f8f9ff;
}

.checkbox-card input {
  margin: 0;
  margin-right: 8px;
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.checkbox-card span {
  font-size: 0.95em;
  color: #2c3e50;
  font-weight: 500;
}

.checkbox-card input:checked + span {
  color: #667eea;
  font-weight: 600;
}

.material-selector {
  margin-top: 10px;
  border: 2px solid #e1e8ed;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.material-selector.hidden {
  display: none;
}

.selector-search {
  padding: 10px;
  background: #f8f9fa;
  border-bottom: 1px solid #e1e8ed;
}

.selector-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9em;
}

.selector-list {
  max-height: 250px;
  overflow-y: auto;
  padding: 8px;
}

.selector-item {
  display: block;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.2s;
  border-radius: 4px;
  font-size: 0.9em;
}

.selector-item:hover {
  background: #f8f9ff;
}

.selector-item input {
  margin-right: 8px;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e1e8ed;
}

.btn-action {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.9em;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-export-primary {
  background: #667eea;
  color: white;
}

.btn-export-primary:hover {
  background: #5568d3;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-poscar {
  background: #4caf50;
  color: white;
}

.btn-poscar:hover {
  background: #45a049;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.btn-cancel {
  background: #f5f5f5;
  color: #666;
}

.btn-cancel:hover {
  background: #e0e0e0;
  color: #333;
}

#detailContent {
  padding: 20px 30px 30px;
}

#detailContent h2 {
  color: #667eea;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #667eea;
}

.detail-section {
  margin-bottom: 30px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.detail-section h3 {
  color: #555;
  margin-bottom: 15px;
  font-size: 1.3em;
}

.detail-section h4 {
  color: #666;
  margin-top: 15px;
  margin-bottom: 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
}

.detail-item {
  display: flex;
  align-items: baseline;
  padding: 10px;
  background: white;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.detail-item label {
  font-weight: 600;
  color: #667eea;
  min-width: 150px;
  margin-right: 10px;
}

.detail-item span {
  color: #333;
  word-break: break-word;
}

.detail-item.full-width {
  grid-column: 1 / -1;
  flex-direction: column;
}

.detail-item.full-width label {
  margin-bottom: 10px;
}

.sites-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sites-list div {
  padding: 8px 12px;
  background: #f0f0f0;
  border-radius: 4px;
}

.cij-matrix-large {
  margin-top: 10px;
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.cij-matrix-large td {
  border: 1px solid #ddd;
  padding: 10px;
  text-align: center;
  font-family: 'Courier New', monospace;
  background: #f8f9fa;
  font-size: 0.95em;
}

.cij-matrix-large tr:first-child td {
  background: #e3f2fd;
  font-weight: 600;
}

.cij-matrix-large td:first-child {
  background: #e3f2fd;
  font-weight: 600;
}

.data-selector {
  background: #fff9e6;
  padding: 15px 20px;
  margin-bottom: 20px;
  border-radius: 8px;
  border-left: 4px solid #ffc107;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
}

.data-selector .selector-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.data-selector label {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.data-selector select {
  min-width: 120px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.95em;
  background: white;
  cursor: pointer;
}

.data-selector select:hover {
  border-color: #667eea;
}

.data-point-section {
  margin-bottom: 20px;
}

.data-point-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 10px 15px;
  border-radius: 6px;
  margin-bottom: 15px;
  font-size: 1.1em;
}

.data-separator {
  margin: 30px 0;
  border: none;
  border-top: 2px dashed #ddd;
}

/* Data subsections for all-data view */
.data-subsection {
  margin-bottom: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 4px solid #667eea;
}

.subsection-header {
  color: #667eea;
  font-size: 1em;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}

/* Elastic Constants Matrix */
.elastic-constants-section {
  margin: 20px 0;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.elastic-constants-section h4 {
  color: #667eea;
  margin-bottom: 15px;
}

.cij-matrix {
  width: 100%;
  border-collapse: collapse;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.cij-matrix th {
  background: #667eea;
  color: white;
  padding: 10px;
  text-align: center;
  font-weight: 600;
}

.cij-matrix td {
  padding: 10px;
  text-align: center;
  border: 1px solid #ddd;
}

.cij-matrix tbody tr:nth-child(even) {
  background: #f8f9fa;
}

.cij-matrix tbody tr:hover {
  background: #e3f2fd;
}

/* 3D Structure Viewer */
.structure-viewer-container {
  margin: 20px 0;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.structure-viewer-container h4 {
  color: #667eea;
  margin-bottom: 15px;
  font-size: 1.1em;
  font-weight: 600;
}

.structure-viewer {
  width: 100%;
  height: 500px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: #fafafa;
  position: relative;
  overflow: hidden;
}

.viewer-controls {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}

.viewer-btn {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.95em;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.viewer-btn:hover {
  background: #5568d3;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.viewer-btn:active {
  transform: translateY(0);
}

.viewer-btn.download-btn {
  background: #4caf50;
}

.viewer-btn.download-btn:hover {
  background: #45a049;
  box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.error-message {
  padding: 20px;
  text-align: center;
  color: #d32f2f;
  font-weight: 500;
}

.chart-container {
  margin-top: 20px;
  padding: 15px;
  background: white;
  border-radius: 8px;
}

.chart-image {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.chart-canvas {
  width: 100%;
  max-width: 800px;
  height: 300px;
  display: block;
  margin: 10px auto;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  h1 {
    font-size: 1.5em;
  }
  
  .search-group {
    flex-direction: column;
  }
  
  .tabs {
    justify-content: flex-start;
  }
  
  .type-tab, .property-tab {
    flex: 1 1 auto;
    min-width: 100px;
    text-align: center;
  }
  
  table {
    font-size: 0.85em;
    min-width: 600px;
  }
  
  th, td {
    padding: 8px 6px;
  }
  
  .table-wrapper {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
  }
  
  .modal-content {
    width: 95%;
    margin: 5% auto;
  }
  
  .detail-grid {
    grid-template-columns: 1fr;
  }
  
  .detail-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .detail-item label {
    min-width: auto;
    margin-bottom: 5px;
  }
}
