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

:root {
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --border:    #e2e4e9;
  --text:      #1a1d23;
  --muted:     #6b7280;
  --accent:    #0070d2;
  --accent-h:  #005fb2;
  --danger:    #d93025;
  --radius:    8px;
  --sidebar-w: 220px;
  --list-w:    300px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

.screen { height: 100vh; }
.hidden { display: none !important; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  padding: 6px 14px; cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-h); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }
.btn-ghost    { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--border); }
.btn-danger   { background: #fce8e6; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #f5c6c2; }
.btn-sm       { font-size: 12px; padding: 4px 10px; }

/* ── App layout ───────────────────────────────────────────── */
#app-screen {
  display: flex; height: 100vh; overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.logo-icon { width: 28px; height: 28px; flex-shrink: 0; }

.open-docs-wrap { padding: 8px 12px 0; }
.open-docs-btn { width: 100%; justify-content: center; }

.search-wrap { padding: 10px 12px; }
.search-wrap input {
  width: 100%; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; background: var(--bg);
}
.search-wrap input:focus { outline: none; border-color: var(--accent); }

.category-list {
  flex: 1; overflow-y: auto; padding: 4px 8px;
}
.cat-item {
  padding: 6px 8px 6px 4px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 4px;
  user-select: none; position: relative;
}
.cat-item:hover { background: var(--bg); color: var(--text); }
.cat-item.active { background: #e8f0fe; color: var(--accent); font-weight: 500; }
.cat-item.dragging { opacity: 0.4; }

/* Drop indicators */
.cat-item.cat-drop-above::before,
.cat-item.cat-drop-below::after {
  content: '';
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 2px; pointer-events: none;
}
.cat-item.cat-drop-above::before { top: -1px; }
.cat-item.cat-drop-below::after  { bottom: -1px; }

.cat-drag-handle {
  color: var(--border); font-size: 13px; line-height: 1;
  cursor: grab; flex-shrink: 0; padding: 0 2px;
}
.cat-item:hover .cat-drag-handle { color: var(--muted); }
.cat-drag-handle:active { cursor: grabbing; }

.cat-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 11px; background: var(--border); border-radius: 20px; padding: 1px 7px; flex-shrink: 0; }

/* ── Theme builder ────────────────────────────────────────── */
.theme-section {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
}
.theme-section-label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 8px;
}
.theme-presets { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.theme-preset-btn {
  font-size: 10px; padding: 2px 7px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--muted);
  cursor: pointer; transition: background 0.1s, color 0.1s;
}
.theme-preset-btn:hover { background: var(--border); color: var(--text); }
.theme-color-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 6px 4px; margin-bottom: 8px;
}
.theme-color-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.theme-color-input {
  width: 28px; height: 22px; padding: 0;
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: none;
}
.theme-color-label { font-size: 9px; color: var(--muted); text-align: center; white-space: nowrap; }
.theme-font-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.theme-field-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.theme-font-select {
  flex: 1; font-size: 11px; padding: 2px 4px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text);
}
.theme-save-btn { width: 100%; }
.theme-save-status { font-size: 11px; margin-top: 4px; }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .btn { width: 100%; }

/* ── Image Manager Panel ──────────────────────────────────── */
.imp-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 280px;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 200; display: flex; flex-direction: column;
}
.imp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.imp-title { font-weight: 600; font-size: 14px; }
.imp-body  { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.imp-upload-label { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.imp-empty { font-size: 13px; color: var(--muted); margin: 0; }
.imp-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.imp-card  {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.imp-thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: var(--bg); cursor: pointer; }
.imp-thumb:hover { opacity: 0.8; }
.imp-card .btn { border-radius: 0; border-top: 1px solid var(--border); }

/* ── Main area ────────────────────────────────────────────── */
#main {
  flex: 1; display: flex; overflow: hidden;
}

/* ── Doc list ─────────────────────────────────────────────── */
#list-panel {
  width: var(--list-w); min-width: var(--list-w);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--surface);
}
.panel-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.panel-header h2 { font-size: 14px; font-weight: 600; }
.badge {
  font-size: 11px; background: var(--border);
  border-radius: 20px; padding: 1px 7px; color: var(--muted);
}

.doc-list { flex: 1; overflow-y: auto; }
.doc-item {
  padding: 8px 10px 8px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  display: flex; align-items: flex-start; gap: 4px;
  position: relative;
}
.doc-item:hover { background: var(--bg); }
.doc-item.active { background: #e8f0fe; }
.doc-item.dragging { opacity: 0.4; }

/* Drop position indicators */
.doc-item.drop-above::before,
.doc-item.drop-below::after {
  content: '';
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 2px; pointer-events: none;
}
.doc-item.drop-above::before { top: -1px; }
.doc-item.drop-below::after  { bottom: -1px; }

.drag-handle {
  color: var(--border); font-size: 14px; line-height: 1;
  padding: 4px 2px; cursor: grab; flex-shrink: 0; user-select: none;
  margin-top: 1px;
}
.doc-item:hover .drag-handle { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }

.doc-item-body { flex: 1; min-width: 0; padding: 2px 6px 2px 0; }
.doc-item-title { font-weight: 500; font-size: 13px; margin-bottom: 3px; }
.doc-item-cat   { font-size: 11px; color: var(--muted); }
.doc-item-date  { font-size: 11px; color: var(--muted); margin-top: 2px; }
.doc-empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Editor ───────────────────────────────────────────────── */
#editor-panel {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--surface);
}
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.editor-actions { display: flex; gap: 8px; }

.editor-meta {
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--border);
}
.title-input {
  width: 100%; border: none; outline: none;
  font-size: 22px; font-weight: 700; color: var(--text);
  margin-bottom: 8px; background: transparent;
}
.title-input::placeholder { color: #c0c4cc; }
.category-input {
  width: 100%; border: none; outline: none;
  font-size: 13px; color: var(--muted); background: transparent;
  margin-bottom: 10px;
}
.category-input::placeholder { color: #c0c4cc; }

.meta-info {
  font-size: 11px; color: var(--muted); padding-bottom: 10px;
}

/* Quill overrides */
#quill-editor { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.ql-container { flex: 1; overflow-y: auto; font-size: 14px; border: none !important; }
.ql-toolbar { border-left: none !important; border-right: none !important; border-top: none !important; }
.ql-editor { min-height: 100%; padding: 16px 24px; }
.ql-editor.ql-blank::before { color: #c0c4cc; font-style: normal; }

/* Images inside docs */
.ql-editor img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 8px 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  /* allow manual resize via the browser's built-in image resize handle */
  resize: both;
  overflow: auto;
}

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

.save-status {
  padding: 6px 24px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); min-height: 30px;
}
.save-status.success { color: #1a7a3c; }
.save-status.error   { color: var(--danger); }
.save-status.loading::before {
  content: '';
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Empty state ──────────────────────────────────────────── */
#empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.empty-content { text-align: center; }
.empty-content svg { margin-bottom: 12px; opacity: 0.35; }
.empty-content p { font-size: 14px; line-height: 1.6; }

