/* ---- Mobile layout mode: outer chrome + page-zoom wrapper ----------
   Every rule here is scoped under `.docx-editor-react[data-de-layout=
   "mobile"]` — the sole gate set by `ReactDocxEditor`'s `layout` prop
   (see ReactDocxEditor.tsx) — so omitting the prop (default 'desktop')
   is provably unaffected: these selectors simply never match. */

.docx-editor-react[data-de-layout="mobile"] {
  /* Touch target token — every mobile control aims for this minimum
     hit size (Apple/Google's ~44px touch-target guidance). */
  --de-mobile-tap: 44px;
}

/* ---- Mobile header row (replaces TitleBar + HeaderActions + MenuBar) */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--de-surface);
  border-bottom: 1px solid var(--de-toolbar-border);
  flex-shrink: 0;
  min-height: var(--de-mobile-tap);
  font-family: var(--de-font-family);
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__logo {
  flex-shrink: 0;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__filename-input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--de-text);
  padding: 6px 4px;
  border-radius: 8px;
  text-overflow: ellipsis;
  transition: background-color 0.15s;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__filename-input:focus {
  background: var(--de-surface-hover);
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__zoom {
  flex-shrink: 0;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__more-btn {
  flex-shrink: 0;
  width: var(--de-mobile-tap);
  height: var(--de-mobile-tap);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: var(--de-text-muted);
  cursor: pointer;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header__more-btn:active {
  background: var(--de-surface-hover);
}

/* Mode switcher sits between the filename input and the "⋯" button —
   keep it from shrinking (it would squash to nothing next to the
   flex:1 filename input) and trim its padding/label so it fits a
   phone-width header alongside everything else. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header .docx-editor-mode-switcher {
  flex-shrink: 0;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header .docx-editor-mode-switcher__trigger,
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header .docx-editor-mode-switcher__trigger--locked {
  height: 30px;
  padding: 0 8px 0 8px;
  font-size: 12px;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-header .docx-editor-mode-switcher__menu {
  min-width: 220px;
}

/* Subtle elevation under the whole header+toolbar chrome, separating it
   from the page surface below it — otherwise the tab-bar row (which now
   shares the toolbar's background) can visually blend into the page. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-toolbar-row {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* ---- Mobile "more" sheet (File/View actions) ------------------------ */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 10000;
  display: flex;
  align-items: flex-end;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet {
  background: var(--de-surface);
  width: 100%;
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.16);
}

/* Standard bottom-sheet affordance — signals "this can be swiped down to
   dismiss" at a glance, independent of whether swipe-to-dismiss is wired
   up. Purely decorative (aria-hidden; the header's close button remains
   the only way to actually close the sheet). */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__grabber {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--de-toolbar-border);
  margin: 8px auto 0;
  flex-shrink: 0;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 14px;
  border-bottom: 1px solid var(--de-toolbar-border);
  flex-shrink: 0;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--de-text);
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--de-text-muted);
  cursor: pointer;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__body {
  overflow-y: auto;
  padding: 8px 14px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--de-surface-hover);
  font-family: var(--de-font-family);
}

/* ---- Grouped iOS-Settings-style cards -------------------------------
   Each section = a small uppercase label + a white rounded card holding
   tappable rows, separated by hairlines. Reads far friendlier than a flat
   text list — icons give each action a recognizable shape at a glance. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__section {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--de-text-muted);
  padding: 16px 8px 8px;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__card {
  background: var(--de-surface);
  border: 1px solid var(--de-toolbar-border);
  border-radius: 14px;
  overflow: hidden;
}

.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--de-text);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row + .docx-editor-mobile-sheet__row {
  border-top: 1px solid var(--de-toolbar-border);
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row:active:not(:disabled) {
  background: var(--de-surface-hover);
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Leading icon sits in a soft tinted rounded square so it reads as an
   "app icon", not a loose glyph. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--de-surface-hover);
  color: var(--de-toolbar-button-fg-active);
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row-icon svg {
  width: 18px;
  height: 18px;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row-label {
  flex: 1 1 auto;
  min-width: 0;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row-check {
  flex-shrink: 0;
  color: var(--de-toolbar-button-fg-active);
  font-weight: 700;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row-chevron {
  flex-shrink: 0;
  display: flex;
  color: var(--de-text-muted);
  opacity: 0.5;
}

/* Destructive rows (Remove watermark, Clear document) — red icon + text. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row[data-danger="true"] {
  color: #dc2626;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__row[data-danger="true"] .docx-editor-mobile-sheet__row-icon {
  background: #fef2f2;
  color: #dc2626;
}

/* ---- View: segmented Pageless / Paged toggle ------------------------ */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__segmented {
  display: flex;
  gap: 3px;
  margin: 8px;
  padding: 3px;
  background: var(--de-surface-hover);
  border-radius: 10px;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__segmented button {
  flex: 1 1 0;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--de-text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__segmented button[data-active="true"] {
  background: var(--de-surface);
  color: var(--de-toolbar-button-fg-active);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
/* When the segmented control leads the card, the following row keeps its
   hairline separator. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__segmented + .docx-editor-mobile-sheet__row {
  border-top: 1px solid var(--de-toolbar-border);
}

/* ---- Watermark quick chips ------------------------------------------ */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 2px 2px;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__chip {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--de-toolbar-border);
  border-radius: 999px;
  background: var(--de-surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--de-text);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-mobile-sheet__chip:active {
  background: var(--de-surface-hover);
  border-color: var(--de-toolbar-button-fg-active);
}

/* ---- Page-zoom sizing wrapper (see ui-widgets/usePageZoom.ts) -------
   The wrapper is the element that participates in the surface's
   flow/scroll sizing (`width`/`height` set inline to the scaled
   dimensions); `.docx-editor-page` itself keeps its natural size and is
   scaled via `transform`, anchored top-left, so it visually fits exactly
   inside the wrapper's clipped bounds instead of leaving blank space. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-page-zoom-wrapper {
  margin: 0 auto var(--de-page-gap);
  /* `clip`, not `hidden`. An `overflow: hidden` box is still a scroll
     container — it just hides the scrollbar and refuses touch/wheel input —
     so ProseMirror's caret `scrollIntoView` (after inserting a template, a
     clause, or simply typing) would scroll THIS element instead of the
     surface. The result was a document stuck at an arbitrary offset the user
     could never scroll back up, with the pages above it apparently gone.
     `overflow: clip` clips identically but creates no scroll port at all, so
     the scroll lands on `.docx-editor-surface`, where it belongs. `hidden`
     stays as the fallback declaration for engines without `clip`
     (pre-Chrome-90 / pre-Safari-16); there the scrollTop reset in
     `usePageZoom`'s `syncWrapperSize` covers the same case. */
  overflow: hidden;
  overflow: clip;
  position: relative;
  flex-shrink: 0;
}
.docx-editor-react[data-de-layout="mobile"] .docx-editor-page-zoom-wrapper .docx-editor-page {
  margin: 0;
}

/* Tighter surface padding on mobile — more of the narrow viewport goes to
   the page itself. Matches `HORIZONTAL_PADDING` in usePageZoom.ts's
   fit-to-width calculation. */
.docx-editor-react[data-de-layout="mobile"] .docx-editor-surface {
  padding: 12px 16px 64px;
}
