/* My layout: the editor's own layer (public/js/my-layout.js).

   Everything here hangs off #my-layout-root, which is a direct
   children of <body>, outside #app and #modal-root. A saved layout rule must start
   with one of those two, so no rule a person can save reaches these controls: black
   text on a black bar is impossible, and the way back always works. The colours
   below are fixed on purpose and do not use the app's variables for the same reason.

   Above every dialog (a modal is 100, the Reword editor 150) and below the toast
   (10000). */
#my-layout-root, #my-layout-root * { box-sizing: border-box; }

/* The element a person is pointing at, and the one they picked. They are boxes
   drawn over the page, never a change to the page, so a redraw cannot lose them. */
#my-layout-root .ml-hover, #my-layout-root .ml-sel {
  position: fixed; pointer-events: none; z-index: 9000; border-radius: 3px;
}
#my-layout-root .ml-hover { border: 1px dashed #2563eb; background: rgba(37, 99, 235, .10); }
#my-layout-root .ml-sel { border: 2px solid #2563eb; background: rgba(37, 99, 235, .08); }
#my-layout-root .ml-hover[hidden], #my-layout-root .ml-sel[hidden] { display: none; }
#my-layout-root .ml-handle {
  position: absolute; right: -12px; bottom: -12px; width: 24px; height: 24px; border-radius: 50%;
  background: #2563eb; border: 2px solid #fff; pointer-events: auto; touch-action: none; cursor: nwse-resize;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
/* While an element is picked it can be dragged, and a finger dragging it must not
   scroll the page instead. Only that one element. */
[data-ml-selected] { touch-action: none !important; }
body.ml-on { -webkit-user-select: none; user-select: none; }

/* The bar. Top centre on a desktop, docked at the bottom on a phone. */
#my-layout-root .ml-bar {
  position: fixed; z-index: 9010; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100vw - 16px); padding: 6px 8px; border-radius: 12px;
  background: #0f172a; color: #fff; font: 600 13px/1.2 system-ui, -apple-system, sans-serif;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .45);
}
#my-layout-root .ml-bar b { font-size: 13px; padding: 0 6px; color: #fff; }
#my-layout-root .ml-bar .ml-view { font-weight: 500; color: #cbd5e1; padding: 0 4px; }
#my-layout-root button {
  font: 600 13px/1.1 system-ui, -apple-system, sans-serif; color: #0f172a; background: #e2e8f0;
  border: 1px solid #94a3b8; border-radius: 8px; padding: 8px 12px; min-height: 36px; min-width: 36px;
  cursor: pointer; width: auto; height: auto; translate: none; order: 0;
}
#my-layout-root button:disabled { opacity: .45; cursor: default; }
#my-layout-root button.ml-primary { background: #2563eb; color: #fff; border-color: #1d4ed8; }
#my-layout-root button.ml-danger { background: #fee2e2; color: #7f1d1d; border-color: #fca5a5; }
#my-layout-root button.ml-on { background: #fde68a; border-color: #d97706; }

/* The sheet: a panel that can be dragged by its title on a desktop. */
#my-layout-root .ml-sheet {
  position: fixed; z-index: 9020; top: 74px; right: 14px; width: 310px; max-height: calc(100vh - 90px); overflow: auto;
  background: #fff; color: #0f172a; border: 1px solid #94a3b8; border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .35); font: 400 13px/1.35 system-ui, -apple-system, sans-serif;
}
#my-layout-root .ml-sheet[hidden], #my-layout-root .ml-dialog[hidden] { display: none; }
#my-layout-root .ml-sh-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #f1f5f9; border-bottom: 1px solid #cbd5e1;
  cursor: move; touch-action: none; border-radius: 12px 12px 0 0;
}
#my-layout-root .ml-sh-head b { flex: 1; font-size: 13px; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#my-layout-root .ml-sh-body { padding: 10px; }
#my-layout-root .ml-note { color: #334155; font-size: 12px; margin: 0 0 8px; }
#my-layout-root .ml-warn { color: #7c2d12; background: #ffedd5; border-radius: 6px; padding: 6px 8px; font-size: 12px; margin: 0 0 8px; }
#my-layout-root .ml-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
#my-layout-root .ml-row > label, #my-layout-root .ml-row > .ml-lab { flex: 0 0 76px; font-weight: 700; font-size: 12px; color: #0f172a; }
#my-layout-root .ml-val { min-width: 54px; text-align: center; font-weight: 700; color: #0f172a; }
#my-layout-root input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid #94a3b8; border-radius: 8px; background: #fff; }
#my-layout-root .ml-check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; color: #0f172a; font-size: 13px; }
#my-layout-root .ml-check input { width: 20px; height: 20px; }

/* The questions: leave with unsaved changes, and which Revert. */
#my-layout-root .ml-dialog {
  position: fixed; z-index: 9030; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100vw - 24px));
  background: #fff; color: #0f172a; border-radius: 12px; border: 1px solid #94a3b8; padding: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .5); font: 400 14px/1.4 system-ui, -apple-system, sans-serif;
}
#my-layout-root .ml-dialog h4 { margin: 0 0 6px; font-size: 15px; color: #0f172a; }
#my-layout-root .ml-dialog p { margin: 0 0 10px; color: #334155; }
#my-layout-root .ml-dialog .ml-stack { display: flex; flex-direction: column; gap: 8px; }

.ml-card .ml-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

@media (max-width: 860px) {
  #my-layout-root .ml-bar {
    top: auto; bottom: 0; left: 0; right: 0; transform: none; max-width: none; border-radius: 12px 12px 0 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  /* A bottom sheet that stops short of the top half of the screen, sitting on the bar. */
  #my-layout-root .ml-sheet {
    top: auto; left: 0; right: 0; width: auto; border-radius: 12px 12px 0 0;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)); max-height: 42vh;
  }
  #my-layout-root .ml-sh-head { cursor: default; }
  /* Room under the page so the bottom of a screen can be scrolled up above the sheet. */
  body.ml-on #app { padding-bottom: 60vh; }
}
