/* ===================================================================
   Inline edit mode — floating left panel + editable region styling.
   Loaded only on pages that opt in (legal pages have a <script> tag
   for /js/edit-mode.js). The panel itself is rendered by JS.
   =================================================================== */

/* ---- Floating panel ------------------------------------------------ */
#editModePanel {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%) translateX(-100%);
  width: 280px;
  max-height: 80vh;
  background: #fff;
  border: 1px solid #ddd;
  border-left: none;
  border-radius: 0 8px 8px 0;
  box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: #2c1810;
  z-index: 99999;
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#editModePanel.open {
  transform: translateY(-50%) translateX(0);
}

#editModePanel header {
  padding: 14px 16px;
  background: #2c1810;
  color: #c9a96e;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(201, 169, 110, 0.3);
}

#editModePanel .em-body {
  padding: 14px 16px;
  flex: 1;
  overflow-y: auto;
}

#editModePanel .em-help {
  font-size: 12px;
  color: #666;
  margin-bottom: 12px;
  line-height: 1.45;
}

/* ---- Toolbar buttons ---------------------------------------------- */
#editModePanel .em-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 14px;
}
#editModePanel .em-tool {
  padding: 8px 4px;
  border: 1px solid #ddd;
  background: #faf7f2;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #2c1810;
  transition: background 0.15s, border-color 0.15s;
}
#editModePanel .em-tool:hover {
  background: #f0ebe3;
  border-color: #8b5a2b;
}
#editModePanel .em-tool.bold   { font-weight: 800; }
#editModePanel .em-tool.italic { font-style: italic; }

/* ---- Save / Cancel actions ---------------------------------------- */
#editModePanel .em-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #eee;
  background: #faf7f2;
}
#editModePanel .em-save,
#editModePanel .em-cancel {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#editModePanel .em-save {
  background: #2c1810;
  color: #fff;
}
#editModePanel .em-save:hover { background: #1a0e08; }
#editModePanel .em-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#editModePanel .em-cancel {
  background: #ddd;
  color: #555;
}
#editModePanel .em-cancel:hover { background: #ccc; }

/* ---- Status messages ---------------------------------------------- */
#editModePanel .em-status {
  font-size: 12px;
  padding: 8px 0 0;
  text-align: center;
  min-height: 1em;
}
#editModePanel .em-status.success { color: #2e7d32; }
#editModePanel .em-status.error   { color: #c62828; }

/* ---- Editable region styling -------------------------------------- */
[data-edit-key].em-editing {
  outline: 2px dashed #8b5a2b;
  outline-offset: 6px;
  border-radius: 4px;
  cursor: text;
  min-height: 40px;
}
[data-edit-key].em-editing:focus,
[data-edit-key].em-editing:focus-within {
  outline-color: #2c1810;
  outline-style: solid;
}

/* Tab handle (visible when panel is closed) */
#editModeTab {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  background: #2c1810;
  color: #c9a96e;
  border: none;
  border-radius: 0 8px 8px 0;
  padding: 16px 8px;
  cursor: pointer;
  z-index: 99998;
  font-size: 12px;
  letter-spacing: 0.08em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-weight: 600;
  text-transform: uppercase;
}
#editModeTab:hover { background: #1a0e08; }

body.em-mode-active {
  /* Reserve a bit of space on the left so the panel doesn't cover content */
  padding-left: 0;
}

/* Wider panel for the "page" context (theme controls take more room) */
body.em-context-page #editModePanel {
  width: 320px;
}

/* ---- Section structure (page context) ----------------------------- */
#editModePanel .em-section {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid #eee;
}
#editModePanel .em-section:last-of-type {
  border-bottom: none;
}
#editModePanel .em-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: #5c3d2e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}

/* ---- Theme switcher ---------------------------------------------- */
#editModePanel .em-theme-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
#editModePanel .em-theme-btn {
  padding: 8px;
  border: 1px solid #ddd;
  background: #faf7f2;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #2c1810;
  transition: background 0.15s, border-color 0.15s;
}
#editModePanel .em-theme-btn.active {
  background: #2c1810;
  color: #c9a96e;
  border-color: #2c1810;
}
#editModePanel .em-theme-btn:hover:not(.active) {
  background: #f0ebe3;
  border-color: #8b5a2b;
}

/* ---- Palette colors ---------------------------------------------- */
#editModePanel .em-palette-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
#editModePanel .em-palette-row label {
  font-size: 12px;
  color: #444;
  flex: 1;
}
#editModePanel .em-palette-row input[type="color"] {
  width: 44px;
  height: 26px;
  padding: 2px;
  border: 1px solid #ddd;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---- Bg image controls ------------------------------------------- */
#editModePanel .em-bg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
#editModePanel .em-bg-thumb {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid #ddd;
  flex-shrink: 0;
}
#editModePanel .em-bg-thumb-empty {
  background: #e8dfd2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
#editModePanel .em-bg-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
#editModePanel .em-bg-upload,
#editModePanel .em-bg-remove {
  padding: 5px 10px;
  border: 1px solid #ddd;
  border-radius: 3px;
  background: #faf7f2;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #2c1810;
  text-align: center;
}
#editModePanel .em-bg-upload {
  background: #8b5a2b;
  color: #fff;
  border-color: #8b5a2b;
}
#editModePanel .em-bg-upload:hover { background: #6b4220; }
#editModePanel .em-bg-remove:hover { background: #f0ebe3; }

#editModePanel .em-bg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
#editModePanel .em-bg-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#editModePanel .em-bg-cell span {
  font-size: 11px;
  color: #666;
  font-weight: 600;
}
#editModePanel .em-bg-cell select,
#editModePanel .em-bg-cell input[type="color"] {
  padding: 5px 6px;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 12px;
  background: #fff;
  width: 100%;
  box-sizing: border-box;
}
#editModePanel .em-bg-cell input[type="color"] {
  height: 28px;
  padding: 2px;
  cursor: pointer;
}

/* Logo size slider */
#editModePanel .em-logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#editModePanel .em-logo-row input[type="range"] {
  flex: 1;
  cursor: pointer;
}
#editModePanel .em-logo-pct {
  font-size: 12px;
  color: #5c3d2e;
  font-weight: 600;
  min-width: 40px;
  text-align: right;
}
