/* ==========================================================================
   MeowMD Markdown Viewer & Workspace Styles (viewer.css)
   ========================================================================== */

/* Workspace Container */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 65px);
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              visibility 0.25s ease;
  z-index: 40;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  border-right: none !important;
  margin: 0 !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 320px;
  box-sizing: border-box;
}

.sidebar-branding {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-branding span {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-box i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.85rem;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.85rem 0.5rem 2.2rem;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-main);
  transition: all var(--transition-fast);
}

.search-box input:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.sidebar-actions {
  display: flex;
  gap: 0.5rem;
}

.sidebar-actions label.btn,
.sidebar-actions button.btn {
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
  flex: 1;
}

.sidebar-actions input[type="file"] {
  display: none;
}

.storage-toggle-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.25rem 0.25rem 0;
}

/* Switch UI */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border-color);
  transition: 0.3s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }

/* File List */
.file-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.75rem 0.5rem;
  min-width: 320px;
  box-sizing: border-box;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-body);
  transition: all var(--transition-fast);
  margin-bottom: 2px;
}

.file-item:hover {
  background-color: var(--bg-hover);
  color: var(--primary);
}

.file-item.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.file-item-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-delete {
  opacity: 0;
  color: var(--danger);
  padding: 2px 6px;
  border-radius: 4px;
  transition: opacity var(--transition-fast);
}

.file-item:hover .file-item-delete {
  opacity: 1;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-app);
  position: relative;
  min-width: 0;
}

/* Viewer Top Bar */
.viewer-topbar {
  padding: 0.6rem 1.25rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: nowrap;
  min-height: 56px;
  box-sizing: border-box;
}

.doc-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
}

#sidebarToggleTopbarBtn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

#sidebarToggleTopbarBtn:hover {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.doc-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
  max-width: clamp(140px, 35vw, 500px);
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.viewer-actions .btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Markdown Render Viewport */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 3rem;
  scroll-behavior: smooth;
}

.markdown-body {
  max-width: 920px;
  margin: 0 auto;
  color: var(--text-body);
  font-family: var(--font-sans);
  line-height: 1.75;
  font-size: 1.05rem;
}

/* Markdown Element Styling */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  color: var(--text-main);
  font-weight: 800;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 1rem;
  position: relative;
}

.markdown-body h1 { font-size: 2.2rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.markdown-body h2 { font-size: 1.65rem; border-bottom: 1px solid var(--border-light); padding-bottom: 0.35rem; }
.markdown-body h3 { font-size: 1.35rem; }
.markdown-body h4 { font-size: 1.15rem; }

.markdown-body p { margin-bottom: 1.25rem; }

.markdown-body a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

.markdown-body a:hover {
  color: var(--primary-hover);
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  background-color: var(--primary-light);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-body);
  font-style: italic;
}

.markdown-body ul, .markdown-body ol {
  padding-left: 1.75rem;
  margin-bottom: 1.25rem;
}

.markdown-body li { margin-bottom: 0.35rem; }

.markdown-body code:not([class*="language-"]) {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 0.2em 0.45em;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--primary);
}

.markdown-body pre {
  margin: 1.5rem 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #1e1e2e;
  position: relative;
}

.markdown-body pre code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  padding: 1.25rem;
  display: block;
  overflow-x: auto;
  color: #cdd6f4;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.markdown-body pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background-color: var(--primary); }

/* Table Styling */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.75rem 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.markdown-body th, .markdown-body td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-light);
  text-align: left;
}

.markdown-body th {
  background-color: var(--bg-surface-subtle);
  font-weight: 800;
  color: var(--text-main);
}

.markdown-body tr:nth-child(even) {
  background-color: var(--bg-surface);
}

/* Diagrams, Math, & 3D Visualizer */
.mermaid-wrapper {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin: 1.5rem 0;
  display: flex;
  justify-content: center;
  overflow-x: auto;
}

.mol-container {
  width: 100%;
  height: 420px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin: 1.5rem 0;
  position: relative;
  background-color: #000000;
}

.chart-wrapper {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin: 1.5rem 0;
  max-width: 700px;
}

/* Empty State / Welcome Screen */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 480px;
  padding: 2rem;
}

.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  margin-bottom: 1.5rem;
}

.empty-state h3 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 480px;
  margin-bottom: 1.75rem;
}

/* Drag and Drop Overlay */
.drag-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(254, 107, 94, 0.92);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  text-align: center;
}

.drag-overlay.active { display: flex; }

.drag-overlay-content h2 { font-size: 2.4rem; font-weight: 800; margin-bottom: 0.5rem; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active { display: flex; }

.modal-content {
  background-color: var(--bg-surface-elevated);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  text-align: center;
}

.modal-content h3 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

@media print {
  .navbar, .sidebar, .viewer-topbar, .toast-container { display: none !important; }
  .app-container { height: auto; display: block; }
  .content-scroll { padding: 0; }
  .markdown-body { max-width: 100%; }
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    box-shadow: var(--shadow-lg);
  }
  .viewer-topbar {
    padding: 0.5rem 0.75rem;
  }
  .doc-meta {
    display: none;
  }
  .content-scroll {
    padding: 1.5rem 1rem;
  }
}
