/* Phase 1: App shell layout */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
  -webkit-app-region: drag;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  -webkit-app-region: no-drag;
}

.toolbar-separator {
  width: 1px;
  height: 20px;
  background: #ccc;
  margin: 0 4px;
  flex-shrink: 0;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
  background: #e4e4e4;
  color: #222;
}

.toolbar-btn:active {
  background: #d4d4d4;
}

.toolbar-btn svg {
  pointer-events: none;
}

/* Active view mode button */
.toolbar-btn.view-btn.active {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #93c5fd;
}

/* Zoom controls — hidden in source-only mode */
.view-mode-source .zoom-buttons,
.view-mode-source .zoom-separator {
  display: none;
}

/* Zoom level label */
.zoom-level {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: #666;
  min-width: 3ch;
  text-align: center;
  user-select: none;
  -webkit-app-region: no-drag;
}

/* Markdown formatting buttons — hidden in preview-only mode */
.view-mode-preview .md-buttons,
.view-mode-preview .md-separator {
  display: none;
}

/* Main content area */
.main-content {
  display: flex;
  flex: 1;
  min-height: 0;
}

.editor {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: none;
  border-right: 1px solid #ddd;
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.preview-container {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.preview {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0.75rem 1rem;
  overflow: auto;
  background: #fafafa;
  color: #333;
  font-size: calc(0.9rem * var(--preview-zoom, 1));
  line-height: 1.5;
}

/* Metadata panel (frontmatter) */
.metadata-panel {
  flex-shrink: 0;
  max-height: 35%;
  border-top: 1px solid #d0d7de;
  background: #f6f8fa;
  overflow-y: auto;
  font-size: 0.85rem;
}

.metadata-panel.hidden {
  display: none;
}

.metadata-header {
  position: sticky;
  top: 0;
  padding: 0.35rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #656d76;
  background: #eef1f5;
  border-bottom: 1px solid #d0d7de;
  user-select: none;
}

.metadata-content {
  padding: 0.5rem 1rem;
}

.metadata-content table {
  width: 100%;
  border-collapse: collapse;
}

.metadata-content td {
  padding: 0.2rem 0.5rem 0.2rem 0;
  vertical-align: top;
  line-height: 1.4;
}

.metadata-content td.meta-key {
  white-space: nowrap;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: #24292f;
  width: 1%;
  padding-right: 1rem;
}

.metadata-content td.meta-value {
  color: #57606a;
  word-break: break-word;
}

/* View mode: Source — only editor visible */
.view-mode-source .editor {
  display: block;
  border-right: none;
}
.view-mode-source .preview-container {
  display: none;
}

/* View mode: Preview — only preview visible */
.view-mode-preview .editor {
  display: none;
}
.view-mode-preview .preview-container {
  display: flex;
}

/* View mode: Split — both visible side by side (default) */
.view-mode-split .editor {
  display: block;
  border-right: 1px solid #ddd;
}
.view-mode-split .preview-container {
  display: flex;
}

/* Folder panel (Phase 8-10) */
.folder-panel {
  width: 220px;
  min-width: 120px;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #ddd;
  background: #f7f7f7;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

.folder-panel.hidden {
  display: none;
}

.folder-path {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  color: #888;
  background: #eee;
  border-bottom: 1px solid #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  user-select: none;
}

.folder-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0;
}

.folder-item {
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.folder-item:hover {
  background: #e0e0e0;
}

.folder-item.selected {
  background: #d0e0f0;
}

.folder-parent {
  color: #666;
  font-style: italic;
}

.folder-dir {
  color: #333;
}

.folder-file {
  color: #0066cc;
}

.folder-empty {
  padding: 0.6rem;
  font-size: 0.8rem;
  color: #999;
  text-align: center;
}

/* New Folder button inside the panel */
.folder-new-folder-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 4px;
  right: 10px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}

.folder-new-folder-btn:hover {
  background: #ddd;
  color: #333;
}

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

.modal-dialog {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #222;
  margin: 0;
}

.modal-input {
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 5px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.modal-input:focus {
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-btn {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  border-radius: 5px;
  border: 1px solid #ccc;
  cursor: pointer;
  background: #f5f5f5;
  color: #333;
  transition: background 0.12s;
}

.modal-btn:hover {
  background: #e8e8e8;
}

.modal-btn-ok {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.modal-btn-ok:hover {
  background: #1d4ed8;
}

/* Resize handle */
.folder-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}

.folder-resize:hover {
  background: rgba(0, 120, 212, 0.2);
}


/* Drop overlay (Phase 6: drag-and-drop) */
#drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 120, 212, 0.12);
  border: 3px dashed rgba(0, 120, 212, 0.5);
  border-radius: 8px;
  margin: 8px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#drop-overlay.visible {
  display: flex;
}

#drop-overlay span {
  background: rgba(0, 120, 212, 0.85);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 500;
  padding: 0.6rem 1.4rem;
  border-radius: 6px;
}

/* Link status bar (browser-style URL preview) */
.link-status {
  position: fixed;
  bottom: 0;
  left: 0;
  max-width: 60%;
  padding: 3px 10px;
  background: #f0f0f0;
  border-top: 1px solid #ccc;
  border-right: 1px solid #ccc;
  border-top-right-radius: 4px;
  font-size: 0.75rem;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 900;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.link-status.visible {
  opacity: 1;
}

/* Links in preview get a pointer cursor */
.preview a {
  cursor: pointer;
}

/* About dialog */
.about-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.about-overlay.hidden {
  display: none;
}

.about-dialog {
  background: #fff;
  border-radius: 14px;
  padding: 2rem 2.5rem;
  text-align: center;
  min-width: 300px;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.08);
  user-select: none;
}

.about-icon {
  width: 96px;
  height: 96px;
  border-radius: 18px;
  margin-bottom: 0.75rem;
}

.about-name {
  margin: 0 0 0.15rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: #1d1d1f;
  letter-spacing: -0.02em;
}

.about-version {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: #86868b;
}

.about-desc {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #555;
}

.about-author {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #555;
}

.about-link {
  display: inline-block;
  margin: 0.25rem 0 0.75rem;
  font-size: 0.85rem;
  color: #0066cc;
  text-decoration: none;
  cursor: pointer;
}

.about-link:hover {
  text-decoration: underline;
}

.about-copyright {
  margin: 0;
  font-size: 0.75rem;
  color: #acacac;
}

/* Web toolbar: app icon */
.toolbar-app-icon {
  display: flex;
  align-items: center;
  padding: 0 4px;
  flex-shrink: 0;
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.toolbar-icon-img {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: block;
  user-select: none;
  transition: opacity 0.15s;
}

.toolbar-app-icon:hover .toolbar-icon-img {
  opacity: 0.75;
}

/* Web toolbar: spacer pushes sign-in to the far right */
.toolbar-spacer {
  flex: 1;
}

/* Sign in / Sign out button */
.toolbar-btn-auth {
  width: auto;
  padding: 0 10px;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #1a73e8;
  border-color: #dadce0;
  background: #fff;
}

.toolbar-btn-auth:hover {
  background: #f0f4ff;
  border-color: #1a73e8;
  color: #1558b0;
}

.toolbar-btn-auth svg {
  flex-shrink: 0;
}

.auth-label {
  white-space: nowrap;
}
