/* ═══════════════════════════════════════════════════════════════════════════
   factory-base.css  —  Factory IoT shared foundation
   Used by: qr-admin.html, floor-walk.html, lead.html, and any new pages
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --amber: #f5a623; --amber-dim: #c47d10; --amber-glow: rgba(245,166,35,0.15);

  /* Semantic colours */
  --green:  #27c87a; --green-dim:  rgba(39,200,122,0.12);
  --red:    #e74c3c; --red-dim:    rgba(231,76,60,0.12);
  --blue:   #4a9eff; --blue-dim:   rgba(74,158,255,0.12);
  --purple: #a855f7; --purple-dim: rgba(168,85,247,0.12);
  --cyan:   #06b6d4; --cyan-dim:   rgba(6,182,212,0.12);
  --orange: #f97316; --orange-dim: rgba(249,115,22,0.12);

  /* Surfaces */
  --bg:       #0a0b0f;
  --surface:  #12141a;
  --surface2: #1a1d27;
  --surface3: #20232f;

  /* Borders */
  --border:  rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);

  /* Text */
  --text:     #e8eaf0;
  --text-dim: #6b7280;
  --text-mid: #9ca3af;

  /* Shape */
  --radius:    14px;
  --radius-sm: 8px;

  /* Safe areas (notch / home indicator) */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);

  /* ── Fluid Typography Scale ── 
     Format: clamp(MIN, FLUID, MAX) */
  /* 4-21-2026  Updated Fluid Typography Scale ── */
  /* We shifted the previous Max to be the new Min for mobile readability */

  --text-xs:   clamp(0.75rem, 0.5vw + 0.65rem, 0.875rem);   /* ~12px → 14px */
  --text-sm:   clamp(0.875rem, 0.8vw + 0.75rem, 1rem);      /* ~14px → 16px */
  --text-base: clamp(1rem, 1vw + 0.9rem, 1.125rem);         /* ~16px → 18px */
  --text-lg:   clamp(1.125rem, 1.2vw + 1rem, 1.375rem);     /* ~18px → 22px */
  --text-xl:   clamp(1.25rem, 1.5vw + 1.1rem, 1.625rem);    /* ~20px → 26px */
}



/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  font-size: var(--text-base);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ──────────────────────────────────────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(10,11,15,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
#topbar h1 {
  font-size: var(--text-xl); font-weight: 700; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#topbar h1 span { color: var(--amber); }

/* ── Top bar buttons ──────────────────────────────────────────────────────── */
.tb-btn {
  height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--border2); background: var(--surface2);
  color: var(--text); font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
  flex-shrink: 0;
}
.tb-btn:active   { background: var(--surface3); height: 20px; padding: 0 0px}
.tb-btn.primary  { background: var(--amber); color: #000; border-color: var(--amber); }
.tb-btn.danger   { color: var(--red); border-color: rgba(231,76,60,.4); }
.tb-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Generic bottom sheet ─────────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); z-index: 49;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border2);
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.32,.72,0,1);
  max-height: 92vh;
  width: 100%; max-width: 100%;
  min-height: 0;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,.2);
  margin: 12px auto 0; flex-shrink: 0;
}
.sheet-hdr {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
}
.sheet-hdr h2 { font-size: var(--text-lg); font-weight: 700; flex: 1; }
.sheet-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface2); border: none;
  color: var(--text-dim); font-size: var(--text-xl); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sheet-body {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
  -webkit-overflow-scrolling: touch;
}
.sheet-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0; display: flex; gap: 8px;
}
.sheet-footer button {
  flex: 1; height: 46px; border-radius: 12px;
  font-size: var(--text-base); font-weight: 700; cursor: pointer; border: none;
}
.btn-cancel { background: var(--surface2); color: var(--text-dim); }
.btn-save   { background: var(--amber); color: #000; }
.btn-save:disabled { opacity: .4; cursor: not-allowed; }

/* ── Form fields (used in sheets) ─────────────────────────────────────────── */
.field label {
  display: block; font-size: var(--text-xs); font-weight: 600;
  color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: var(--text-base); padding: 10px 12px;
  outline: none; -webkit-appearance: none;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--amber-dim);
}
.field textarea { resize: vertical; min-height: 60px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

/* ── Stat pills ────────────────────────────────────────────────────────────── */
.stat-pill {
  font-size: var(--text-xs); padding: 3px 8px; border-radius: 5px;
  background: var(--surface2); color: var(--text-mid);
  display: flex; align-items: center; gap: 4px;
}
.stat-pill.warn   { background: rgba(245,166,35,.15); color: var(--amber); }
.stat-pill.danger { background: var(--red-dim);       color: var(--red);   }
.stat-pill.ok     { background: var(--green-dim);     color: var(--green); }
.stat-pill.info   { background: var(--blue-dim);      color: var(--blue);  }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(18,20,26,.95);
  border: 1px solid var(--border2); border-radius: 12px;
  padding: 10px 18px; font-size: var(--text-base); font-weight: 500;
  white-space: nowrap; max-width: 88vw; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .25s;
  z-index: 80; backdrop-filter: blur(12px);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Presence dot (used by lead / supervisor views) ───────────────────────── */
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.dot.green  { background: var(--green);  box-shadow: 0 0 4px var(--green);  }
.dot.amber  { background: var(--amber);  box-shadow: 0 0 4px var(--amber);  }
.dot.red    { background: var(--red);    box-shadow: 0 0 4px var(--red);    }
.dot.grey   { background: var(--text-dim); }

/* ── Line status badge ─────────────────────────────────────────────────────── */
.line-status {
  font-size: var(--text-xs); font-weight: 700; padding: 2px 7px;
  border-radius: 4px; text-transform: uppercase; letter-spacing: .05em;
  flex-shrink: 0;
}
.line-status.running { background: var(--green-dim); color: var(--green); }
.line-status.down    { background: var(--red-dim);   color: var(--red);   }
.line-status.idle    { background: var(--surface2);  color: var(--text-dim); }

/* ── Responsive breakpoints ───────────────────────────────────────────────── */
/* Phone  < 768px : compact chrome                                            */
/* Tablet ≥ 768px : full layout, centred sheets                               */

@media (max-width: 767px) {
  #topbar { padding: calc(var(--safe-top) + 8px) 12px 8px; gap: 8px; }

  .tb-btn { height: 32px; padding: 0 10px; }

  /* sheets go near full-height on phones */
  .sheet { max-height: 96vh; border-radius: 16px 16px 0 0; }
  .sheet-body { padding: 12px 14px; gap: 10px; }
  .sheet-hdr  { padding: 12px 14px 10px; }
  .sheet-footer { padding: 10px 14px; }
  .sheet-footer button { height: 44px; }

  /* STRICT 16px min size on inputs to prevent iOS zoom */
  .field input, .field select, .field textarea { 
    font-size: max(16px, var(--text-base)); 
    padding: 9px 10px; 
  }
  .field label { margin-bottom: 4px; }
  .stat-pill { padding: 2px 6px; }
}

/* removed: body{transform:scale(.95)} broke position:fixed sheets on mobile
   (a transformed ancestor becomes the containing block for fixed children).
   Mobile layout reflows responsively without this zoom hack. */

@media (min-width: 768px) {
  /* sheets cap width and centre on tablet */
  .sheet {
    max-width: 520px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
  }
  .sheet.open {
    transform: translateX(-50%) translateY(0);
  }
}
