/* Custom controls: pick (select popover), date and month pickers, segmented tabs, modal, drawer, toast. */

/* Pick trigger looks like an input */
.pick { display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; height: 34px; min-width: 130px; padding: 0 10px 0 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--input-bg); cursor: pointer; text-align: left; white-space: nowrap; }
.pick.is-block { width: 100%; height: 36px; }
.pick:hover { border-color: var(--faint); }
.pick .pick-text { overflow: hidden; text-overflow: ellipsis; }
.pick .pick-text.is-placeholder { color: var(--faint); }
.pick svg { width: 14px; height: 14px; color: var(--faint); flex: none; }

/* Popover */
.pop { position: fixed; z-index: 80; min-width: 180px; max-height: 320px; overflow-y: auto; background: var(--elevated); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-pop); padding: 4px; opacity: 0; transform: translateY(-7px) scale(0.96); transform-origin: top left; transition: opacity 140ms ease, transform 170ms var(--pop-spring); }
.pop.is-open { opacity: 1; transform: none; transition: opacity 150ms var(--pop-spring), transform 185ms var(--pop-spring); }
.pop-search { padding: 4px 4px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.pop-search .input { height: 32px; }
.opt { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; white-space: nowrap; }
.opt:hover, .opt.is-active { background: var(--selected); }
.opt.is-selected { font-weight: 500; }
.opt .opt-check { margin-left: auto; width: 14px; height: 14px; color: var(--text); }
.opt small { color: var(--faint); margin-left: 6px; }
.opt-empty { padding: 10px; color: var(--faint); font-size: 13px; }

/* Calendar (date range and single date) */
.cal { padding: 10px; width: 272px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-weight: 500; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { font-size: 11px; color: var(--faint); text-align: center; height: 24px; line-height: 24px; }
.cal-day { height: 34px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; font-family: var(--font-num); font-size: 13px; font-variant-numeric: tabular-nums; }
.cal-day:hover { background: var(--selected); }
.cal-day.is-out { color: var(--faint); opacity: 0.5; }
.cal-day.is-today { box-shadow: inset 0 0 0 1px var(--border-strong); }
.cal-day.is-in { background: var(--selected); border-radius: 0; }
.cal-day.is-edge { background: var(--text); color: var(--bg); }
.cal-foot { display: flex; justify-content: space-between; gap: 6px; padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--border); }

/* Month picker */
.months-head { padding: 6px 6px 0; }
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 6px; width: 240px; }
.months .cal-day { font-family: var(--font-text); }
.months .cal-day.is-edge { background: var(--text); color: var(--bg); }

/* Segmented tabs */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.seg button { height: 28px; padding: 0 12px; border: 0; background: transparent; border-radius: 6px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.is-on { background: var(--selected); color: var(--text); }

/* Switch (for yes/no settings) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; border: 0; background: transparent; padding: 0; }
.switch-track { width: 34px; height: 20px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background var(--t-fast) var(--ease); }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--elevated); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform var(--t-fast) var(--ease); }
.switch.is-on .switch-track { background: var(--text); }
.switch.is-on .switch-track::after { transform: translateX(14px); background: var(--bg); }

/* Modal */
.scrim { position: fixed; inset: 0; z-index: 70; background: var(--scrim); display: grid; place-items: center; padding: 16px; opacity: 0; transition: opacity 165ms ease; }
.scrim.is-open { opacity: 1; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--elevated); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-pop); opacity: 0; transform: translateY(10px) scale(0.955); transition: opacity 155ms ease, transform 195ms var(--pop-spring); }
.scrim.is-open .modal { opacity: 1; }
.modal.is-wide { max-width: 760px; }
.scrim.is-open .modal { transform: none; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head .btn-icon { margin-left: auto; }
.modal-sub { padding: 0 20px; color: var(--muted); font-size: 13px; }
.modal-body { padding: 16px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.modal-error { color: var(--danger); font-size: 13px; min-height: 18px; padding: 0 20px; }

/* Drawer: staff detail, payslip */
.drawer-scrim { place-items: stretch end; padding: 0; }
.drawer { width: min(560px, 100vw); height: 100vh; overflow-y: auto; background: var(--elevated); border-left: 1px solid var(--border-strong); transform: translateX(28px); opacity: 1; transition: transform 240ms var(--spring); }
.scrim.is-open .drawer { transform: none; }
.drawer .modal-body { display: flex; flex-direction: column; gap: 18px; }
.drawer h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* Payslip lines in the drawer */
.slip { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.slip td { padding: 7px 0; border-bottom: 1px solid var(--border); }
.slip td:last-child { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.slip tr.slip-total td { font-weight: 600; border-bottom: 0; border-top: 1px solid var(--border-strong); }

/* Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--elevated); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow-pop); font-size: 13.5px; max-width: 360px; opacity: 0; transform: translateY(14px) scale(0.96); transition: opacity 165ms ease, transform 200ms var(--pop-spring); }
.toast.is-on { opacity: 1; transform: none; }
.toast.is-danger { border-color: var(--danger); color: var(--danger-ink); }

/* Notice banner inside a page */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-tile); background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; }
.notice.is-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn-ink); }
.notice.is-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger-ink); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

/* Phones: pop-ups rise from the bottom as sheets; menus never run off screen; toasts sit above the tab bar. */
@media (max-width: 760px) {
  .scrim:not(.drawer-scrim) { place-items: end stretch; padding: 0; }
  .scrim:not(.drawer-scrim) .modal, .scrim:not(.drawer-scrim) .modal.is-wide { max-width: none; max-height: 92vh; border-radius: 16px 16px 0 0; border-bottom: 0;
    transform: translateY(40px); padding-bottom: env(safe-area-inset-bottom); }
  .scrim.is-open:not(.drawer-scrim) .modal { transform: none; }
  .modal::before { content: ''; display: block; width: 36px; height: 4px; border-radius: 99px; background: var(--border-strong); margin: 8px auto 0; }
  .modal-head { padding: 12px 16px 4px; }
  .modal-sub, .modal-error { padding-left: 16px; padding-right: 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { position: sticky; bottom: 0; background: var(--elevated); padding: 10px 16px 14px; border-top: 1px solid var(--border); }
  .modal-foot:empty { display: none; }
  .modal-foot .btn { flex: 1; justify-content: center; }
  .drawer { width: 100vw; border-left: 0; }
  .pop { max-width: calc(100vw - 16px); max-height: 60vh; }
  .opt { height: 42px; }
  .cal { width: min(300px, calc(100vw - 32px)); }
  .cal-day { height: 38px; }
  .toasts { left: 12px; right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
  .seg button { height: 32px; }
}

/* Motion, matched to CRM v3: pages slide up as they arrive, buttons give a little when pressed,
   segmented tabs and calendars glide, and a just-saved thing glows once. */
@keyframes hrPageIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes hrBodyIn { from { opacity: 0; transform: translateY(6px); } }
@keyframes hrCalNext { from { opacity: 0.4; transform: translateX(10px); } }
@keyframes hrCalPrev { from { opacity: 0.4; transform: translateX(-10px); } }
@keyframes hrGlow { 0% { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 6px var(--accent-soft); } 100% { box-shadow: 0 0 0 0 transparent; } }
.page { animation: hrPageIn 210ms var(--spring) both; }
.modal-body, .drawer .modal-body { animation: hrBodyIn 195ms var(--spring) both; }
.btn, .seg button, .opt, .cal-day, .switch, .pick { transition: transform 95ms var(--pop-spring), background 130ms ease, border-color 130ms ease, color 130ms ease, box-shadow 130ms ease; }
.btn:active:not(:disabled), .seg button:active, .pick:active, .switch:active { transform: scale(0.972); }
table .btn:active:not(:disabled) { transform: none; }
.cal-grid.is-next, .months.is-next { animation: hrCalNext 155ms var(--pop-spring); }
.cal-grid.is-prev, .months.is-prev { animation: hrCalPrev 155ms var(--pop-spring); }
.is-glow { animation: hrGlow 1200ms var(--spring); }
.rcell, .desk-chip, .desk-empty { transition: transform 95ms var(--pop-spring), border-color 130ms ease, background 130ms ease; }
.rcell:active:not(:disabled), .desk-chip:active:not(:disabled), .desk-empty:active:not(:disabled) { transform: scale(0.94); }

@media (prefers-reduced-motion: reduce) {
  .pop, .scrim, .modal, .drawer, .toast, .switch-track::after, .btn, .seg button, .opt, .cal-day, .switch, .pick, .rcell, .desk-chip, .desk-empty { transition: none; }
  .page, .modal-body, .cal-grid, .months, .is-glow { animation: none; }
}

/* Receipt photos: thumbnails in forms, larger tiles in the viewer. */
.btn.is-warn-text { color: var(--warn); }
.photo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.photo-thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer; }
.photo-x svg { width: 13px; height: 13px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo-big { display: flex; flex-direction: column; gap: 6px; }
.photo-big img { width: 100%; height: 220px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); display: block; }
