:root {
  --ink: #172126;
  --muted: #64727a;
  --line: #dbe4e7;
  --bg: #f5f7f8;
  --card: #ffffff;
  --brand: #16705b;
  --brand-dark: #10272b;
  --accent: #d97706;
  --ok: #15803d;
  --warn: #a16207;
  --danger: #b42318;
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

body.auth-locked {
  display: block;
}

body.auth-locked .side,
body.auth-locked .main {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 7px 11px;
  background: var(--brand);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

button.secondary {
  background: #e8f3ef;
  color: var(--brand);
  border: 1px solid #bad8d0;
}

button.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.danger {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #efbbb5;
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

input,
select,
textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  padding: 7px 9px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #34434a;
  font-weight: 800;
}

.permission-form {
  display: grid;
  gap: 14px;
}

.permission-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.permission-box legend {
  padding: 0 6px;
  font-weight: 900;
}

.permission-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
  padding: 8px 10px;
}

.check-row input {
  min-height: 0;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--brand-dark);
  color: white;
  padding: 16px 11px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 7px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  margin-bottom: 10px;
}

.brand span,
.brand > img {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: var(--brand-dark);
  font-weight: 900;
}

.brand > img,
img.app-logo {
  object-fit: contain;
  background: #fff;
}

.shop-brand-preview { display: flex; align-items: center; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #f8fbfa; }
.shop-brand-preview img { width: 88px; height: 88px; flex: 0 0 88px; object-fit: contain; border-radius: 18px; background: #fff; box-shadow: 0 8px 22px rgba(23,60,52,.14); }

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.68);
}

#nav {
  display: grid;
  gap: 5px;
}

.nav-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  text-align: left;
  color: rgba(255, 255, 255, 0.82);
  background: transparent;
}

.nav-btn.active,
.nav-btn:hover {
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.role-box {
  min-width: 180px;
  display: grid;
  gap: 8px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(16, 39, 43, 0.82), rgba(22, 112, 91, 0.7)),
    url("https://images.unsplash.com/photo-1540555700478-4be289fbecef?auto=format&fit=crop&w=1200&q=80") center/cover;
}

/* Phase 2: BrandUI layer replaces static bg when active */
.login-screen.bm-bg-active {
  background: transparent;
}

.login-card {
  width: min(100%, 390px);
  display: grid;
  gap: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  padding: 26px;
  box-shadow: 0 18px 40px rgba(16, 39, 43, 0.22);
}

.app-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--brand-dark);
  font-weight: 900;
}

.login-card h1 {
  margin: 4px 0 0;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.password-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}

.password-field input {
  width: 100%;
}

.password-toggle {
  min-width: 64px;
  padding: 0 12px;
  border: 1px solid #c9d6d1;
  border-radius: 10px;
  background: #f3f7f5;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.password-toggle[aria-pressed="true"] {
  background: #e7f6ef;
  border-color: #9fd0bf;
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.privacy {
  margin: 18px 22px 0;
  display: grid;
  gap: 4px;
  border: 1px solid #b7d7cf;
  border-left: 5px solid var(--brand);
  border-radius: 8px;
  background: #eef8f4;
  padding: 12px 14px;
}

.privacy span {
  color: #496760;
  line-height: 1.6;
}

.content {
  padding: 18px 22px 42px;
  display: grid;
  gap: 16px;
}

.grid {
  display: grid;
  gap: 12px;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two {
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
}

.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.metric,
.task-card,
.room,
.setting-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-body {
  padding: 15px;
}

.metric {
  min-height: 112px;
  display: grid;
  align-content: space-between;
  border-left: 5px solid var(--brand);
  padding: 13px;
}

.metric span,
.mini {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 25px;
}

.metric small {
  color: var(--ok);
}

.task-list,
.room-grid,
.settings-grid,
.log-list {
  display: grid;
  gap: 10px;
}

.task-card {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.task-top,
.task-actions,
.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.task-actions {
  flex-wrap: wrap;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #edf3f0;
  color: #255b4f;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status.ok {
  background: #dcfce7;
  color: #166534;
}

.status.warn {
  background: #fef3c7;
  color: #92400e;
}

.status.danger {
  background: #fee2e2;
  color: #991b1b;
}

.ops-booking-alert {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: start center;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(15, 23, 42, 0.48);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ops-booking-alert.hidden {
  display: none;
}

.ops-booking-alert-card {
  width: min(100%, 440px);
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
  display: grid;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  background: #ffffff;
  border: 2px solid var(--brand);
  border-radius: 14px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.24);
  -webkit-overflow-scrolling: touch;
}

.ops-booking-alert-card h2,
.ops-booking-alert-card p {
  margin: 0;
}

.ops-alert-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ops-alert-actions button {
  min-height: 50px;
}

.room-grid {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.room {
  min-height: 90px;
  display: grid;
  gap: 5px;
  padding: 11px;
}

.room.busy {
  background: #fff7ed;
  border-color: #f0bf80;
}

.room.clean {
  background: #effaf5;
  border-color: #a7d5bf;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

body.phone-booking-open {
  overflow: hidden;
}

.phone-booking-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: stretch;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(15, 23, 42, 0.58);
}
/* brand background makes direct body children position:relative; modal layers must opt out. */
body.bm-bg-host > .teacher-transfer-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483645 !important;
}
.teacher-transfer-dialog{width:100%;max-width:none;height:calc(100dvh - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));max-height:calc(100dvh - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));border-radius:0;box-shadow:none}.teacher-transfer-head{position:relative;z-index:3;display:grid!important;grid-template-columns:minmax(84px,1fr) auto minmax(84px,1fr);align-items:center;background:#fff}.teacher-transfer-head h2{text-align:center;margin:0}.teacher-transfer-head>[data-teacher-transfer-close]{justify-self:start}.teacher-transfer-head-spacer{display:block}.teacher-transfer-body{min-height:0;overflow:hidden;display:grid;grid-template-rows:auto minmax(0,1fr);gap:12px}.teacher-transfer-summary{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:0;padding:12px;border-radius:12px;background:var(--surface-soft,#f7f8fa)}.teacher-transfer-summary p{margin:0}.teacher-transfer-form{min-height:0;display:grid;grid-template-rows:minmax(0,1fr) auto;gap:12px}.teacher-transfer-list{min-height:0;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}.teacher-transfer-choice{display:flex;align-items:center;gap:8px;padding:12px 8px;border-bottom:1px solid var(--line,#ddd)}.teacher-transfer-actions{position:relative;z-index:2;display:flex;justify-content:flex-end;margin:0;padding:12px 0 0;border-top:1px solid var(--line,#ddd);background:#fff}.teacher-transfer-button{margin-top:10px}.teacher-transfer-open{overflow:hidden}@media(max-width:720px){.teacher-transfer-summary{grid-template-columns:1fr}.teacher-transfer-actions{display:grid;grid-template-columns:1fr 1fr}.teacher-transfer-actions button{width:100%}}

body.history-query-open {
  overflow: hidden;
}

.history-query-overlay {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: none;
  place-items: stretch;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  background: rgba(15, 23, 42, 0.72);
}

.history-query-overlay.is-open {
  display: grid !important;
}

.history-query-overlay.hidden {
  display: none !important;
}

.history-query-dialog {
  width: 100%;
  max-width: none;
  height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border-radius: 0;
  box-shadow: none;
}

.history-query-body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.history-query-form {
  margin-bottom: 12px;
}

.history-query-summary {
  margin-bottom: 10px;
}

.history-query-results .task-list {
  max-height: none;
}

.booking-inbox-scroll {
  max-height: min(72vh, 860px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}

.booking-inbox-panel {
  min-height: 0;
}

.phone-booking-dialog {
  width: 100%;
  max-width: none;
  height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border-radius: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.35);
}

.phone-booking-dialog .panel-head {
  flex-direction: row;
  align-items: center;
}

.phone-booking-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  gap: 12px;
}

.phone-booking-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.phone-booking-body {
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.phone-booking-form,
.phone-booking-form label,
.phone-booking-form input,
.phone-booking-form select,
.phone-booking-form textarea {
  min-width: 0;
  max-width: 100%;
}

.phone-booking-form-actions {
  grid-column: 1 / -1;
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px -4px -4px;
  padding: 12px 4px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, #fff 78%, rgba(255,255,255,0.92));
  border-top: 1px solid #d8e1dc;
}

.phone-booking-form-actions button {
  min-width: 150px;
}

.catalog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.catalog button {
  min-height: 70px;
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  text-align: left;
}

.receipt {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.receipt-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.total {
  display: flex;
  justify-content: space-between;
  font-size: 22px;
  font-weight: 900;
  margin: 12px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

th {
  font-size: 13px;
  background: #f8faf9;
}

.table-wrap {
  overflow: auto;
}

.notif-monitor-row.is-selected td {
  background: #eef7f4;
}

.notif-lifecycle {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.notif-lifecycle li {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfefe;
}

.notif-lifecycle li.done {
  border-color: #9fd0c2;
  background: #f2fbf7;
}

.notif-lifecycle li.pending {
  opacity: 0.65;
}

.notif-lifecycle-label {
  font-weight: 700;
}

.notif-lifecycle-arrow {
  color: #6b7c77;
  font-size: 12px;
}

.notif-test-fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  grid-column: span 1;
}

.notif-test-fieldset legend {
  padding: 0 6px;
  font-weight: 700;
}

.notif-test-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.notif-test-result {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #9fd0c2;
  border-radius: 12px;
  background: #f2fbf7;
  display: grid;
  gap: 6px;
}

.notif-test-result ul {
  margin: 0;
  padding-left: 18px;
}

.notif-matrix-table th,
.notif-matrix-table td {
  text-align: center;
  vertical-align: middle;
}

.notif-matrix-table th:first-child,
.notif-matrix-table td:first-child {
  text-align: left;
}

.notif-matrix-cell input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.setting-card {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.ai-control-panel {
  border-color: #0f766e;
}

.ai-control-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.ai-control-body button {
  min-width: 150px;
}

.log-list .line {
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.qr-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.qr-card img {
  width: min(100%, 260px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
}

.qr-card code {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf9;
  color: #255b4f;
  padding: 9px;
  overflow-wrap: anywhere;
}

.teacher-row {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  align-items: center;
  gap: 11px;
}

.teacher-photo {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
}

.teacher-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-width: 1050px) {
  body {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
    height: auto;
  }

  #nav {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .metrics,
  .two,
  .three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .panel-head,
  .task-top,
  .line,
  .teacher-row {
    align-items: stretch;
    flex-direction: column;
  }

  .content,
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .privacy {
    margin-left: 14px;
    margin-right: 14px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .phone-booking-overlay {
    place-items: stretch;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  }

  .phone-booking-dialog {
    width: 100%;
    max-width: none;
    height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    border-radius: 0;
  }

  .phone-booking-form-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .phone-booking-head-actions {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 96px;
  }

  .phone-booking-form-actions button {
    width: 100%;
  }
}
/* WebCall: one top-layer call UI. Controls remain visible without scrolling the dashboard. */
html.web-call-active,
body.web-call-active {
  overflow: hidden !important;
  overscroll-behavior: none;
}

.web-call-audio {
  display: block !important;
  position: fixed !important;
  width: 1px !important;
  height: 1px !important;
  left: -9999px !important;
  opacity: 0.001 !important;
  pointer-events: none !important;
}

.counter-call-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483640;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + env(safe-area-inset-top, 0px))
    16px
    calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(4, 20, 18, 0.84);
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.counter-call-overlay.hidden {
  display: none;
}

.counter-call-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.counter-call-header {
  padding: 24px 24px 10px;
}

.counter-call-header strong {
  display: block;
  color: #176854;
  font-size: 16px;
}

.counter-call-card h2 {
  margin: 8px 0 0;
  font-size: clamp(30px, 7vw, 42px);
  line-height: 1.15;
}

.counter-call-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 4px 24px 12px;
  -webkit-overflow-scrolling: touch;
}

#counterCallStatus {
  margin: 0 0 10px;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 900;
  line-height: 1.35;
}

.counter-call-safe-note {
  margin: 0;
  color: #52645f;
  font-size: 16px;
  line-height: 1.45;
}

.counter-call-card b {
  display: block;
  margin: 18px 0 4px;
  font-size: 30px;
}

.counter-call-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 24px 24px;
  border-top: 1px solid #dce7e3;
  background: #fff;
}

.counter-call-actions button {
  min-height: 68px;
  font-size: 20px;
  font-weight: 900;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#counterCallPlayAudioBtn,
#counterCallHangupBtn {
  grid-column: 1 / -1;
}

#counterCallHangupBtn {
  min-height: 76px;
}

@media (max-width: 700px) {
  .counter-call-overlay {
    align-items: stretch;
    padding: 0;
  }

  .counter-call-card {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .counter-call-header {
    padding:
      calc(18px + env(safe-area-inset-top, 0px))
      18px
      8px;
  }

  .counter-call-content {
    padding: 4px 18px 10px;
  }

  .counter-call-actions {
    padding:
      12px
      18px
      calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .counter-call-card {
    width: min(760px, 100%);
  }

  .counter-call-header {
    padding-top: 12px;
  }

  .counter-call-card h2 {
    font-size: 28px;
  }

  .counter-call-content {
    padding-block: 0 6px;
  }

  .counter-call-safe-note {
    display: none;
  }

  .counter-call-card b {
    margin: 8px 0 0;
    font-size: 24px;
  }

  .counter-call-actions {
    padding-block: 10px;
  }

  .counter-call-actions button {
    min-height: 54px;
  }
}

/* v1.2.2 bounded history panels and settings entry center */
.bm-history-panel .panel-head{align-items:center;flex-wrap:wrap;gap:10px}
.bm-history-panel .panel-head-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap}
.bm-history-count{display:inline-flex;align-items:center;justify-content:center;min-height:36px;padding:6px 11px;border-radius:999px;background:#e7f5f0;color:#075f4f;font-size:14px;font-weight:900;white-space:nowrap}
.bm-history-scroll{height:clamp(260px,38vh,430px);min-height:220px;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding-right:4px}
.bm-history-scroll.table-wrap{display:block}
.bm-assistance-list{align-content:start}
.bm-assistance-list .task-card{gap:6px}
.bm-history-clean{min-width:148px}
.bm-history-clean.is-confirming{background:#b42318!important;color:#fff!important;border-color:#b42318!important;box-shadow:0 0 0 4px rgba(180,35,24,.13)}
.bm-history-clean[disabled]{opacity:.55;cursor:not-allowed}
.bm-history-note{width:100%;margin:0;color:#60756f;font-size:13px}
.bm-settings-entry-shell{display:grid;gap:16px}
.bm-settings-entry-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px}
.bm-settings-entry-card{display:flex;min-height:150px;flex-direction:column;align-items:flex-start;justify-content:space-between;gap:12px;padding:18px;border:1px solid #bcd8d0;border-radius:18px;background:#fff;color:#103f35;text-align:left;box-shadow:0 7px 20px rgba(0,65,52,.07)}
.bm-settings-entry-card:hover{transform:translateY(-1px);border-color:#078d70;box-shadow:0 9px 24px rgba(0,65,52,.11)}
.bm-settings-entry-card strong{font-size:20px}
.bm-settings-entry-card span{color:#5b716b;line-height:1.55}
.bm-settings-subpage-head{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:14px}
.bm-settings-subpage-head h2{margin:0}
.bm-settings-subpage-content>.bm-accordion,.bm-settings-subpage-content>.panel,.bm-settings-subpage-content>.grid{margin-bottom:14px}
.booking-date-groups{display:grid;gap:12px}
.booking-date-group{border:1px solid #d8e7e2;border-radius:16px;background:#fff;overflow:hidden}
.booking-date-group>summary{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;cursor:pointer;font-weight:800;color:#103f35;background:#f2faf7}
.booking-date-group>summary::-webkit-details-marker{display:none}
.booking-date-group>summary strong{display:inline-flex;align-items:center;justify-content:center;min-width:48px;padding:4px 10px;border-radius:999px;background:#e0f4ed;color:#08755f;font-size:13px}
.booking-date-group .schedule-card-list,.booking-date-group .job-list{padding:12px}
.schedule-booking-card{border-left:4px solid #08755f}
@media(max-width:700px){.bm-history-scroll{height:360px}.bm-history-panel .panel-head-actions{width:100%;justify-content:stretch}.bm-history-panel .panel-head-actions>*{flex:1}.bm-settings-entry-grid{grid-template-columns:1fr}.bm-settings-entry-card{min-height:125px}}

.counter-call-history-panel {
  margin: 0 24px 24px;
  padding: 18px;
}

.counter-call-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.counter-call-history-head span,
.counter-call-history-meta {
  color: var(--muted);
  font-size: 13px;
}

.counter-call-history-head strong {
  display: block;
  font-size: 20px;
  margin-top: 4px;
}

.counter-call-history-list {
  display: grid;
  gap: 10px;
}

.counter-call-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfefd;
}

.counter-call-history-number {
  display: block;
  font-size: 20px;
  font-weight: 900;
  word-break: break-all;
}

.counter-call-history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 5px;
}

.counter-call-history-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eef7f4;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.counter-call-history-status.missed {
  background: #fff1f0;
  color: var(--danger);
}

.counter-call-callback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  min-height: 42px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 900;
  text-decoration: none;
}

@media (max-width: 760px) {
  .counter-call-history-panel {
    margin: 0 12px 18px;
  }

  .counter-call-history-item {
    grid-template-columns: 1fr;
  }

  .counter-call-callback {
    width: 100%;
  }
}

.counter-call-history-name {
  display: block;
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.25;
  word-break: break-word;
}

.counter-call-history-name + .counter-call-history-number {
  margin-top: 4px;
  color: var(--muted);
  font-size: 17px;
}

/* Official website admin link */
.bm-official-site-link-body { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bm-official-site-link { min-width: 180px; text-align: center; text-decoration: none; }
.bm-official-site-link-body .mini { width: 100%; margin: 2px 0 0; }
@media (max-width: 700px) { .bm-official-site-link-body { align-items: stretch; } .bm-official-site-link { width: 100%; } }
.bm-official-site-entry-card { cursor: default; }
.bm-official-site-entry-card:hover { transform: none; }
.bm-official-site-quick-input { width: 100%; color: var(--ink); font-weight: 800; }
.bm-official-site-quick-input input { margin-top: 6px; width: 100%; }
.bm-official-site-entry-actions { display: flex; width: 100%; gap: 10px; flex-wrap: wrap; }
.bm-official-site-entry-actions .bm-official-site-link { flex: 1 1 180px; }
@media (max-width: 700px) { .bm-official-site-entry-actions .bm-official-site-link { flex-basis: 100%; } }
/* Full-screen recurring schedule management on phones. */
#recurringBookingOverlay { position: fixed; inset: 0; z-index: 15000; overflow: auto; background: rgba(0, 0, 0, .45); }
.recurring-management { width: min(900px, 96vw); max-height: 94dvh; overflow: auto; margin: 3dvh auto; }
.recurring-management form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.recurring-management form label { flex: 1; min-width: 160px; }
.recurring-management input { width: 100%; box-sizing: border-box; }
.recurring-management-row { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 0; border-bottom: 1px solid #ccd8d4; overflow-wrap: anywhere; }
.recurring-management-row > div { flex: 1; min-width: 180px; }
.recurring-management button { white-space: normal; }
#teacherForm label[hidden] { display: none !important; }
