/* ==========================================================================
   Wiki Graph Viewer — Stylesheet
   TASK-014  IR-LAY-001, IR-LAY-002
   TASK-015  NFR-USE-001
   TASK-037  IR-CP-001 through IR-CP-004
   ========================================================================== */

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #222;
  background: #fff;
  overflow: hidden;
}

/* --- Toolbar  IR-LAY-003 ------------------------------------------------ */
#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: #1a1a2e;
  color: #fff;
  height: 48px;
  flex-shrink: 0;
  z-index: 100;
}

.toolbar-left { flex: 0 0 auto; display: flex; align-items: center; }
.toolbar-center { flex: 1 1 auto; display: flex; align-items: center; gap: 12px; }
.toolbar-right { flex: 0 0 auto; display: flex; gap: 6px; }

.app-title { font-size: 16px; font-weight: 600; white-space: nowrap; }

/* --- Vault selector -------------------------------------------------------- */
.vault-selector-container {
  margin-left: 12px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.vault-selector {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  max-width: 200px;
  text-overflow: ellipsis;
  outline: none;
  transition: background 0.15s;
}
.vault-selector:hover { background: rgba(255,255,255,0.25); }
.vault-selector option { color: #222; background: #fff; }

.vault-name {
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}

.toolbar-btn {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s;
}
.toolbar-btn:hover:not(:disabled) { background: rgba(255,255,255,0.25); }
.toolbar-btn:disabled { opacity: 0.4; cursor: default; }

/* --- Search  FR-SF-001 -------------------------------------------------- */
.search-container { position: relative; flex: 0 1 280px; }

#search-input {
  width: 100%;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 13px;
  outline: none;
}
#search-input::placeholder { color: rgba(255,255,255,0.5); }
#search-input:focus { border-color: #4A90D9; background: rgba(255,255,255,0.15); }

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  color: #222;
  border: 1px solid #ccc;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 200;
}
.search-dropdown .search-item {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #eee;
}
.search-dropdown .search-item:hover,
.search-dropdown .search-item.active { background: #e8f0fe; }
.search-dropdown .search-item .search-path {
  font-size: 11px;
  color: #888;
  margin-left: 6px;
}

/* --- Type Filters  FR-SF-003 -------------------------------------------- */
.type-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.type-filter-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.type-filter-btn .swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.type-filter-btn.inactive {
  opacity: 0.4;
  text-decoration: line-through;
}

/* --- Breadcrumb  IR-LAY-004 --------------------------------------------- */
#breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 16px;
  background: #f0f0f0;
  font-size: 12px;
  min-height: 26px;
  flex-shrink: 0;
  overflow-x: auto;
  white-space: nowrap;
}
#breadcrumb-bar a {
  color: #4A90D9;
  text-decoration: none;
  cursor: pointer;
}
#breadcrumb-bar a:hover { text-decoration: underline; }
#breadcrumb-bar .sep { color: #999; margin: 0 2px; }

/* --- Panels  IR-LAY-001, IR-LAY-002 ------------------------------------ */
#panels {
  display: flex;
  flex: 1 1 auto;
  overflow: hidden;
  height: calc(100vh - 48px - 26px); /* toolbar + breadcrumb */
}

/* --- Graph Panel  IR-GP-002 --------------------------------------------- */
#graph-panel {
  flex: 0 0 45%;
  position: relative;
  background: #F8F9FA;
  overflow: hidden;
  min-width: 300px;
}

#graph-svg {
  width: 100%;
  height: 100%;
}

/* --- Divider  NFR-USE-002 ----------------------------------------------- */
.divider {
  flex: 0 0 5px;
  background: #d0d0d0;
  cursor: col-resize;
  transition: background 0.15s;
  z-index: 10;
}
.divider:hover, .divider.dragging { background: #4A90D9; }

/* --- Content Panel  IR-CP-001 through IR-CP-004 ------------------------ */
#content-panel {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 300px;
}

.metadata-bar {
  padding: 8px 16px;
  background: #fafafa;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  min-height: 40px;
  flex-shrink: 0;
}

.metadata-bar .meta-title { font-weight: 600; font-size: 15px; }
.metadata-bar .meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
}
.metadata-bar .meta-tag {
  background: #e0e0e0;
  color: #333;
  padding: 1px 8px;
  border-radius: 8px;
  font-size: 11px;
}
.metadata-bar .meta-info {
  color: #666;
  font-size: 12px;
}

/* TASK-PE005 — Page export button & dropdown */
.meta-export {
  position: relative;
  margin-left: auto;
}
.meta-export-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f5f5f5;
  cursor: pointer;
  color: #333;
}
.meta-export-btn:hover { background: #e8e8e8; }
.meta-export-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  min-width: 140px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 4px 0;
  margin-top: 4px;
}
.meta-export-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: #333;
}
.meta-export-option:hover { background: #f0f4ff; }
.meta-export-dropdown.hidden { display: none; }

/* IR-CP-002 — Scrollable */
.content-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 32px;
}

/* IR-CP-003 — Typography */
.content-body .content-inner {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.6;
}

.content-body h1 { font-size: 1.8em; margin: 0.8em 0 0.4em; border-bottom: 1px solid #eee; padding-bottom: 0.3em; }
.content-body h2 { font-size: 1.5em; margin: 1em 0 0.4em; }
.content-body h3 { font-size: 1.25em; margin: 0.8em 0 0.3em; }
.content-body h4, .content-body h5, .content-body h6 { font-size: 1.1em; margin: 0.6em 0 0.3em; }
.content-body p { margin: 0.6em 0; }
.content-body ul, .content-body ol { margin: 0.5em 0 0.5em 1.5em; }
.content-body li { margin: 0.2em 0; }
.content-body blockquote {
  border-left: 4px solid #4A90D9;
  padding: 8px 16px;
  margin: 0.8em 0;
  background: #f5f8ff;
  color: #444;
}
.content-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
  font-size: 14px;
}
.content-body th, .content-body td {
  border: 1px solid #ddd;
  padding: 6px 10px;
  text-align: left;
}
.content-body th { background: #f5f5f5; font-weight: 600; }
.content-body hr { border: none; border-top: 1px solid #ddd; margin: 1.5em 0; }
.content-body img { max-width: 100%; }

/* IR-CP-003 — Inline code */
.content-body code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.9em;
}

/* IR-CP-004 — Code blocks */
.content-body pre {
  background: #F5F5F5;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 12px 16px;
  overflow-x: auto;
  margin: 0.8em 0;
}
.content-body pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

/* Mermaid diagram containers */
.content-body .mermaid {
  display: block;
  margin: 1em 0;
  text-align: center;
  overflow-x: auto;
}
.content-body .mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Internal wiki links in content */
.content-body a.wiki-link {
  color: #4A90D9;
  text-decoration: none;
  border-bottom: 1px dashed #4A90D9;
  cursor: pointer;
}
.content-body a.wiki-link:hover { border-bottom-style: solid; }
.content-body a[target="_blank"]::after { content: " ↗"; font-size: 0.8em; }

/* --- Legend  FR-GV-014 -------------------------------------------------- */
.legend {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.92);
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 11px;
  z-index: 20;
  pointer-events: none;
  max-width: 150px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
  transition: opacity 0.2s;
}
.legend-item.dimmed { opacity: 0.5; }
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* --- Zoom Controls  FR-GV-013 ------------------------------------------ */
.zoom-controls {
  position: absolute;
  bottom: 50px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}
.zoom-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.zoom-btn:hover { background: #e8e8e8; }

/* Content panel zoom controls */
.content-zoom-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
}
#content-panel {
  position: relative;
}
.zoom-btn-reset {
  font-size: 16px;
}

/* --- Stats Bar  FR-GS-001 ----------------------------------------------- */
.stats-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  border-top: 1px solid #ddd;
  padding: 4px 12px;
  font-size: 11px;
  color: #555;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  z-index: 15;
}
.stats-bar .stat-item { white-space: nowrap; }

/* --- Tooltip  FR-GV-010 ------------------------------------------------ */
.tooltip {
  position: fixed;
  background: #1a1a2e;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  pointer-events: none;
  z-index: 300;
  max-width: 280px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  line-height: 1.4;
}
.tooltip .tip-path { opacity: 0.7; font-size: 11px; }
.tooltip .tip-type { font-weight: 600; }

/* --- Empty message  NFR-REL-001 ---------------------------------------- */
.empty-message {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 48px - 26px);
  font-size: 16px;
  color: #666;
  text-align: center;
  padding: 32px;
}

.welcome-content {
  text-align: center;
}
.welcome-content h2 {
  font-size: 1.4em;
  margin-bottom: 12px;
  color: #1a1a2e;
}
.welcome-content p {
  margin: 8px 0;
  font-size: 15px;
}
.welcome-hint {
  color: #888;
  font-size: 13px;
}

/* --- Utility ------------------------------------------------------------ */
.hidden { display: none !important; }

/* --- Refresh Button Spinner  FR-RF-003 --------------------------------- */
.toolbar-btn.refreshing {
  pointer-events: none;
  opacity: 0.7;
}
.toolbar-btn.refreshing .refresh-icon {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Toast Notifications  FR-UP-003 ------------------------------------ */
.toast-container {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  animation: toast-in 0.3s ease;
  max-width: 360px;
}
.toast.success { background: #27ae60; }
.toast.error { background: #e74c3c; }
.toast.info { background: #2980b9; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* --- D3 Graph Nodes & Edges -------------------------------------------- */
.node-circle {
  cursor: pointer;
  stroke: #fff;
  stroke-width: 1.5px;
  transition: r 0.2s, stroke-width 0.2s;
}
.node-circle.active {
  stroke: #E74C3C;
  stroke-width: 3px;
}
.node-circle.error-node {
  stroke: #E74C3C;
  stroke-dasharray: 4 3;
  stroke-width: 2px;
}
.node-label {
  font-size: 10px;
  fill: #333;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}
.edge-line {
  stroke: #bbb;
  stroke-width: 1px;
  fill: none;
  transition: opacity 0.2s, stroke-width 0.2s;
}
.edge-line.highlighted {
  stroke: #555;
  stroke-width: 2px;
}
.edge-line.dimmed { opacity: 0.15; }
.edge-arrowhead { fill: #bbb; }
.edge-arrowhead.highlighted { fill: #555; }
.edge-arrowhead.dimmed { opacity: 0.15; }

/* --- New Vault button --------------------------------------------------- */
.btn-new-vault {
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  font-weight: 300;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

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

.modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  width: 480px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a2e;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { color: #222; }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: #333;
}

.form-required { color: #e74c3c; margin-left: 2px; }
.form-optional { font-weight: 400; color: #888; font-size: 12px; }

.form-group input[type="text"],
.form-group select,
.form-group textarea {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  color: #222;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input[type="text"]:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: #4A90D9; box-shadow: 0 0 0 2px rgba(74,144,217,0.15); }

.form-group textarea { resize: vertical; min-height: 56px; }
.form-hint { font-size: 11px; color: #888; line-height: 1.4; }

.form-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  color: #c0392b;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid #e8e8e8;
}

.modal-btn {
  padding: 7px 18px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.modal-btn-secondary {
  background: #f5f5f5;
  border-color: #ccc;
  color: #333;
}
.modal-btn-secondary:hover { background: #e8e8e8; }

.modal-btn-primary {
  background: #1a1a2e;
  color: #fff;
  border-color: #1a1a2e;
}
.modal-btn-primary:hover { background: #2c2c4e; border-color: #2c2c4e; }
.modal-btn-primary:disabled { opacity: 0.5; cursor: default; }

/* --- Path input row & Browse button ------------------------------------ */
.path-input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.path-input-row input { flex: 1 1 auto; }
.btn-browse { flex-shrink: 0; white-space: nowrap; }

/* --- Inline directory browser ------------------------------------------ */
.dir-browser {
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fafafa;
  margin-top: 6px;
  overflow: hidden;
}

.dir-browser-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
}

.dir-nav-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  color: #333;
}
.dir-nav-btn:hover { background: #e0e0e0; }

.dir-browser-current {
  font-size: 12px;
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.dir-browser-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
}

.dir-browser-list li {
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #222;
}
.dir-browser-list li:hover { background: #e8f0fe; }
.dir-browser-list li::before { content: "📁"; font-size: 13px; }
.dir-browser-list li.empty { color: #888; cursor: default; font-style: italic; }
.dir-browser-list li.empty::before { content: ""; }

.dir-browser-footer {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #ddd;
  background: #f0f0f0;
}

/* --- Import file info  TASK-EI009 -------------------------------------- */
.import-file-info {
  font-size: 13px;
  color: #666;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fafafa;
}
.import-file-info.has-file {
  color: #222;
  background: #f0f8ff;
  border-color: #4A90D9;
}

/* --- Import progress bar  TASK-EI009 ----------------------------------- */
.import-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.import-progress-bar {
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
}
.import-progress-fill {
  height: 100%;
  background: #4A90D9;
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}
.import-progress-fill.indeterminate {
  width: 30%;
  animation: progress-slide 1.5s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.import-progress-text {
  font-size: 12px;
  color: #666;
}

/* --- Responsive  NFR-USE-001 ------------------------------------------- */
@media (max-width: 1023px) {
  #panels { flex-direction: column; }
  #graph-panel { flex: 0 0 50%; min-width: unset; min-height: 250px; }
  .divider {
    flex: 0 0 5px;
    cursor: row-resize;
    width: 100%;
  }
  #content-panel { flex: 1 1 50%; min-width: unset; }
}
