:root {
  --bg: #f3f4f6;
  --panel-bg: #ffffff;
  --bar-bg: #ffffff;
  --border: #e2e5ea;
  --text: #1f2733;
  --muted: #6b7480;
  --accent: #3a7afe;
  --accent-contrast: #ffffff;
  --btn-bg: #f6f7f9;
  --btn-bg-hover: #eceef2;
  --btn-border: #dfe3e9;
  --danger: #d64545;
  --ok: #2e9e5b;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.12);
  --menu-h: 44px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #14171c;
  --panel-bg: #1b1f27;
  --bar-bg: #1b1f27;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9099a6;
  --accent: #5b8dff;
  --accent-contrast: #0d1017;
  --btn-bg: #232833;
  --btn-bg-hover: #2c3340;
  --btn-border: #333a47;
  --danger: #ef6a6a;
  --ok: #47c07d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

/* ---------- App bar ---------- */
.app-bar {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand .logo {
  width: 24px;
  height: 24px;
  color: var(--accent);
  flex: 0 0 auto;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-tag {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Buttons ---------- */
.icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  flex: 0 0 auto;
  vertical-align: -0.12em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  border-radius: 7px;
  transition: background 0.12s ease;
}

.ghost-button:hover {
  background: var(--btn-bg-hover);
}

#theme-toggle .theme-icon-dark {
  display: none;
}
:root[data-theme="dark"] #theme-toggle .theme-icon-light {
  display: none;
}
:root[data-theme="dark"] #theme-toggle .theme-icon-dark {
  display: inline-block;
}

/* ---------- Workspace ---------- */
.workspace {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  padding: 10px;
  gap: 0;
}

.panel {
  flex: 1 1 0;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  container-type: inline-size;
}

/* Collapse toolbar text to icons when a panel gets narrow */
@container (max-width: 560px) {
  .tool-label {
    display: none;
  }
  .doc-status {
    display: none;
  }
}

/* Single-panel mode */
body.single #panel-right,
body.single #splitter {
  display: none;
}

/* The remaining panel always fills the width, even after the splitter
   was dragged (which leaves an inline flex-basis on the left panel). */
body.single #panel-left {
  flex: 1 1 auto !important;
}

/* ---------- Maximize one panel to full screen ---------- */
.panel-expand {
  flex: 0 0 auto;
}
.panel-expand .compress-icon {
  display: none;
}
.panel.maximized .panel-expand .expand-icon {
  display: none;
}
.panel.maximized .panel-expand .compress-icon {
  display: inline-block;
}

/* While one panel is maximized, hide the other panel and the splitter, and
   let the maximized panel fill the whole workspace (overriding any inline
   flex-basis left behind by dragging the splitter). */
body.has-maximized .splitter,
body.has-maximized .panel:not(.maximized) {
  display: none;
}
body.has-maximized .panel.maximized {
  flex: 1 1 auto !important;
}

/* In single-panel mode the lone panel already fills the screen, so the
   per-panel expand control would be redundant. */
body.single .panel-expand {
  display: none;
}

.panel-menu {
  flex: 0 0 auto;
  height: var(--menu-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
}

.doc-name {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 42%;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-weight: 600;
  color: var(--text);
}

.doc-name:hover {
  background: var(--btn-bg);
  border-color: var(--btn-border);
}

.doc-name .doc-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-name .icon {
  color: var(--muted);
  font-size: 12px;
}

.doc-status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.doc-status.dirty {
  color: var(--accent);
  font-weight: 600;
}

.spacer {
  flex: 1 1 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}

.tool:hover {
  background: var(--btn-bg-hover);
  border-color: var(--btn-border);
}

.tool .icon {
  font-size: 13px;
  color: var(--muted);
}

.tool .caret {
  font-size: 9px;
  margin-left: -2px;
}

.tool-label {
  font-size: 13px;
}

/* ---------- Dropdown menus ---------- */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 190px;
  padding: 5px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  z-index: 40;
  display: none;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.dropdown-item:hover {
  background: var(--btn-bg-hover);
}

.dropdown-item .icon {
  color: var(--muted);
  font-size: 13px;
}

.dropdown-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--border);
}

/* ---------- Editor host ---------- */
.editor-host {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.editor {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Let the embedded editor fill the panel */
.editor .jse-main {
  height: 100%;
}

.drop-overlay {
  position: absolute;
  inset: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-bg));
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  pointer-events: none;
  z-index: 20;
}

.editor-host.dragover .drop-overlay {
  display: flex;
}

/* ---------- Splitter ---------- */
.splitter {
  flex: 0 0 14px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: col-resize;
  position: relative;
  user-select: none;
}

.splitter-grip {
  width: 4px;
  flex: 0 1 60px;
  min-height: 24px;
  border-radius: 4px;
  background: var(--border);
  transition: background 0.12s ease;
}

.splitter:hover .splitter-grip {
  background: var(--accent);
}

.xfer {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 50%;
  background: var(--panel-bg);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.xfer:hover {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 8px;
  background: #23272f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 100;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--danger);
}
.toast.ok {
  background: var(--ok);
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .brand-tag {
    display: none;
  }
  .workspace {
    flex-direction: column;
  }
  .splitter {
    flex-basis: 14px;
    flex-direction: row;
    cursor: row-resize;
  }
  .splitter-grip {
    width: 60px;
    height: 4px;
    flex: 0 0 auto;
  }
  .tool-label {
    display: none;
  }
}
