/* ---------- Icons ---------- */
.icon {
  width: 24px; height: 24px; flex: 0 0 auto;
  display: inline-block;
  background-color: currentColor;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-size: contain; mask-size: contain;
}
.icon-img { width: 24px; height: 24px; flex: 0 0 auto; object-fit: contain; }

/* ---------- Buttons ---------- */
.btn {
  height: 44px; padding: 0 20px; border-radius: var(--r-xxxxl);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: var(--fs-m); font-weight: 700;
  background: var(--fw-primary); color: var(--fw-on-primary);
}
.btn:active { filter: brightness(.92); }
.btn:disabled { background: var(--fw-black-30); color: #fff; }
.btn.block { width: 100%; }
.btn.outline { background: transparent; color: var(--fw-primary); border: 1.5px solid var(--fw-primary); }
.btn.light { background: #fff; color: #000; }
.btn.neutral { background: var(--fw-black-10); color: var(--fw-text-primary); }
.btn.small { height: 36px; padding: 0 14px; font-size: var(--fs-sm); border-radius: var(--r-l); }
.btn.danger { background: var(--fw-red-1); color: #fff; }
.btn.text { background: transparent; color: var(--fw-primary); height: 36px; padding: 0 8px; font-weight: 600; }

.fab {
  position: absolute; right: 20px; bottom: 20px;
  width: 56px; height: 56px; border-radius: var(--r-round);
  background: var(--fw-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2);
  z-index: 4;
}
.fab .icon { width: 26px; height: 26px; }
.fab:active { filter: brightness(.94); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--fw-text-secondary); }
.input, .textarea, .select {
  height: 40px; border-radius: var(--r-m);
  background: var(--fw-surface); border: 1px solid var(--fw-outline-variant);
  padding: 0 var(--sp-m); font-size: var(--fs-m); color: var(--fw-text-primary);
  width: 100%;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--fw-primary); }
.textarea { height: auto; min-height: 88px; padding: 10px var(--sp-m); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--fw-text-secondary); }
.checkbox-row, .radio-row, .switch-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
}
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px; background: var(--fw-black-30); flex: 0 0 auto; transition: background .15s; }
.switch::after { content:""; position:absolute; top:2px; left:2px; width:24px; height:24px; border-radius:50%; background:#fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch.on { background: var(--fw-primary); }
.switch.on::after { transform: translateX(20px); }
.checkbox { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--fw-black-30); flex: 0 0 auto; display:flex;align-items:center;justify-content:center; }
.checkbox.checked { background: var(--fw-primary); border-color: var(--fw-primary); }
.checkbox.checked .icon { width: 14px; height: 14px; background: #fff; }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--fw-black-30); flex: 0 0 auto; display:flex;align-items:center;justify-content:center; }
.radio.checked { border-color: var(--fw-primary); }
.radio.checked::after { content:""; width: 12px; height: 12px; border-radius: 50%; background: var(--fw-primary); }

/* ---------- Avatars ---------- */
.avatar {
  border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; overflow: hidden; position: relative;
  background-size: cover; background-position: center;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xs { width: var(--avatar-xs); height: var(--avatar-xs); font-size: 10px; }
.avatar.s  { width: var(--avatar-s); height: var(--avatar-s); font-size: 12px; }
.avatar.m  { width: var(--avatar-m); height: var(--avatar-m); font-size: 15px; }
.avatar.ml { width: var(--avatar-ml); height: var(--avatar-ml); font-size: 18px; }
.avatar.l  { width: var(--avatar-l); height: var(--avatar-l); font-size: 20px; }
.avatar.xl { width: var(--avatar-xl); height: var(--avatar-xl); font-size: 26px; }
.avatar.xxl{ width: var(--avatar-xxl); height: var(--avatar-xxl); font-size: 40px; }
.avatar-badge {
  position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--fw-green); border: 2px solid var(--fw-surface);
}
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -10px; border: 2px solid var(--fw-surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--fw-surface-container); border-radius: var(--r-l);
  border: 1px solid var(--fw-outline);
}
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; min-height: 56px;
  background: var(--fw-surface);
  border-bottom: 1px solid var(--fw-outline);
}
.list-row:active { background: var(--fw-scrim-04); }
.list-row .icon { color: var(--fw-text-secondary); }
.list-row-title { font-size: var(--fs-m); color: var(--fw-text-primary); font-weight: 500; }
.list-row-sub { font-size: var(--fs-s); color: var(--fw-text-secondary); margin-top: 2px; }
.list-row.selected { background: var(--fw-primary-container); }
.list-section-header {
  padding: 8px 16px; font-size: var(--fs-s); font-weight: 700; letter-spacing: .04em;
  color: var(--fw-text-secondary); text-transform: uppercase; background: var(--fw-bg);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: var(--r-round); background: var(--fw-black-5); font-size: var(--fs-sm); font-weight: 600;
  color: var(--fw-text-primary); border: 1px solid transparent;
}
.chip.active { background: var(--fw-primary); color: #fff; }
.badge {
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--fw-red-3);
  color: #fff; font-size: 11px; font-weight: 700; display:flex;align-items:center;justify-content:center;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 48px 32px; gap: 12px; color: var(--fw-text-secondary);
}
.empty-state .icon-img, .empty-state .icon { width: 96px; height: 96px; opacity: .8; }
.empty-state h3 { font-size: var(--fs-l); color: var(--fw-text-primary); font-weight: 700; }
.empty-state p { font-size: var(--fs-sm); max-width: 320px; }

/* ---------- Modal / dialog ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fade-in .15s ease;
  padding: 20px;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
.dialog {
  background: var(--fw-surface); border-radius: var(--r-xl); width: 100%; max-width: 380px;
  padding: 24px; box-shadow: var(--shadow-3);
  animation: pop-in .18s cubic-bezier(.2,.8,.3,1.2);
}
@keyframes pop-in { from { transform: scale(.92); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.dialog h2 { font-size: var(--fs-xl); font-weight: 700; margin-bottom: 8px; }
.dialog p { font-size: var(--fs-m); color: var(--fw-text-secondary); line-height: 1.4; margin-bottom: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .btn { height: 40px; padding: 0 16px; }

.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .15s ease;
}
.sheet {
  background: var(--fw-surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; padding: 8px 0 calc(16px + var(--safe-b));
  animation: sheet-up .22s cubic-bezier(.2,.8,.3,1);
  box-shadow: 0 -8px 24px rgba(0,0,0,.18);
}
@keyframes sheet-up { from { transform: translateY(100%) } to { transform: translateY(0) } }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--fw-black-20); margin: 8px auto 12px; }
.sheet-title { font-size: var(--fs-l); font-weight: 700; padding: 0 20px 12px; }
.sheet-row {
  display: flex; align-items: center; gap: 16px; padding: 14px 20px; font-size: var(--fs-m);
}
.sheet-row:active { background: var(--fw-scrim-04); }
.sheet-row .icon { color: var(--fw-primary); }

/* ---------- Toast ---------- */
#toast-host { position: fixed; left: 0; right: 0; bottom: calc(24px + var(--safe-b) + var(--bottomnav-h)); display:flex; justify-content:center; z-index: 200; pointer-events:none; }
.toast {
  background: var(--fw-black-85); color: #fff; padding: 12px 20px; border-radius: var(--r-round);
  font-size: var(--fs-sm); font-weight: 600; box-shadow: var(--shadow-2);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { transform: translateY(12px); opacity:0 } to { transform: translateY(0); opacity:1 } }

/* ---------- Segmented control / tabs ---------- */
.segmented { display: flex; background: var(--fw-black-5); border-radius: var(--r-m); padding: 3px; gap: 2px; }
.segmented button { flex: 1; height: 32px; border-radius: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--fw-text-secondary); }
.segmented button.active { background: var(--fw-surface); color: var(--fw-text-primary); box-shadow: var(--shadow-1); }

.tabs { display: flex; border-bottom: 1px solid var(--fw-outline); background: var(--fw-surface); overflow-x: auto; }
.tabs button { padding: 12px 18px; font-size: var(--fs-sm); font-weight: 600; color: var(--fw-text-secondary); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--fw-primary); border-color: var(--fw-primary); }

/* ---------- Loading ---------- */
.loading-pane { display: flex; align-items: center; justify-content: center; height: 100%; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--fw-outline-variant); border-top-color: var(--fw-primary); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: var(--fw-skeleton); border-radius: var(--r-m); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .5 } }

/* ---------- Speed-dial FAB (quick share) ---------- */
.speed-dial-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 90; }
.speed-dial { position: absolute; right: 20px; bottom: 20px; display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 12px; z-index: 95; }
.speed-dial-item { display: flex; align-items: center; gap: 10px; }
.speed-dial-item .label { background: var(--fw-black-85); color: #fff; font-size: var(--fs-sm); font-weight: 600; padding: 6px 12px; border-radius: var(--r-round); }
.speed-dial-item .mini-fab { width: 44px; height: 44px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-2); display: flex; align-items: center; justify-content: center; color: var(--fw-primary); }

/* ---------- Assistant (global voice/text quick-add) ---------- */
.assistant-fab {
  /* The FAB is only ever shown while logged in, same as the bottom tab
     bar — so it always needs to clear it, not just conditionally.
     --fab-bottom-bar-h is set by assistant-widget.js on every navigation —
     some screens (a list's "Add an item" bar, a thread's compose bar) have
     their own fixed-height bar sitting in that same bottom band, which the
     FAB would otherwise sit on top of. */
  position: fixed; left: calc(20px + var(--safe-l)); bottom: calc(20px + var(--safe-b) + var(--bottomnav-h) + var(--fab-bottom-bar-h, 0px));
  width: 56px; height: 56px; border-radius: var(--r-round);
  background: var(--fw-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2); z-index: 60; border: none;
}
.assistant-fab:active { filter: brightness(.94); }
.assistant-fab .icon { width: 26px; height: 26px; }
.assistant-modal { display: flex; flex-direction: column; gap: 14px; }
.assistant-modal textarea {
  width: 100%; min-height: 72px; border-radius: var(--r-m); background: var(--fw-black-5);
  border: 1px solid var(--fw-outline-variant); padding: 10px 12px; font-size: var(--fs-m);
  color: var(--fw-text-primary); resize: none;
}
.assistant-row { display: flex; align-items: center; gap: 10px; }
.assistant-mic {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  background: var(--fw-black-5); display: flex; align-items: center; justify-content: center; color: var(--fw-text-secondary);
}
.assistant-mic.recording { background: var(--fw-red-2); color: #fff; animation: pulse 1s ease-in-out infinite; }
.assistant-mic[disabled] { opacity: .35; }
.assistant-hint { font-size: var(--fs-xs); color: var(--fw-text-secondary); text-align: center; }
.assistant-results { display: flex; flex-direction: column; gap: 8px; }
.assistant-result-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--fw-black-5); border-radius: var(--r-m); font-size: var(--fs-sm);
}
.assistant-result-row.failed { color: var(--fw-red-1); }
.assistant-result-row .txt { flex: 1; }
.assistant-result-row .undo { font-size: var(--fs-xs); font-weight: 700; color: var(--fw-primary); }

/* ---- ClassDojo screen (read-only Story + Messages bridge) ---- */
.cd-tabs { display: flex; gap: 4px; padding: 8px 12px; position: sticky; top: 0; z-index: 2;
  background: var(--fw-surface); border-bottom: 1px solid var(--fw-outline-variant); }
.cd-tab { flex: 1; padding: 8px 0; border: none; background: transparent; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--fw-text-secondary); cursor: pointer; }
.cd-tab.active { background: var(--fw-primary-container); color: var(--fw-primary); }
.cd-list { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.cd-loading { display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 32px 0; color: var(--fw-text-secondary); font-size: var(--fs-sm); }
.cd-banner { display: flex; gap: 10px; align-items: flex-start; margin: 10px 12px 0;
  padding: 10px 12px; border-radius: 12px; background: var(--fw-surface-container);
  font-size: var(--fs-xs); line-height: 1.4; }
.cd-banner-warn { background: color-mix(in srgb, var(--fw-orange) 16%, transparent); }
.cd-banner code { font-size: 0.9em; background: var(--fw-black-10); padding: 1px 4px; border-radius: 4px; }
.cd-card { background: var(--fw-surface); border: 1px solid var(--fw-outline-variant);
  border-radius: 14px; padding: 12px 14px; }
.cd-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cd-card-title { font-weight: 700; font-size: var(--fs-sm); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-card-time { color: var(--fw-text-secondary); font-size: var(--fs-xxs); flex: 0 0 auto; }
.cd-card-body { margin-top: 6px; font-size: var(--fs-sm); line-height: 1.45; white-space: pre-wrap; }
.cd-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cd-attach { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--fw-surface-container); }
.cd-attach-link { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs);
  color: var(--fw-primary); text-decoration: none; }
.cd-card-meta { margin-top: 8px; display: flex; align-items: center; gap: 4px;
  color: var(--fw-text-secondary); font-size: var(--fs-xxs); }
.cd-card-meta .icon { vertical-align: middle; }
.cd-msg-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--fw-surface); border: 1px solid var(--fw-outline-variant); border-radius: 12px; }
.cd-msg-row.cd-unread { border-color: var(--fw-primary); }
.cd-msg-main { flex: 1; min-width: 0; }
.cd-msg-top { display: flex; justify-content: space-between; gap: 8px; }
.cd-msg-name { font-weight: 700; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-msg-preview { color: var(--fw-text-secondary); font-size: var(--fs-xs); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-badge { flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--fw-primary); color: var(--fw-on-primary); font-size: var(--fs-xxs);
  font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* ---- ClassDojo: chat thread, chevrons, lightbox ---- */
.cd-msg-row { width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.cd-msg-chevron { flex: 0 0 auto; opacity: .5; }
.cd-chat { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.cd-chat-row { display: flex; }
.cd-chat-row.mine { justify-content: flex-end; }
.cd-chat-col { max-width: 78%; width: fit-content; display: flex; flex-direction: column; }
.cd-chat-row.mine .cd-chat-col { align-items: flex-end; }
.cd-chat-sender { font-size: var(--fs-xxs); color: var(--fw-text-secondary); margin: 0 0 2px 6px; }
.cd-bubble { background: var(--fw-surface-container); padding: 8px 12px; border-radius: 14px;
  font-size: var(--fs-sm); line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.cd-chat-row.mine .cd-bubble { background: var(--fw-primary); color: var(--fw-on-primary); }
.cd-chat-time { font-size: var(--fs-xxs); color: var(--fw-text-secondary); margin: 2px 6px 0; }
.cd-readonly-note { display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px; font-size: var(--fs-xxs); color: var(--fw-text-secondary);
  border-top: 1px solid var(--fw-outline-variant); background: var(--fw-surface); }
.cd-attach { cursor: zoom-in; }
.cd-lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.cd-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.cd-lightbox-close { position: absolute; top: 16px; right: 16px; width: 40px; height: 40px;
  border: none; border-radius: 50%; background: rgba(255,255,255,.15); cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.cd-lightbox-close .icon { background-color: #fff; }

/* ClassDojo: which parent's inbox a thread belongs to (only shown with 2+ accounts) */
.cd-acct-tag { margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: var(--fs-xxs);
  font-weight: 600; background: var(--fw-primary-container); color: var(--fw-primary); vertical-align: middle; }

/* ClassDojo: message compose bar */
.cd-compose { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  border-top: 1px solid var(--fw-outline-variant); background: var(--fw-surface); }
.cd-compose textarea { flex: 1; resize: none; border: 1px solid var(--fw-outline-variant);
  border-radius: 18px; padding: 9px 14px; font: inherit; font-size: var(--fs-sm);
  background: var(--fw-surface-container); color: var(--fw-text-primary); max-height: 120px; line-height: 1.35; }
.cd-send { flex: 0 0 auto; width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--fw-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.cd-send:disabled { opacity: .5; }
.cd-send .icon { background-color: var(--fw-on-primary); }
