/* The shared parts (app/src/ui/*.tsx). Every value is a token from tokens.css. */

/* ---- Button */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--touch); padding: 0 var(--s5); border-radius: var(--r-control);
  font: 600 var(--t-md)/1.2 var(--sans); text-decoration: none; white-space: nowrap;
  border: 1.5px solid transparent; cursor: pointer; transition: background-color var(--quick), border-color var(--quick);
}
.ui-btn:disabled, .ui-btn[aria-disabled=true] { cursor: default }
.ui-primary { background: var(--action); color: var(--on-action) }
.ui-primary:hover:not(:disabled) { background: var(--action-hover) }
.ui-primary:disabled:not([aria-busy]) { background: var(--disabled) }
.ui-secondary { background: var(--surface-card); color: var(--action); border-color: var(--action) }
.ui-secondary:hover:not(:disabled) { background: var(--action-soft) }
.ui-secondary[aria-pressed=true] { background: var(--action); color: var(--on-action) }
/* pressed stays pressed under the pointer: a phone's last tap leaves it there, and the pale hover fill under white text read 1.15 to 1 */
.ui-secondary[aria-pressed=true]:hover:not(:disabled) { background: var(--action-hover) }
.ui-quiet { background: none; color: var(--text-muted) }
.ui-quiet:hover:not(:disabled) { background: var(--surface-soft); color: var(--text) }
/* in a dialog, a sheet or a menu every button has an edge, so none reads as floating text (Moti, walk 6: "a border on all buttons in the menus") */
.ui-dialog .ui-quiet, .ui-sheet-left .ui-quiet, .ui-menu .ui-quiet { border-color: var(--line-strong) }
.ui-danger { background: var(--surface-card); color: var(--count-ink); border-color: var(--count) }
.ui-danger:hover:not(:disabled) { background: var(--surface-soft) }
.ui-link { background: none; color: var(--action); padding: 0 var(--s1); text-decoration: underline; text-underline-offset: 3px }
.ui-secondary:disabled:not([aria-busy]), .ui-quiet:disabled, .ui-danger:disabled, .ui-link:disabled { opacity: .5 }
.ui-sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--t-sm) }
.ui-sm.ui-icon { width: 36px }
.ui-icon { width: var(--touch); padding: 0; border-radius: var(--r-pill); font-size: var(--t-lg) }
.ui-block { width: 100%; white-space: normal }   /* a full-width button wraps a long name rather than leaving the screen */
.ui-back {
  display: inline-flex; align-items: center; gap: var(--s1); align-self: flex-start; min-height: var(--touch);
  padding: 0 var(--s2); margin: 0 0 var(--s3) calc(-1 * var(--s2)); border-radius: var(--r-control);
  font: 600 var(--t-md)/1.2 var(--sans); color: var(--action); text-decoration: none;
}
.ui-back > span { font-size: var(--t-lg) }
.ui-back:hover { background: var(--surface-soft) }
.ui-spin { width: 1em; height: 1em; border-radius: var(--r-pill); border: 2px solid currentColor; border-right-color: transparent; animation: ui-spin .7s linear infinite }
@keyframes ui-spin { to { transform: rotate(360deg) } }

/* ---- Field */
.ui-field { display: block; margin: 0 0 var(--s4) }
.ui-label { display: block; font: 600 var(--t-sm)/1.3 var(--sans); margin: 0 0 var(--s1); color: var(--text) }
.ui-hint { display: block; font-size: var(--t-sm); color: var(--text-muted); margin: var(--s1) 0 0 }
.ui-labelline { display: flex; align-items: baseline; gap: var(--s1); margin: 0 0 var(--s1) }
.ui-labelline .ui-label { margin: 0 }
.ui-need { font-size: var(--t-sm); color: var(--text-muted) }
.ui-input {
  width: 100%; min-height: var(--touch); border: 1px solid var(--line); border-radius: var(--r-control);
  padding: 10px var(--s3); background: var(--surface-card); font: var(--t-base)/var(--lh) var(--sans); color: var(--text);
}
/* iOS WebKit gives a date its own width, wider than a phone's card (Moti, 2026-10-29: "picking a saturday date extends
   off screen"); without its native look it takes the field's width, and its value sits left like every other field's */
.ui-input:is([type=date], [type=time], [type=datetime-local], [type=month]) { -webkit-appearance: none; appearance: none; min-width: 0; display: block; box-sizing: border-box }
.ui-input::-webkit-date-and-time-value { text-align: left }
.ui-input:focus-visible { border-color: var(--action) }
.ui-input[aria-invalid=true] { border-color: var(--count) }
textarea.ui-input { min-height: 140px; background: var(--surface-input); resize: vertical }
.ui-error { display: block; color: var(--count-ink); font: 600 var(--t-sm)/1.3 var(--sans); margin: var(--s1) 0 0 }

/* ---- Card */
.ui-card { background: var(--surface-card); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s4) var(--s4) }
.ui-card.ui-clergy { background: var(--needs-soft); border: 0; border-left: 4px solid var(--needs) }
.ui-card.ui-ask { background: var(--action); border: 0; color: var(--on-action) }
.ui-card.ui-note { background: var(--action-soft); border-color: var(--action) }
.ui-card > :first-child { margin-top: 0 }
.ui-card > :last-child { margin-bottom: 0 }
/* a button set straight in a card, under something else, keeps the standard gap (Moti, 2026-11-09: "no padding") */
.ui-card > :not(.ui-btn) + .ui-btn { margin-top: var(--s3) }

/* ---- Chip and Count */
.ui-chip { display: inline-flex; align-items: center; font: 700 var(--t-xs)/1 var(--sans); padding: 5px 9px; border-radius: var(--r-pill); white-space: nowrap; flex: none }
.ui-chip.ui-good { background: var(--good-soft); color: var(--action) }
.ui-chip.ui-needs { background: var(--needs-soft); color: var(--needs-ink) }
.ui-chip.ui-quiet { background: var(--quiet-soft); color: var(--text-muted) }
.ui-chip.ui-live { background: var(--action-soft); color: var(--action); text-transform: uppercase; letter-spacing: var(--caps) }
.ui-chip.ui-stop { background: var(--count-soft); color: var(--stop-ink) }
.ui-chip.ui-edge { box-shadow: inset 0 0 0 1.5px var(--edge, currentColor) }
.ui-chip.ui-edge.ui-good { --edge: var(--good) }
.ui-chip.ui-edge.ui-needs { --edge: var(--needs) }
.ui-chip.ui-edge.ui-stop { --edge: var(--count) }
.ui-chipbtn { border: 0; gap: var(--s1); font-size: var(--t-sm); padding: var(--s2) var(--s3); min-height: 32px; cursor: pointer }
.ui-chipbtn:hover { box-shadow: inset 0 0 0 1px currentColor }
.ui-count { display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--count); color: var(--on-action); font: 700 var(--t-xs)/20px var(--sans); text-align: center; flex: none }

/* ---- Segmented */
/* as wide as its words: a column or grid around it would otherwise stretch it, the last choice seeming to fill the row */
.ui-seg { display: inline-flex; width: fit-content; max-width: 100%; flex-wrap: wrap; border: 1.5px solid var(--line-strong); border-radius: var(--r-control); overflow: hidden; background: var(--surface-card) }
.ui-seg button { border: 0; background: none; padding: 0 var(--s4); min-height: var(--touch); font: 600 var(--t-md) var(--sans); color: var(--action) }
.ui-seg button + button { border-left: 1px solid var(--line) }
.ui-seg button[data-state=on] { background: var(--action); color: var(--on-action) }

/* ---- Choice: cards, one chosen; Choices: several */
.ui-choice { display: grid; gap: var(--s2) }
.ui-copt {
  display: flex; gap: var(--s3); align-items: center; width: 100%; min-height: 64px; padding: var(--s3) var(--s4);
  background: var(--surface-card); border: 2px solid var(--line); border-radius: var(--r-control);
  color: var(--text); text-align: left; font: inherit; cursor: pointer;
}
.ui-copt:hover { border-color: var(--line-strong) }
.ui-copt[data-state=on] { border-color: var(--action) }
.ui-copt[data-disabled] { cursor: default }
.ui-ccheck { width: 24px; height: 24px; border-radius: var(--r-pill); border: 2px solid var(--line-strong); flex: none; display: grid; place-items: center }
.ui-copt[data-state=on] .ui-ccheck { background: var(--action); border-color: var(--action) }
.ui-copt[data-state=on] .ui-ccheck::after { content: '✓'; color: var(--on-action); font: 700 var(--t-sm)/1 var(--sans) }

/* ---- Sheet and Dialog */
.ui-scrim { position: fixed; inset: 0; z-index: 200; background: var(--scrim); animation: ui-fade var(--quick) ease-out }
.ui-dialog {
  /* clear of a phone's clock and home bar: the app draws under both. Its top stays put, so what opens inside it grows
     it downward and nothing above moves (Moti, 2026-11-10: "make the modal not jump around") */
  --dlg-top: calc(env(safe-area-inset-top) + min(8dvh, 72px));
  position: fixed; z-index: 201; left: 50%; top: var(--dlg-top); transform: translateX(-50%);
  width: min(720px, calc(100vw - var(--s8))); max-height: calc(100dvh - var(--dlg-top) - var(--s4) - env(safe-area-inset-bottom));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-float); animation: ui-fade var(--quick) ease-out;
}
.ui-dialog.ui-narrow { width: min(420px, calc(100vw - var(--s8))) }
/* a whole page's worth, like the library over a lesson: the full screen on a phone, a large window on a computer */
.ui-dialog.ui-wide { top: calc(50% + (env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2); transform: translate(-50%, -50%); width: min(960px, calc(100vw - var(--s8))); height: calc(100dvh - var(--s8) - env(safe-area-inset-top) - env(safe-area-inset-bottom)); max-height: none }
@media (max-width: 640px) {
  .ui-dialog.ui-wide { top: 50%; width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0 }
  .ui-dialog.ui-wide .ui-shd { padding-top: calc(var(--s2) + env(safe-area-inset-top)) }
  .ui-dialog.ui-wide .ui-sbd { padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom)) }
}
.ui-sheet-left {
  position: fixed; z-index: 201; left: 0; top: 0; bottom: 0; width: min(340px, 86vw);
  display: flex; flex-direction: column; background: var(--surface-bar); box-shadow: var(--shadow-float);
  padding-top: env(safe-area-inset-top); animation: ui-slide var(--quick) ease-out;
}
.ui-shd { display: flex; gap: var(--s2); align-items: center; padding: var(--s2) var(--s2) var(--s2) var(--s4); background: var(--surface-bar); border-bottom: 1px solid var(--line) }
.ui-shd h2 { flex: 1; margin: 0; font: 600 var(--t-xl)/var(--lh-tight) var(--serif) }
.ui-sbd { padding: var(--s4); overflow: auto }
.ui-sdesc { margin: 0 0 var(--s3); color: var(--text-muted) }
@keyframes ui-fade { from { opacity: 0 } }
@keyframes ui-slide { from { transform: translateX(-100%) } }

/* ---- Menu */
.ui-menu { min-width: 240px; max-width: min(340px, var(--radix-dropdown-menu-content-available-width)); background: var(--surface-card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-float); padding: var(--s2); z-index: 210; animation: ui-fade var(--quick) ease-out }
.ui-mitem { display: flex; align-items: center; gap: var(--s2); min-height: var(--touch); padding: 0 var(--s3); border-radius: var(--r-control); font: 500 var(--t-md) var(--sans); cursor: pointer; outline: none; user-select: none }
.ui-mitem[data-highlighted] { background: var(--surface-soft) }
.ui-mitem[data-highlighted]:focus-visible, .ui-mitem:focus-visible { box-shadow: inset 0 0 0 3px var(--focus), inset 0 0 0 5px var(--focus-edge) }
.ui-msep { height: 1px; background: var(--line); margin: var(--s1) 0 }
.ui-mlabel { padding: var(--s2) var(--s2) var(--s3); border-bottom: 1px solid var(--line); margin-bottom: var(--s1) }

/* ---- ListRow */
.ui-list { display: grid; gap: var(--s2) }
.ui-lrow {
  display: flex; gap: var(--s3); align-items: center; width: 100%; min-height: 64px; padding: var(--s3) var(--s4);
  background: var(--surface-card); border: 2px solid transparent; border-radius: var(--r-control); box-shadow: 0 0 0 1px var(--line);
  color: var(--text); text-decoration: none; text-align: left; font: inherit;
}
a.ui-lrow:hover, button.ui-lrow:hover { box-shadow: 0 0 0 1px var(--action) }
.ui-lrow[aria-current] { border-color: var(--action) }
.ui-lrow.ui-locked { opacity: .7 }
.ui-lead { width: 32px; height: 32px; border-radius: var(--r-pill); display: grid; place-items: center; flex: none; font-weight: 700; background: var(--quiet-soft); color: var(--text-muted) }
.ui-lead.ui-done { background: var(--action); color: var(--on-action) }
.ui-lead.ui-cur { background: var(--good-soft); color: var(--action) }
.ui-lead.ui-blue { background: var(--link-soft); color: var(--link); text-decoration: none; padding: 0 }
.ui-lbody { flex: 1; min-width: 0 }
.ui-lbody b { display: block; font-size: var(--t-base) }
.ui-lbody span { display: block; font-size: var(--t-sm); color: var(--text-muted) }

/* ---- SectionHead and Kicker */
.ui-kicker { margin: 0; font: 700 var(--t-xs)/1.3 var(--sans); letter-spacing: var(--caps); text-transform: uppercase; color: var(--text-muted) }
.ui-shead { display: flex; gap: var(--s2); align-items: center; margin: var(--s5) 2px var(--s2) }

/* ---- Page, Stack, Row */
.ui-page { margin: 0 auto; padding: var(--s5) var(--s4) var(--s12) }
.ui-page.ui-column { max-width: calc(760px + 2 * var(--s4)) }
.ui-page > h1 + p { margin: var(--s2) 0 var(--s4) }
.ui-page > .ui-card { margin: var(--s3) 0 }
.ui-page.ui-wide { max-width: calc(1120px + 2 * var(--s4)) }
.ui-stack { display: flex; flex-direction: column }
.ui-row { display: flex; align-items: center; flex-wrap: wrap }
.ui-grow { flex: 1; min-width: 0 }
.ui-title { margin: 0; font: 600 var(--t-2xl)/var(--lh-tight) var(--serif) }
.ui-title small { display: block; font: 400 var(--t-sm)/1.4 var(--sans); color: var(--text-muted) }
.ui-titlerow { display: flex; gap: var(--s3); align-items: flex-start; justify-content: space-between }
.ui-titlerow .ui-title { flex: 1; min-width: 0 }
.ui-titlerow > .ui-btn { flex: none }

/* ---- Hebrew */
.ui-he { font-family: var(--hebrew); font-weight: 500; line-height: var(--lh-hebrew) }
.ui-he.ui-stam { font-family: var(--hebrew-stam); font-weight: 400 }
.ui-he.ui-sefarad { font-family: var(--hebrew-sefarad); font-weight: 400 }
.ui-he.ui-s { font-size: var(--he-s) } .ui-he.ui-m { font-size: var(--he-m) } .ui-he.ui-l { font-size: var(--he-l) }

/* ---- Avatar and SaveState */
.ui-av { display: inline-grid; place-items: center; border-radius: var(--r-pill); color: var(--on-action); font-weight: 700; flex: none; line-height: 1 }
.ui-glyph { display: inline-block; vertical-align: -0.125em; flex: none }
.ui-save { margin: var(--s2) 0 0; font-size: var(--t-sm); color: var(--text-muted) }
.ui-save.ui-failed { color: var(--count-ink); font-weight: 600 }

/* ---- Notice and the toasts */
.ui-notice { display: flex; gap: var(--s3); align-items: center; padding: var(--s2) var(--s2) var(--s2) var(--s3); border-radius: var(--r-control); border: 1px solid; font-size: var(--t-md); color: var(--text); min-height: var(--touch) }
.ui-notice.ui-n-success { background: var(--good-soft); border-color: var(--good) }
.ui-notice.ui-n-error { background: var(--count-soft); border-color: var(--count) }
.ui-notice.ui-n-info { background: var(--link-soft); border-color: var(--link-edge) }
/* a notice under the button that caused it keeps its distance (Moti, 2026-10-01: "no padding between button and notification") */
.ui-btn + .ui-notice { margin-top: var(--s3) }
.ui-nicon { width: 24px; height: 24px; border-radius: var(--r-pill); display: grid; place-items: center; flex: none; font: 700 var(--t-sm)/1 var(--sans); color: var(--on-action) }
.ui-n-success .ui-nicon { background: var(--good) } .ui-n-error .ui-nicon { background: var(--count-ink) } .ui-n-info .ui-nicon { background: var(--link) }
.ui-ntext { flex: 1; min-width: 0 }
.ui-toasts { position: fixed; z-index: 300; left: 0; right: 0; top: calc(var(--s3) + env(safe-area-inset-top)); display: grid; gap: var(--s2); justify-items: center; padding: 0 var(--s4); pointer-events: none }
.ui-toast { width: min(460px, 100%); pointer-events: auto; box-shadow: var(--shadow-float); border-radius: var(--r-control); opacity: 0; transform: translateY(-8px); transition: opacity var(--quick), transform var(--quick) }
.ui-toast.ui-in { opacity: 1; transform: none }

/* ---- CopyField */
.ui-copy { display: flex; gap: var(--s2) }
.ui-copy .ui-input { flex: 1; min-width: 0; font-size: var(--t-sm); background: var(--surface-soft); text-overflow: ellipsis }

/* ---- Loader: GabChai, what is getting ready, and how far along */
.ui-loader { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s5) var(--s4); text-align: center }
.ui-loader-cover { position: absolute; inset: 0; z-index: 3; background: var(--surface); transition: opacity .5s ease-out }
.ui-loader-gc { width: 96px; height: 96px; object-fit: contain; animation: ui-bob 1.6s ease-in-out infinite }
.ui-loader-label { margin: 0; font: 600 var(--t-lg) var(--serif); color: var(--text) }
/* a room's loader: GabChai's tallit video on its own black (Loader, tallit) */
.ui-loader-tallit { background: var(--greeting-black) }
/* a room's loader is GabChai alone: its line is for a screen reader only (Moti, 2026-10-27: "remove the text too") */
.ui-loader-tallit .ui-loader-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap }
.ui-loader-video { height: min(42dvh, 320px); aspect-ratio: 464 / 688; object-fit: contain }
@keyframes ui-bob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }

@media (prefers-reduced-motion: reduce) {
  .ui-toast { transition: none; transform: none }
  .ui-btn { transition: none }
  .ui-scrim, .ui-dialog, .ui-sheet-left, .ui-menu { animation: none }
  .ui-spin { animation: none }
  .ui-loader-gc { animation: none }
  .ui-loader-cover { transition: none }
}
.ui-confirm-body { margin: 0 0 var(--s3) }
.ui-colors { display: flex; flex-wrap: wrap; gap: var(--s2) }
.ui-colors button { padding: 2px; border: 0; background: none; border-radius: var(--r-pill); cursor: pointer; min-width: var(--touch); min-height: var(--touch); display: inline-flex; align-items: center; justify-content: center }
.ui-colors button[aria-checked=true] { box-shadow: 0 0 0 2px var(--surface-card), 0 0 0 4px var(--text) }
