/* ===== MATH Keys LaTeX editor =====
   Light workspace styled to the extension's guide: --bg-page gray,
   white cards, mint keys, teal ink, the #589983→#3C7871 gradient.
   Layout: site header on top, editor fills the rest of the viewport. */
:root {
  --ed-bg: #f8f9fa;          /* extension --bg-page  */
  --ed-card: #ffffff;        /* extension --bg-card  */
  --ed-border: #e4e5e6;      /* extension --border-color */
  --ed-heading: #022e16;
  --ed-body: #212529;
  --ed-key-bg: #DCEEE7;
  --ed-key-hover: #C7E5D9;
  --ed-key-active: #B3DBC9;
  --ed-key-text: #0B4A3B;
  --ed-accent: #3C7871;
  --ed-grad: linear-gradient(#589983, #3C7871);
  --ed-grad-hover: linear-gradient(#66a893, #458a80);
  --ed-red: #c0392b;
}

html, body.editor-body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.editor-body {
  display: flex;
  flex-direction: column;
  background: var(--ed-bg);
  font-family: "Fira Sans", "Segoe UI", Roboto, sans-serif;
}

/* the shared .site-header is position:sticky for normal pages — here it's
   just the first row of a fixed-height flex column */
.ed-site-header { position: static; flex-shrink: 0; }

/* ---------- Editor toolbar ---------- */
.ed-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 16px;
  background: var(--ed-bg);
  border-bottom: 1px solid var(--ed-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ed-title {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--ed-heading);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 3px 10px;
  min-width: 110px;
  max-width: 260px;
  flex: 0 1 auto;
}
.ed-title:hover { border-color: var(--ed-border); background: var(--ed-card); }
.ed-title:focus { outline: none; border-color: var(--ed-accent); background: var(--ed-card); }

/* same quiet confirmation as the extension's "Saved" note */
.ed-save-status { color: rgba(60, 120, 113, 0.9); font-size: 0.78rem; }

.ed-topbar-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.ed-btn {
  border: none;
  border-radius: 8px;
  padding: 6px 13px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
  white-space: nowrap;
}

/* primary — extension gradient button */
.ed-btn-green { background: var(--ed-grad); color: #fff; }
.ed-btn-green:hover { background: var(--ed-grad-hover); }

/* bare-arrow chevron that collapses/expands the site header above the
   editor — no button chrome, just the arrow */
.ed-btn-toggle-nav {
  background: transparent;
  border: none;
  color: var(--ed-accent);
  font-size: 0.85rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.ed-btn-toggle-nav:hover { opacity: 1; background: var(--ed-key-bg); }

/* secondary — mint key surface, like NEW/COPY in the extension footer */
.ed-btn-key { background: var(--ed-key-bg); color: var(--ed-key-text); }
.ed-btn-key:hover { background: var(--ed-key-hover); }
.ed-btn-key:active { background: var(--ed-key-active); }

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

/* documents sidebar */
.ed-sidebar {
  width: 190px;
  flex-shrink: 0;
  background: var(--ed-bg);
  border-right: 1px solid var(--ed-border);
  display: flex;
  flex-direction: column;
}

.ed-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  color: var(--ed-heading);
  opacity: 0.8;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.ed-icon-btn {
  background: var(--ed-key-bg);
  border: none;
  color: var(--ed-key-text);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.ed-icon-btn:hover { background: var(--ed-key-hover); }

.ed-doc-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px;
  overflow-y: auto;
  flex: 1;
}

.ed-doc-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ed-body);
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 2px;
}
.ed-doc-list li:hover { background: var(--ed-key-hover); color: var(--ed-key-text); }
.ed-doc-list li.active { background: var(--ed-key-bg); color: var(--ed-key-text); font-weight: 600; }

.ed-doc-list li .doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-doc-list li .doc-delete {
  visibility: hidden;
  background: none;
  border: none;
  color: var(--ed-body);
  opacity: 0.5;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
}
.ed-doc-list li:hover .doc-delete { visibility: visible; }
.ed-doc-list li .doc-delete:hover { color: #dc3545; opacity: 1; }

.ed-sidebar-foot {
  padding: 10px 14px;
  color: var(--ed-body);
  opacity: 0.55;
  font-size: 0.7rem;
  border-top: 1px solid var(--ed-border);
}

/* panes */
.ed-pane {
  display: flex;
  flex-direction: column;
  min-width: 160px;
  min-height: 0;
}

.ed-pane-source { flex: 1 1 50%; background: var(--ed-card); }
.ed-pane-preview { flex: 1 1 50%; background: var(--ed-card); }

.ed-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 34px;
  padding: 0 12px;
  background: var(--ed-bg);
  border-bottom: 1px solid var(--ed-border);
  color: var(--ed-heading);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.ed-pane-label { font-weight: 600; letter-spacing: 0.5px; opacity: 0.8; }

/* Live / PDF preview toggle — same pill language as the keyboard tabs */
.ed-pv-tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--ed-card);
  border: 1px solid var(--ed-border);
  border-radius: 8px;
  padding: 2px;
  margin-right: auto;
}

.ed-pv-tab {
  background: transparent;
  border: none;
  color: var(--ed-body);
  border-radius: 6px;
  padding: 2px 12px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.ed-pv-tab:hover:not(.active) { background: var(--ed-key-bg); color: var(--ed-key-text); }
.ed-pv-tab.active { background: var(--ed-grad); color: #fff; }

.ed-preview[hidden] { display: none; }

/* PDF.js canvas pages — Overleaf-style gray backdrop with paper shadows */
.ed-pdf-holder {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #4c5560;
  padding: 18px 0;
}
.ed-pdf-holder[hidden] { display: none; }

.ed-pdf-page {
  display: block;
  margin: 0 auto 18px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.ed-btn:disabled { opacity: 0.6; cursor: default; }

.ed-compile-status { font-size: 0.72rem; }
.ed-compile-status.ok { color: #3C7871; }
.ed-compile-status.err { color: var(--ed-red); }

.ed-select {
  background: var(--ed-card);
  color: var(--ed-body);
  border: 1px solid var(--ed-border);
  border-radius: 7px;
  font: inherit;
  font-size: 0.78rem;
  padding: 4px 8px;
}

/* CodeMirror */
.ed-cm-holder { flex: 1; min-height: 0; }
.ed-cm-holder .CodeMirror {
  height: 100%;
  font-family: "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 8px 0;
}
.ed-cm-holder .CodeMirror-activeline-background { background: #eef7f3; }
.ed-cm-holder .CodeMirror-gutters { background: var(--ed-bg); border-right: 1px solid var(--ed-border); }

/* gutter / resizer */
.ed-gutter {
  width: 6px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--ed-border);
}
.ed-gutter:hover, .ed-gutter.dragging { background: var(--ed-accent); }

/* preview */
.ed-preview {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
  min-height: 0;
}

.ed-error {
  background: #fdecea;
  color: var(--ed-red);
  border-bottom: 1px solid #f5c6c0;
  padding: 10px 14px;
  font-size: 0.83rem;
  font-family: "JetBrains Mono", monospace;
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ---------- MATH Keys keyboard panel ---------- */
.ed-keyboard {
  flex-shrink: 0;
  background: var(--ed-bg);
  border-top: 1px solid var(--ed-border);
  padding: 12px 16px;
  max-height: 320px;
  overflow-y: auto;
}

.ed-kb-field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* the live math field — white rounded card, like the extension's output area */
.ed-mq-field {
  flex: 1;
  min-width: 260px;
  background: var(--ed-card);
  border-radius: 8px;
  border: 1px solid var(--ed-border);
  padding: 10px 14px;
  font-size: 20px;
  min-height: 46px;
}

.ed-kb-field-actions { display: flex; gap: 8px; align-items: center; }

/* tabs — extension .mode_tabs: white pill container, active = gradient */
.ed-kb-tabs {
  display: inline-flex;
  gap: 2px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  background: var(--ed-card);
  border: 1px solid var(--ed-border);
  border-radius: 10px;
  padding: 3px;
}

.ed-kb-tab {
  background: transparent;
  border: none;
  color: var(--ed-body);
  border-radius: 7px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.ed-kb-tab:hover:not(.active) { background: var(--ed-key-bg); color: var(--ed-key-text); }
.ed-kb-tab.active { background: var(--ed-grad); color: #fff; }

.ed-kb-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* keys — the extension's mint key look (.keyboard__row > *) */
.ed-key {
  min-width: 46px;
  height: 40px;
  padding: 0 10px;
  background: var(--ed-key-bg);
  border: none;
  border-radius: 8px;
  color: var(--ed-key-text);
  font-family: "Fira Sans", "Segoe UI", Roboto, "KaTeX_Main", "Times New Roman", Symbola, sans-serif;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, transform 0.05s ease;
  -webkit-user-select: none;
  user-select: none;
}
.ed-key:hover { background: var(--ed-key-hover); }
.ed-key:active { background: var(--ed-key-active); transform: scale(0.95); }
.ed-key sub, .ed-key sup { font-size: 0.65em; }

/* transient notice, e.g. "Added \usepackage{graphicx}" */
.ed-toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--ed-grad);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(2, 46, 22, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .ed-sidebar { display: none; }
}
