/* Memory Viewer Styles - NewNa.AI Theme */

.memory-viewer-container {
  background: #1a1a1a;
  border: 1px solid #6B46C1;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(107, 70, 193, 0.1);
  padding: 20px;
  margin: 20px 0;
}

.memory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #6B46C1;
}

.memory-header h3 {
  margin: 0;
  color: #e0e0e0;
  font-size: 1.5em;
}

.memory-controls {
  display: flex;
  gap: 15px;
  align-items: center;
}

.memory-search-input {
  padding: 8px 12px;
  background: #0d0d0d;
  border: 1px solid #6B46C1;
  color: #e0e0e0;
  border-radius: 4px;
  width: 250px;
  font-size: 14px;
}

.memory-search-input::placeholder {
  color: #999;
}

.memory-search-input:focus {
  outline: none;
  border-color: #6B46C1;
  box-shadow: 0 0 0 2px rgba(107, 70, 193, 0.2);
}

.view-mode-buttons {
  display: flex;
  gap: 5px;
}

.view-mode-btn {
  padding: 8px 16px;
  background: #0d0d0d;
  color: #999;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.view-mode-btn:hover {
  background: #2a2a2a;
  color: #e0e0e0;
  border-color: #6B46C1;
}

.view-mode-btn.active {
  background: #6B46C1;
  color: white;
  border-color: #6B46C1;
}

.memory-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
  padding: 15px;
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 6px;
}

.stat-item {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 12px;
  color: #999;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: bold;
  color: #6B46C1;
}

.memory-content {
  min-height: 300px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}

.empty-state p {
  margin: 10px 0;
  font-size: 16px;
}

/* List View */
.memory-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entity-card {
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 15px;
  transition: all 0.2s;
  cursor: pointer;
}

.entity-card:hover {
  border-color: #6B46C1;
  box-shadow: 0 2px 8px rgba(107, 70, 193, 0.2);
  transform: translateY(-1px);
}

.entity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.entity-name {
  font-weight: 600;
  color: #e0e0e0;
  font-size: 16px;
}

.entity-type {
  display: inline-block;
  padding: 4px 8px;
  background: #6B46C1;
  color: white;
  border-radius: 4px;
  font-size: 12px;
  text-transform: uppercase;
}

.entity-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 10px;
  font-size: 12px;
  color: #999;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.observations-list {
  margin-top: 10px;
  padding-left: 20px;
}

.observation-item {
  color: #e0e0e0;
  margin: 5px 0;
  font-size: 14px;
  list-style-type: none;
  position: relative;
}

.observation-item::before {
  content: '•';
  color: #6B46C1;
  position: absolute;
  left: -15px;
}

.entity-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.action-btn {
  padding: 6px 12px;
  background: transparent;
  color: #999;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.action-btn:hover {
  background: #6B46C1;
  color: white;
  border-color: #6B46C1;
}

.action-btn.delete-btn:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* Relations */
.relations-section {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #333;
}

.relations-section h4 {
  font-size: 14px;
  color: #999;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.relation-item {
  display: inline-block;
  padding: 4px 8px;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 4px;
  margin: 4px;
  font-size: 13px;
}

.relation-arrow {
  color: #6B46C1;
  margin: 0 5px;
}

/* Graph View */
#memory-graph {
  width: 100%;
  height: 500px;
  background: #0d0d0d;
  border: 1px solid #333;
  border-radius: 6px;
  position: relative;
}

.graph-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

.graph-control-btn {
  padding: 8px 12px;
  background: #1a1a1a;
  color: #e0e0e0;
  border: 1px solid #6B46C1;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.graph-control-btn:hover {
  background: #6B46C1;
  color: white;
}

/* Loading State */
.loading-state {
  text-align: center;
  padding: 60px;
  color: #999;
}

.loading-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 3px solid #333;
  border-top-color: #6B46C1;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Importance Score Bar */
.importance-bar {
  height: 4px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 10px;
}

.importance-fill {
  height: 100%;
  background: linear-gradient(90deg, #6B46C1, #8B5CF6);
  transition: width 0.3s;
}

/* Tag Styles */
.memory-tag {
  display: inline-block;
  padding: 2px 6px;
  background: #6B46C1;
  color: white;
  border-radius: 3px;
  font-size: 11px;
  margin-left: 5px;
}

/* Dark mode scrollbar */
.memory-content::-webkit-scrollbar {
  width: 8px;
}

.memory-content::-webkit-scrollbar-track {
  background: #0d0d0d;
}

.memory-content::-webkit-scrollbar-thumb {
  background: #6B46C1;
  border-radius: 4px;
}

.memory-content::-webkit-scrollbar-thumb:hover {
  background: #8B5CF6;
}

/* Mobile and iOS Optimizations */
@media (max-width: 768px) {
  .memory-viewer-container {
    margin: 10px;
    padding: 15px;
    border-radius: 12px;
  }
  
  .memory-header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }
  
  .memory-header h3 {
    font-size: 1.2em;
    text-align: center;
  }
  
  .memory-controls {
    flex-direction: column;
    gap: 10px;
    width: 100%;
  }
  
  .memory-search-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    -webkit-appearance: none;
    border-radius: 8px;
  }
  
  .view-mode-buttons {
    width: 100%;
    justify-content: stretch;
    gap: 8px;
  }
  
  .view-mode-btn {
    flex: 1;
    padding: 12px 8px;
    font-size: 14px;
    min-height: 44px; /* iOS touch target size */
    -webkit-tap-highlight-color: transparent;
  }
  
  .memory-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px;
  }
  
  .stat-value {
    font-size: 20px;
  }
  
  .memory-list {
    gap: 15px;
  }
  
  .entity-card {
    padding: 12px;
    margin: 0 -5px; /* Extend to edges for easier tapping */
    -webkit-tap-highlight-color: transparent;
  }
  
  .entity-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .entity-name {
    font-size: 18px;
    line-height: 1.3;
  }
  
  .entity-type {
    align-self: flex-start;
    padding: 6px 10px;
    font-size: 11px;
  }
  
  .entity-meta {
    flex-wrap: wrap;
    gap: 10px;
    font-size: 13px;
  }
  
  .observations-list {
    padding-left: 15px;
  }
  
  .observation-item {
    font-size: 15px;
    line-height: 1.5;
    margin: 8px 0;
  }
  
  .entity-actions {
    flex-direction: row;
    width: 100%;
    gap: 8px;
  }
  
  .action-btn {
    flex: 1;
    padding: 10px 8px;
    font-size: 14px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Graph view on mobile */
  #memory-graph {
    height: 350px;
    touch-action: pan-x pan-y;
  }
  
  .graph-controls {
    top: auto;
    bottom: 10px;
    left: 10px;
    right: 10px;
    flex-direction: row;
    justify-content: space-around;
  }
  
  .graph-control-btn {
    padding: 10px 12px;
    font-size: 13px;
    min-width: auto;
  }
  
  /* Empty state */
  .empty-state {
    padding: 40px 15px;
  }
  
  .empty-state p {
    font-size: 15px;
  }
  
  /* Relations on mobile */
  .relation-item {
    padding: 6px 10px;
    font-size: 14px;
    margin: 5px;
  }
  
  /* Loading state */
  .loading-state {
    padding: 40px;
  }
  
  .loading-spinner {
    width: 32px;
    height: 32px;
  }
  
  /* Importance bar */
  .importance-bar {
    height: 6px;
    margin-top: 12px;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* iOS only */
  .memory-viewer-container {
    -webkit-overflow-scrolling: touch;
  }
  
  .memory-content {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    min-height: 300px;
    max-height: calc(100vh - 300px);
  }
  
  .memory-list {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Prevent iOS bounce effect */
  .memory-viewer-container {
    position: relative;
    overflow: hidden;
  }
  
  /* Fix iOS input issues */
  input, textarea, select, button {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  
  input[type="text"] {
    -webkit-user-select: text;
  }
  
  /* Prevent double-tap zoom */
  button, .action-btn, .view-mode-btn, .graph-control-btn {
    touch-action: manipulation;
  }
  
  /* Fix iOS safe area */
  @supports (padding: max(0px)) {
    .memory-viewer-container {
      padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
  }
}

/* Small mobile devices */
@media (max-width: 375px) {
  .memory-header h3 {
    font-size: 1.1em;
  }
  
  .view-mode-btn {
    padding: 10px 6px;
    font-size: 13px;
  }
  
  .memory-stats {
    grid-template-columns: 1fr;
  }
  
  .entity-name {
    font-size: 16px;
  }
  
  .observation-item {
    font-size: 14px;
  }
  
  .action-btn {
    font-size: 13px;
  }
}