/* ============================================================
   Feingold Medical Legal — case enquiry widget
   Everything is scoped under .fml so it survives being dropped
   into a WordPress theme. No external fonts or assets.
   ============================================================ */

/* This file styles only the widget. It sets nothing on the host page beyond
   the margin reset below, so it can be loaded into an existing theme safely. */
body { margin: 0; }

/* ---- design tokens ---- */
.fml {
  --navy-900: #0a2240;
  --navy-700: #16406e;
  --navy-500: #1f5c99;
  --brass:    #b5872f;
  --brass-lt: #d9a94a;

  --surface:      #ffffff;
  --surface-alt:  #f6f7f9;
  --surface-sunk: #eef1f5;
  --border:       #dfe4ea;
  --text:         #17202b;
  --muted:        #5d6875;
  --danger:       #b42318;
  --success:      #2f9e63;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px rgba(10,34,64,.18), 0 2px 8px rgba(10,34,64,.08);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  position: fixed; right: 24px; bottom: 24px; z-index: 99999;
  width: min(410px, calc(100vw - 32px));
  font-family: var(--sans); font-size: 15px; line-height: 1.55;
  color: var(--text);
}
.fml *, .fml *::before, .fml *::after { box-sizing: border-box; }

@media (prefers-color-scheme: dark) {
  .fml {
    --surface:      #131923;
    --surface-alt:  #0e141d;
    --surface-sunk: #1b2331;
    --border:       #2a3444;
    --text:         #e8ecf2;
    --muted:        #97a3b4;
    --navy-500:     #4e93d6;
    --shadow: 0 18px 48px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  }
}

/* ---- launcher ---- */
.fml-launcher {
  width: 60px; height: 60px; margin-left: auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--navy-900); border: none; border-radius: 50%;
  cursor: pointer; box-shadow: 0 10px 28px rgba(10,34,64,.32);
  transition: transform .25s ease, background .25s ease;
}
.fml-launcher:hover { background: var(--navy-700); transform: translateY(-2px); }
.fml-launcher svg { width: 26px; height: 26px; fill: #fff; }
.fml-launcher .icon-close { display: none; }
.fml.is-open .icon-open { display: none; }
.fml.is-open .icon-close { display: block; }

.fml-nudge {
  position: absolute; right: 74px; bottom: 14px;
  width: max-content; max-width: 234px;
  padding: 10px 13px; font-size: 13.5px; line-height: 1.45;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); animation: fml-rise .4s ease both;
}
.fml-nudge::after {
  content: ''; position: absolute; right: -6px; bottom: 18px;
  width: 10px; height: 10px; background: var(--surface);
  border-right: 1px solid var(--border); border-top: 1px solid var(--border);
  transform: rotate(45deg);
}
.fml-nudge-close {
  position: absolute; top: -8px; right: -8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer;
}

/* ---- panel ---- */
.fml-panel {
  display: none; flex-direction: column;
  height: min(680px, calc(100vh - 120px));
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.fml.is-open .fml-panel { display: flex; animation: fml-rise .32s cubic-bezier(.2,.8,.2,1) both; }
@keyframes fml-rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.fml-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--navy-900); color: #fff;
  border-bottom: 2px solid var(--brass);
}
.fml-logo { flex: none; display: block; }
.fml-header-text { flex: 1; min-width: 0; }
.fml-header-text h2 {
  margin: 0; font-family: var(--serif);
  font-size: 16.5px; font-weight: 600; letter-spacing: .015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fml-header-text p {
  margin: 2px 0 0; font-size: 12.5px; color: rgba(255,255,255,.72);
  display: flex; align-items: center; gap: 6px;
}
.fml-dot { width: 6px; height: 6px; border-radius: 50%; background: #34c77b; flex: none; }
.fml-icon-btn {
  flex: none; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.08); border: none; border-radius: 8px;
  color: #fff; font-size: 19px; line-height: 1; cursor: pointer;
  transition: background .2s ease;
}
.fml-icon-btn:hover { background: rgba(255,255,255,.18); }

/* ---- conversation ---- */
.fml-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px; background: var(--surface-alt); scrollbar-width: thin;
}
.fml-log::-webkit-scrollbar { width: 8px; }
.fml-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.fml-intro {
  padding: 15px 16px; margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--brass);
  border-radius: var(--radius-sm);
}
.fml-intro h3 { margin: 0 0 7px; font-family: var(--serif); font-size: 15.5px; font-weight: 600; color: var(--navy-700); }
.fml-intro p { margin: 0 0 9px; font-size: 14px; color: var(--muted); }
.fml-intro ul { margin: 0; padding-left: 17px; font-size: 13.5px; color: var(--muted); }
.fml-intro li { margin-bottom: 3px; }
@media (prefers-color-scheme: dark) { .fml-intro h3 { color: var(--brass-lt); } }

/* flex-start so the avatar sits beside the message, not beside the timestamp
   underneath it, which reads as misalignment. */
.fml-row { display: flex; gap: 9px; margin-bottom: 14px; align-items: flex-start; animation: fml-rise .26s ease both; }
.fml-row.user { flex-direction: row-reverse; }
.fml-avatar { flex: none; width: 28px; height: 28px; margin-top: 2px; display: block; }
.fml-row.user .fml-avatar { display: none; }

.fml-bubble-wrap { max-width: 82%; min-width: 0; }
.fml-bubble { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14.5px; overflow-wrap: anywhere; }
.fml-row.bot .fml-bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.fml-row.user .fml-bubble { background: var(--navy-700); color: #fff; border-bottom-right-radius: 3px; }
.fml-row.error .fml-bubble {
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
}
.fml-bubble p { margin: 0 0 8px; }
.fml-bubble p:last-child { margin-bottom: 0; }
.fml-bubble ul { margin: 8px 0; padding-left: 17px; }
.fml-bubble li { margin-bottom: 4px; }
.fml-bubble strong { font-weight: 650; }
.fml-bubble code {
  padding: 1px 5px; border-radius: 4px; font-size: 13px;
  background: var(--surface-sunk);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fml-bubble a { color: var(--navy-500); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.fml-row.user .fml-bubble a, .fml-row.user .fml-bubble code { color: #fff; }

/* Blinking caret while tokens stream in. */
.fml-bubble.streaming > p:last-child::after {
  content: ''; display: inline-block;
  width: 2px; height: 1em; margin-left: 2px;
  background: var(--navy-500); vertical-align: -2px;
  animation: fml-blink 1s step-end infinite;
}
@keyframes fml-blink { 50% { opacity: 0; } }

.fml-time { margin-top: 4px; font-size: 11px; color: var(--muted); }
.fml-row.user .fml-time { text-align: right; }

.fml-retry {
  margin-top: 7px; padding: 4px 10px;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; font-size: 12.5px; color: var(--navy-500); cursor: pointer;
}
.fml-retry:hover { background: var(--surface-sunk); }

.fml-typing { display: none; }
.fml-typing.is-visible { display: flex; }
.fml-dots { display: flex; gap: 4px; align-items: center; padding: 14px; }
.fml-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: fml-bounce 1.3s infinite ease-in-out; }
.fml-dots span:nth-child(2) { animation-delay: .16s; }
.fml-dots span:nth-child(3) { animation-delay: .32s; }
@keyframes fml-bounce { 0%,70%,100% { opacity:.35; transform: none; } 35% { opacity:1; transform: translateY(-4px); } }

/* ---- intake form ---- */
.fml-form {
  padding: 16px; margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-top: 3px solid var(--brass);
  border-radius: var(--radius-sm);
}
.fml-form h3 { margin: 0 0 3px; font-family: var(--serif); font-size: 15.5px; font-weight: 600; color: var(--navy-700); }
.fml-form > p { margin: 0 0 13px; font-size: 13px; color: var(--muted); }
@media (prefers-color-scheme: dark) { .fml-form h3 { color: var(--brass-lt); } }

.fml-field { margin-bottom: 11px; }
.fml-field label { display: block; margin-bottom: 4px; font-size: 12.5px; font-weight: 600; }
.fml-hint { display: block; margin-top: 3px; font-size: 11.5px; font-weight: 400; color: var(--muted); }
.fml-field input, .fml-field select, .fml-field textarea {
  width: 100%; padding: 9px 11px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: 7px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.fml-field textarea { resize: vertical; min-height: 66px; }
.fml-field input:focus, .fml-field select:focus, .fml-field textarea:focus {
  outline: none; border-color: var(--navy-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy-500) 18%, transparent);
}
.fml-field.invalid input, .fml-field.invalid select { border-color: var(--danger); }
.fml-error { margin-top: 4px; font-size: 12px; color: var(--danger); }
.fml-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
@media (max-width: 420px) { .fml-grid { grid-template-columns: 1fr; gap: 0; } }

.fml-form-actions { display: flex; gap: 9px; margin-top: 14px; }
.fml-btn { padding: 10px 14px; font: inherit; font-size: 14px; font-weight: 600; border-radius: 8px; cursor: pointer; transition: background .2s ease, opacity .2s ease; }
.fml-btn-primary { flex: 1; background: var(--navy-900); color: #fff; border: 1px solid var(--navy-900); }
.fml-btn-primary:hover:not(:disabled) { background: var(--navy-700); }
.fml-btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.fml-btn-ghost { background: none; color: var(--muted); border: 1px solid var(--border); }
.fml-btn-ghost:hover:not(:disabled) { background: var(--surface-sunk); }
.fml-btn-ghost:disabled { opacity: .5; cursor: not-allowed; }

.fml-success {
  padding: 15px 16px; margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
}
.fml-success h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 15px; color: var(--success); }
.fml-success p { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.fml-cal {
  display: inline-block; padding: 8px 14px;
  background: var(--navy-900); color: #fff;
  border-radius: 7px; font-size: 13.5px; font-weight: 600; text-decoration: none;
}

/* ---- composer ---- */
.fml-composer { padding: 12px 14px 13px; background: var(--surface); border-top: 1px solid var(--border); }
.fml-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fml-chip {
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface-alt); border: 1px solid var(--border);
  font: inherit; font-size: 12.5px; color: var(--navy-500);
  cursor: pointer; transition: background .18s ease, border-color .18s ease;
}
.fml-chip:hover { background: var(--surface-sunk); border-color: var(--navy-500); }

.fml-input-row { display: flex; gap: 9px; align-items: flex-end; }
.fml-input-shell {
  flex: 1; display: flex; align-items: flex-end;
  padding: 3px 3px 3px 12px; border-radius: 11px;
  background: var(--surface-alt); border: 1px solid var(--border);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.fml-input-shell:focus-within {
  border-color: var(--navy-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy-500) 15%, transparent);
}
.fml-input {
  flex: 1; padding: 9px 0; max-height: 108px;
  border: none; background: none; resize: none;
  font: inherit; font-size: 14.5px; line-height: 1.5; color: var(--text);
}
.fml-input:focus { outline: none; }
.fml-input::placeholder { color: var(--muted); }

.fml-send {
  flex: none; width: 38px; height: 38px; margin-left: 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--navy-900); border: none; border-radius: 9px;
  color: #fff; cursor: pointer; transition: background .2s ease, opacity .2s ease;
}
.fml-send:hover:not(:disabled) { background: var(--navy-700); }
.fml-send:disabled { opacity: .4; cursor: not-allowed; }
.fml-send svg { width: 17px; height: 17px; fill: currentColor; }

.fml-footnote { margin: 9px 0 0; font-size: 10.5px; line-height: 1.45; color: var(--muted); text-align: center; }

.fml-jump {
  position: absolute; left: 50%; bottom: 122px; z-index: 2;
  transform: translateX(-50%);
  display: none; align-items: center; gap: 6px;
  padding: 6px 13px; border: none; border-radius: 999px;
  background: var(--navy-900); color: #fff;
  font: inherit; font-size: 12.5px; cursor: pointer;
  box-shadow: 0 5px 16px rgba(10,34,64,.3);
}
.fml-jump.is-visible { display: flex; }

.fml-sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Focus ring. Text fields are excluded because their container already shows
   focus with a blue ring, and stacking a second outline inside it looks broken. */
.fml :focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.fml-input:focus-visible,
.fml-field input:focus-visible,
.fml-field select:focus-visible,
.fml-field textarea:focus-visible { outline: none; }

@media (max-width: 480px) {
  .fml { right: 12px; left: 12px; bottom: 12px; width: auto; }
  .fml-panel { height: min(78vh, calc(100vh - 108px)); }
}

@media (prefers-reduced-motion: reduce) {
  .fml *, .fml *::before, .fml *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
