/* Components (spec 6-6). Every color and font size is a token from tokens.css. */

/* ---------- icons (6-7): 24px default, 20px inside buttons ---------- */
.icon { width: 24px; height: 24px; flex: none; }
.btn .icon, .chip .icon, .toast .icon { width: 20px; height: 20px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-width: 88px;
  min-height: var(--touch);
  padding: 0 var(--sp-4);
  border: 1.5px solid var(--transparent);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  line-height: 1.25;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: transform var(--t-press) var(--ease), filter var(--t-press) var(--ease), background-color var(--t-press) var(--ease);
  user-select: none;
}
.btn-lg { min-height: var(--btn-lg); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:active { background: var(--primary-pressed); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border-input); }
.btn-text { background: var(--transparent); color: var(--primary); min-width: var(--touch); padding: 0 var(--sp-3); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-danger-text { background: var(--transparent); color: var(--danger); }
.btn:not(.btn-primary):active { filter: brightness(.95); transform: scale(.98); }
.btn-primary:active { transform: scale(.98); }
.btn[aria-disabled="true"],
.btn:disabled {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--surface-2);
  cursor: not-allowed;
  filter: none;
  transform: none;
}
.btn-reason { margin-top: var(--sp-1); font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--text-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.btn-row.end { justify-content: flex-end; }

/* ---------- choice chips: 40 visible + 4px transparent above/below = 48 ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--sp-2);
}
.chips.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
}
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  flex: none;
  min-height: 48px;
  padding: 0 var(--sp-4);
  border: 4px solid var(--transparent);
  border-radius: var(--r-pill);
  background: var(--surface);
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1.5px var(--border-input);
  color: var(--text);
  font-size: var(--fs-body-sm);
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
}
.chip .icon { display: none; width: 16px; height: 16px; }
.chip.is-on,
.chip[aria-checked="true"],
.chip[aria-pressed="true"] {
  background-color: var(--primary-soft);
  box-shadow: inset 0 0 0 1.5px var(--primary);
  color: var(--primary);
}
.chip.is-on .icon,
.chip[aria-checked="true"] .icon,
.chip[aria-pressed="true"] .icon { display: block; }
.chip[aria-disabled="true"] {
  background-color: var(--surface-2);
  box-shadow: none;
  color: var(--text-2);
  cursor: not-allowed;
}

/* ---------- reason chips (not pressable) ---------- */
.reason {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  font-weight: 600;
  white-space: nowrap;
}
.reason.is-deadline { background: var(--warn-soft); color: var(--warn); }
.reason.is-overdue { background: var(--danger-soft); color: var(--danger); }
.reason.is-birthday { background: var(--ok-soft); color: var(--ok); }

/* ---------- sheets ---------- */
#sheet-root, #dialog-root { position: relative; z-index: 40; }
#dialog-root { z-index: 50; }
.sheet-layer, .dialog-layer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
.scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--t-sheet-out) var(--ease);
}
.sheet-layer.is-open .scrim { opacity: 1; transition-duration: var(--t-sheet-in); }
.sheet {
  position: relative;
  width: 100%;
  max-width: var(--content-max);
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  border: 1px solid var(--layer-border);
  border-bottom: 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform var(--t-sheet-out) var(--ease);
}
.sheet-layer.is-open .sheet { transform: none; transition-duration: var(--t-sheet-in); }
.sheet-layer.is-closing { pointer-events: none; }
.sheet-handle {
  width: 36px;
  height: 4px;
  margin: var(--sp-2) auto 0;
  border-radius: 2px;
  background: var(--border-input);
  flex: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-2) 0 var(--sp-4);
  flex: none;
}
.sheet-title { flex: 1; min-width: 0; font-size: var(--fs-section); line-height: var(--lh-section); }
.sheet-close { min-width: var(--touch); }
.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
}

/* ---------- dialog ---------- */
.dialog-layer { justify-content: center; padding: var(--gutter); }
.dialog-layer .scrim { opacity: 1; }
.dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-lg);
  border: 1px solid var(--layer-border);
  box-shadow: var(--shadow-sheet);
}
.dialog-title { font-size: var(--fs-section); line-height: var(--lh-section); }
.dialog-body { margin-top: var(--sp-3); color: var(--text); }
.dialog-body p + p { margin-top: var(--sp-2); }
.dialog .field-label { margin-top: var(--sp-4); }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-6);
}
.dialog-actions .btn { flex: 1 1 120px; min-height: var(--btn-lg); }
.dialog-actions.has-extra { flex-direction: column; }
.dialog-actions.has-extra .btn { flex: none; width: 100%; }
.dialog-actions.has-extra [data-act="cancel"] { order: 3; }
.dialog-actions.has-extra [data-act="ok"] { order: 2; }

/* ---------- toast: 16px above the visible bottom bar ---------- */
#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--toast-bottom, calc(16px + env(safe-area-inset-bottom)));
  z-index: 60;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  max-width: var(--content-max);
  min-height: var(--touch);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--text);
  color: var(--bg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--t-toast) var(--ease), transform var(--t-toast) var(--ease);
}
.toast.is-shown { opacity: 1; transform: none; }
.toast-text {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.toast-action { color: var(--bg); min-width: 88px; text-decoration: underline; }

/* ---------- banner (one at a time, top of screen) ---------- */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3) var(--gutter);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
}
.banner .icon { color: var(--warn); }
.banner-text { flex: 1 1 200px; min-width: 0; }
.banner.is-update { background: var(--primary-soft); }
.banner.is-update .icon { color: var(--primary); }
.banner.is-sample { background: var(--surface-2); }

/* ---------- fields ---------- */
.field-label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
  font-weight: 600;
  color: var(--text);
}
.field {
  display: block;
  width: 100%;
  min-height: var(--btn-lg);
  padding: var(--sp-3) var(--sp-3);
  border: 1.5px solid var(--border-input);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-body);
  line-height: 1.4;
}
textarea.field { min-height: calc(4 * 1.5em + 2 * var(--sp-3)); line-height: 1.5; resize: vertical; }
select.field { appearance: auto; }
.field:focus,
.field:focus-visible {
  border-color: var(--primary);
  outline: 3px solid var(--focus);
  outline-offset: 0;
}
.field[aria-invalid="true"] { border: 2px solid var(--danger); }
.field-hint { margin-top: var(--sp-1); font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--text-2); }
.field-error {
  display: flex;
  gap: var(--sp-1);
  align-items: flex-start;
  margin-top: var(--sp-1);
  color: var(--danger);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
}
.field-error .icon { width: 20px; height: 20px; margin-top: 2px; }
.field-warning {
  margin-top: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
}
.field-warning .btn-row { margin-top: var(--sp-2); }
.form-row + .form-row { margin-top: var(--sp-5); }

/* ---------- date buttons ---------- */
.date-buttons .date-show {
  margin-top: var(--sp-1);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
  color: var(--text-2);
  min-height: 1.5em;
}
.date-buttons .date-input { margin-top: var(--sp-2); }
.date-buttons .date-input.is-picker-only {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---------- progress ---------- */
.progress {
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  appearance: none;
}
.progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
.progress::-webkit-progress-value { background: var(--ok); border-radius: 4px; }
.progress::-moz-progress-bar { background: var(--ok); border-radius: 4px; }
.progress-row { display: flex; align-items: center; gap: var(--sp-3); }
.progress-row .progress { flex: 1; }
.progress-label { font-size: var(--fs-body-sm); line-height: var(--lh-body-sm); color: var(--text); white-space: nowrap; }

/* ---------- bottom tab bar and [+] ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--divider);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner {
  display: flex;
  max-width: var(--content-max);
  margin: 0 auto;
  height: var(--tabbar-h);
}
.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-2);
  text-decoration: none;
  font-size: var(--fs-tab);
  line-height: 1.2;
  font-weight: 600;
}
.tab-label { white-space: nowrap; }
.tab.is-active,
.tab[aria-current="page"] { color: var(--primary); }
.tab.is-active::before,
.tab[aria-current="page"]::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}
.tab-dot {
  position: absolute;
  top: 8px;
  right: calc(50% - 18px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}
.fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 21;
  width: var(--fab);
  height: var(--fab);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-fab);
}
.fab .icon { width: 28px; height: 28px; }
.fab:active { background: var(--primary-pressed); }

/* ---------- top bar (screens with back) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: var(--topbar-h);
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--sp-1);
  background: var(--bg);
}
.topbar-back { min-width: var(--touch); width: var(--touch); padding: 0; }
.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: var(--fs-section);
  line-height: var(--lh-section);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-action { min-width: var(--touch); }

/* ---------- screen head / empty state / section ---------- */
.screen-head { padding: var(--sp-5) 0 var(--sp-3); }
.screen-title { font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 700; }
.section { margin-top: var(--sp-6); }
.section-title { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 700; margin-bottom: var(--sp-2); }
.empty-state {
  margin-top: var(--sp-6);
  padding: var(--sp-8) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--layer-border);
  text-align: center;
}
.empty-title { font-size: var(--fs-name); line-height: var(--lh-name); font-weight: 600; }
.empty-state .btn { margin-top: var(--sp-5); }

/* ---------- today row (skeleton; filled in stage 4) ---------- */
.task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-2);
  min-height: 76px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--layer-border);
  box-shadow: var(--shadow-card);
  transition: opacity var(--t-fold) var(--ease);
}
.task-row + .task-row { margin-top: var(--sp-2); }
.row-body {
  display: block;
  width: 100%;
  min-height: var(--touch);
  text-align: left;
  color: var(--text);
}
.row-line1 { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); }
.row-name { font-size: var(--fs-name); line-height: var(--lh-name); font-weight: 600; }
.row-state { margin-left: auto; font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--text-2); }
.row-state.is-warn { color: var(--warn); font-weight: 600; }
.row-line2 {
  display: block; /* ellipsis needs a block box; an inline span pushed the page wider than the screen */
  max-width: 100%;
  margin-top: var(--sp-1);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); }
.row-actions .btn { min-height: var(--touch); }
:root[data-text="xl"] .row-line1 { flex-direction: column; align-items: flex-start; }
:root[data-text="xl"] .row-state { margin-left: 0; }
:root[data-text="xl"] .row-line2 { white-space: normal; }

/* ---------- customer row ---------- */
.cust-row {
  display: block;
  min-height: 64px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--layer-border);
  color: var(--text);
  text-decoration: none;
}
.cust-row + .cust-row { margin-top: var(--sp-2); }
.cust-row-line2 { font-size: var(--fs-body-sm); line-height: var(--lh-body-sm); color: var(--text-2); }

/* ---------- fixed bottom bars: S21 contact bar, form save bar ---------- */
.contact-bar,
.form-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--divider);
  padding: var(--sp-2) calc(var(--gutter) + env(safe-area-inset-right)) calc(var(--sp-2) + env(safe-area-inset-bottom)) calc(var(--gutter) + env(safe-area-inset-left));
}
.contact-bar { display: flex; gap: var(--sp-2); padding-top: 0; padding-bottom: env(safe-area-inset-bottom); }
.contact-bar .btn {
  flex: 1;
  min-width: 0;
  height: 64px;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--sp-1);
  font-size: var(--fs-caption);
}
.contact-bar .btn .icon { width: 24px; height: 24px; }

/* ---------- number pad (skeleton; stage 6) ---------- */
.numpad { display: grid; grid-template-columns: repeat(3, 72px); gap: var(--sp-3) var(--sp-4); justify-content: center; }
.numpad .key {
  width: 72px;
  height: 64px;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-display);
  line-height: var(--lh-display);
  font-weight: 600;
}
.numpad .key-text { font-size: var(--fs-body-sm); }

/* ---------- veil and lock cover ---------- */
#veil {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#lock-root:empty { display: none; }
#lock-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  overflow-y: auto;
}
