/* ===========================================
   VARIABLES
   =========================================== */
:root {
  --bg: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a24;
  --bg-hover: #252535;
  --border: #2a2a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #7c8aff;
  --card-width: 176px;
  --card-img-height: 176px;
}

/* ===========================================
   RESET
   =========================================== */
*, *:before, *:after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ===========================================
   SCROLLBAR
   =========================================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ===========================================
   LAYOUT
   =========================================== */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 50px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-center { flex: 1; display: flex; justify-content: center; gap: 16px; overflow-x: auto; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.logo { font-weight: 700; font-size: 1.2em; color: var(--accent); letter-spacing: 1px; }

.lang-select {
  padding: 5px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.8em;
  cursor: pointer;
}

.toolbar {
  height: 44px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}
.toolbar-left { display: flex; gap: 6px; }
.toolbar-center { flex: 1; display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.toolbar-right { display: flex; gap: 4px; }

.main-layout { flex: 1; display: flex; overflow: hidden; }

/* ===========================================
   BUTTONS
   =========================================== */
.btn {
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn:hover:not(.disabled) { border-color: var(--accent); color: var(--text); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 0.75em; }

.base-buttons {
  display: flex;
  gap: 2px;
  background: var(--bg-card);
  border-radius: 6px;
  padding: 3px;
}
.base-btn {
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 600;
  transition: all 0.15s ease;
}
.base-btn:hover { color: var(--text); }
.base-btn.active { background: var(--accent); color: #fff; }

.view-tab {
  padding: 6px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.15s ease;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.group-btn {
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75em;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.group-btn:hover { border-color: var(--accent); color: var(--text); }
.group-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.search-input {
  width: 280px;
  padding: 9px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9em;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* ===========================================
   LEFT PANEL
   =========================================== */
.left-panel {
  width: 85px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex-shrink: 0;
}
.lib-icon {
  width: 65px;
  height: 65px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  overflow: hidden;
}
.lib-icon:hover { border-color: var(--accent); }
.lib-icon.active { border-color: var(--accent); background: var(--bg-hover); }
.lib-icon img { width: 42px; height: 42px; object-fit: cover; border-radius: 4px; }
.lib-icon span { font-size: 0.65em; color: var(--text-muted); text-align: center; margin-top: 2px; }

/* ===========================================
   CENTER PANEL
   =========================================== */
.center-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.content-area { flex: 1; overflow: auto; padding: 16px; }
.content-area.grid-view {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-content: start;
}
.content-area.tree-view { display: flex; flex-direction: column; gap: 8px; }
.content-area.graph-view { position: relative; padding: 0; overflow: hidden; }

/* ===========================================
   CARDS
   =========================================== */
.card {
  width: var(--card-width);
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card-checkbox { position: absolute; top: 8px; left: 8px; z-index: 2; width: 18px; height: 18px; }
.card-img { display: block; width: 100%; height: var(--card-img-height); object-fit: cover; background: var(--bg-hover); }
.card-placeholder {
  width: 100%;
  height: var(--card-img-height);
  background: linear-gradient(135deg, var(--bg-hover), var(--bg-card));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5em;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.6;
  text-transform: uppercase;
}
.card-name { padding: 10px; font-size: 0.85em; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===========================================
   TREE VIEW
   =========================================== */
.tree-group { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tree-header { padding: 12px 16px; display: flex; align-items: center; gap: 10px; cursor: pointer; transition: background 0.15s; }
.tree-header:hover { background: var(--bg-hover); }
.tree-toggle { width: 20px; font-weight: bold; color: var(--accent); text-align: center; }
.tree-group-name { flex: 1; font-weight: 500; }
.tree-count { color: var(--text-muted); font-size: 0.85em; }
.tree-items { display: none; padding: 0 16px 12px; flex-direction: column; gap: 4px; }
.tree-items.expanded { display: flex; }
.tree-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px; cursor: pointer; transition: background 0.15s; }
.tree-item:hover { background: var(--bg-hover); }
.tree-img { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.tree-placeholder { width: 32px; height: 32px; background: var(--bg-hover); border-radius: 4px; display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--accent); }
.tree-name { flex: 1; font-size: 0.9em; }

/* ===========================================
   GRAPH VIEW
   =========================================== */
.graph-container { width: 100%; height: 100%; position: relative; }
.graph-container svg { display: block; width: 100%; height: 100%; }
.graph-sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  z-index: 10;
  max-height: calc(100% - 32px);
  overflow-y: auto;
}
.graph-section { margin-bottom: 16px; }
.graph-section:last-child { margin-bottom: 0; }
.graph-section-title { font-size: 0.75em; font-weight: 600; color: var(--accent); text-transform: uppercase; margin-bottom: 8px; }
.graph-stat { display: flex; justify-content: space-between; font-size: 0.85em; margin-bottom: 4px; }
.graph-stat-value { font-weight: 600; color: var(--accent); }
.graph-checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.8em; margin-bottom: 4px; cursor: pointer; }
.graph-checkbox input { cursor: pointer; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.graph-slider { margin-top: 8px; }
.graph-slider-label { display: flex; justify-content: space-between; font-size: 0.75em; margin-bottom: 4px; }
.graph-slider-value { color: var(--accent); }
.graph-slider input[type="range"] { width: 100%; height: 4px; background: var(--border); border-radius: 2px; -webkit-appearance: none; cursor: pointer; }
.graph-slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: var(--accent); border-radius: 50%; cursor: pointer; }
.graph-controls { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; z-index: 10; }
.graph-legend { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px; padding: 8px 16px; z-index: 10; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.75em; }

/* ===========================================
   DETAIL PANEL
   =========================================== */
.detail-panel { width: 0; background: var(--bg-secondary); border-left: 1px solid var(--border); overflow: hidden; transition: width 0.3s ease; flex-shrink: 0; }
.detail-panel.open { width: 360px; }
.detail-content { width: 360px; height: 100%; overflow-y: auto; }
.detail-header { position: relative; width: 100%; height: 200px; background: linear-gradient(145deg, var(--bg-card), var(--bg)); display: flex; align-items: center; justify-content: center; }
.detail-close { position: absolute; top: 10px; right: 10px; background: var(--bg-hover); border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; cursor: pointer; color: var(--text); display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.detail-close:hover { background: var(--accent); color: #fff; }
.detail-img { width: 150px; height: 150px; object-fit: cover; border-radius: 12px; }
.detail-placeholder { font-size: 4em; font-weight: 700; color: var(--accent); opacity: 0.4; text-transform: uppercase; }
.detail-body { padding: 20px; }
.detail-ref { font-size: 0.9em; color: var(--accent); font-weight: 600; margin-bottom: 4px; }
.detail-mrf { font-size: 0.7em; color: var(--text-muted); font-family: monospace; cursor: pointer; padding: 6px 10px; background: var(--bg-card); border-radius: 4px; margin-bottom: 12px; word-break: break-all; transition: all 0.15s; }
.detail-mrf:hover { color: var(--accent); background: var(--bg-hover); }
.detail-name { font-size: 1.2em; font-weight: 600; margin-bottom: 8px; }
.detail-desc { font-size: 0.9em; color: var(--text-muted); line-height: 1.5; margin-bottom: 16px; }
.detail-section { margin-top: 16px; }
.detail-section h4 { font-size: 0.85em; color: var(--accent); margin-bottom: 8px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { padding: 6px 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; font-size: 0.8em; color: var(--text-muted); cursor: pointer; transition: all 0.15s; }
.tag-chip:hover { border-color: var(--accent); color: var(--text); }

/* ===========================================
   MODAL
   =========================================== */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal.open { display: flex; }
.modal-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-width: 500px; width: 90%; position: relative; }
.modal-close { position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); }
.modal-close:hover { color: var(--text); }
.modal h2 { margin-bottom: 16px; }
.api-info code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }

/* ===========================================
   TOAST
   =========================================== */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 14px 28px; border-radius: 10px; font-size: 0.9em; font-weight: 500; opacity: 0; transition: opacity 0.3s; z-index: 1000; pointer-events: none; }
.toast.show { opacity: 1; }

/* ===========================================
   UTILITIES
   =========================================== */
.loading, .empty { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-muted); }
.empty { font-size: 0.9em; }
.hidden { display: none !important; }
