/* App layout */
html, body, #app {
  height: 100%;
  margin: 0;
}

#app {
  display: flex;
  flex-direction: column;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid hsl(var(--border));
  overflow-y: hidden;
  background: hsl(var(--muted) / 0.3);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease;
  position: relative;
}

.sidebar.collapsed {
  width: 52px;
  min-width: 52px;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  transition: margin-left 0.3s ease;
}

.main-content.snippets-full,
.main-content.drawings-full {
  /* no extra rules needed — already no padding */
}

.page-editor {
  height: 100%;
}

.page-editor .toastui-editor-defaultUI,
.page-editor .toastui-editor-main,
.page-editor .toastui-editor-md-container,
.page-editor .toastui-editor-ww-container {
  height: 100%;
}

/* Pointer cursor for all interactive elements */
button { cursor: pointer; }

/* Material Symbols icon class */
.ms {
  font-family: 'Material Symbols Outlined';
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
  font-size: 1.25rem;
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
  user-select: none;
  flex-shrink: 0;
}

/* Sidebar Nav Buttons */
.nav-btn {
  padding: 0.5rem;
  border-radius: 0.5rem;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
  cursor: pointer;
}

.nav-btn:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

.nav-btn.active {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
}

.collapse-toggle {
  position: absolute;
  bottom: 1rem;
  right: -12px;
  width: 24px;
  height: 24px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  color: hsl(var(--muted-foreground));
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.collapse-toggle:hover {
  color: hsl(var(--foreground));
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 4.5rem;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(0);
  }
  
  .sidebar.collapsed {
    transform: translateX(-100%);
  }
  
  /* main-content fills full width on mobile too */
}

/* Snippet Manager Adjustments */
.snippet-manager {
  display: flex;
  height: 100%;
  margin: 0;
}

.sidebar-asset-drop {
  border: 1px dashed hsl(var(--border));
  border-radius: 0.75rem;
  padding: 1rem 0.75rem;
  text-align: center;
  background: hsl(var(--background));
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.sidebar-asset-drop-active {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.08);
}

.sidebar-asset-upload-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  cursor: pointer;
}

.sidebar-asset-upload-btn:hover {
  background: hsl(var(--accent));
}

.prose h1 { font-size: 2rem; font-weight: 700; margin: 1.5rem 0 1rem; border-bottom: 1px solid hsl(var(--border)); padding-bottom: 0.5rem; }
.prose h2 { font-size: 1.5rem; font-weight: 600; margin: 1.25rem 0 0.75rem; }
.prose h3 { font-size: 1.25rem; font-weight: 600; margin: 1rem 0 0.5rem; }
.prose p { margin: 0.75rem 0; line-height: 1.7; }
.prose ul, .prose ol { margin: 0.75rem 0; padding-left: 1.5rem; }
.prose li { margin: 0.25rem 0; line-height: 1.7; }
.prose code { background: hsl(var(--muted)); padding: 0.15rem 0.4rem; border-radius: 0.25rem; font-size: 0.875em; }
.prose pre { background: hsl(var(--muted)); padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin: 1rem 0; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 3px solid hsl(var(--primary)); padding-left: 1rem; margin: 1rem 0; color: hsl(var(--muted-foreground)); }
.prose a { color: hsl(var(--primary)); text-decoration: underline; }
.prose a:hover { opacity: 0.8; }
.prose table { border-collapse: collapse; margin: 1rem 0; width: 100%; }
.prose th, .prose td { border: 1px solid hsl(var(--border)); padding: 0.5rem 0.75rem; text-align: left; }
.prose th { background: hsl(var(--muted)); font-weight: 600; }
.prose img { max-width: 100%; border-radius: 0.5rem; }
.prose hr { border: none; border-top: 1px solid hsl(var(--border)); margin: 1.5rem 0; }

/* Sidebar tree */
.tree-item {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  border-radius: 0.375rem;
  margin: 1px 0.5rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  transition: background 0.15s;
  user-select: none;
}

.tree-item:hover {
  background: hsl(var(--accent));
}

.tree-item.active {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
  font-weight: 600;
  box-shadow: inset 2px 0 0 hsl(var(--primary));
}

.tree-item .icon {
  margin-right: 0.5rem;
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.tree-children {
  padding-left: 0.75rem;
}

/* Toast UI Editor overrides */
.toastui-editor-defaultUI {
  border: 1px solid hsl(var(--border)) !important;
  border-radius: 0.5rem !important;
}

.toastui-editor-defaultUI .toastui-editor-md-tab-container {
  background: hsl(var(--muted)) !important;
}

/* Dark mode overrides */
.dark .toastui-editor-defaultUI {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}

.dark .toastui-editor-defaultUI .toastui-editor-md-tab-container {
  background: hsl(var(--muted)) !important;
}

.dark .toastui-editor-defaultUI .CodeMirror {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}

.dark .toastui-editor-preview {
  background: hsl(var(--background)) !important;
  color: hsl(var(--foreground)) !important;
}

.dark .toastui-editor-md-preview {
  background: hsl(var(--background)) !important;
}

.dark .toastui-editor-defaultUI .toastui-editor-toolbar {
  background: hsl(var(--muted)) !important;
  border-bottom: 1px solid hsl(var(--border)) !important;
}

/* Loading spinner */
.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Notification toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  z-index: 1000;
  animation: slideUp 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast.success { background: hsl(142 76% 36%); color: white; }
.toast.error { background: hsl(var(--destructive)); color: white; }
.toast.info { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }

@keyframes slideUp {
  from { transform: translateY(1rem); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mermaid diagrams */
.mermaid {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.breadcrumb a {
  color: hsl(var(--muted-foreground));
  text-decoration: none;
}

.breadcrumb a:hover {
  color: hsl(var(--foreground));
}

.breadcrumb .separator {
  margin: 0 0.125rem;
}


.drop-zone {
  border: 2px dashed hsl(var(--border));
  border-radius: 0.75rem;
  padding: 2rem;
  text-align: center;
  transition: all 0.2s;
  margin-bottom: 1.5rem;
  outline: none;
}

.drop-zone:focus {
  border-color: hsl(var(--primary));
}

.drop-zone-active {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.04);
}

/* Unified document grid — used by FolderViewer and AssetViewer */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.doc-card {
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  overflow: hidden;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  transition: box-shadow 0.15s;
}

.doc-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* Asset card thumbnail area */
.doc-card-preview {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: hsl(var(--muted) / 0.5);
  overflow: hidden;
}

.asset-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-info {
  padding: 0.5rem 0.625rem;
}

.asset-name {
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.asset-actions {
  display: flex;
  gap: 0.25rem;
}

.asset-btn {
  padding: 0.25rem;
  border-radius: 0.25rem;
  color: hsl(var(--muted-foreground));
  transition: all 0.15s;
}

.asset-btn:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

.asset-btn-danger:hover {
  background: hsl(0 84% 95%);
  color: hsl(0 84% 40%);
}

.asset-wiki-path {
  font-size: 0.6875rem;
  font-family: monospace;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  margin-top: 0.25rem;
  padding: 0.125rem 0.25rem;
  background: hsl(var(--muted));
  border-radius: 0.25rem;
}

.asset-wiki-path:hover {
  color: hsl(var(--foreground));
}

.snippet-content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: hsl(var(--background));
}

.snippet-item {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid hsl(var(--border));
  cursor: pointer;
  transition: background 0.15s;
}

.snippet-item:hover {
  background: hsl(var(--muted) / 0.5);
}

.snippet-item.active {
  background: hsl(var(--accent));
}

.ace_editor {
  flex: 1;
  width: 100% !important;
  height: 100% !important;
}

.snippet-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: hsl(var(--muted-foreground));
}

/* Notification badge */
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 9999px;
  background: hsl(var(--destructive));
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}

/* ── AI Chat Panel ─────────────────────────────────────────────────────── */
.ai-panel {
  display: flex;
  flex-direction: column;
  width: 360px;
  min-width: 280px;
  border-left: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 200;
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.1);
  font-size: 0.875rem;
}

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

.ai-panel-title {
  font-weight: 600;
  flex: 1;
}

.ai-panel-model-select {
  font-size: 0.7rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid hsl(var(--border));
  border-radius: 4px;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  opacity: 0.7;
}

.ai-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.ai-panel-empty {
  text-align: center;
  opacity: 0.4;
  margin-top: 2rem;
}

.ai-message {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 100%;
}

.ai-message-role {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.4;
  letter-spacing: 0.05em;
}

.ai-message--user .ai-message-content {
  background: hsl(var(--primary) / 0.08);
  border: 1px solid hsl(var(--primary) / 0.15);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.ai-message--assistant .ai-message-content {
  padding: 0.25rem 0;
}

.ai-message-content .prose p:last-child {
  margin-bottom: 0;
}

/* Tool call badges */
.ai-tool-calls {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.ai-tool-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid;
}

.ai-tool-badge--running {
  background: hsl(45 90% 96%);
  border-color: hsl(45 80% 80%);
  color: hsl(35 70% 35%);
}

.ai-tool-badge--done {
  background: hsl(140 60% 96%);
  border-color: hsl(140 50% 75%);
  color: hsl(140 50% 30%);
}

.ai-tool-badge--error {
  background: hsl(0 80% 97%);
  border-color: hsl(0 70% 80%);
  color: hsl(0 60% 40%);
}

.ai-tool-icon {
  flex-shrink: 0;
}

.ai-tool-label {
  font-weight: 500;
}

.ai-tool-error {
  opacity: 0.7;
  font-size: 0.7rem;
}

/* Typing indicator */
.ai-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.25rem 0;
}

.ai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: hsl(var(--primary) / 0.5);
  animation: ai-bounce 0.7s infinite alternate ease-in-out;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-bounce {
  from {
    transform: translateY(0);
    opacity: 0.4;
  }
  to {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Error bar */
.ai-panel-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: hsl(0 80% 97%);
  color: hsl(0 60% 40%);
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.ai-panel-error .nav-btn {
  margin-left: auto;
}

/* Input bar */
.ai-panel-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

.ai-panel-input {
  flex: 1;
  resize: none;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.ai-panel-input:focus {
  outline: none;
  border-color: hsl(var(--primary));
}

.ai-panel-input:disabled {
  opacity: 0.5;
}

.ai-panel-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
  background: hsl(var(--primary));
  color: white;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.ai-panel-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-panel-send:hover:not(:disabled) {
  opacity: 0.85;
}

/* ── AI Settings Panel ─────────────────────────────────────────────────── */
.ai-settings-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.ai-settings-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

.ai-settings-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.ai-settings-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.ai-settings-empty {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  line-height: 1.6;
}

.ai-settings-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  background: hsl(var(--background));
}

.ai-settings-item-info {
  flex: 1;
  min-width: 0;
}

.ai-settings-item-name {
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-settings-item-meta {
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.125rem;
}

.ai-settings-item-actions {
  display: flex;
  gap: 0.125rem;
  flex-shrink: 0;
}

.ai-settings-form {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.ai-settings-form-title {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.ai-settings-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  margin-top: 0.25rem;
}

.ai-settings-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  border: 1px solid hsl(var(--border));
  border-radius: 6px;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: inherit;
  box-sizing: border-box;
}

.ai-settings-input:focus {
  outline: none;
  border-color: hsl(var(--primary));
}

.ai-settings-textarea {
  resize: vertical;
  min-height: 80px;
  font-family: monospace;
  font-size: 0.75rem;
  line-height: 1.5;
}

.ai-settings-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ai-settings-btn-primary {
  padding: 0.4rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.ai-settings-btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ai-settings-btn-primary:hover:not(:disabled) {
  opacity: 0.88;
}

.ai-settings-btn-secondary {
  padding: 0.4rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  cursor: pointer;
  transition: background 0.15s;
}

.ai-settings-btn-secondary:hover {
  background: hsl(var(--accent));
}

.ai-settings-encrypt-error {
  font-size: 0.75rem;
  color: hsl(var(--destructive));
  padding: 6px 8px;
  border-radius: 6px;
  background: hsl(var(--destructive) / 0.08);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-settings-encrypt-note {
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
  padding: 8px 4px 0;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  line-height: 1.4;
}
