/* ============================================================
   MyMD — app.css
   Layered AFTER design-system.css (LaunchLab).
   Only MyMD-specific pieces live here. No new palette:
   everything is built on LaunchLab :root tokens.
   The only hard-coded colours are the dark code-block surface
   (matches the loaded highlight.js github-dark theme) — an
   intentional syntax-highlighting exception.
   ============================================================ */

/* ===========================================================
   LOGIN CARD (admin / editor / callback gates)
   =========================================================== */
.login-card {
  max-width: 400px;
  margin: 14vh auto 0;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-card .brand-mark {
  margin: 0 auto 18px;
  width: 44px; height: 44px;
  border-radius: 12px;
  font-size: 20px;
}
.login-card h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 6px; color: var(--text); }
.login-card p { color: var(--text-2); margin: 0 0 24px; font-size: 13.5px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-error { color: var(--danger-text); margin-top: 14px; font-size: 12.5px; }

/* ===========================================================
   SPINNER / LOADING / EMPTY STATE
   =========================================================== */
.loading { display: flex; justify-content: center; padding: 60px; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 56px 20px; color: var(--text-3); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text-2); margin: 0 0 4px; }
.empty-state p { margin: 0; font-size: 13px; }

/* ===========================================================
   TOASTS (LaunchLab toast, stacked bottom-right)
   =========================================================== */
.toast-stack {
  position: fixed;
  right: 20px; bottom: 20px;
  display: flex; flex-direction: column-reverse; gap: 10px;
  z-index: 1100;
  pointer-events: none;
}
.toast-stack .toast {
  pointer-events: auto;
  animation: toastIn .22s var(--ease);
}
.toast.leaving { animation: toastOut .2s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ===========================================================
   ADMIN — upload zone, toolbar, article list, pagination
   =========================================================== */
.admin-content { display: none; }

.upload-zone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 36px 24px;
  text-align: center;
  margin-bottom: 24px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.upload-zone-icon {
  width: 44px; height: 44px;
  margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.upload-zone h3 { font-size: 14.5px; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.upload-zone p { font-size: 12.5px; color: var(--text-3); margin: 0; }
.upload-zone.dragover .upload-zone-icon { transform: scale(1.05); }

.upload-progress { margin-top: 16px; display: none; max-width: 420px; margin-left: auto; margin-right: auto; }
.upload-progress.visible { display: block; }
.progress-bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0%; transition: width .3s ease; }
.progress-text { font-size: 12px; color: var(--text-3); }

.articles-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.articles-toolbar .input { flex: 1; }
.search-count { font-size: 12.5px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

.articles-list {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.article-item {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px;
  transition: background var(--t-fast);
}
.article-item + .article-item { border-top: 1px solid var(--border); }
.article-item:hover { background: var(--surface-2); }
.article-info { flex: 1; min-width: 0; }
.article-slug-row { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; flex-wrap: wrap; }
.article-slug-link {
  font-weight: 600; font-size: 14px; color: var(--accent-text);
  text-decoration: none; word-break: break-all;
}
.article-slug-link:hover { text-decoration: underline; }
.article-original {
  font-size: 12px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.article-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

/* Ghost icon button variant + danger hover */
.btn-icon.btn-ghost { color: var(--text-3); border-color: transparent; background: transparent; }
.btn-icon.btn-ghost:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger-text); }
.btn-icon svg { width: 16px; height: 16px; }

/* inline slug edit */
.slug-edit { display: flex; align-items: center; gap: 6px; width: 100%; }
.slug-edit .input { width: auto; flex: 1; max-width: 280px; padding: 6px 10px; font-size: 13px; }

.pagination {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  margin-top: 20px; flex-wrap: wrap;
}
.pagination .page-indicator {
  font-size: 12.5px; color: var(--text-3); padding: 0 8px;
  font-variant-numeric: tabular-nums;
}

/* ===========================================================
   READER — public article page
   =========================================================== */
body.reader { background: var(--bg); }
.article-wrapper { max-width: 740px; margin: 0 auto; padding: 64px 24px 120px; }

.article-content { color: var(--text); }
.article-content h1 {
  font-size: 2.1rem; font-weight: 700; line-height: 1.2;
  letter-spacing: -.02em; margin: 0 0 18px; color: var(--text);
}
.article-content h2 {
  font-size: 1.5rem; font-weight: 600; line-height: 1.3;
  letter-spacing: -.01em; margin: 44px 0 14px; color: var(--text);
}
.article-content h3 { font-size: 1.2rem; font-weight: 600; line-height: 1.4; margin: 32px 0 12px; color: var(--text); }
.article-content h4, .article-content h5, .article-content h6 { font-size: 1.05rem; font-weight: 600; margin: 24px 0 10px; color: var(--text); }
.article-content p { margin: 0 0 20px; font-size: 1.06rem; line-height: 1.8; color: var(--text); }
.article-content a {
  color: var(--accent-text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--t-fast);
}
.article-content a:hover { text-decoration-color: var(--accent); }
.article-content strong { font-weight: 600; color: var(--text); }
.article-content img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 24px 0; box-shadow: var(--shadow-md); }
.article-content ul, .article-content ol { margin: 0 0 20px; padding-left: 26px; }
.article-content li { margin-bottom: 8px; font-size: 1.06rem; line-height: 1.7; }
.article-content li::marker { color: var(--text-muted); }
.article-content blockquote {
  margin: 24px 0; padding: 14px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-2);
}
.article-content blockquote p:last-child { margin-bottom: 0; }
.article-content hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }

/* inline code on light reading surface */
.article-content :not(pre) > code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: .875em;
  background: var(--surface-2);
  color: var(--accent-text);
  padding: 2px 6px;
  border-radius: 4px;
}
/* fenced code blocks — dark surface to match github-dark highlight theme */
.article-content .code-block {
  position: relative;
  margin: 24px 0;
}
.article-content .code-block pre { margin: 0; }
.article-content pre {
  background: #0d1117;            /* github-dark canvas — syntax theme exception */
  border: 1px solid #1f2733;
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-md);
}
.article-content pre code {
  display: block;
  padding: 18px 56px 18px 22px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: .88rem; line-height: 1.6;
  color: #e6edf3; background: none; border-radius: 0;
  white-space: pre-wrap; word-wrap: break-word; word-break: break-word;
}
.code-copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid #30363d;
  border-radius: var(--radius-sm);
  background: rgba(22, 27, 34, .92);
  color: #8b949e;
  cursor: pointer;
  z-index: 2;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.code-copy-btn:hover {
  color: #e6edf3;
  border-color: #8b949e;
  background: #161b22;
}
.code-copy-btn:active { transform: scale(.96); }
.code-copy-btn svg { width: 15px; height: 15px; }
.code-copy-btn .icon-check { display: none; }
.code-copy-btn.copied {
  color: #3fb950;
  border-color: color-mix(in srgb, #3fb950 60%, #30363d);
}
.code-copy-btn.copied .icon-copy { display: none; }
.code-copy-btn.copied .icon-check { display: block; }
.article-content table { width: 100%; border-collapse: collapse; margin: 24px 0; font-size: .95rem; }
.article-content thead th { background: var(--surface-2); font-weight: 600; text-align: left; padding: 11px 14px; border-bottom: 2px solid var(--border-strong); }
.article-content tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.article-content tbody tr:hover { background: var(--surface-2); }

/* 404 */
.not-found { max-width: 520px; margin: 0 auto; text-align: center; padding: 18vh 24px; }
.not-found .code { font-size: 5.5rem; font-weight: 700; color: var(--border-strong); line-height: 1; margin-bottom: 12px; }
.not-found h2 { font-size: 1.4rem; font-weight: 600; margin: 0 0 8px; color: var(--text); }
.not-found p { color: var(--text-3); margin: 0 0 28px; }

/* ===========================================================
   FLOATING ACTIONS (reader): download + AI chat
   =========================================================== */
.fab {
  position: fixed; top: 20px;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: transform var(--t-fast), background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  z-index: 999; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
}
.fab:hover { transform: scale(1.06); box-shadow: var(--shadow-lg); color: var(--text); border-color: var(--border-strong); }
.fab svg { width: 20px; height: 20px; }
.download-fab { right: 20px; }
.download-fab:hover { background: var(--accent); color: #fff; border-color: transparent; }
.chat-fab { left: 20px; background: var(--accent); color: #fff; border-color: transparent; }
.chat-fab:hover { filter: brightness(1.05); color: #fff; }

/* ===========================================================
   AI CHAT WIDGET
   =========================================================== */
.chat-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.chat-overlay.open { opacity: 1; pointer-events: auto; }

.chat-modal {
  position: fixed; bottom: 20px; left: 20px;
  width: 420px; max-width: calc(100vw - 40px);
  height: 600px; max-height: calc(100vh - 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(16px) scale(.97); opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.chat-modal.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }

.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-header-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff;
}
.chat-header-icon svg { width: 16px; height: 16px; }
.chat-header h3 { font-size: 14.5px; font-weight: 600; margin: 0; color: var(--text); }

.chat-model-bar { padding: 8px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-model-select { width: 100%; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.chat-msg { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.6; word-break: break-word; }
.chat-msg-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-assistant { align-self: flex-start; background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.chat-msg-assistant p { margin: 0 0 8px; }
.chat-msg-assistant p:last-child { margin-bottom: 0; }
.chat-msg-assistant code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: .85em; background: var(--surface); padding: 1px 5px; border-radius: 3px; color: var(--accent-text); }
.chat-msg-assistant .code-block { position: relative; margin: 8px 0; }
.chat-msg-assistant pre { background: #0d1117; border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.chat-msg-assistant .code-block pre { margin: 0; }
.chat-msg-assistant pre code { background: none; padding: 0 44px 0 0; color: #e6edf3; font-size: .82rem; }
.chat-msg-assistant .code-copy-btn { top: 6px; right: 6px; width: 28px; height: 28px; }

.chat-welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; text-align: center; padding: 24px; color: var(--text-3); gap: 6px; }
.chat-welcome svg { width: 38px; height: 38px; opacity: .35; margin-bottom: 4px; }
.chat-welcome h4 { font-size: 14px; font-weight: 600; color: var(--text-2); margin: 0; }
.chat-welcome p { font-size: 12.5px; max-width: 280px; margin: 0; }

.chat-input-area { padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.chat-input-wrapper { flex: 1; }
.chat-input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 16px; line-height: 1.5;
  resize: none; min-height: 42px; max-height: 120px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.chat-send-btn { width: 42px; height: 42px; border: none; border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background var(--t-fast), color var(--t-fast); flex-shrink: 0; }
.chat-send-btn svg { width: 20px; height: 20px; }
.chat-send-btn.mic-state { background: transparent; color: var(--text-3); }
.chat-send-btn.mic-state:hover { background: var(--surface-2); color: var(--text); }
.chat-send-btn.send-state { background: var(--accent); color: #fff; }
.chat-send-btn.send-state:hover { filter: brightness(1.05); }
.chat-send-btn.recording-state { background: var(--danger-soft); color: var(--danger-text); animation: recordPulse 1.5s infinite; }
@keyframes recordPulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 30%, transparent); } 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--danger) 0%, transparent); } }
.chat-send-btn.transcribing-state { background: var(--surface-2); color: var(--text-3); pointer-events: none; }
.chat-send-btn .chat-spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

/* ===========================================================
   EDITOR — full-screen split workspace (LaunchLab-styled)
   =========================================================== */
body.editor-page, html.editor-html { height: 100%; overflow: hidden; }

.editor-container { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

.editor-header {
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0; z-index: 10;
}
.editor-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--surface);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.editor-back:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.editor-back svg { width: 18px; height: 18px; }

.editor-filename {
  flex: 1; min-width: 0;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 13.5px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.editor-filename:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.editor-filename[readonly] { opacity: .6; cursor: default; }

.save-status { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; flex-shrink: 0; min-width: 96px; transition: color .3s ease; }
.save-status__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.save-status--idle { color: var(--text-muted); }
.save-status--saving { color: var(--warning-text); }
.save-status--saving .save-status__dot { animation: pulseDot 1s ease infinite; }
.save-status--saved { color: var(--success-text); }
.save-status--unsaved { color: var(--danger-text); }
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.editor-header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.editor-toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 6px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0; flex-wrap: wrap;
}
.toolbar-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.toolbar-btn:hover { background: var(--surface-2); color: var(--text); }
.toolbar-btn:active { background: var(--border); transform: scale(.95); }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.toolbar-spacer { flex: 1; }
.toolbar-toggle { display: none; }

.editor-split { display: grid; grid-template-columns: 1fr 1fr; flex: 1; overflow: hidden; }
.editor-pane { display: flex; flex-direction: column; overflow: hidden; }
.editor-pane:last-child { border-left: 1px solid var(--border); }
.editor-pane-label {
  padding: 7px 20px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); border-bottom: 1px solid var(--border);
  background: var(--surface-2); flex-shrink: 0;
}
.editor-textarea {
  flex: 1; width: 100%; padding: 24px;
  border: none; outline: none; resize: none;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 14px; line-height: 1.75;
  color: var(--text); background: var(--surface); tab-size: 2;
}
.editor-textarea.drag-over { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -8px; }
.editor-textarea::placeholder { color: var(--text-muted); }
.editor-preview { flex: 1; overflow-y: auto; padding: 24px 28px; background: var(--surface); }
.editor-preview .preview-empty { display: grid; place-items: center; height: 200px; color: var(--text-muted); font-size: 13.5px; font-style: italic; }

@media (max-width: 768px) {
  .editor-split { grid-template-columns: 1fr; }
  .editor-pane.preview-pane { display: none; }
  .editor-pane.preview-pane.visible { display: flex; }
  .editor-pane.editor-pane-left.hidden { display: none; }
  .toolbar-toggle {
    display: inline-flex; align-items: center;
    padding: 6px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: transparent;
    color: var(--text-2); font-family: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
  }
  .toolbar-toggle.active { background: var(--accent); color: #fff; border-color: transparent; }
  .editor-header { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  .editor-filename { order: 5; flex-basis: 100%; }
}

/* ===========================================================
   RESPONSIVE — reader + chat
   =========================================================== */
@media (max-width: 640px) {
  .article-wrapper { padding: 36px 18px 100px; }
  .article-content h1 { font-size: 1.6rem; }
  .article-content h2 { font-size: 1.3rem; }
  .article-content h3 { font-size: 1.12rem; }
  .article-content p, .article-content li { font-size: 1rem; }
  .chat-modal { inset: 0; width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .chat-fab { top: max(12px, env(safe-area-inset-top, 12px)); left: 12px; width: 40px; height: 40px; }
  .download-fab { top: max(12px, env(safe-area-inset-top, 12px)); right: 12px; width: 40px; height: 40px; }
  .toast-stack { left: 12px; right: 12px; bottom: 12px; }
  .toast-stack .toast { max-width: 100%; }
  .article-item { flex-wrap: wrap; }
  .article-actions { margin-left: auto; }
}
