/* Mobile workflow surfaces: Owner inbox, tasks, schedules, diary, hall, funds.
   Presentation only. Runtime semantics remain in web/index.html. */
@media (max-width: 760px) {
  body.mobile-ui-v1 dialog > .identity-form,
  body.mobile-ui-v1 dialog > form.identity-form,
  body.mobile-ui-v1 dialog > section.identity-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: visible;
  }
  body.mobile-ui-v1 dialog h3 {
    margin: 0;
    font-size: clamp(23px, 7vw, 32px);
    line-height: 1.1;
  }
  body.mobile-ui-v1 .identity-help {
    margin: 0;
    line-height: 1.55;
  }
  body.mobile-ui-v1 .owner-inbox-scroll,
  body.mobile-ui-v1 .resident-log-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding: 2px 2px 16px;
    overflow: visible;
  }

  body.mobile-ui-v1 .inbox-tools {
    position: sticky;
    z-index: 2;
    top: 0;
    display: grid;
    gap: 8px;
    padding: 8px 0;
    background: #fffdf3;
  }
  body.mobile-ui-v1 .inbox-search {
    width: 100%;
    min-height: 50px;
    padding: 11px;
  }
  body.mobile-ui-v1 .inbox-filters {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 6px;
  }
  body.mobile-ui-v1 .inbox-filter {
    flex: 0 0 auto;
    min-height: 42px;
    border: 2px solid #10110f;
    border-radius: 0;
  }
  body.mobile-ui-v1 .inbox-category,
  body.mobile-ui-v1 .inbox-resident-group > details {
    border: 2px solid #10110f;
    border-radius: 0;
    background: #fff;
  }
  body.mobile-ui-v1 .inbox-category > summary,
  body.mobile-ui-v1 .inbox-resident-group > details > summary {
    min-height: 48px;
    padding: 12px;
  }
  body.mobile-ui-v1 .visit-inbox-item {
    padding: 13px 12px;
    overflow-wrap: anywhere;
  }

  body.mobile-ui-v1 .task-read-toolbar {
    position: sticky;
    z-index: 2;
    top: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
    padding: 12px;
    border: 3px solid #10110f;
    border-radius: 0;
    background: #fff700;
    box-shadow: 4px 4px 0 #10110f;
  }
  body.mobile-ui-v1 .task-read-all,
  body.mobile-ui-v1 .task-read-one,
  body.mobile-ui-v1 [data-task-retry] {
    width: 100%;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #19a447;
    color: #fff;
    box-shadow: 3px 3px 0 #10110f;
    font-weight: 900;
  }
  body.mobile-ui-v1 .task-quest-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  body.mobile-ui-v1 .task-quest-card small { overflow-wrap: anywhere; }

  body.mobile-ui-v1 .hall-toolbar,
  body.mobile-ui-v1 .hall-compose,
  body.mobile-ui-v1 .hall-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }
  body.mobile-ui-v1 .hall-compose textarea {
    width: 100%;
    min-height: 132px;
    padding: 12px;
  }
  body.mobile-ui-v1 .hall-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.mobile-ui-v1 #hallDialog {
    overflow: hidden !important;
  }
  body.mobile-ui-v1 #hallDialog > .identity-form {
    height: calc(100dvh - max(24px, env(safe-area-inset-top)) - var(--mobile-safe-bottom));
    min-height: 0;
    overflow: hidden;
  }
  body.mobile-ui-v1 .hall-board {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    display: grid;
    align-content: start;
    gap: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 2px 18px;
  }
  body.mobile-ui-v1 .hall-message,
  body.mobile-ui-v1 .hall-fork {
    overflow-wrap: anywhere;
  }

  body.mobile-ui-v1 .diary-library {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 2px solid #10110f;
    border-radius: 0;
  }
  body.mobile-ui-v1 .diary-index {
    display: flex;
    flex: 0 0 auto;
    gap: 7px;
    max-height: none;
    padding: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 0;
    border-bottom: 2px solid #10110f;
  }
  body.mobile-ui-v1 .diary-index-label { display: none; }
  body.mobile-ui-v1 .diary-index-button {
    flex: 0 0 min(68vw, 250px);
    min-height: 66px;
  }
  body.mobile-ui-v1 .diary-reader {
    min-height: 48dvh;
    padding: 16px 14px;
    overflow: visible;
  }
  body.mobile-ui-v1 .diary-page h4 {
    margin: 8px 0 16px;
    font-size: 25px;
  }
  body.mobile-ui-v1 .diary-page-body {
    font-size: 16px;
    line-height: 1.75;
    overflow-wrap: anywhere;
  }

  body.mobile-ui-v1 .schedule-form {
    padding: 14px 12px;
    border: 3px solid #10110f;
    border-radius: 0;
    background: #fff;
    box-shadow: 4px 4px 0 #f7a8c8;
  }
  body.mobile-ui-v1 .resident-calendar {
    grid-template-columns: 1fr;
  }
  body.mobile-ui-v1 .calendar-day {
    padding: 14px;
  }
  body.mobile-ui-v1 .schedule-time-24 {
    grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr);
  }
  body.mobile-ui-v1 .schedule-time-24 select { min-height: 52px; }
  body.mobile-ui-v1 .schedule-actions {
    display: grid;
    gap: 8px;
    align-items: stretch;
  }
  body.mobile-ui-v1 .schedule-submit { width: 100%; min-height: 50px; }

  body.mobile-ui-v1 .manifest-list,
  body.mobile-ui-v1 .activity-list,
  body.mobile-ui-v1 .visit-inbox-list,
  body.mobile-ui-v1 .causal-timeline,
  body.mobile-ui-v1 .credential-list,
  body.mobile-ui-v1 .capability-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  body.mobile-ui-v1 .credential-card,
  body.mobile-ui-v1 .causal-entry,
  body.mobile-ui-v1 .visit-inbox-item {
    min-width: 0;
    border-radius: 0;
  }

  body.mobile-ui-v1 .funds-head {
    align-items: flex-start;
    gap: 10px;
  }
  body.mobile-ui-v1 .funds-close {
    flex: 0 0 auto;
    min-width: 72px;
  }
  body.mobile-ui-v1 .funds-pie-wrap,
  body.mobile-ui-v1 .funds-legend {
    width: 100%;
    min-width: 0;
  }
  body.mobile-ui-v1 .funds-resident summary {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
  }
  body.mobile-ui-v1 .funds-money {
    grid-column: 2;
    text-align: left;
  }
  body.mobile-ui-v1 .funds-detail { overflow-wrap: anywhere; }

  body.mobile-ui-v1 .batch-admit-textarea,
  body.mobile-ui-v1 #batchPersonaJson,
  body.mobile-ui-v1 #batchIdentityJson {
    width: 100%;
    min-height: 42dvh;
    font-size: 13px;
  }
  body.mobile-ui-v1 .capability-heading,
  body.mobile-ui-v1 .capability-parameters-head {
    align-items: stretch;
    flex-direction: column;
  }
  body.mobile-ui-v1 .capability-add,
  body.mobile-ui-v1 .capability-parameter-add { width: 100%; }

  body.mobile-ui-v1 .behavior-trace,
  body.mobile-ui-v1 .session-card {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  /* Hall is a phone timeline, not a compressed desktop form. */
  body.mobile-ui-v1 #hallDialog {
    padding: 0 !important;
    background: #fffdf3 !important;
  }
  body.mobile-ui-v1 #hallDialog > .identity-form {
    position: relative;
    display: grid !important;
    /* title, help, toolbar, status, scrollable history, composer */
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
    gap: 0;
    width: 100%;
    height: var(--em-mobile-viewport-height, 100dvh);
    min-height: 0 !important;
    padding: max(14px, env(safe-area-inset-top)) 12px
      max(10px, env(safe-area-inset-bottom)) !important;
    border: 0;
    box-shadow: none;
    background:
      linear-gradient(180deg, #fff700 0 104px, transparent 104px),
      #fffdf3;
  }
  body.mobile-ui-v1 #hallDialog h3 {
    order: 0;
    padding: 4px 72px 4px 2px;
    font-size: 27px;
  }
  body.mobile-ui-v1 #hallDialog > .identity-form > .identity-help:first-of-type {
    order: 0;
    max-width: calc(100% - 64px);
    padding: 0 2px 12px;
    color: #30342f;
    font-size: 11px;
    line-height: 1.35;
  }
  body.mobile-ui-v1 #hallDialog .hall-toolbar {
    order: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    padding: 10px 0;
    border-bottom: 3px solid #10110f;
  }
  body.mobile-ui-v1 #hallDialog #hallCallAll {
    min-height: 46px;
    padding: 8px 11px;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #19a447;
    color: #fff;
    box-shadow: 3px 3px 0 #10110f;
    font-weight: 900;
  }
  body.mobile-ui-v1 #hallDialog .hall-presence {
    display: flex;
    align-items: center;
    min-width: 0;
    padding: 8px 10px;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #fff;
    color: #10110f;
    font-weight: 850;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-picker {
    grid-column: 1 / -1;
    max-height: 190px;
    padding: 9px;
    overflow: hidden;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #fffdf3;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-head {
    align-items: flex-start;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-tools button {
    min-height: 38px;
    border: 2px solid #10110f;
    border-radius: 0;
    font-weight: 850;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-groups {
    grid-template-columns: minmax(0, 1fr);
    max-height: 112px;
    overflow-y: auto;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-group {
    border: 2px solid #10110f;
    border-radius: 0;
  }
  body.mobile-ui-v1 #hallDialog .hall-audience-member {
    min-height: 36px;
  }
  body.mobile-ui-v1 #hallDialog #hallStatus {
    order: 2;
    min-height: 0;
    padding: 5px 2px;
    color: #48604f;
    font-size: 10px;
  }
  body.mobile-ui-v1 #hallDialog .hall-board {
    position: relative;
    z-index: 1;
    order: 3;
    min-height: 0;
    margin: 0 -2px;
    padding: 8px 2px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
  body.mobile-ui-v1 #hallDialog .hall-message {
    position: relative;
    padding: 14px 13px;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #fff;
    box-shadow: 4px 4px 0 #f7a8c8;
  }
  /* The repeated decorative "大廳記錄" tab used a negative margin and
     covered the timestamp/detail row on narrow phones. The dialog title
     already names the timeline, so cards begin directly with their data. */
  body.mobile-ui-v1 #hallDialog .hall-message::before {
    content: none !important;
    display: none !important;
  }
  body.mobile-ui-v1 #hallDialog .hall-message > small {
    display: block;
    margin-bottom: 8px;
    color: #5f665f;
  }
  body.mobile-ui-v1 #hallDialog .hall-message > p {
    margin: 0 0 12px;
    font-size: 16px;
    line-height: 1.55;
  }
  body.mobile-ui-v1 #hallDialog .hall-total-progress {
    grid-template-columns: 1fr auto;
    border: 0;
    border-left: 5px solid #19a447;
    border-radius: 0;
    background: #f4f7ed;
  }
  body.mobile-ui-v1 #hallDialog .hall-progress-track {
    grid-column: 1 / -1;
  }
  body.mobile-ui-v1 #hallDialog .hall-forks summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-weight: 900;
  }
  body.mobile-ui-v1 #hallDialog .hall-fork {
    grid-template-columns: minmax(0, 1fr);
    border-left: 4px solid #19a447;
    border-radius: 0;
  }
  body.mobile-ui-v1 #hallDialog .hall-compose {
    position: relative;
    z-index: 2;
    order: 4;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin: 0 -12px calc(-1 * max(10px, env(safe-area-inset-bottom)));
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    border-top: 3px solid #10110f;
    background: #fff700;
  }
  body.mobile-ui-v1 #hallDialog .hall-compose textarea {
    min-height: 54px;
    max-height: 112px;
    padding: 11px;
    resize: none;
    border: 3px solid #10110f;
    border-radius: 0;
    background: #fff;
  }
  body.mobile-ui-v1 #hallDialog .hall-actions {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  body.mobile-ui-v1 #hallDialog .hall-actions button {
    min-width: 76px;
    min-height: 44px;
    padding: 6px 8px;
    border: 2px solid #10110f;
    border-radius: 0;
    font-weight: 900;
  }
  body.mobile-ui-v1 #hallDialog .hall-primary {
    background: #19a447;
    color: #fff;
  }
  body.mobile-ui-v1 #hallDialog > .identity-form > .identity-form-actions {
    position: absolute !important;
    z-index: 5;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    bottom: auto !important;
    display: block;
    width: 58px;
    margin: 0 !important;
    padding: 0 !important;
    border: 0;
    background: transparent;
  }
  body.mobile-ui-v1 #hallDialog #hallClose {
    width: 58px;
    min-height: 44px;
    padding: 5px;
    border: 2px solid #10110f;
    border-radius: 0;
    background: #fff;
    color: #10110f;
    box-shadow: 3px 3px 0 #f7a8c8;
    font-size: 12px;
  }

  /* Resident schedule keeps the same control/preview meaning on phones, stacked instead of squeezed. */
  body.mobile-ui-v1 .schedule-calendar-shell {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  body.mobile-ui-v1 .schedule-control-pane {
    padding: 12px;
    border: 2px solid #10110f;
    border-right: 2px solid #10110f;
    background: rgba(255, 250, 225, .96);
  }
  body.mobile-ui-v1 .schedule-calendar-nav > div {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  body.mobile-ui-v1 .schedule-preview-pane {
    padding: 0;
    background: rgba(255,255,255,.72);
  }
  body.mobile-ui-v1 .schedule-day-page {
    height: auto;
    min-height: 360px;
    border: 0;
    border-radius: 0;
  }
  body.mobile-ui-v1 .schedule-day-page > header {
    align-items: flex-start;
    flex-direction: column;
  }
  body.mobile-ui-v1 .schedule-day-timeline {
    padding: 10px;
    overflow: visible;
  }
  body.mobile-ui-v1 .calendar-empty {
    min-height: 240px;
  }
  body.mobile-ui-v1 .day-schedule-block,
  body.mobile-ui-v1 .day-schedule-event {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    border: 2px solid #10110f;
    border-left-width: 6px;
  }
  body.mobile-ui-v1 .day-schedule-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body.mobile-ui-v1 .schedule-add-controls,
  body.mobile-ui-v1 .schedule-add-controls button {
    width: 100%;
  }
  body.mobile-ui-v1 .schedule-add-controls button {
    min-height: 50px;
  }
  body.mobile-ui-v1 .schedule-calendar-shell.editor-open .schedule-block-form {
    position: absolute;
    inset: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    z-index: 121;
    top: auto;
    left: auto;
    width: auto;
    max-height: none;
    margin: 0;
    padding: 16px;
    border-radius: 18px;
    transform: none;
    overflow-y: auto;
  }
  body.mobile-ui-v1 .schedule-calendar-shell.editor-open .schedule-block-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  body.mobile-ui-v1 .schedule-calendar-shell.editor-open .schedule-block-grid label.wide {
    grid-column: auto;
  }
  body.mobile-ui-v1 .schedule-editor-close {
    position: sticky;
    top: 0;
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }
  body.mobile-ui-v1 .schedule-block-form {
    padding: 12px;
    border: 2px solid #10110f;
    border-radius: 0;
  }
  body.mobile-ui-v1 .schedule-block-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  body.mobile-ui-v1 .schedule-block-grid label.wide {
    grid-column: auto;
  }

}

@media (max-width: 760px) and (orientation: landscape) {
  body.mobile-ui-v1 .chat-room {
    grid-template-columns: minmax(0, 1fr);
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  body.mobile-ui-v1 .em-mobile-more-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
