/* ============================================================================
   RMS Telegram Mini App — component styles (D1 §5).
   Every rule references --rms-* tokens only (no hardcoded hex / font-family);
   the token root + faces live in rms-tokens.css, loaded first.
   D1 §2.1: mobile renders on the LIGHT system.
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--rms-font-body);
  font-variant-numeric: tabular-nums;
  background: var(--rms-canvas);
  color: var(--rms-text);
  font-size: var(--rms-web-h3-size);
  line-height: 1.5;
  padding: var(--rms-space-8) var(--rms-space-16) var(--rms-space-64) var(--rms-space-16);
}

#app {
  max-width: 600px;
  margin: 0 auto;
}

.screen {
  display: block;
  animation: fadeIn 0.3s ease-in;
}

/*
 * `hidden` must hide anything, not only screens. Kept as a bare class so every
 * classList.add('hidden') in app.js takes effect (see git history for the bug
 * where scoping it to .screen.hidden left the offline panel stuck on).
 */
.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}

/* ---- Header ---- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--rms-space-16);
  padding-bottom: var(--rms-space-12);
  border-bottom: var(--rms-border-hair) solid var(--rms-border);
}

.header h1 {
  font-family: var(--rms-font-display);
  font-size: var(--rms-web-h1-size);
  font-weight: var(--rms-web-h1-weight);
}

/* Overdue count — an alarm badge, so it borrows the Overdue status hue (never
   the tenant accent: §6 quarantine keeps semantics off chrome color). */
.badge {
  background: var(--rms-status-overdue);
  color: var(--rms-status-overdue-on);
  padding: var(--rms-space-4) var(--rms-space-8);
  border-radius: var(--rms-radius-chit);
  font-family: var(--rms-font-mono);
  font-size: var(--rms-web-small-size);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- §5.11 Status Chit — the signature (hue + glyph + fill-shape + label) ---- */
.rms-chit {
  display: inline-flex;
  align-items: center;
  gap: var(--rms-space-4);
  padding: var(--rms-space-2) var(--rms-space-8);
  border-radius: var(--rms-radius-chit);
  border: var(--rms-border-hair) solid transparent;
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  white-space: nowrap;
}
.rms-chit__glyph { font-size: 1.05em; line-height: 1; }
.rms-chit__label { text-transform: uppercase; }

.rms-chit--blocked { background: var(--rms-status-blocked); color: var(--rms-status-blocked-on); border-width: var(--rms-border-chit); border-color: var(--rms-status-blocked-on); }
.rms-chit--overdue { background: var(--rms-status-overdue); color: var(--rms-status-overdue-on); font-weight: 700; }
.rms-chit--unassigned { background: var(--rms-status-unassigned); color: var(--rms-status-unassigned-on); border-style: dashed; border-color: var(--rms-status-unassigned-on); }
.rms-chit--pendingverification { background: var(--rms-status-pendingverification); color: var(--rms-status-pendingverification-on); border-style: dashed; border-color: var(--rms-status-pendingverification-on); }
.rms-chit--inprogress { background: var(--rms-status-inprogress); color: var(--rms-status-inprogress-on); }
.rms-chit--pending { background: var(--rms-surface); color: var(--rms-status-pending); border-color: var(--rms-status-pending); }
.rms-chit--completed { background: var(--rms-status-completed); color: var(--rms-status-completed-on); }
.rms-chit--skipped {
  color: var(--rms-status-skipped-on);
  border-color: var(--rms-status-skipped);
  background-color: var(--rms-status-skipped);
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0, rgba(255, 255, 255, 0.18) 2px, transparent 2px, transparent 5px);
}
.rms-chit--canceled { background: transparent; color: var(--rms-status-canceled); border-color: var(--rms-status-canceled); }
.rms-chit--canceled .rms-chit__label { text-decoration: line-through; }

/* ---- §5 Role badge — P/L/S avatar pill (full-round, letter backstop) ---- */
.rms-role {
  display: inline-flex;
  align-items: center;
  gap: var(--rms-space-8);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
  font-weight: 600;
}
.rms-role__pill {
  display: inline-grid;
  place-items: center;
  width: var(--rms-space-24);
  height: var(--rms-space-24);
  border-radius: var(--rms-radius-avatar);
  font-weight: 700;
  line-height: 1;
}
.rms-role--owner .rms-role__pill, .rms-role--manager .rms-role__pill { background: var(--rms-role-manager); color: var(--rms-role-manager-on); }
.rms-role--owner .rms-role__label, .rms-role--manager .rms-role__label { color: var(--rms-role-manager-on-tint); }
.rms-role--shiftlead .rms-role__pill { background: var(--rms-role-shiftlead); color: var(--rms-role-shiftlead-on); }
.rms-role--shiftlead .rms-role__label { color: var(--rms-role-shiftlead-on-tint); }
.rms-role--staff .rms-role__pill { background: var(--rms-role-staff); color: var(--rms-role-staff-on); }
.rms-role--staff .rms-role__label { color: var(--rms-role-staff-on-tint); }

/* ---- Task list ---- */
.task-list {
  display: flex;
  flex-direction: column;
  gap: var(--rms-space-12);
}

.task-section h3 {
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
  font-weight: 600;
  color: var(--rms-text-secondary);
  margin-top: var(--rms-space-12);
  margin-bottom: var(--rms-space-8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-card {
  padding: var(--rms-space-12);
  background: var(--rms-surface);
  border-radius: var(--rms-radius-ios);
  cursor: pointer;
  transition: background 0.2s;
  border: var(--rms-border-hair) solid var(--rms-border);
  box-shadow: var(--rms-elev-ios-card);
}

.task-card:active { background: var(--rms-surface-sunken); }

.task-card-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--rms-space-8);
}

.task-card-heading {
  display: flex;
  flex-direction: column;
  gap: var(--rms-space-4);
  min-width: 0;
}

.task-name {
  font-family: var(--rms-font-body);
  font-weight: 600;
}

.task-started {
  font-family: var(--rms-font-mono);
  font-size: var(--rms-web-small-size);
  color: var(--rms-text-tertiary);
  margin-left: var(--rms-space-8);
  white-space: nowrap;
}

/* ---- Buttons ---- */
button {
  padding: var(--rms-space-8) var(--rms-space-16);
  border: none;
  border-radius: var(--rms-radius-ios);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-h3-size);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

button:focus-visible {
  outline: var(--rms-border-chit) solid var(--rms-focus);
  outline-offset: var(--rms-space-2);
}

.primary-btn {
  background: var(--rms-role-staff);
  color: var(--rms-role-staff-on);
  width: 100%;
  margin-top: var(--rms-space-12);
  padding: var(--rms-space-12);
}
.primary-btn:active { background: var(--rms-role-staff-on-tint); }

.secondary-btn {
  background: var(--rms-surface-sunken);
  color: var(--rms-text);
  width: 100%;
  margin-top: var(--rms-space-8);
  padding: var(--rms-space-12);
  border: var(--rms-border-hair) solid var(--rms-border);
}
.secondary-btn:active { background: var(--rms-border); }

.refresh-btn {
  background: var(--rms-surface-sunken);
  color: var(--rms-text);
  width: 100%;
  margin-bottom: var(--rms-space-12);
  border: var(--rms-border-hair) solid var(--rms-border);
}

.back-button {
  background: none;
  color: var(--rms-link);
  padding: 0;
  margin-bottom: var(--rms-space-12);
  font-weight: 600;
}

/* ---- Task detail ---- */
.task-detail-info {
  display: flex;
  gap: var(--rms-space-8);
  align-items: center;
  margin-bottom: var(--rms-space-16);
  flex-wrap: wrap;
}

.task-detail-info h2,
.instructions strong,
#screen-completion h2,
#screen-profile h2 {
  font-family: var(--rms-font-display);
}

#task-detail-container h2 { font-family: var(--rms-font-display); font-size: var(--rms-web-h1-size); }

.station {
  background: var(--rms-surface-sunken);
  color: var(--rms-text-secondary);
  padding: var(--rms-space-4) var(--rms-space-8);
  border-radius: var(--rms-radius-tile);
  font-size: var(--rms-web-small-size);
}

.instructions { margin-bottom: var(--rms-space-16); }
.instructions strong { display: block; margin-bottom: var(--rms-space-8); font-weight: 600; }
.instructions p { line-height: 1.6; }

.task-detail-info img {
  max-width: 100%;
  border-radius: var(--rms-radius-ios);
  margin: var(--rms-space-12) 0;
}

/* ---- Forms ---- */
.custom-field { margin-bottom: var(--rms-space-12); }
.custom-field label { display: block; margin-bottom: var(--rms-space-4); font-weight: 600; }

.custom-field input,
.custom-field select,
.form-section select,
.form-section input[type="text"],
textarea {
  width: 100%;
  padding: var(--rms-space-8);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-radius: var(--rms-radius-ios);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-h3-size);
  background: var(--rms-surface);
  color: var(--rms-text);
}

.custom-field input:focus-visible,
.custom-field select:focus-visible,
.form-section select:focus-visible,
.form-section input[type="text"]:focus-visible,
textarea:focus-visible {
  outline: var(--rms-border-chit) solid var(--rms-focus);
  outline-offset: 0;
  border-color: var(--rms-focus);
}

.photo-section { margin-bottom: var(--rms-space-12); }
.photo-section label { display: block; margin-bottom: var(--rms-space-8); font-weight: 600; }
.photo-section input[type="file"] { width: 100%; }

.photo-error {
  display: block;
  color: var(--rms-status-blocked);
  font-size: var(--rms-web-small-size);
  margin-top: var(--rms-space-4);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

/* ---- Tabs ---- */
.tab-button {
  background: none;
  border: none;
  border-radius: 0;
  padding: var(--rms-space-8) var(--rms-space-16);
  color: var(--rms-text-tertiary);
  font-size: var(--rms-web-body-size);
  cursor: pointer;
  flex: 1;
}
.tab-button.active {
  color: var(--rms-role-staff);
  border-bottom: var(--rms-border-chit) solid var(--rms-role-staff);
}

/* ---- Loading ---- */
.loading-spinner {
  width: var(--rms-space-32);
  height: var(--rms-space-32);
  border: var(--rms-space-4) solid var(--rms-border);
  border-top-color: var(--rms-role-staff);
  border-radius: var(--rms-radius-avatar);
  animation: spin 0.8s linear infinite;
  margin: var(--rms-space-48) auto;
}

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none; } }

/* ---- Offline state ---- */
.offline-state {
  background: var(--rms-surface);
  color: var(--rms-status-unassigned-on);
  border: var(--rms-border-hair) solid var(--rms-status-unassigned);
  border-left: var(--rms-edgebar-l1) solid var(--rms-status-unassigned);
  padding: var(--rms-space-16);
  border-radius: var(--rms-radius-ios);
  margin: var(--rms-space-12) 0;
  text-align: center;
}

/* ---- Error state ---- */
.error-box {
  background: var(--rms-surface);
  color: var(--rms-status-blocked);
  border: var(--rms-border-hair) solid var(--rms-status-blocked);
  border-left: var(--rms-edgebar-l2) solid var(--rms-status-blocked);
  padding: var(--rms-space-24);
  border-radius: var(--rms-radius-ios);
  text-align: center;
  margin-top: var(--rms-space-48);
}
.error-box h2 { margin-bottom: var(--rms-space-12); font-family: var(--rms-font-display); }

/* ---- Profile ---- */
.profile-info {
  background: var(--rms-surface);
  border: var(--rms-border-hair) solid var(--rms-border);
  padding: var(--rms-space-16);
  border-radius: var(--rms-radius-ios);
  box-shadow: var(--rms-elev-ios-card);
}
.profile-info p { margin-bottom: var(--rms-space-8); display: flex; align-items: center; gap: var(--rms-space-8); }
.profile-info .rms-role { margin-left: 0; }

/* FEAT-009 CTL-370 ChangeLocationAction — the multi-scope location block on Profile (SCR-056),
   mirroring the .profile-info card chrome so it reads as one system. */
.profile-location {
  background: var(--rms-surface);
  border: var(--rms-border-hair) solid var(--rms-border);
  padding: var(--rms-space-16);
  border-radius: var(--rms-radius-ios);
  box-shadow: var(--rms-elev-ios-card);
  margin-top: var(--rms-space-12);
  display: flex;
  flex-direction: column;
  gap: var(--rms-space-8);
}
.profile-location p { margin: 0; }

/* ---- FEAT-002 location context: SCR-059 picker · CTL-366 switcher · empty · announce ---- */
.location-picker-hint {
  color: var(--rms-text-secondary);
  margin-bottom: var(--rms-space-16);
}

.location-list {
  display: flex;
  flex-direction: column;
  gap: var(--rms-space-8);
}

.location-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--rms-space-8);
  width: 100%;
  padding: var(--rms-space-16);
  background: var(--rms-surface);
  color: var(--rms-text);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-radius: var(--rms-radius-ios);
  box-shadow: var(--rms-elev-ios-card);
  text-align: left;
  cursor: pointer;
}

.location-row:active { background: var(--rms-surface-sunken); }
.location-row__name { font-weight: 600; }
.location-row__type { color: var(--rms-text-tertiary); font-size: var(--rms-disp-meta-size); }

.location-switcher {
  width: 100%;
  margin-bottom: var(--rms-space-12);
  padding: var(--rms-space-12);
  background: var(--rms-surface-sunken);
  color: var(--rms-text);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-radius: var(--rms-radius-ios);
}

.empty-state {
  background: var(--rms-surface);
  color: var(--rms-text-secondary);
  border: var(--rms-border-hair) solid var(--rms-border);
  padding: var(--rms-space-24);
  border-radius: var(--rms-radius-ios);
  margin: var(--rms-space-12) 0;
  text-align: center;
}

.location-announce {
  background: var(--rms-surface);
  color: var(--rms-link);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-left: var(--rms-edgebar-l1) solid var(--rms-link);
  padding: var(--rms-space-12) var(--rms-space-16);
  border-radius: var(--rms-radius-ios);
  margin-bottom: var(--rms-space-12);
}

/* FEAT-003 SCR-053 — CTL-369 numeric range field inline validation copy. Overdue hue is the
   design system's danger signal (also used by .badge); token-bound, no hardcoded colour. */
.field-error {
  display: block;
  margin-top: var(--rms-space-4);
  color: var(--rms-status-overdue);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
}
[data-ctl="CTL-369"][aria-invalid="true"] {
  border-color: var(--rms-status-overdue);
}

/* FEAT-003 SCR-052 — the web-only-task indicator (mobileEnabled=false); a sunken note, not a form. */
.web-only-indicator {
  background: var(--rms-surface-sunken);
  color: var(--rms-text-secondary);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-radius: var(--rms-radius-ios);
  padding: var(--rms-space-12) var(--rms-space-16);
  margin-bottom: var(--rms-space-12);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
}

/* FEAT-028 G20a — SCR-054 checklist lines and SCR-057 vendor inputs; token-bound, existing idioms only. */
.receiving-line {
  border-bottom: var(--rms-border-hair) solid var(--rms-border);
  padding: var(--rms-space-12) 0;
}
.receiving-line__exp { color: var(--rms-text-secondary); margin-left: var(--rms-space-8); }
/* The inactive one of the two mutually exclusive vendor inputs is dimmed (SCR-057). */
.is-inactive { opacity: 0.5; }

/* FEAT-003 G20b — the attached photo's thumbnail in the take-or-choose control. */
.photo-thumb {
  display: block;
  max-width: 160px;
  margin-top: var(--rms-space-8);
  border-radius: var(--rms-radius-ios);
}
.photo-thumb.hidden { display: none; }

/* ---- E3 — SCR-052 reassign (CTL-325 / CTL-326) ---- */
.reassign-section {
  margin-top: var(--rms-space-16);
  padding-top: var(--rms-space-12);
  border-top: var(--rms-border-hair) solid var(--rms-border);
}
.reassign-section [data-field="reassign-drawer"] { margin-top: var(--rms-space-12); }

/* ---- UX-01 — SCR-050/052 due time and owner, SCR-052 required evidence, SCR-056 restaurant name ---- */
.task-meta {
  color: var(--rms-text-secondary);
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
}
.task-detail-due { font-weight: 600; margin-bottom: var(--rms-space-4); }
.task-detail-assignee { color: var(--rms-text-secondary); margin-bottom: var(--rms-space-12); }
.required-evidence {
  background: var(--rms-surface-sunken);
  border: var(--rms-border-hair) solid var(--rms-border);
  border-radius: var(--rms-radius-ios);
  padding: var(--rms-space-12) var(--rms-space-16);
  margin-bottom: var(--rms-space-16);
}
.required-evidence strong { display: block; margin-bottom: var(--rms-space-4); font-weight: 600; }
.required-evidence ul { margin: 0; padding-left: var(--rms-space-16); }
.profile-restaurant { font-family: var(--rms-font-display); font-weight: 600; }

/* ---- UX-28 — SCR-057 labelled sections and the items-left line above the MainButton ---- */
.form-section { margin-bottom: var(--rms-space-16); }
.form-section-title {
  font-family: var(--rms-font-body);
  font-size: var(--rms-web-small-size);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--rms-text-secondary);
  margin-bottom: var(--rms-space-8);
}
.form-section-title label { font: inherit; color: inherit; }
.form-section select,
.form-section input[type="text"] { width: 100%; min-height: 44px; }
.unexpected-or {
  display: block;
  margin: var(--rms-space-8) 0 var(--rms-space-4);
  color: var(--rms-text-secondary);
  font-size: var(--rms-web-small-size);
}
.items-left { color: var(--rms-text-secondary); font-size: var(--rms-web-small-size); }
