/* ============================================================================
   RDF-StarBase - Modern UI Styles
   ============================================================================ */

/* CSS Custom Properties */
:root {
  /* Dark Theme (Catppuccin Mocha inspired) */
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-tertiary: #313244;
  --bg-elevated: #45475a;
  
  --text-primary: #cdd6f4;
  --text-secondary: #a6adc8;
  --text-muted: #6c7086;
  
  --accent-color: #89b4fa;
  --accent-hover: #b4befe;
  --accent-secondary: #f5c2e7;
  
  --success: #a6e3a1;
  --warning: #f9e2af;
  --error: #f38ba8;
  
  --border-color: #45475a;
  --border-subtle: #313244;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  
  --header-height: 56px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  /* Light Theme (Catppuccin Latte inspired) */
  --bg-primary: #eff1f5;
  --bg-secondary: #e6e9ef;
  --bg-tertiary: #dce0e8;
  --bg-elevated: #ccd0da;
  
  --text-primary: #4c4f69;
  --text-secondary: #5c5f77;
  --text-muted: #7c7f93;
  
  --accent-color: #1e66f5;
  --accent-hover: #7287fd;
  --accent-secondary: #ea76cb;
  
  --success: #40a02b;
  --warning: #df8e1d;
  --error: #d20f39;
  
  --border-color: #ccd0da;
  --border-subtle: #dce0e8;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

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

html, body, #root {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================================
   Header
   ============================================================================ */
.app-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  gap: 1rem;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left {
  flex: 0 0 auto;
}

.header-center {
  flex: 1;
  justify-content: center;
}

.header-right {
  flex: 0 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent-color);
}

.logo span {
  background: linear-gradient(135deg, var(--accent-color), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.repo-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.repo-selector select {
  min-width: 250px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color var(--transition);
}

.repo-selector select:focus {
  outline: none;
  border-color: var(--accent-color);
}

.stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.stats strong {
  color: var(--accent-color);
  font-weight: 600;
}

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn.primary {
  background: var(--accent-color);
  color: #1e1e2e;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn.secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn.secondary:hover:not(:disabled) {
  background: var(--bg-elevated);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.icon-btn.active {
  background: var(--accent-color);
  color: #1e1e2e;
}

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

.theme-toggle {
  background: var(--bg-tertiary);
}

/* ============================================================================
   Main Content
   ============================================================================ */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Query Panel */
.query-panel {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
}

.query-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.quick-queries {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.quick-query-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.quick-query-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.execute-btn {
  font-weight: 600;
}

.editor-container {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(243, 139, 168, 0.15);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 0.85rem;
}

.error-bar button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
}

.error-bar button:hover {
  opacity: 1;
}

/* ============================================================================
   Results Area
   ============================================================================ */
.results-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.view-tabs {
  display: flex;
  gap: 0.25rem;
}

.view-tab {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.view-tab:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.view-tab.active {
  background: var(--accent-color);
  color: #1e1e2e;
}

.view-tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.result-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.panel-toggles {
  display: flex;
  gap: 0.25rem;
}

.results-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.results-main {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

.side-panel {
  width: 320px;
  border-left: 1px solid var(--border-color);
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}

.close-panel {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 10;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.close-panel:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ============================================================================
   Results Table
   ============================================================================ */
.table-wrapper {
  overflow: auto;
  max-height: 100%;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.results-table th,
.results-table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}

.results-table tr:hover td {
  background: var(--bg-tertiary);
}

/* ============================================================================
   Graph View
   ============================================================================ */
.graph-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;
}

.graph-container {
  flex: 1;
  height: 100%;
  min-height: 400px;
  position: relative;
}

.graph-svg {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
}

.tooltip {
  position: fixed;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  max-width: 400px;
  word-break: break-all;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  z-index: 1000;
}

/* Graph Details Panel */
.graph-details-panel {
  position: absolute;
  right: 1rem;
  top: 1rem;
  width: 320px;
  max-height: calc(100% - 2rem);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.graph-details-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
}

.graph-details-header h4 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.graph-details-header .close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.graph-details-header .close-btn:hover {
  color: var(--text-primary);
}

.graph-details-content {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.detail-uri {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-color);
  margin-bottom: 0.25rem;
}

.detail-full-uri {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  word-break: break-all;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.properties-table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
}

.properties-table th,
.properties-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.properties-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.properties-table td {
  color: var(--text-primary);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-properties {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

.edge-detail {
  margin-bottom: 0.75rem;
}

.edge-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.edge-value {
  font-size: 0.9rem;
  color: var(--accent-color);
  font-weight: 500;
}

.edge-value-small {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  word-break: break-all;
}

/* ============================================================================
   JSON View
   ============================================================================ */
.json-view {
  height: 100%;
  overflow: auto;
}

.json-view pre {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

/* ============================================================================
   Special Results
   ============================================================================ */
.ask-result {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
}

.ask-result span {
  font-size: 3rem;
  font-weight: 700;
}

.ask-result span.true {
  color: var(--success);
}

.ask-result span.false {
  color: var(--error);
}

.update-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  color: var(--success);
}

.update-result h3 {
  margin-top: 1rem;
  font-size: 1.25rem;
}

.update-result p {
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.empty-results {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ============================================================================
   Modal
   ============================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent-color);
}

.form-group small {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.error-message {
  padding: 0.5rem 0.75rem;
  background: rgba(243, 139, 168, 0.15);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 0.85rem;
}

/* ============================================================================
   Offline & Loading Screens
   ============================================================================ */
.offline-screen,
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: var(--bg-primary);
}

.offline-content {
  text-align: center;
  max-width: 400px;
  padding: 2rem;
  color: var(--text-secondary);
}

.offline-content h2 {
  margin-top: 1rem;
  color: var(--error);
}

.offline-content p {
  margin-top: 0.5rem;
}

.offline-instructions {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  text-align: left;
}

.offline-instructions h3 {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.offline-instructions code {
  display: block;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-color);
}

.loading-screen {
  flex-direction: column;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ============================================================================
   Scrollbar
   ============================================================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 768px) {
  .header-center {
    display: none;
  }
  
  .stats {
    display: none;
  }
  
  .quick-queries {
    display: none;
  }
  
  .side-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }
}
