.mf-app {
  --mf-mobile-css-ready: 1;
  display: none;
}

@media (max-width: 760px) {
  :root {
    --mf-ink: #17312d;
    --mf-muted: #647a74;
    --mf-line: #c9d9d5;
    --mf-soft: #edf5f2;
    --mf-surface: #ffffff;
    --mf-primary: #0d6657;
    --mf-primary-strong: #084c42;
    --mf-success: #1f765f;
    --mf-warn: #9a5a08;
    --mf-warn-soft: #fff4dc;
    --mf-danger: #a13d36;
    --mf-focus: #f3a712;
    --mf-shadow: 0 18px 48px rgba(28, 63, 56, .11);
  }

  html.mf-mobile-active {
    min-width: 0;
    background: #f3f7f6;
  }

  body.mf-mobile-active {
    min-width: 0;
    overflow-x: hidden;
    background:
      radial-gradient(circle at 100% 0, rgba(69, 145, 127, .12), transparent 36%),
      linear-gradient(180deg, #f7faf9 0, #edf4f2 100%);
    color: var(--mf-ink);
  }

  body.mf-mobile-active > .shell,
  body.mf-mobile-active > #attachmentModal {
    display: none !important;
  }

  body.mf-mobile-active > .mf-app:not([hidden]) {
    display: block;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: env(safe-area-inset-top) 16px calc(28px + env(safe-area-inset-bottom));
    color: var(--mf-ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  }

  .mf-app *,
  .mf-app *::before,
  .mf-app *::after {
    box-sizing: border-box;
  }

  .mf-app button,
  .mf-app input,
  .mf-app textarea {
    font: inherit;
  }

  .mf-app button {
    white-space: normal;
  }

  .mf-header {
    width: 100%;
    max-width: 560px;
    min-height: 68px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
  }

  .mf-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--mf-ink);
    color: #fff;
    font-size: 18px;
    font-weight: 850;
    box-shadow: 0 8px 20px rgba(23, 49, 45, .18);
  }

  .mf-brand {
    min-width: 0;
  }

  .mf-brand strong,
  .mf-brand span {
    display: block;
  }

  .mf-brand strong {
    overflow: hidden;
    font-size: 16px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mf-brand span {
    margin-top: 2px;
    color: var(--mf-muted);
    font-size: 12px;
  }

  .mf-connection {
    max-width: 92px;
    padding: 6px 9px;
    overflow: hidden;
    border: 1px solid #c7ddd7;
    border-radius: 999px;
    background: #e7f3ef;
    color: var(--mf-primary);
    font-size: 11px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mf-connection[data-tone="loading"] {
    color: #506d66;
  }

  .mf-connection[data-tone="error"] {
    border-color: #efc9c5;
    background: #fff0ee;
    color: var(--mf-danger);
  }

  .mf-login,
  .mf-search-screen,
  .mf-create-screen,
  .mf-code-screen {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
  }

  .mf-login[hidden],
  .mf-search-screen[hidden],
  .mf-create-screen[hidden],
  .mf-code-screen[hidden] {
    display: none;
  }

  .mf-kicker {
    margin: 26px 0 9px;
    color: var(--mf-primary);
    font-size: 12px;
    font-weight: 850;
    letter-spacing: .12em;
  }

  .mf-search-screen h1,
  .mf-create-screen h1,
  .mf-login h1 {
    margin: 0;
    color: var(--mf-ink);
    font-size: clamp(26px, 8vw, 34px);
    font-weight: 820;
    letter-spacing: -.035em;
    line-height: 1.17;
  }

  .mf-lead,
  .mf-login p {
    margin: 10px 0 0;
    color: var(--mf-muted);
    font-size: 14px;
    line-height: 1.65;
  }

  .mf-flow-note {
    margin-top: 20px;
    padding: 12px 14px;
    border-left: 3px solid #63a493;
    border-radius: 4px 12px 12px 4px;
    background: rgba(255, 255, 255, .65);
    color: #49635d;
    font-size: 12px;
    line-height: 1.55;
  }

  .mf-search {
    margin-top: 25px;
  }

  .mf-search label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 780;
  }

  .mf-search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 84px;
    gap: 8px;
  }

  .mf-search input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    margin: 0;
    border: 1px solid #a9c0ba;
    border-radius: 13px;
    background: rgba(255, 255, 255, .94);
    color: var(--mf-ink);
    padding: 0 13px;
    font-size: 16px;
    box-shadow: 0 5px 16px rgba(28, 63, 56, .04);
  }

  .mf-search input::placeholder {
    color: #8da09b;
  }

  .mf-button {
    width: 100%;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 9px 14px;
    border: 1px solid #9fb8b2;
    border-radius: 13px;
    background: rgba(255, 255, 255, .94);
    color: var(--mf-ink);
    font-size: 15px;
    font-weight: 780;
    line-height: 1.25;
    box-shadow: none;
    cursor: pointer;
  }

  .mf-button--primary {
    border-color: var(--mf-primary);
    background: var(--mf-primary);
    color: #fff;
    box-shadow: 0 9px 22px rgba(13, 102, 87, .2);
  }

  .mf-button--primary:active {
    background: var(--mf-primary-strong);
    transform: translateY(1px);
  }

  .mf-button--compact {
    width: auto;
    min-width: 72px;
    min-height: 44px;
    padding-inline: 12px;
    font-size: 13px;
  }

  .mf-button:disabled,
  .mf-link:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  .mf-search-message {
    min-height: 22px;
    margin-top: 12px;
    color: var(--mf-muted);
    font-size: 13px;
    line-height: 1.55;
  }

  .mf-search-message[data-tone="error"] {
    color: var(--mf-danger);
  }

  .mf-add-patient {
    width: auto;
    min-height: 44px;
    margin-top: 8px;
    border-color: transparent;
    background: transparent;
    color: var(--mf-primary);
    font-size: 13px;
    text-decoration: underline;
    text-underline-offset: 3px;
    box-shadow: none;
  }

  .mf-results {
    display: grid;
    gap: 10px;
    margin-top: 12px;
  }

  .mf-result {
    width: 100%;
    min-height: 76px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid var(--mf-line);
    border-radius: 15px;
    background: rgba(255, 255, 255, .92);
    color: var(--mf-ink);
    text-align: left;
    box-shadow: 0 6px 20px rgba(28, 63, 56, .05);
    cursor: pointer;
  }

  .mf-result::after {
    content: "›";
    color: #799089;
    font-size: 24px;
    font-weight: 500;
  }

  .mf-result strong,
  .mf-result span {
    display: block;
  }

  .mf-result strong {
    font-size: 16px;
  }

  .mf-result span {
    margin-top: 4px;
    overflow-wrap: anywhere;
    color: var(--mf-muted);
    font-size: 12px;
    line-height: 1.45;
  }

  .mf-result:active {
    border-color: #78a99c;
    background: #f7fbfa;
  }

  .mf-empty,
  .mf-error-card {
    padding: 18px;
    border: 1px dashed #b8ccc7;
    border-radius: 15px;
    background: rgba(255, 255, 255, .64);
    color: var(--mf-muted);
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
  }

  .mf-empty p {
    margin: 6px 0 0;
    color: var(--mf-muted);
    font-size: 12px;
    line-height: 1.55;
  }

  .mf-empty .mf-empty-action {
    margin-top: 14px;
  }

  .mf-error-card {
    border-style: solid;
    border-color: #efcfcb;
    background: #fff7f6;
    color: var(--mf-danger);
  }

  .mf-login {
    margin-top: 42px;
    padding: 24px 20px;
    border: 1px solid var(--mf-line);
    border-radius: 20px;
    background: rgba(255, 255, 255, .92);
    box-shadow: var(--mf-shadow);
  }

  .mf-login .mf-button {
    margin-top: 20px;
    text-decoration: none;
  }

  .mf-create-screen {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .mf-back {
    min-width: 44px;
    min-height: 44px;
    margin: 10px 0 0;
    padding: 7px 4px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--mf-primary);
    font-size: 13px;
    font-weight: 760;
    text-align: left;
    cursor: pointer;
  }

  .mf-back::before {
    content: "‹";
    display: inline-block;
    margin-right: 5px;
    font-size: 21px;
    line-height: .8;
    vertical-align: -2px;
  }

  .mf-create-screen .mf-kicker {
    margin-top: 12px;
  }

  .mf-create-form {
    display: grid;
    gap: 16px;
    margin-top: 24px;
    padding: 18px;
    border: 1px solid var(--mf-line);
    border-radius: 19px;
    background: rgba(255, 255, 255, .88);
    box-shadow: 0 10px 30px rgba(28, 63, 56, .06);
  }

  .mf-create-form label {
    display: grid;
    gap: 7px;
    color: var(--mf-ink);
    font-size: 14px;
    font-weight: 760;
  }

  .mf-required {
    color: var(--mf-danger);
  }

  .mf-create-form input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #a9c0ba;
    border-radius: 12px;
    background: #fff;
    color: var(--mf-ink);
    font-size: 16px;
    font-weight: 500;
  }

  .mf-create-form input:disabled,
  .mf-back:disabled,
  .mf-duplicate-card:disabled {
    opacity: .58;
    cursor: not-allowed;
  }

  .mf-create-form input:disabled {
    background: #edf2f0;
  }

  .mf-form-message {
    min-height: 21px;
    color: var(--mf-muted);
    font-size: 13px;
    line-height: 1.55;
  }

  .mf-form-message[data-tone="error"] {
    color: var(--mf-danger);
  }

  .mf-duplicate-candidates {
    display: grid;
    gap: 9px;
  }

  .mf-duplicate-candidates:empty {
    display: none;
  }

  .mf-duplicate-heading {
    color: var(--mf-ink);
    font-size: 13px;
    font-weight: 820;
  }

  .mf-duplicate-card {
    width: 100%;
    min-height: 68px;
    display: grid;
    gap: 4px;
    padding: 12px 13px;
    border: 1px solid #d9bea0;
    border-radius: 13px;
    background: #fffaf1;
    color: var(--mf-ink);
    text-align: left;
    cursor: pointer;
  }

  .mf-duplicate-card strong,
  .mf-duplicate-card span {
    display: block;
    overflow-wrap: anywhere;
  }

  .mf-duplicate-card strong {
    font-size: 15px;
  }

  .mf-duplicate-card span {
    color: var(--mf-muted);
    font-size: 12px;
    line-height: 1.4;
  }

  .mf-patient-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 22px 0 13px;
    padding: 13px 14px;
    border: 1px solid var(--mf-line);
    border-radius: 15px;
    background: rgba(255, 255, 255, .8);
  }

  .mf-patient {
    min-width: 0;
  }

  .mf-patient strong,
  .mf-patient span {
    display: block;
  }

  .mf-patient strong {
    overflow: hidden;
    font-size: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mf-patient span {
    margin-top: 4px;
    color: var(--mf-muted);
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  .mf-code-card {
    min-height: 272px;
    display: grid;
    align-content: center;
    justify-items: center;
    padding: 26px 16px;
    border: 1px solid #bcd2cc;
    border-radius: 22px;
    background:
      linear-gradient(145deg, rgba(255, 255, 255, .98), rgba(247, 251, 250, .96)),
      var(--mf-surface);
    text-align: center;
    box-shadow: var(--mf-shadow);
  }

  .mf-code-card[data-state="full"] {
    border-color: #e5bf80;
    background: linear-gradient(145deg, #fffdfa, #fff8e9);
  }

  .mf-code-label {
    color: var(--mf-muted);
    font-size: 12px;
    font-weight: 760;
    letter-spacing: .08em;
  }

  .mf-code {
    max-width: 100%;
    margin: 10px 0 12px;
    padding-left: .12em;
    overflow: hidden;
    color: var(--mf-ink);
    font-size: clamp(34px, 11.4vw, 52px);
    font-variant-numeric: tabular-nums;
    font-weight: 860;
    letter-spacing: .12em;
    line-height: 1.05;
    text-overflow: clip;
    white-space: nowrap;
  }

  .mf-code-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e7f4ef;
    color: var(--mf-success);
    font-size: 12px;
    font-weight: 800;
  }

  .mf-code-status[data-tone="full"] {
    background: var(--mf-warn-soft);
    color: var(--mf-warn);
  }

  .mf-code-meta {
    width: 100%;
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mf-code-meta div {
    min-width: 0;
    padding: 10px 8px;
    border-radius: 11px;
    background: var(--mf-soft);
  }

  .mf-code-meta span,
  .mf-code-meta strong {
    display: block;
  }

  .mf-code-meta span {
    color: var(--mf-muted);
    font-size: 11px;
  }

  .mf-code-meta strong {
    margin-top: 3px;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mf-code-help {
    margin: 13px 0 0;
    color: var(--mf-muted);
    font-size: 12px;
    line-height: 1.55;
  }

  .mf-code-help[data-tone="full"] {
    color: var(--mf-warn);
    font-weight: 700;
  }

  .mf-actions {
    display: grid;
    gap: 10px;
    margin-top: 14px;
  }

  .mf-link {
    width: 100%;
    min-height: 44px;
    margin: 3px 0 0;
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #526b65;
    font-size: 13px;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
  }

  .mf-loading {
    display: grid;
    justify-items: center;
    gap: 12px;
    color: var(--mf-muted);
    font-size: 14px;
  }

  .mf-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #dbe9e5;
    border-top-color: var(--mf-primary);
    border-radius: 50%;
    animation: mf-spin .8s linear infinite;
  }

  @keyframes mf-spin {
    to { transform: rotate(360deg); }
  }

  .mf-button:focus-visible,
  .mf-result:focus-visible,
  .mf-back:focus-visible,
  .mf-duplicate-card:focus-visible,
  .mf-link:focus-visible,
  .mf-search input:focus-visible,
  .mf-create-form input:focus-visible,
  .mf-copy-fallback textarea:focus-visible {
    outline: 3px solid var(--mf-focus);
    outline-offset: 2px;
  }

  .mf-copy-fallback {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    align-items: end;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    background: rgba(16, 32, 29, .52);
  }

  .mf-copy-fallback[hidden] {
    display: none;
  }

  .mf-copy-sheet {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 20px;
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 -18px 52px rgba(12, 33, 28, .2);
  }

  .mf-copy-sheet h2 {
    margin: 0;
    font-size: 19px;
  }

  .mf-copy-sheet p {
    margin: 7px 0 11px;
    color: var(--mf-muted);
    font-size: 13px;
    line-height: 1.5;
  }

  .mf-copy-fallback textarea {
    width: 100%;
    min-height: 150px;
    margin: 0 0 12px;
    padding: 11px;
    border: 1px solid #aec4be;
    border-radius: 12px;
    background: #f8fbfa;
    color: var(--mf-ink);
    font-size: 16px;
    line-height: 1.55;
    resize: none;
  }

  .mf-toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 110;
    max-width: 528px;
    margin: 0 auto;
    pointer-events: none;
    text-align: center;
  }

  .mf-toast:not(:empty) {
    padding: 11px 14px;
    border-radius: 12px;
    background: var(--mf-ink);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(10, 33, 28, .25);
  }

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

@media (max-width: 340px) {
  body.mf-mobile-active > .mf-app:not([hidden]) {
    padding-right: 12px;
    padding-left: 12px;
  }

  .mf-header {
    grid-template-columns: 36px minmax(0, 1fr);
    row-gap: 2px;
  }

  .mf-mark {
    width: 34px;
    height: 34px;
    grid-row: 1 / span 2;
  }

  .mf-connection {
    grid-column: 2;
    justify-self: start;
  }

  .mf-code-card {
    padding-right: 13px;
    padding-left: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mf-app * {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
