/* my-gui date field and calendar (js/date.js, docs/spec.md 18). Tokens only, so the light, dark and
   beige themes come from tokens.css. */

/* ---------- the field ---------- */

.m-date { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.m-date[hidden] { display: none; }
:where([data-m-daterange]) { display: flex; flex-wrap: wrap; gap: 8px; }
:where([data-m-daterange]) > .m-date { flex: 1 1 180px; }
.m-colrange > .m-date { flex: 0 0 auto; }
.m-date > input.m-date-src { display: none; }
.m-date-box { position: relative; display: flex; min-width: 0; }
.m-date-box > .m-date-field { flex: 1 1 auto; width: 100%; min-width: 0; padding-inline-end: 34px; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.m-date-btn {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--m-r);
  background: none;
  color: var(--m-text-3);
  cursor: pointer;
}
.m-date-btn .m-i { width: 15px; height: 15px; }
.m-date-btn:hover, .m-date.is-open .m-date-btn { color: var(--m-accent); }
.m-date-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--m-ring); }
.m-date-btn:disabled { opacity: .5; cursor: not-allowed; }

/* what the typed text means, under the field without moving the page */
.m-date-echo {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  z-index: 60;
  width: max-content;
  max-width: min(360px, 90vw);
  padding: 5px 9px;
  border: 1px solid var(--m-glass-edge);
  border-radius: 9px;
  background: var(--m-modal);
  box-shadow: var(--m-pop-sh);
  color: var(--m-text-2);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.35;
  pointer-events: none;
}
.m-date-echo[hidden], .m-date-msg[hidden] { display: none; }

/* ---------- the calendar ---------- */

.m-date-pop {
  --m-date-cell: 34px;
  position: fixed;
  inset: auto;
  z-index: 120;
  display: flex;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 16px);
  margin: 0;
  padding: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--m-glass-edge);
  border-radius: 14px;
  background: var(--m-modal);
  box-shadow: var(--m-pop-sh);
  color: var(--m-text);
  text-align: start;
  animation: m-date-in .16s ease;
}
@keyframes m-date-in { from { opacity: 0; } to { opacity: 1; } }

.m-date-quick { display: flex; flex-direction: column; gap: 2px; padding-inline-end: 10px; border-inline-end: 1px solid var(--m-line); }
.m-date-quick > .m-btn { justify-content: flex-start; }

.m-date-main { display: flex; flex-direction: column; min-width: 0; }
.m-date-months { display: flex; gap: 18px; align-items: flex-start; }
.m-date-head { display: grid; grid-template-columns: 28px 1fr 28px; align-items: center; gap: 4px; min-height: 32px; }
.m-date-gap { width: 28px; }
.m-date-title { justify-content: center; color: var(--m-text); font-size: 13px; font-weight: 800; }

.m-date-grid { border-collapse: separate; border-spacing: 0 2px; table-layout: fixed; }
.m-date-grid th { height: 24px; padding: 0; color: var(--m-text-3); font-size: 10.5px; font-weight: 800; letter-spacing: .04em; text-align: center; text-transform: uppercase; }
.m-date-grid td { width: var(--m-date-cell); height: var(--m-date-cell); padding: 0; }
.m-date-grid .m-date-wk { width: 28px; padding-inline-end: 4px; font-weight: 600; letter-spacing: 0; opacity: .85; }
/* the band of a period runs behind the two round ends */
.m-date-grid td.is-in { background: rgba(var(--m-accent-rgb), .13); }
.m-date-grid td.is-start { background: linear-gradient(to right, transparent 50%, rgba(var(--m-accent-rgb), .13) 50%); }
.m-date-grid td.is-end { background: linear-gradient(to left, transparent 50%, rgba(var(--m-accent-rgb), .13) 50%); }

.m-date-day, .m-date-cell {
  position: relative;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--m-text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m-date-day { width: var(--m-date-cell); height: var(--m-date-cell); padding: 0; }
.m-date-day:hover, .m-date-cell:hover { background: rgba(var(--m-ink), .08); }
.m-date-day.is-weekend { color: var(--m-text-2); }
/* a holiday and the app's mark: a dot as well, so it does not rest on colour alone */
.m-date-day.is-holiday { color: var(--m-danger-text); font-weight: 800; }
.m-date-day.is-holiday::after, .m-date-day.is-marked::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: currentColor;
}
.m-date-day.is-today, .m-date-cell.is-today { box-shadow: inset 0 0 0 1px var(--m-accent); }
.m-date-day.is-selected, .m-date-cell.is-selected { background: var(--m-accent); color: var(--m-on-accent); font-weight: 800; }
.m-date-day.is-off, .m-date-cell.is-off { opacity: .35; text-decoration: line-through; cursor: not-allowed; }
.m-date-day.is-off:not(.is-selected):hover, .m-date-cell.is-off:not(.is-selected):hover { background: none; }
.m-date-day:focus-visible, .m-date-cell:focus-visible { outline: 2px solid var(--m-accent); outline-offset: 1px; }

.m-date-pickview { width: calc(var(--m-date-cell) * 7); }
.m-date-cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-block: 8px; }
.m-date-cells--years { grid-template-columns: repeat(4, 1fr); }
.m-date-cell { min-height: 40px; padding: 0 4px; }

.m-date-hint { min-height: 1.5em; max-width: calc(var(--m-date-cell) * 7 + 28px); margin-block-start: 4px; color: var(--m-text-3); font-size: 11.5px; font-weight: 600; }
.is-range .m-date-hint { max-width: none; }
.m-date-foot { display: flex; align-items: center; gap: 8px; margin-block-start: auto; padding-block-start: 8px; border-block-start: 1px solid var(--m-line); }

/* ---------- bottom sheet (narrow screens) ---------- */

.m-date-scrim { position: fixed; inset: 0; z-index: 115; background: rgba(0, 0, 0, .45); touch-action: none; }
.m-date-pop.is-sheet {
  --m-date-cell: min(46px, calc((100vw - 52px) / 7));
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  flex-direction: column;
  width: auto;
  max-width: none;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  border-width: 1px 0 0;
  border-radius: 18px 18px 0 0;
  animation: m-date-sheet .22s var(--m-ease);
}
@keyframes m-date-sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.m-date-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.m-date-name { overflow: hidden; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.is-sheet .m-date-quick { flex-direction: row; flex-shrink: 0; gap: 6px; overflow-x: auto; padding: 0 0 4px; border: 0; }
.is-sheet .m-date-quick > .m-btn { flex: 0 0 auto; min-height: 40px; background: rgba(var(--m-ink), .05); }
.is-sheet .m-date-main, .is-sheet .m-date-months { align-items: center; }
.is-sheet .m-date-head { grid-template-columns: 44px 1fr 44px; width: calc(var(--m-date-cell) * 7); }
.is-sheet .m-date-head .m-btn { min-height: 44px; }
.is-sheet .m-date-gap { width: 44px; }
.is-sheet .m-date-day { font-size: 15px; }
.is-sheet .m-date-grid .m-date-wk { width: 24px; }
.is-sheet .m-date-grid:has(.m-date-wk) { --m-date-cell: min(46px, calc((100vw - 76px) / 7)); }
.is-sheet .m-date-cell { min-height: 48px; font-size: 14px; }
.is-sheet .m-date-hint { text-align: center; }
.is-sheet .m-date-foot { align-self: stretch; }
.is-sheet .m-date-foot .m-btn { min-height: 44px; }

/* ---------- touch ---------- */

@media (pointer: coarse) {
  .m-date-box > .m-date-field { height: 44px; padding-inline-end: 46px; font-size: 16px; }   /* 16px: iOS does not zoom in */
  .m-date-btn { width: 44px; }
  .m-date-pop:not(.is-sheet) { --m-date-cell: 40px; }
}

/* the filter row of a table: narrow fields */
.m-colrange .m-date-box > .m-date-field { min-width: 112px; }
.m-table.is-cards .m-colrange .m-date-box > .m-date-field { min-width: 0; }

@media (prefers-reduced-motion: reduce) {
  .m-date-pop { animation: none; }
}
@media (forced-colors: active) {
  .m-date-pop { border: 1px solid CanvasText; box-shadow: none; }
  .m-date-day.is-selected, .m-date-cell.is-selected { outline: 2px solid Highlight; }
  .m-date-grid td.is-in { outline: 1px dashed Highlight; outline-offset: -3px; }
}
@media print {
  .m-date-pop, .m-date-scrim, .m-date-btn, .m-date-echo { display: none; }
}
