/* ================================================================ Phone and tablet view */
.m-app, .m-preview-bar { display: none; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }

body.mobile { overflow: auto; height: auto; background: var(--bg); }
body.mobile .appbar, body.mobile .row-handle { display: none !important; }
/* While editing, the printed sheet stays laid out off-screen so the page fit stays accurate. */
body.mobile:not(.m-preview) .layout {
  position: fixed; left: -20000px; top: 0; width: 1200px; height: 900px;
  visibility: hidden; pointer-events: none;
}
body.mobile .m-app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* Top bar */
/* Every phone bar here is the shared compact bar: --n5-bar-*-compact in no5tyle.css */
.m-top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  box-sizing: border-box; height: calc(var(--n5-bar-height-compact) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--n5-bar-pad-compact) 0;
  background: var(--bar-bg); -webkit-backdrop-filter: var(--bar-filter); backdrop-filter: var(--bar-filter);
  border-bottom: .5px solid var(--border);
}
.m-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start;
  padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
}
.m-title-main { max-width: 100%; font-weight: 700; font-size: var(--n5-bar-title-size); line-height: 1.25; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-title-main::after {
  content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-3px) rotate(45deg);
}
.m-title-sub { max-width: 100%; font-size: var(--n5-bar-sub-size); line-height: 1.25; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-icon {
  width: var(--n5-bar-button-compact); height: var(--n5-bar-button-compact); flex: none; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--fill); color: var(--primary); cursor: pointer;
}
.m-icon svg { width: 20px; height: 20px; }
/* The app switcher, left of the program's name */
.m-switcher { --qs-switch-size: var(--n5-bar-icon-compact); }
.m-switcher .brand-mark { width: var(--n5-bar-icon-compact); height: var(--n5-bar-icon-compact); }

/* Week list: one short row per activity, so a term fits on about a screen */
.m-list { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 10px 12px 104px; }
.m-week {
  display: grid; grid-template-columns: 52px 1fr; gap: 6px; margin-bottom: 8px; padding: 0 6px 0 12px;
  background: var(--surface); border-radius: 18px;
}
.m-wk { padding-top: 15px; font-size: 12.5px; font-weight: 700; color: var(--muted); line-height: 1.1; }
.m-rows { display: flex; flex-direction: column; min-width: 0; }
.m-row {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px;
  padding: 6px 2px 6px 10px; border: 0; border-left: 4px solid var(--cat, transparent);
  background: none; text-align: left; cursor: pointer;
}
.m-row + .m-row { border-top: .5px solid var(--border-soft); }
.m-row:active { background: var(--tint-fill); }
.m-when { width: 92px; flex: none; display: flex; flex-direction: column; line-height: 1.2; }
.m-when b { font-size: 13.5px; font-weight: 600; }
.m-when small { font-size: 12px; color: var(--text-2); }
.m-what { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.m-act { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-act i { font-weight: 400; color: var(--muted); }
.m-meta { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-meta .sep { margin: 0 5px; color: var(--muted); }
.m-meta .patrol { font-weight: 700; }
.m-ch { flex: none; display: grid; }
.m-ch .ch-icon { width: 26px; height: 26px; }
.m-chev { width: 16px; height: 16px; flex: none; color: var(--muted); }
.m-row.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 7px, var(--fill) 7px 14px); border-radius: 10px; }
.m-row.off .m-act { font-style: italic; color: var(--text-2); }
.m-empty { padding: 48px 16px; text-align: center; color: var(--text-2); }

/* Bottom bar */
.m-bottom {
  position: fixed; left: 12px; right: 12px; bottom: max(env(safe-area-inset-bottom), 12px); z-index: 5;
  max-width: 560px; margin: 0 auto;
  display: flex; justify-content: center; gap: 4px; padding: 6px;
  border-radius: 999px;
  background: var(--glass-sheen), var(--glass-bg);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.m-bottom button {
  flex: 1; height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; border-radius: 999px; background: transparent; color: var(--primary);
  font-size: 15px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.m-bottom button:active { background: var(--hover); }
.m-bottom .m-primary { background: var(--primary); color: #fff; }

/* Preview: the real sheet, scaled to the screen (pinch to zoom) */
body.mobile.m-preview .m-app { display: none; }
body.mobile.m-preview .m-preview-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  box-sizing: border-box; height: calc(var(--n5-bar-height-compact) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--n5-bar-pad-compact) 0;
  background: var(--bar-bg); -webkit-backdrop-filter: var(--bar-filter); backdrop-filter: var(--bar-filter);
  border-bottom: .5px solid var(--border);
}
body.mobile.m-preview .layout, body.mobile.m-preview .workspace, body.mobile.m-preview .ws-body { display: block; height: auto; }
body.mobile.m-preview .ws-body.settings-open .canvas { padding-right: 0; }
body.mobile.m-preview .sidebar, body.mobile.m-preview .directory, body.mobile.m-preview .ws-toolbar, body.mobile.m-preview .canvas-tip, body.mobile.m-preview .canvas-note { display: none; }
body.mobile.m-preview .canvas { overflow: visible; padding: 72px 12px 24px; }
body.mobile.m-preview .sheet { pointer-events: none; }
body.mobile.m-preview .prog .ph, body.mobile.m-preview .prog .ed:empty::before, body.mobile.m-preview .doc-group .ph { visibility: hidden; }

/* Panels: full screen on phones, a centred sheet on tablets */
.m-panels {
  position: fixed; inset: 0; z-index: 25;
  display: flex; align-items: stretch; justify-content: center;
  background: rgba(0, 0, 0, .35);
}
.m-panels[hidden] { display: none; }
.m-panel { width: 100%; height: 100%; display: flex; flex-direction: column; background: var(--bg); }
@media (min-width: 700px) {
  .m-panels { align-items: center; padding: 24px; }
  .m-panel { width: min(640px, 100%); height: min(88vh, 920px); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
  .m-panel.m-small { height: auto; max-height: 88vh; }
}
.m-panel-head {
  display: flex; flex: none; align-items: center; gap: 8px;
  box-sizing: border-box; height: calc(var(--n5-bar-height-compact) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 4px 0;
  background: var(--bar-bg); -webkit-backdrop-filter: var(--bar-filter); backdrop-filter: var(--bar-filter);
  border-bottom: .5px solid var(--border);
}
.m-panel-head h2 { flex: 1; margin: 0; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-head-btn {
  min-width: 44px; height: 44px; margin: -4px 0; padding: 0 10px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: none; color: var(--primary);
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.m-head-btn svg { width: 22px; height: 22px; }
.m-panel-body { flex: 1; overflow-y: auto; padding: 12px 12px max(16px, env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }

.m-group { margin-bottom: 14px; overflow: hidden; background: var(--surface); border-radius: 18px; }
.m-group-label { margin: 4px 6px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.m-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px;
  border: 0; background: none; text-align: left; font-size: 15.5px; cursor: pointer;
}
.m-item + .m-item { border-top: 1px solid var(--border); }
.m-item:active { background: var(--tint-fill); }
.m-item-text { flex: 1; display: flex; flex-direction: column; font-weight: 600; }
.m-item-text small { font-size: 12.5px; font-weight: 400; color: var(--text-2); }

/* Settings screens show the desktop sidebar's own controls */
.m-settings > .card-body { padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }

/* Activity editor */
.m-card { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; padding: 14px; background: var(--surface); border-radius: 18px; }
.m-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.m-field > span:first-child { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.m-field textarea {
  width: 100%; min-height: 44px; padding: 10px; resize: vertical;
  border: 1px solid var(--input-border); border-radius: var(--radius); background: var(--surface); font: inherit;
}
.m-field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.m-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.m-switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.m-switch input { width: 22px; height: 22px; accent-color: var(--primary); }
.m-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.m-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px;
  border: 1px solid var(--input-border); border-radius: 999px; background: var(--surface); font-size: 14px; cursor: pointer;
}
.m-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.m-chip .dot { width: 12px; height: 12px; margin: 0; }
.m-chip .ch { display: contents; }
.m-chip .ch-icon { width: 22px; height: 22px; }
.m-other { margin-top: 4px; }
.m-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.m-actions .btn { width: 100%; height: 46px; white-space: normal; }
.m-editor .days .day { padding: 8px 0; font-size: 12.5px; }
.m-busy { padding: 18px 8px; text-align: center; color: var(--text-2); }
.m-busy p { margin: 8px 0 0; }
.m-spinner {
  display: inline-block; width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--tint-fill-strong); border-top-color: var(--primary); animation: m-spin .8s linear infinite;
}
@keyframes m-spin { to { transform: rotate(360deg); } }

/* Touch sizes; 16px text in inputs stops iOS zooming in when one is focused */
body.mobile input[type=text], body.mobile input[type=email], body.mobile input[type=date], body.mobile input[type=time],
body.mobile input[type=number], body.mobile select, body.mobile textarea { min-height: 44px; font-size: 16px; }
body.mobile .popover { max-width: calc(100vw - 24px); }
body.mobile .popover:has(.prog-list) { min-width: min(340px, calc(100vw - 24px)); }

@media print {
  .m-app, .m-preview-bar, .m-panels { display: none !important; }
  body.mobile .layout {
    position: static !important; visibility: visible !important; left: auto !important;
    width: auto !important; height: auto !important;
  }
  body.mobile .canvas { padding: 0 !important; }
}

/* Dark mode: some challenge icons are dark navy, so give icons outside the sheet a light disc to sit on */
@media screen and (prefers-color-scheme: dark) {
  .m-ch .ch-icon, .m-chip .ch-icon, .choice .ch-icon, .ch-preview .ch-icon {
    border-radius: 50%; background: rgba(255, 255, 255, .88); padding: 2px;
  }
}

/* Whole weeks: a "+" under each week's label, empty weeks, and the day picker */
/* Label and "+" together fit a one-line row's 52px, so weeks stay as short as before */
.m-wk { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding-top: 9px; }
.m-wk-add {
  position: relative; display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: 50%; background: var(--tint-fill); color: var(--primary); cursor: pointer;
}
.m-wk-add svg { width: 14px; height: 14px; }
/* A bigger area to tap than it looks */
.m-wk-add::after { content: ''; position: absolute; inset: -8px -10px; }
.m-wk-add:active { background: var(--tint-fill-strong); }
.m-row.m-empty-week { border-left-style: dashed; border-left-color: var(--border); }
.m-row.m-empty-week .m-add-hint { color: var(--primary); font-weight: 600; }
.m-week-title { margin: 0 0 4px; }
.m-card .days .day { padding: 10px 0; }

/* Formattable text fields (js/rich.js), styled as the text boxes */
.m-rich {
  width: 100%; min-height: 44px; padding: 10px; white-space: pre-wrap; overflow-wrap: anywhere;
  border: 1px solid var(--input-border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  line-height: 1.35; cursor: text;
}
.m-rich.tall { min-height: 84px; }
.m-rich:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.m-rich:empty::before { content: attr(data-ph); color: var(--muted); pointer-events: none; }

/* "Aa" beside a picked field's name: its style toolbar */
.m-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.m-style {
  min-width: 34px; height: 26px; padding: 0 8px; border: 0; border-radius: 8px;
  background: var(--fill); color: var(--text-2); font: 600 13px/1 system-ui, sans-serif; cursor: pointer;
}
.m-style:active { background: var(--tint-fill); color: var(--primary); }

.m-note { margin: 4px 8px 12px; }
