/* P2-B: Dokumentieren-Blatt und Ausbau (mobil). Nach dem Entwurf in Claude
   Design (Dokumentieren, Besuch planen, Termin absagen, Kunde · Ausbau), mit
   den Farben und Groessen aus styles.css. Alles steht unter
   html.rl-mobile-mode; am Desktop bleibt das Blatt unsichtbar. */

html.rl-mobile-mode .mobile-composer {
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --mc-line: #ececeb;
  position: fixed;
  inset: auto 0 0 0;
  width: min(100%, 620px);
  max-width: none;
  height: auto;
  max-height: min(92dvh, calc(var(--rl-visual-height, 100dvh) - env(safe-area-inset-top) - 8px));
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 -10px 30px rgba(20, 30, 40, .18);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
}
/* styles.css zentriert jeden offenen Dialog (dialog[open] { margin: auto }). */
html.rl-mobile-mode .mobile-composer[open] {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  animation: mc-in 180ms cubic-bezier(.2, .8, .2, 1);
}
@keyframes mc-in { from { transform: translateY(18px); opacity: .72; } }
html.rl-mobile-mode .mobile-composer::backdrop { background: rgba(20, 30, 40, .48); }
html.rl-mobile-mode .mobile-composer *,
html.rl-mobile-mode .rl-ausbau * { box-sizing: border-box; }

/* Offene Tastatur (mobile.js setzt die sichtbare Hoehe): Das Blatt fuellt den
   sichtbaren Bereich, Speichern steht direkt ueber der Tastatur. */
html.rl-mobile-mode.rl-keyboard-open .mobile-composer {
  inset: var(--rl-visual-top, 0px) 0 auto 0;
  height: var(--rl-visual-height, 100dvh);
  max-height: var(--rl-visual-height, 100dvh);
  border-radius: 0;
}
html.rl-mobile-mode.rl-keyboard-open .mobile-composer .mc-grip { display: none; }
html.rl-mobile-mode.rl-keyboard-open .mobile-composer .mc-head { padding-top: max(8px, env(safe-area-inset-top)); }
html.rl-mobile-mode.rl-keyboard-open .mobile-composer .mc-foot { padding-bottom: 10px; }

.mobile-composer .mc-grip { flex: none; width: 100%; height: 18px; position: relative; touch-action: none; }
.mobile-composer .mc-grip::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: #c9ccd0; }
.mobile-composer .mc-head {
  flex: none;
  padding: 2px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.mobile-composer .mc-head h2 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: -.015em; outline: none; }
.mobile-composer .mc-head p { margin: 0; color: var(--ink-50); font-size: 14px; }
.mobile-composer .mc-close {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: var(--mist);
  color: var(--ink);
  cursor: pointer;
}
.mobile-composer .mc-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.mobile-composer .mc-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.mobile-composer .mc-foot {
  flex: none;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--mc-line);
  background: var(--paper);
}
.mobile-composer .mc-foot--quiet { padding-top: 10px; }
.mobile-composer .mc-where { margin: 0; color: var(--ink-50); font-size: 13px; text-align: center; }
.mobile-composer .mc-status { margin: 0; font-size: 14px; line-height: 1.4; color: var(--ink-70); }
.mobile-composer .mc-status:empty { display: none; }
.mobile-composer .mc-status.is-error { color: var(--red-deep); font-weight: 600; }
/* Ein fehlendes Pflichtfeld steht am Feld, nicht am Speichern-Knopf. */
.mobile-composer .mc-field-error { margin: 6px 0 0; color: var(--red-deep); font-size: 14px; font-weight: 600; line-height: 1.4; }
/* Speichern (Runde 2): tintenschwarz, 44px, ueber die ganze Breite. Nur
   "Besuch einplanen" ist rot wie "Besuch planen" (Entscheidung PO 02.10.). */
.mobile-composer .mc-save {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.mobile-composer .mc-save.is-plan { border-color: var(--red-action); background: var(--red-action); }
.mobile-composer .mc-save:disabled { cursor: not-allowed; opacity: .55; }
.mobile-composer .mc-save[aria-busy="true"] { opacity: .8; }

/* Waehlbare Pillen: weiss mit 3:1-Rand, gewaehlt tintenschwarz. */
/* Auswahl-Chip (V2): 36px sichtbar, 44px Treffer; Zeilen 8px auseinander. */
:is(.mobile-composer, .rl-ausbau) .mc-choice {
  position: relative;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-control);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* ::after misst ab der Innenkante (1px Rand): -5px ergibt 44px Treffer. */
:is(.mobile-composer, .rl-ausbau) .mc-choice::after { content: ""; position: absolute; inset: -5px 0; }
:is(.mobile-composer, .rl-ausbau) .mc-choice[aria-checked="true"],
:is(.mobile-composer, .rl-ausbau) .mc-choice[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}
:is(.mobile-composer, .rl-ausbau) .mc-choice:disabled { cursor: not-allowed; opacity: .5; }
:is(.mobile-composer, .rl-ausbau) .mc-choice:focus-visible,
.mobile-composer .mc-close:focus-visible,
.mobile-composer .mc-save:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
:is(.mobile-composer, .rl-ausbau) .mc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
/* Art (V2-Notiz): Besuch · Anruf · Notiz als ein Schalter, 38px, Treffer 44. */
.mobile-composer .mc-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border-control);
  border-radius: 12px;
}
.mobile-composer .mc-modes .mc-choice {
  min-width: 0;
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-70);
  font-weight: 700;
}
.mobile-composer .mc-modes .mc-choice::after { inset: -3px -1px; }
.mobile-composer .mc-modes .mc-choice[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.mobile-composer .mc-mode-hint { margin-top: -6px; }
.mobile-composer .mc-mode-hint[hidden] { display: none; }
.mobile-composer .mc-planned { display: flex; align-items: center; gap: 6px; margin: -4px 0 0; color: var(--blue); font-size: 13px; font-weight: 700; line-height: 1.35; }
.mobile-composer .mc-planned svg { flex: none; }
/* Ohne geplanten Besuch: grau, dass ein spontaner angelegt wird. */
.mobile-composer .mc-planned.is-quiet { color: var(--ink-50); font-weight: 500; }
/* "Es gibt schon einen Termin": ein Satz und der Weg, ihn zu verschieben. */
.mobile-composer .mc-known { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--blue-edge); border-radius: 12px; background: var(--blue-soft); }
.mobile-composer .mc-known[hidden] { display: none; }
.mobile-composer .mc-known p { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
.mobile-composer .mc-secondary {
  position: relative;
  align-self: flex-start;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  background: var(--paper);
  color: var(--blue);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.mobile-composer .mc-secondary::after { content: ""; position: absolute; inset: -3px 0; }
.mobile-composer .mc-planned[hidden],
.mobile-composer .mc-group[hidden],
.mobile-composer .mc-field[hidden] { display: none; }
.mobile-composer .mc-group,
.mobile-composer .mc-subgroup { display: flex; flex-direction: column; gap: 8px; }
.mobile-composer .mc-subgroup { padding: 12px; border: 1px solid var(--mc-line); border-radius: 14px; background: var(--mist-2); }
.mobile-composer .mc-label { font-size: 14px; font-weight: 700; color: var(--ink-70); }
:is(.mobile-composer, .rl-ausbau) .mc-hint { margin: 0; color: var(--ink-50); font-size: 13px; font-weight: 500; line-height: 1.4; }
.mobile-composer .mc-draft { margin: 0; color: var(--ink-50); font-size: 13px; }
:is(.mobile-composer, .rl-ausbau) .mc-link {
  position: relative;
  min-height: 32px;
  margin: -6px 0;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
:is(.mobile-composer, .rl-ausbau) .mc-link::after { content: ""; position: absolute; inset: -6px 0; }

.mobile-composer .mc-field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; color: var(--ink-70); }
/* Feld (V2): 44px, 16px Schrift (iOS zoomt erst darunter). */
.mobile-composer .mc-field input,
.mobile-composer .mc-field select,
.mobile-composer .mc-field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-control);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 400;
}
.mobile-composer .mc-field select { padding-right: 36px; }
/* Uhrzeit und Auswahl waren im Browser 46px hoch: fest 44 wie jedes Feld. */
.mobile-composer .mc-field :is(input, select) { height: 44px; }
.mobile-composer .mc-field textarea { min-height: 88px; resize: none; line-height: 1.4; }
.mobile-composer #mc-plan-note { min-height: 72px; }
.mobile-composer .mc-field input[readonly],
.mobile-composer .mc-field textarea[readonly] { background: var(--mist-2); color: var(--ink-70); }
.mobile-composer .mc-field :focus { outline: 3px solid rgba(10, 91, 168, .25); outline-offset: 1px; border-color: var(--blue); }
.mobile-composer .mc-optional { color: var(--ink-50); font-weight: 400; }
.mobile-composer .mc-row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

/* Tage: Wochentag und Datum, dazu ein Kalender fuer ein anderes Datum. Das
   Datumsfeld liegt unsichtbar ueber dem Kalender-Knopf: So oeffnet ein Tipp
   direkt das iOS-Datumsrad. */
.mobile-composer .mc-days { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.mobile-composer .mc-days::-webkit-scrollbar { display: none; }
.mobile-composer .mc-day {
  flex: none;
  min-width: 72px;
  min-height: 56px;
  padding: 0 12px;
  flex-direction: column;
  gap: 0;
  border-radius: 14px;
}
.mobile-composer .mc-day small { font-size: 12px; font-weight: 600; opacity: .8; }
.mobile-composer .mc-day--cal { min-width: 56px; padding: 0; overflow: hidden; }
/* Die Tage sind 56px hoch, ihr Treffer ist ihre Flaeche; ohne ::after liegt
   das unsichtbare Datumsfeld oben und oeffnet das iOS-Datumsrad direkt. */
.mobile-composer .mc-day::after { content: none; }
.mobile-composer .mc-date-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  cursor: pointer;
}

/* "Termin absagen": eindeutig, aber leiser als Speichern. */
.mobile-composer .mc-danger {
  position: relative;
  min-height: 40px;
  padding: 0 14px;
  /* Derselbe Rand wie "Termin absagen" auf der Kundenseite (3,5:1). */
  border: 1px solid #d9666d;
  border-radius: 10px;
  background: var(--paper);
  color: var(--red-deep);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.mobile-composer .mc-danger::after { content: ""; position: absolute; inset: -3px 0; }

/* Die Rueckfrage "Termin absagen?" (rl-ask) als zwei Knoepfe nebeneinander,
   "Behalten" links, wie im Entwurf. */
html.rl-mobile-mode .rl-ask__actions:has(> button:nth-child(2):last-child) { grid-template-columns: 1fr 1fr; }
html.rl-mobile-mode .rl-ask__actions:has(> button:nth-child(2):last-child) > [data-ask-value=""] { order: -1; }
html.rl-mobile-mode .rl-ask h2 { font-size: 20px; }

/* --- Ausbau ------------------------------------------------------------------ */
html.rl-mobile-mode .rl-ausbau { display: flex; flex-direction: column; gap: 12px; font-size: 15px; color: var(--ink); }
.rl-ausbau .ausbau-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border: 1px solid #e3e3e1; border-radius: 14px; background: var(--paper); }
.rl-ausbau .ausbau-card--fields { padding: 2px 16px; gap: 0; }
.rl-ausbau .ausbau-row--tri { padding: 12px 0; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid #ececeb; }
.rl-ausbau .ausbau-row--tri:first-child { border-top: 0; }
.rl-ausbau .ausbau-row__head { min-height: 22px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rl-ausbau .ausbau-row__head strong { font-size: 15px; }
.rl-ausbau .ausbau-row__head--sub span { font-size: 14px; font-weight: 700; color: var(--ink-70); }
.rl-ausbau .mc-choice.ausbau-tri { min-width: 64px; padding: 0 12px; }
/* F-A1: die Stufe nur zum Lesen, geaendert wird sie ueber ⋯. */
.rl-ausbau .ausbau-stage-now { color: var(--ink-70); font-size: 15px; font-weight: 600; text-align: right; }
.rl-ausbau .ausbau-state { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.rl-ausbau .ausbau-state.is-saving { color: var(--ink-50); font-weight: 600; }
.rl-ausbau .ausbau-state.is-saved { color: var(--green); }
.rl-ausbau .ausbau-state.is-error { color: var(--red-deep); }
.rl-ausbau .ausbau-facts strong { font-size: 15px; }
.rl-ausbau .ausbau-fact { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.rl-ausbau .ausbau-fact span:first-child { color: var(--ink-70); }
.rl-ausbau .ausbau-off { padding: 0 4px; }
.mobile-composer .mc-body--ausbau { background: var(--mist); }

@media (prefers-reduced-motion: reduce) {
  html.rl-mobile-mode .mobile-composer[open] { animation: none; }
}
