/* MAS shared design system — Apple-style grouped UI, light + dark */
:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #f9f9fb;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.32);
  --separator: rgba(60, 60, 67, 0.18);
  --accent: #007aff;
  --accent-press: #0062cc;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --indigo: #5856d6;
  --chrome: rgba(249, 249, 251, 0.78);
  --scrim: rgba(0, 0, 0, 0.32);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.18);
  --radius: 12px;
  --radius-lg: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-elev-2: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.62);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --accent-press: #409cff;
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --indigo: #5e5ce6;
    --chrome: rgba(22, 22, 24, 0.78);
    --scrim: rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --bg-elev: #1c1c1e; --bg-elev-2: #2c2c2e;
  --fill: rgba(118,118,128,0.24); --fill-strong: rgba(118,118,128,0.36);
  --label: #fff; --label-2: rgba(235,235,245,0.62); --label-3: rgba(235,235,245,0.3);
  --separator: rgba(84,84,88,0.6); --accent: #0a84ff; --accent-press: #409cff;
  --green: #30d158; --orange: #ff9f0a; --red: #ff453a; --indigo: #5e5ce6;
  --chrome: rgba(22,22,24,0.78); --scrim: rgba(0,0,0,0.55);
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font: 100%/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--label); min-height: 100dvh; overscroll-behavior-y: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }

/* ---------- Type ---------- */
.large-title { font-size: 2.125rem; line-height: 1.12; font-weight: 700; letter-spacing: -0.022em; margin: 0; }
.title-2 { font-size: 1.375rem; line-height: 1.2; font-weight: 700; letter-spacing: -0.016em; margin: 0; }
.headline { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; }
.subhead { font-size: 0.9375rem; color: var(--label-2); }
.footnote { font-size: 0.8125rem; line-height: 1.35; color: var(--label-2); letter-spacing: 0.005em; }
.caption { font-size: 0.75rem; color: var(--label-2); letter-spacing: 0.01em; }
.section-header { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--label-2); padding: 0 1rem 0.4rem; margin-top: 1.5rem; }
.section-footer { padding: 0.4rem 1rem 0; }

/* ---------- Grouped lists ---------- */
.group { background: var(--bg-elev); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 0.75rem; min-height: 3.25rem; padding: 0.6rem 1rem;
  position: relative; width: 100%; background: none; border: 0; text-align: left; cursor: pointer;
  transition: background-color 120ms ease-out;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 1rem; right: 0; height: 0.5px; background: var(--separator); }
.row.has-icon + .row::before, .row + .row.has-icon::before { left: 3.6rem; }
.row:active, .row.pressed { background: var(--fill); }
.row[disabled] { cursor: default; }
.row[disabled]:active { background: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 1.0625rem; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 0.875rem; color: var(--label-2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 0.5rem; height: 0.85rem; flex: none; color: var(--label-3); }
.row-icon { width: 2rem; height: 2rem; border-radius: 0.5rem; display: grid; place-items: center; flex: none; color: #fff; }
.row-icon svg { width: 1.15rem; height: 1.15rem; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--fill); color: var(--label-2); white-space: nowrap; letter-spacing: 0.01em; }
.chip svg { width: 0.75rem; height: 0.75rem; }
.chip.green { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.chip.orange { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.chip.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.chip.blue { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.chip.indigo { background: color-mix(in srgb, var(--indigo) 16%, transparent); color: var(--indigo); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 3.25rem; padding: 0 1.25rem; border-radius: var(--radius); font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em;
  background: var(--accent); color: #fff; width: 100%;
  transition: transform 100ms ease-out, background-color 120ms ease-out, opacity 150ms ease-out;
  user-select: none; -webkit-user-select: none;
}
.btn svg { width: 1.2rem; height: 1.2rem; }
.btn:active, .btn.pressed { transform: scale(0.97); background: var(--accent-press); }
.btn.secondary { background: var(--fill); color: var(--accent); }
.btn.secondary:active { background: var(--fill-strong); }
.btn.tinted-red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.btn.tinted-orange { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.btn.green { background: var(--green); }
.btn.small { min-height: 2.25rem; font-size: 0.9375rem; padding: 0 0.9rem; border-radius: 999px; width: auto; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-row { display: flex; gap: 0.6rem; }
.btn-row .btn { flex: 1; }
.text-btn { background: none; border: 0; color: var(--accent); font-size: 1.0625rem; padding: 0.5rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.15rem; min-height: 2.75rem; }
.text-btn:active { opacity: 0.4; }
.text-btn svg { width: 0.7rem; height: 1.1rem; }
.text-btn.bold { font-weight: 600; }
.text-btn.red { color: var(--red); }

/* ---------- Inputs ---------- */
.field { width: 100%; border: 0; background: var(--bg-elev); border-radius: var(--radius); padding: 0.85rem 1rem; font-size: 1.0625rem; outline: none; }
textarea.field { min-height: 7.5rem; resize: vertical; line-height: 1.4; }
.field:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.field::placeholder { color: var(--label-3); }
.group .field { border-radius: 0; background: none; }
.group .field:focus { box-shadow: none; }

/* ---------- Checkbox row ---------- */
.check { width: 1.4rem; height: 1.4rem; border-radius: 50%; border: 2px solid var(--label-3); display: grid; place-items: center; flex: none; transition: background-color 150ms ease-out, border-color 150ms ease-out, transform 150ms ease-out; }
.check svg { width: 0.8rem; height: 0.8rem; color: #fff; opacity: 0; transform: scale(0.6); transition: opacity 150ms, transform 200ms cubic-bezier(.3,1.6,.6,1); }
.row[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
.row[aria-checked="true"] .check svg { opacity: 1; transform: none; }

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.photo-tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--fill); animation: tile-in 360ms cubic-bezier(.2,.9,.3,1) both; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .del { position: absolute; top: 0.3rem; right: 0.3rem; width: 1.75rem; height: 1.75rem; border-radius: 50%; border: 0; background: rgba(0,0,0,0.55); color: #fff; display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.photo-tile .del svg { width: 0.75rem; height: 0.75rem; }
.photo-tile .del:active { transform: scale(0.9); }
.photo-tile.add { display: grid; place-items: center; color: var(--label-3); border: 1.5px dashed var(--separator); background: none; animation: none; }
@keyframes tile-in { from { opacity: 0; transform: scale(0.85); } }

/* ---------- Progress ring / meter ---------- */
.meter { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--green); border-radius: 3px; transition: width 400ms cubic-bezier(.2,.9,.3,1); }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 0; right: 0; top: calc(var(--safe-top) + 0.6rem); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; z-index: 1000; pointer-events: none; padding: 0 1rem; }
.toast {
  pointer-events: auto; max-width: 30rem; width: 100%; display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.8rem 1rem; border-radius: 16px; background: var(--chrome); backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 8px 30px rgba(0,0,0,0.16); font-size: 0.9375rem; line-height: 1.35; font-weight: 500;
}
.toast .ico { flex: none; width: 1.4rem; height: 1.4rem; border-radius: 50%; display: grid; place-items: center; color: #fff; margin-top: 1px; }
.toast .ico svg { width: 0.8rem; height: 0.8rem; }
.toast.error .ico { background: var(--red); }
.toast.success .ico { background: var(--green); }
.toast.info .ico { background: var(--accent); }
.toast.warn .ico { background: var(--orange); }
.toast pre { margin: 0.3rem 0 0; font: inherit; white-space: pre-wrap; font-weight: 400; color: var(--label-2); }

/* ---------- Sheet ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; z-index: 500; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 501; max-height: calc(100dvh - var(--safe-top) - 2.5rem);
  background: var(--bg); border-radius: 14px 14px 0 0; box-shadow: var(--shadow-sheet);
  display: flex; flex-direction: column; transform: translateY(100%); will-change: transform; touch-action: none;
  max-width: 40rem; margin: 0 auto;
}
.sheet-grabber { padding: 0.45rem 0 0.2rem; display: grid; place-items: center; cursor: grab; flex: none; }
.sheet-grabber i { width: 2.25rem; height: 5px; border-radius: 3px; background: var(--label-3); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.1rem 1rem 0.6rem; flex: none; gap: 0.5rem; }
.sheet-head h2 { font-size: 1.0625rem; font-weight: 600; margin: 0; text-align: center; flex: 1; letter-spacing: -0.01em; }
.sheet-head .text-btn { min-width: 4.5rem; }
.sheet-body { overflow-y: auto; padding: 0 1rem calc(var(--safe-bottom) + 1.25rem); touch-action: pan-y; overscroll-behavior: contain; }

.sheet.wide { max-width: 60rem; }
@media (min-width: 900px) { .sheet { bottom: 1.5rem; border-radius: 16px; max-height: calc(100dvh - 3rem); } }

/* ---------- Image viewer ---------- */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 900; display: grid; place-items: center; opacity: 0; transition: opacity 200ms ease-out; }
.viewer.open { opacity: 1; }
.viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; transform: scale(0.92); transition: transform 300ms cubic-bezier(.2,.9,.3,1); }
.viewer.open img { transform: none; }
.viewer button { position: absolute; top: calc(var(--safe-top) + 0.75rem); right: 0.75rem; width: 2.25rem; height: 2.25rem; border-radius: 50%; border: 0; background: rgba(255,255,255,0.18); color: #fff; display: grid; place-items: center; cursor: pointer; }
.viewer button svg { width: 0.9rem; height: 0.9rem; }

/* ---------- Spinner ---------- */
.spinner { width: 1.25rem; height: 1.25rem; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 3rem 1.5rem; color: var(--label-2); }
.empty svg { width: 3rem; height: 3rem; color: var(--label-3); margin: 0 auto 0.75rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 120ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .toast { background: var(--bg-elev); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .group, .toast, .field { outline: 1px solid var(--label-3); }
}

/* ---------- Shared cards ---------- */
.err-card { background: color-mix(in srgb, var(--red) 10%, var(--bg-elev)); border-radius: var(--radius); padding: 1rem; color: var(--label); }
.err-card b { color: var(--red); }
.rv-invalid { opacity: 0.7; box-shadow: inset 3px 0 0 var(--red); }

/* ---------- Machine avatar (shared base; technician app restyles it) ---------- */
.m-avatar { position: relative; flex: none; width: 2.75rem; height: 2.75rem; border-radius: 0.8rem; display: grid; place-items: center;
  background: linear-gradient(150deg, #1a3f8f, #0c1d4a); color: #b4d4ff; }
.m-avatar svg { width: 1.6rem; height: 1.6rem; }
.m-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.m-avatar.lg { width: 3.75rem; height: 3.75rem; border-radius: 1.05rem; }
.m-avatar.lg svg { width: 2.15rem; height: 2.15rem; }

/* Icon picker */
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.4rem, 1fr)); gap: 0.5rem; }
.icon-picker button { aspect-ratio: 1; border: 0; border-radius: 0.8rem; background: var(--fill); color: var(--label); display: grid; place-items: center; cursor: pointer; transition: transform 100ms ease-out, background-color 150ms, box-shadow 150ms; }
.icon-picker button svg { width: 1.6rem; height: 1.6rem; }
.icon-picker button:active { transform: scale(0.94); }
.icon-picker button[aria-pressed="true"] { background: linear-gradient(150deg, #1a3f8f, #0c1d4a); color: #cfe3ff; box-shadow: 0 0 0 2px var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.78rem; font-weight: 600; color: var(--label-2); letter-spacing: 0.02em; }
.form-grid .field, .form-grid select.field { background: var(--bg-elev); font-size: 1rem; padding: 0.7rem 0.85rem; font-weight: 400; color: var(--label); }
.m-specline { font-size: 0.85rem; color: var(--label-2); }
