/* MiCash contract editor (contract-editor.js). The page itself is the client's contract page (contract.css: black on
   white, the same sizes); around it, the editor's own controls follow the light or dark look. */

.ce {
  --ce-accent: #0A6FDB; --ce-accent-soft: rgba(10, 111, 219, .12);
  --ce-chrome: rgba(255, 255, 255, .86); --ce-chrome-solid: #ffffff; --ce-chrome-border: rgba(0, 0, 0, .09);
  --ce-chrome-text: #1d1d1f; --ce-chrome-muted: #6e737b; --ce-chrome-hover: rgba(0, 0, 0, .05);
  --ce-canvas: transparent; --ce-danger: #c62828;
  --ce-client: #2f6fed; --ce-client-bg: #eaf1ff; --ce-me: #b26a00; --ce-me-bg: #fff3dd;
  --ce-ease: cubic-bezier(.32, .72, 0, 1);
  position: relative; color: var(--ce-chrome-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.ce-dark {
  --ce-accent: #40B6FF; --ce-accent-soft: rgba(64, 182, 255, .16);
  --ce-chrome: rgba(30, 32, 37, .86); --ce-chrome-solid: #1e2025; --ce-chrome-border: rgba(255, 255, 255, .12);
  --ce-chrome-text: #F5F6F7; --ce-chrome-muted: #8D929A; --ce-chrome-hover: rgba(255, 255, 255, .08); --ce-danger: #FF6B6B;
}
@media (prefers-color-scheme: dark) {
  .ce:not(.ce-light) {
    --ce-accent: #40B6FF; --ce-accent-soft: rgba(64, 182, 255, .16);
    --ce-chrome: rgba(30, 32, 37, .86); --ce-chrome-solid: #1e2025; --ce-chrome-border: rgba(255, 255, 255, .12);
    --ce-chrome-text: #F5F6F7; --ce-chrome-muted: #8D929A; --ce-chrome-hover: rgba(255, 255, 255, .08); --ce-danger: #FF6B6B;
  }
}
.ce *, .ce *::before, .ce *::after { box-sizing: border-box; }
.ce [hidden] { display: none !important; }
:where(.ce) button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------- toolbar */
.ce-bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: 6px; margin: 0 auto 14px; max-width: 900px;
  background: var(--ce-chrome); border: 1px solid var(--ce-chrome-border); border-radius: 14px;
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .12); overflow-x: auto; scrollbar-width: none;
}
.ce-bar::-webkit-scrollbar { display: none; }
.ce-host .ce-bar { display: none; }
.ce-tb {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; min-width: 34px; padding: 0 9px;
  border: 0; border-radius: 9px; background: transparent; font-size: 14px; color: var(--ce-chrome-text);
  transition: background .2s var(--ce-ease), transform .15s var(--ce-ease);
}
.ce-tb:hover:not(:disabled) { background: var(--ce-chrome-hover); }
.ce-tb:active:not(:disabled) { transform: scale(.96); }
.ce-tb:disabled { opacity: .35; cursor: default; }
.ce-tb.on { background: var(--ce-accent-soft); color: var(--ce-accent); }
.ce-fmt { font-family: ui-serif, Georgia, serif; font-size: 17px; width: 34px; padding: 0; }
.ce-kind { appearance: none; -webkit-appearance: none; padding: 0 28px 0 10px; cursor: pointer; font: inherit; font-size: 14px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.ce-kind option { color: #111; }
.ce-primary { background: var(--ce-accent); color: #fff; font-weight: 600; padding: 0 12px; }
.ce-primary:hover:not(:disabled) { background: var(--ce-accent); filter: brightness(1.08); }
.ce-fill { background: var(--ce-me-bg); color: var(--ce-me); font-weight: 600; font-size: 13px; }
.ce-fill:hover:not(:disabled) { background: var(--ce-me-bg); filter: brightness(.97); }
.ce-sep { flex: none; width: 1px; height: 22px; background: var(--ce-chrome-border); margin: 0 4px; }
.ce-legend { flex: none; display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 0 8px; font-size: 12.5px; color: var(--ce-chrome-muted); white-space: nowrap; }
.ce-legend .ce-dot + .ce-dot, .ce-legend .ce-dot:not(:first-child) { margin-left: 8px; }
.ce-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.ce-dot-client { background: var(--ce-client); }
.ce-dot-me { background: var(--ce-me); }

/* ---------------------------------------------------------------- the page */
.ce-canvas { background: var(--ce-canvas); padding: 4px 0 40px; }
.ce-notes:empty { display: none; }
.ce-notes { max-width: 760px; margin: 0 auto 12px; }
.ce-problem { margin: 0 0 6px; padding: 10px 14px; border-radius: 10px; background: rgba(198, 40, 40, .1); color: var(--ce-danger); font-size: 14px; }
.ce-paper {
  max-width: 760px; margin: 0 auto; padding: 56px 64px 64px; background: #fff; color: #1d1d1d; border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 12px 40px rgba(0, 0, 0, .14);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.ce-doc { position: relative; font-size: 16px; line-height: 1.75; color: #1d1d1d; }

/* Sections: the client page's sizes (contract.css .doc) */
.ce-b { outline: 1.5px dashed transparent; outline-offset: 7px; border-radius: 2px; min-height: 1.75em; overflow-wrap: anywhere;
  transition: outline-color .2s var(--ce-ease); caret-color: #0A6FDB; }
.ce-b:focus { outline: none; }
.ce-b.ce-active { outline: 1.5px dashed rgba(10, 111, 219, .45); }
.ce-b:focus.ce-active { outline: 1.5px solid rgba(10, 111, 219, .55); }
.ce-p { margin: 0 0 18px; }
.ce-title { font-size: 28px; line-height: 1.25; text-align: center; margin: 8px 0 36px; font-weight: 700; }
.ce-h2 { font-size: 17px; margin: 34px 0 10px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.ce-h3 { font-size: 16px; margin: 28px 0 8px; font-weight: 700; font-style: italic; }
.ce-b u { text-underline-offset: 3px; }
.ce-b.ce-blank::before { content: attr(data-placeholder); color: #a9adb3; pointer-events: none; position: absolute; }
.ce-b.ce-blank { position: relative; }
.ce-b.ce-blank.ce-title::before { left: 0; right: 0; text-align: center; }

/* Fields: the client page's grey boxes, tinted by who fills them */
.ce-chip {
  display: inline-block; vertical-align: baseline; margin: 0 2px; padding: 0 8px; max-width: 100%; line-height: 1.6;
  font-size: 15px; font-weight: 400; font-style: normal; text-decoration: none; color: #111; cursor: pointer; user-select: none; -webkit-user-select: none;
  background: #f3f4f6; border-bottom: 1.5px dashed #9aa0a6; border-radius: 4px 4px 0 0;
  transition: background .2s var(--ce-ease), box-shadow .2s var(--ce-ease);
}
.ce-chip.ce-req { border-bottom-style: solid; }
.ce-chip.ce-client { background: var(--ce-client-bg); border-bottom-color: var(--ce-client); }
.ce-chip.ce-me { background: var(--ce-me-bg); border-bottom-color: var(--ce-me); }
.ce-chip.ce-empty { color: #6b7280; }
.ce-chip.ce-client.ce-empty { color: #3b5ea8; }
.ce-chip.ce-me.ce-empty { color: #8a5a12; }
.ce-chip.ce-todo { box-shadow: 0 0 0 1.5px var(--ce-me) inset; }
.ce-chip.ce-req::after { content: "*"; margin-left: 2px; font-size: 12px; vertical-align: super; line-height: 0; }
.ce-chip.ce-client.ce-req::after { color: var(--ce-client); }
.ce-chip.ce-me.ce-req::after { color: var(--ce-me); }
.ce-chip:hover { box-shadow: 0 0 0 2px rgba(10, 111, 219, .25); }
.ce-chip.ce-missing { background: #fdecec; border-bottom-color: #c62828; color: #c62828; }
.ce-chip.ce-flash { animation: ce-flash .9s var(--ce-ease); }
@keyframes ce-flash { 0%, 100% { box-shadow: 0 0 0 0 rgba(10, 111, 219, 0); } 30% { box-shadow: 0 0 0 5px rgba(10, 111, 219, .35); } }
.ce-h2 .ce-chip, .ce-h3 .ce-chip, .ce-title .ce-chip { font-weight: 400; font-style: normal; }

/* Section controls */
.ce-add {
  position: absolute; left: -8px; z-index: 3; width: 24px; height: 24px; padding: 0; transform: translate(-50%, -50%);
  display: grid; place-items: center; border-radius: 50%; border: 0; background: #0A6FDB; color: #fff;
  box-shadow: 0 0 0 3px #fff, 0 3px 10px rgba(10, 111, 219, .35); transition: transform .2s var(--ce-ease);
}
.ce-add svg { width: 15px; height: 15px; }
.ce-add-top { margin-top: -7px; }
.ce-add-bottom { margin-top: 7px; }
.ce-add:hover { transform: translate(-50%, -50%) scale(1.12); }
.ce-add:active { transform: translate(-50%, -50%) scale(.94); }
.ce-tools {
  position: absolute; right: -10px; z-index: 3; display: flex; gap: 2px; padding: 3px; transform: translateY(calc(-100% - 12px));
  background: #fff; border: 1px solid rgba(0, 0, 0, .08); border-radius: 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
}
.ce-tool { width: 30px; height: 28px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: #3a3f47; }
.ce-tool:hover:not(:disabled) { background: rgba(0, 0, 0, .05); }
.ce-tool:disabled { opacity: .3; cursor: default; }
.ce-tool.ce-danger { color: #c62828; }

/* Signature lines, as the client sees them */
.ce-sigs { margin-top: 56px; display: grid; gap: 34px; pointer-events: none; user-select: none; -webkit-user-select: none; }
.ce-sigline { border-bottom: 1px solid #111; min-height: 56px; }
.ce-sigwho { margin-top: 8px; font-size: 15px; color: #8a8a8a; }

/* Fields not in the text */
.ce-tray:empty { display: none; }
.ce-tray { max-width: 760px; margin: 16px auto 0; padding: 14px 16px; border-radius: 14px; background: var(--ce-chrome); border: 1px solid var(--ce-chrome-border); }
.ce-tray-title { margin: 0 0 10px; font-size: 13px; color: var(--ce-chrome-muted); }
.ce-tray-row { display: flex; flex-wrap: wrap; gap: 8px; }
.ce-traychip { display: inline-flex; align-items: center; border-radius: 8px; overflow: hidden; font-size: 14px; }
.ce-traychip.ce-client { background: var(--ce-client-bg); color: #24479a; }
.ce-traychip.ce-me { background: var(--ce-me-bg); color: #7a4a00; }
.ce-trayput { border: 0; background: transparent; padding: 6px 4px 6px 10px; color: inherit; }
.ce-traydel { border: 0; background: transparent; padding: 6px 8px; color: inherit; opacity: .6; display: grid; place-items: center; }
.ce-traydel:hover { opacity: 1; }

/* ---------------------------------------------------------------- menus and the field popup */
.ce-pop {
  position: absolute; z-index: 20; min-width: 220px; max-width: min(320px, calc(100% - 16px)); padding: 6px;
  background: var(--ce-chrome-solid); color: var(--ce-chrome-text); border: 1px solid var(--ce-chrome-border); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .22); animation: ce-in .22s var(--ce-ease);
}
.ce-pop-wide { width: 300px; max-height: min(70vh, 560px); overflow-y: auto; }
@keyframes ce-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.ce-menu { display: flex; flex-direction: column; }
.ce-menu-h { padding: 8px 10px 4px; font-size: 12px; font-weight: 600; color: var(--ce-chrome-muted); }
.ce-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; padding: 8px 10px; border: 0; border-radius: 9px; background: transparent; text-align: left; }
.ce-item:hover { background: var(--ce-chrome-hover); }
.ce-item-t { font-size: 14.5px; }
.ce-item-d { font-size: 12px; color: var(--ce-chrome-muted); }
.ce-seg { display: flex; gap: 2px; padding: 2px; margin: 4px 8px 6px; border-radius: 9px; background: var(--ce-chrome-hover); }
.ce-seg button { flex: 1; border: 0; border-radius: 7px; padding: 6px 8px; font-size: 13px; background: transparent; color: var(--ce-chrome-muted); }
.ce-seg button.on { background: var(--ce-chrome-solid); color: var(--ce-chrome-text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

.ce-sheet-back { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .35); animation: ce-fade .2s ease-out; }
@keyframes ce-fade { from { opacity: 0; } to { opacity: 1; } }
.ce-sheet {
  width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 20px 20px;
  background: var(--ce-chrome-solid); color: var(--ce-chrome-text); border: 1px solid var(--ce-chrome-border); border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35); animation: ce-in .26s var(--ce-ease);
}
.ce-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ce-sheet-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.ce-x { border: 0; background: var(--ce-chrome-hover); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; }
.ce-row { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.ce-row-l { font-size: 13px; color: var(--ce-chrome-muted); }
.ce-row .ce-seg { margin: 0; }
.ce-row input, .ce-row select, .ce-row textarea {
  width: 100%; font: inherit; font-size: 15px; padding: 9px 12px; border-radius: 10px; color: var(--ce-chrome-text);
  background: var(--ce-chrome-hover); border: 1px solid var(--ce-chrome-border);
}
.ce-row input:focus, .ce-row select:focus, .ce-row textarea:focus { outline: none; border-color: var(--ce-accent); box-shadow: 0 0 0 3px var(--ce-accent-soft); }
.ce-row textarea { resize: vertical; }
.ce-hint { font-size: 12.5px; color: var(--ce-chrome-muted); }
.ce-check { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 14px; }
.ce-check input { width: 18px; height: 18px; accent-color: var(--ce-accent); }
.ce-err { color: var(--ce-danger); font-size: 14px; margin: 0 0 10px; }
.ce-err:empty { display: none; }
.ce-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.ce-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 10px 18px; font-size: 15px; font-weight: 600; transition: transform .15s var(--ce-ease); }
.ce-btn:active { transform: scale(.97); }
.ce-btn-primary { background: #0A6FDB; color: #fff; }
.ce-btn-danger { background: transparent; color: var(--ce-danger); padding-left: 4px; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 640px) {
  .ce-paper { padding: 34px 20px 44px; border-radius: 4px; }
  .ce-doc { font-size: 15.5px; }
  .ce-title { font-size: 24px; }
  .ce-legend { display: none; }
  .ce-tools { right: -6px; }
  .ce-sheet-back { place-items: end center; padding: 0; }
  .ce-sheet { width: 100%; border-radius: 20px 20px 0 0; max-height: 88vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { .ce *, .ce *::before { animation: none !important; transition: none !important; } }

/* Drop-downs in the field popup draw themselves (Safari keeps its own white control otherwise, with our light text
   on it), with the list in the editor's light or dark look. */
.ce-row select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
  background-color: var(--ce-chrome-hover);
}
.ce { color-scheme: light; }
.ce-dark { color-scheme: dark; }
@media (prefers-color-scheme: dark) { .ce:not(.ce-light) { color-scheme: dark; } }
.ce-row select option { color: var(--ce-chrome-text); background: var(--ce-chrome-solid); }
