// Customer-facing screens (mobile)
// 1. Cek Pesanan — landing page where user inputs Order ID
// 2. Tracking   — order detail with 8-stage timeline, ring progress, history

const { useState, useEffect, useMemo, useRef } = React;

const MI = ({ name, size, style }) => (
  <span
    className="material-symbols-outlined"
    style={{ fontSize: size ? `${size}px` : undefined, lineHeight: 1, ...style }}
  >{name}</span>
);

// ═══════════════════════════════════════════════════════
// SCREEN 1 — CEK PESANAN
// ═══════════════════════════════════════════════════════
function CekPesananScreen({ navigate, theme }) {
  const [orderId, setOrderId] = useState("ORD-260526-001");
  const [err, setErr] = useState("");

  const submit = (e) => {
    e?.preventDefault();
    const id = orderId.trim();
    if (!id) { setErr("Masukkan ID pesanan dulu"); return; }
    navigate("tracking");
  };

  return (
    <div className="cp-page">
      {/* Backdrop — gradient + decorative pattern (replaces video bg in real app) */}
      <div className="cp-bg">
        <div className="cp-bg-grad" style={{
          background: `linear-gradient(160deg, #0b1620 0%, ${theme.primary}88 60%, ${theme.primary} 100%)`
        }} />
        <div className="cp-bg-pattern" />
      </div>

      <div className="cp-content">
        {/* Logo + brand */}
        <div className="cp-brand">
          <div className="cp-logo">
            <img src="assets/logo.png" alt="Damelkeun" />
          </div>
          <span className="cp-brand-name">Damelkeun</span>
        </div>

        <div className="cp-hero">
          <h1>
            Track pesanan kamu<br />
            <span className="cp-accent">real-time</span>, transparan.
          </h1>
          <p>Jasa konveksi yang fokus memberi update jelas, dari DP sampai pesanan tiba di tangan Anda.</p>
        </div>

        {/* Form card */}
        <form className="cp-card" onSubmit={submit}>
          <div className="cp-badge" style={{ background: `${theme.primary}25`, color: "#fff" }}>
            <MI name="manage_search" size={14} />
            Lacak Pesanan
          </div>
          <h2>Cek Status Pesanan</h2>
          <p className="cp-sub">Masukkan ID pesanan untuk lihat progres produksi</p>

          {err && (
            <div className="cp-err">
              <MI name="error" size={16} />
              {err}
            </div>
          )}

          <label>ID PESANAN</label>
          <div className="cp-input-wrap">
            <MI name="tag" size={18} style={{ position: "absolute", left: 14, opacity: 0.45 }} />
            <input
              value={orderId}
              onChange={(e) => { setOrderId(e.target.value.toUpperCase()); setErr(""); }}
              placeholder="ORD-260525-001"
              spellCheck="false"
              autoComplete="off"
            />
          </div>

          <button type="submit" style={{
            background: `linear-gradient(135deg, ${theme.primary}, ${theme.secondary})`,
            boxShadow: `0 10px 28px ${theme.primary}55`,
          }}>
            Lacak Pesanan
            <MI name="arrow_forward" size={18} />
          </button>

          <div className="cp-info">
            <MI name="tips_and_updates" size={16} />
            <p>ID pesanan dikirim via <strong>WhatsApp</strong> saat order dibuat.</p>
          </div>
        </form>

        {/* Feature pills */}
        <div className="cp-features">
          {[
            { icon: "schedule", title: "Real-time", desc: "Update tanpa refresh" },
            { icon: "chat",     title: "WA Notif",  desc: "Otomatis tiap update" },
            { icon: "verified", title: "Transparan", desc: "8 tahap terlacak" },
          ].map((f) => (
            <div className="cp-feat" key={f.title}>
              <div className="cp-feat-ic" style={{ background: `${theme.primary}33`, color: theme.primary }}>
                <MI name={f.icon} size={16} />
              </div>
              <div>
                <p className="cp-feat-t">{f.title}</p>
                <p className="cp-feat-d">{f.desc}</p>
              </div>
            </div>
          ))}
        </div>

        <p className="cp-footer">© 2026 Damelkeun Jaya Mandiri</p>
      </div>

      <style>{`
        .cp-page { position: relative; width: 100%; min-height: 100%; color: #fff; }
        .cp-bg { position: absolute; inset: 0; overflow: hidden; }
        .cp-bg-grad { position: absolute; inset: 0; }
        .cp-bg-pattern {
          position: absolute; inset: 0;
          background-image:
            radial-gradient(circle at 20% 30%, rgba(255,255,255,0.06) 0, transparent 30%),
            radial-gradient(circle at 80% 70%, rgba(255,255,255,0.04) 0, transparent 25%);
        }
        .cp-content { position: relative; padding: 64px 22px 40px; display: flex; flex-direction: column; gap: 22px; }

        .cp-brand { display: flex; align-items: center; gap: 10px; }
        .cp-logo {
          width: 44px; height: 44px; background: white; border-radius: 12px; padding: 6px;
          display: flex; align-items: center; justify-content: center;
          box-shadow: 0 6px 18px rgba(0,0,0,0.25);
        }
        .cp-logo img { width: 100%; height: 100%; object-fit: contain; }
        .cp-brand-name { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.3px; }

        .cp-hero h1 {
          font-size: 1.85rem; font-weight: 800; line-height: 1.15; letter-spacing: -1px;
          margin-bottom: 10px;
        }
        .cp-accent {
          background: linear-gradient(135deg, #4ade80, #60a5fa);
          -webkit-background-clip: text; -webkit-text-fill-color: transparent;
        }
        .cp-hero p { font-size: 0.88rem; opacity: 0.85; line-height: 1.55; }

        .cp-card {
          background: rgba(255,255,255,0.1);
          backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
          border: 1px solid rgba(255,255,255,0.18);
          border-radius: 20px; padding: 20px;
        }
        .cp-badge {
          display: inline-flex; align-items: center; gap: 4px;
          padding: 4px 10px; border-radius: 16px;
          font-size: 0.66rem; font-weight: 800; letter-spacing: 0.4px; text-transform: uppercase;
          margin-bottom: 10px;
        }
        .cp-card h2 { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.3px; }
        .cp-sub { font-size: 0.78rem; opacity: 0.75; margin-bottom: 14px; }
        .cp-card label { display: block; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.5px; margin-bottom: 6px; opacity: 0.85; }
        .cp-input-wrap { position: relative; display: flex; align-items: center; margin-bottom: 14px; }
        .cp-input-wrap input {
          width: 100%; padding: 13px 14px 13px 40px; border-radius: 12px;
          border: 1.5px solid rgba(255,255,255,0.5);
          background: rgba(255,255,255,0.95); color: #1a1a1a;
          font-family: ui-monospace, "SF Mono", Menlo, monospace;
          font-size: 0.92rem; font-weight: 700; letter-spacing: 0.5px;
          outline: none; box-sizing: border-box;
        }
        .cp-input-wrap input::placeholder { color: #9ca3af; font-weight: 400; }
        .cp-input-wrap .material-symbols-outlined { color: #6b7280; }

        .cp-err {
          display: flex; align-items: center; gap: 6px;
          background: rgba(248, 113, 113, 0.18); color: #fecaca;
          border: 1px solid rgba(248,113,113,0.35);
          padding: 8px 12px; border-radius: 10px;
          font-size: 0.78rem; font-weight: 600; margin-bottom: 12px;
        }

        .cp-card button {
          width: 100%; height: 48px; border: none; border-radius: 12px;
          color: white; font-size: 0.92rem; font-weight: 800; cursor: pointer;
          display: flex; align-items: center; justify-content: center; gap: 6px;
        }
        .cp-card button:active { transform: translateY(1px); }

        .cp-info {
          display: flex; align-items: flex-start; gap: 6px;
          padding: 10px 12px; margin-top: 14px;
          background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
          border-radius: 10px; font-size: 0.72rem; line-height: 1.5; opacity: 0.85;
        }
        .cp-info .material-symbols-outlined { color: #fbbf24; flex-shrink: 0; margin-top: 1px; }

        .cp-features { display: flex; flex-direction: column; gap: 8px; }
        .cp-feat {
          display: flex; align-items: center; gap: 10px;
          background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
          padding: 10px 12px; border-radius: 12px;
        }
        .cp-feat-ic {
          width: 32px; height: 32px; border-radius: 9px;
          display: flex; align-items: center; justify-content: center; flex-shrink: 0;
        }
        .cp-feat-t { font-size: 0.82rem; font-weight: 800; }
        .cp-feat-d { font-size: 0.7rem; opacity: 0.7; }

        .cp-footer { text-align: center; font-size: 0.65rem; opacity: 0.55; margin-top: 6px; }
      `}</style>
    </div>
  );
}

// ═══════════════════════════════════════════════════════
// SCREEN 2 — TRACKING
// ═══════════════════════════════════════════════════════
function TrackingScreen({ navigate, theme, scenario }) {
  const order = useMemo(() => buildMainOrder(scenario), [scenario]);
  const [refreshing, setRefreshing] = useState(false);
  const [lastSync, setLastSync] = useState(new Date());

  // Polling simulation
  useEffect(() => {
    const i = setInterval(() => {
      setRefreshing(true);
      setTimeout(() => { setRefreshing(false); setLastSync(new Date()); }, 600);
    }, 8000);
    return () => clearInterval(i);
  }, []);

  const currentIdx = useMemo(() => {
    for (let i = 0; i < STAGES.length; i++) {
      if (Number(order[STAGES[i].key]) < 100) return i;
    }
    return STAGES.length;
  }, [order]);

  const status = STATUS_INFO[order.status] || STATUS_INFO.Active;
  const allDone = order.status === "Done" || order.overall_persen === 100;

  // Stage completion dates (mock — backfill from history)
  const stageDates = {
    dp:            "2026-05-12",
    belanja_kain:  "2026-05-20",
    potong_kain:   "2026-05-22",
    sablon_bordir: "2026-05-24",
    jahit:         "2026-05-26",
    qc:            "2026-05-27",
    packing:       "2026-05-28",
    pengiriman:    "2026-05-29",
  };

  const fmtDate = (iso) => {
    if (!iso) return "";
    const d = new Date(iso);
    const hari = ["Min","Sen","Sel","Rab","Kam","Jum","Sab"][d.getDay()];
    const bln  = ["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des"][d.getMonth()];
    return `${hari}, ${d.getDate()} ${bln}`;
  };

  return (
    <div className="tr-page" style={{ background: theme.bg }}>
      {/* Decorative blobs */}
      <div className="tr-blob tr-blob-1" style={{ background: `${theme.primary}22` }} />
      <div className="tr-blob tr-blob-2" style={{ background: `${theme.secondary}22` }} />

      {/* Header */}
      <header className="tr-header">
        <button className="tr-back" onClick={() => navigate("cek-pesanan")}>
          <MI name="arrow_back" size={20} />
        </button>
        <div className="tr-brand-logo">
          <img src="assets/logo.png" alt="" />
        </div>
        <div className="tr-brand-text">
          <h1>Damelkeun</h1>
          <p>Tracking Pesanan</p>
        </div>
        <div className={`tr-live ${refreshing ? "syncing" : ""}`}>
          <span className="tr-live-dot" style={{ background: theme.primary }} />
          <span>{refreshing ? "Sync..." : "Live"}</span>
        </div>
      </header>

      <main className="tr-main">
        {/* Order hero */}
        <div className="tr-hero" style={{ borderTop: `3px dashed ${theme.primary}` }}>
          <div className="tr-hero-top">
            <div>
              <span className="tr-pill" style={{ background: `${theme.primary}1a`, color: theme.primary }}>
                <MI name="receipt" size={14} />
                {order.order_id}
              </span>
              <h2>{order.nama_pembeli}</h2>
              <div className="tr-meta">
                <span><MI name="event" size={14} />{fmtDate(order.tanggal_order)}</span>
                <span className="tr-dot">•</span>
                <span><MI name="inventory_2" size={14} />{order.qty} pcs</span>
              </div>
            </div>
            <span className="tr-status" style={{ background: status.bg, color: status.color }}>
              <MI name={status.icon} size={14} />
              {status.label}
            </span>
          </div>
          <div className="tr-product" style={{ borderLeft: `3px solid ${theme.primary}` }}>
            <span>DETAIL PRODUK</span>
            <p>{order.detail_produk}</p>
          </div>
        </div>

        {/* Ring + overall */}
        <div className="tr-overall">
          <div className="tr-ring-wrap">
            <svg viewBox="0 0 120 120">
              <circle cx="60" cy="60" r="52" fill="none" stroke="#e2e8f0" strokeWidth="10" />
              <circle
                cx="60" cy="60" r="52" fill="none"
                stroke={`url(#tr-grad)`} strokeWidth="10" strokeLinecap="round"
                strokeDasharray={`${(order.overall_persen/100)*326.7} 326.7`}
                transform="rotate(-90 60 60)"
                style={{ transition: "stroke-dasharray 0.8s ease-out" }}
              />
              <defs>
                <linearGradient id="tr-grad">
                  <stop offset="0%" stopColor={theme.primary} />
                  <stop offset="100%" stopColor={theme.secondary} />
                </linearGradient>
              </defs>
            </svg>
            <div className="tr-ring-text">
              <span className="tr-ring-num" style={{ color: theme.primary }}>{order.overall_persen}</span>
              <span className="tr-ring-pct">%</span>
            </div>
          </div>
          <div className="tr-overall-info">
            <p className="tr-oi-label">Progress Total Produksi</p>
            {allDone ? (
              <p className="tr-oi-done">
                <MI name="celebration" size={20} />
                {order.status === "Done" ? "Pesanan Anda Selesai!" : "—"}
              </p>
            ) : order.status === "Cancel" ? (
              <p className="tr-oi-cancel">
                <MI name="cancel" size={18} />
                Pesanan dibatalkan
              </p>
            ) : currentIdx < STAGES.length ? (
              <>
                <p className="tr-oi-current-label">Sedang dikerjakan:</p>
                <p className="tr-oi-current" style={{ color: theme.primary }}>
                  <MI name={STAGES[currentIdx].icon} size={18} />
                  {STAGES[currentIdx].label}
                </p>
              </>
            ) : null}
          </div>
        </div>

        {/* Timeline */}
        <div className="tr-tl-card">
          <div className="tr-section-head">
            <MI name="timeline" size={18} style={{ color: theme.primary }} />
            <h3>Tahapan Produksi</h3>
            <span className="tr-counter">
              {STAGES.filter((s) => Number(order[s.key]) === 100).length}/{STAGES.length}
            </span>
          </div>
          <div className="tr-timeline">
            {STAGES.map((s, idx) => {
              const val = Number(order[s.key] || 0);
              const done = val === 100;
              const active = idx === currentIdx && order.status !== "Cancel";
              return (
                <div key={s.key} className={`tr-stage ${done ? "done" : ""} ${active ? "active" : ""}`}>
                  <div className="tr-stage-col">
                    <div className="tr-stage-circle" style={{
                      background: done ? theme.primary : (active ? theme.secondary : "#e2e8f0"),
                      boxShadow: active ? `0 0 0 6px ${theme.secondary}22` : "none",
                    }}>
                      <MI name={done ? "check" : s.icon} size={16} />
                    </div>
                    {idx < STAGES.length - 1 && (
                      <div className="tr-stage-conn" style={{ background: done ? theme.primary : "#e2e8f0" }} />
                    )}
                  </div>
                  <div className="tr-stage-info">
                    <div className="tr-stage-head">
                      <div>
                        <p className="tr-stage-name">{s.label}</p>
                        <p className="tr-stage-desc">{s.desc}</p>
                      </div>
                      <span className="tr-stage-pct" style={{
                        background: done ? `${theme.primary}1a` : (active ? `${theme.secondary}1a` : "transparent"),
                        color: done ? theme.primary : (active ? theme.secondary : "#94a3b8"),
                      }}>{val}%</span>
                    </div>
                    {!done && val > 0 && (
                      <div className="tr-stage-bar">
                        <div className="tr-stage-fill" style={{
                          width: `${val}%`,
                          background: `linear-gradient(90deg, ${theme.primary}, ${theme.secondary})`,
                        }} />
                      </div>
                    )}
                    {done && (
                      <div className="tr-stage-done">
                        <span style={{ color: theme.primary }}>
                          <MI name="check_circle" size={14} />
                          Selesai
                        </span>
                        <span className="tr-date" style={{ background: `${theme.primary}15`, color: theme.primary }}>
                          <MI name="event_available" size={12} />
                          {fmtDate(stageDates[s.key])}
                        </span>
                      </div>
                    )}
                  </div>
                </div>
              );
            })}
          </div>
        </div>

        {/* History with photos */}
        <div className="tr-hist-card">
          <div className="tr-section-head">
            <MI name="history" size={18} style={{ color: theme.primary }} />
            <h3>Riwayat Update</h3>
            <span className="tr-counter">{SAMPLE_HISTORY.length}</span>
          </div>
          <div className="tr-hist-list">
            {SAMPLE_HISTORY.slice(0, 4).map((h) => {
              const stageObj = STAGES.find((s) => s.key === h.stage);
              const label = stageObj ? stageObj.label : h.stage;
              const hasPhoto = h.foto_urls && h.foto_urls.length > 0;
              const dt = new Date(h.timestamp);
              return (
                <div key={h.id} className={`tr-hist-item ${hasPhoto ? "has-photo" : ""}`}>
                  <div className="tr-hist-dot" style={{ background: theme.primary }} />
                  <div className="tr-hist-body">
                    <p className="tr-hist-stage">
                      {label}
                      {hasPhoto && (
                        <span className="tr-photo-badge" style={{ background: theme.primary }}>
                          <MI name="photo_camera" size={11} />
                        </span>
                      )}
                    </p>
                    <p className="tr-hist-change">
                      <span className="tr-hist-old">{h.old_value}%</span>
                      <span className="tr-hist-arrow">→</span>
                      <span className="tr-hist-new">{h.new_value}%</span>
                    </p>
                    <p className="tr-hist-time">
                      {fmtDate(h.timestamp)} • {dt.toLocaleTimeString("id-ID", { hour: "2-digit", minute: "2-digit" })}
                    </p>
                    {hasPhoto && (
                      <div className="tr-hist-photos">
                        {h.foto_urls.map((id, i) => {
                          const ph = PHOTO_PLACEHOLDERS[id];
                          return (
                            <div key={i} className="tr-photo-thumb" style={{
                              background: `linear-gradient(135deg, hsl(${ph.hue},65%,55%), hsl(${ph.hue+30},65%,45%))`,
                            }}>
                              <span>{ph.label}</span>
                            </div>
                          );
                        })}
                      </div>
                    )}
                  </div>
                </div>
              );
            })}
          </div>
        </div>

        {/* Deadline */}
        {!allDone && order.status !== "Cancel" && (
          <div className="tr-deadline" style={{ background: "#fef9ec", color: "#92400e" }}>
            <MI name="timer" size={20} />
            <div>
              <p className="tr-dl-label">Deadline Pesanan</p>
              <p className="tr-dl-text">10 hari lagi (5 Juni 2026)</p>
            </div>
          </div>
        )}

        {/* Meta */}
        <div className="tr-meta-row">
          <span><MI name="update" size={14} />Update terakhir: {lastSync.toLocaleTimeString("id-ID", { hour: "2-digit", minute: "2-digit" })}</span>
        </div>

        <button className="tr-cta" onClick={() => navigate("cek-pesanan")} style={{ borderColor: theme.primary, color: theme.primary }}>
          <MI name="manage_search" size={16} />
          Cek pesanan lain
        </button>
      </main>

      <style>{`
        .tr-page { position: relative; min-height: 100%; overflow-x: hidden; color: #1d1e20; }
        .tr-blob { position: fixed; border-radius: 50%; filter: blur(60px); pointer-events: none; }
        .tr-blob-1 { width: 240px; height: 240px; top: -60px; left: -60px; }
        .tr-blob-2 { width: 200px; height: 200px; bottom: 0; right: -60px; }

        .tr-header {
          position: sticky; top: 0; z-index: 10;
          padding: 12px 14px; backdrop-filter: blur(12px);
          background: ${theme.bg}cc;
          border-bottom: 1px solid rgba(0,0,0,0.05);
          display: flex; align-items: center; gap: 8px;
        }
        .tr-back {
          width: 32px; height: 32px; border-radius: 10px;
          background: white; border: 1px solid rgba(0,0,0,0.06);
          display: flex; align-items: center; justify-content: center;
          cursor: pointer; color: #1d1e20; flex-shrink: 0;
        }
        .tr-brand-logo {
          width: 32px; height: 32px; background: white; border-radius: 9px; padding: 3px;
          display: flex; align-items: center; justify-content: center;
          box-shadow: 0 2px 8px rgba(0,0,0,0.06); flex-shrink: 0;
        }
        .tr-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
        .tr-brand-text { flex: 1; min-width: 0; }
        .tr-brand-text h1 { font-size: 0.95rem; font-weight: 800; letter-spacing: -0.3px; }
        .tr-brand-text p { font-size: 0.62rem; opacity: 0.65; }
        .tr-live {
          display: inline-flex; align-items: center; gap: 4px;
          padding: 5px 9px; background: white; border-radius: 12px;
          font-size: 0.65rem; font-weight: 800;
          box-shadow: 0 1px 4px rgba(0,0,0,0.06); flex-shrink: 0;
        }
        .tr-live-dot { width: 5px; height: 5px; border-radius: 50%; animation: livePulse 1.5s ease-in-out infinite; }
        .tr-live.syncing .tr-live-dot { animation-duration: 0.5s; }
        @keyframes livePulse { 0%,100%{opacity:1} 50%{opacity:.3} }

        .tr-main { position: relative; z-index: 1; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

        .tr-hero { background: white; border-radius: 16px; padding: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); }
        .tr-hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
        .tr-pill {
          display: inline-flex; align-items: center; gap: 4px;
          font-family: monospace; font-size: 0.7rem; font-weight: 800;
          padding: 3px 9px; border-radius: 14px; margin-bottom: 6px;
        }
        .tr-hero h2 { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.3px; margin-bottom: 4px; }
        .tr-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 0.72rem; opacity: 0.75; }
        .tr-meta > span:not(.tr-dot) { display: inline-flex; align-items: center; gap: 3px; }
        .tr-dot { opacity: 0.4; }
        .tr-status {
          display: inline-flex; align-items: center; gap: 4px;
          padding: 5px 10px; border-radius: 14px;
          font-size: 0.7rem; font-weight: 800; white-space: nowrap; flex-shrink: 0;
        }
        .tr-product { background: rgba(0,0,0,0.03); padding: 10px 12px; border-radius: 0 10px 10px 0; }
        .tr-product span { font-size: 0.6rem; font-weight: 800; opacity: 0.5; letter-spacing: 0.5px; display: block; margin-bottom: 3px; }
        .tr-product p { font-size: 0.82rem; line-height: 1.4; font-weight: 500; }

        .tr-overall {
          background: white; border-radius: 16px; padding: 16px;
          box-shadow: 0 4px 20px rgba(0,0,0,0.05);
          display: flex; align-items: center; gap: 14px;
        }
        .tr-ring-wrap { position: relative; width: 90px; height: 90px; flex-shrink: 0; }
        .tr-ring-wrap svg { width: 100%; height: 100%; }
        .tr-ring-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
        .tr-ring-num { font-size: 1.6rem; font-weight: 800; letter-spacing: -1.5px; line-height: 1; }
        .tr-ring-pct { font-size: 0.85rem; opacity: 0.6; font-weight: 700; }
        .tr-overall-info { flex: 1; min-width: 0; }
        .tr-oi-label { font-size: 0.62rem; font-weight: 800; opacity: 0.5; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 6px; }
        .tr-oi-current-label { font-size: 0.7rem; opacity: 0.65; margin-bottom: 3px; }
        .tr-oi-current { font-size: 0.92rem; font-weight: 800; display: flex; align-items: center; gap: 4px; }
        .tr-oi-done { display: flex; align-items: center; gap: 5px; font-size: 0.95rem; font-weight: 800; color: #15803d; }
        .tr-oi-cancel { display: flex; align-items: center; gap: 5px; font-size: 0.88rem; font-weight: 800; color: #dc2626; }

        .tr-tl-card, .tr-hist-card { background: white; border-radius: 16px; padding: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.05); }
        .tr-section-head { display: flex; align-items: center; gap: 5px; margin-bottom: 14px; }
        .tr-section-head h3 { font-size: 0.85rem; font-weight: 800; flex: 1; }
        .tr-counter {
          font-size: 0.7rem; font-weight: 800; opacity: 0.6;
          padding: 2px 8px; background: rgba(0,0,0,0.05); border-radius: 8px;
          font-family: monospace;
        }
        .tr-timeline { display: flex; flex-direction: column; }
        .tr-stage { display: flex; gap: 10px; }
        .tr-stage-col { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
        .tr-stage-circle {
          width: 30px; height: 30px; border-radius: 50%; color: white;
          display: flex; align-items: center; justify-content: center;
          transition: all 0.4s; z-index: 1;
        }
        .tr-stage:not(.done):not(.active) .tr-stage-circle { color: #94a3b8; }
        .tr-stage.active .tr-stage-circle { animation: stagePulse 1.5s ease-in-out infinite; color: white; }
        @keyframes stagePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
        .tr-stage-conn { width: 2px; flex: 1; min-height: 32px; margin: 3px 0; }
        .tr-stage-info { flex: 1; padding-bottom: 16px; padding-top: 2px; min-width: 0; }
        .tr-stage:last-child .tr-stage-info { padding-bottom: 0; }
        .tr-stage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 3px; }
        .tr-stage-name { font-size: 0.82rem; font-weight: 700; line-height: 1.3; }
        .tr-stage-desc { font-size: 0.65rem; opacity: 0.55; margin-top: 2px; }
        .tr-stage:not(.done):not(.active) .tr-stage-name,
        .tr-stage:not(.done):not(.active) .tr-stage-desc { opacity: 0.45; }
        .tr-stage-pct { font-size: 0.65rem; font-weight: 800; font-family: monospace; padding: 2px 6px; border-radius: 6px; flex-shrink: 0; }
        .tr-stage-bar { height: 4px; background: rgba(0,0,0,0.06); border-radius: 4px; overflow: hidden; margin-top: 4px; }
        .tr-stage-fill { height: 100%; border-radius: 4px; transition: width 0.6s; }
        .tr-stage-done { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
        .tr-stage-done > span:first-child {
          display: inline-flex; align-items: center; gap: 3px;
          font-size: 0.66rem; font-weight: 800;
        }
        .tr-date {
          display: inline-flex; align-items: center; gap: 3px;
          padding: 2px 6px; border-radius: 10px;
          font-size: 0.62rem; font-weight: 700;
        }

        .tr-hist-list { display: flex; flex-direction: column; gap: 8px; }
        .tr-hist-item {
          display: flex; gap: 8px; padding: 8px 10px;
          background: rgba(0,0,0,0.025); border-radius: 10px;
          align-items: flex-start;
        }
        .tr-hist-item.has-photo { background: ${theme.primary}0d; }
        .tr-hist-dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
        .tr-hist-body { flex: 1; min-width: 0; }
        .tr-hist-stage { font-size: 0.78rem; font-weight: 800; margin-bottom: 2px; }
        .tr-photo-badge {
          display: inline-flex; align-items: center;
          margin-left: 5px; color: white;
          padding: 1px 5px; border-radius: 5px; vertical-align: middle;
        }
        .tr-hist-change { font-size: 0.74rem; margin-bottom: 2px; }
        .tr-hist-old { color: #94a3b8; text-decoration: line-through; font-family: monospace; }
        .tr-hist-arrow { margin: 0 5px; opacity: 0.5; }
        .tr-hist-new { font-weight: 800; font-family: monospace; }
        .tr-hist-time { font-size: 0.65rem; opacity: 0.6; }
        .tr-hist-photos {
          display: flex; gap: 6px; margin-top: 6px;
          overflow-x: auto; padding-bottom: 2px;
        }
        .tr-hist-photos::-webkit-scrollbar { display: none; }
        .tr-photo-thumb {
          flex-shrink: 0; width: 80px; height: 80px;
          border-radius: 8px; padding: 6px;
          display: flex; align-items: flex-end;
          color: white; font-size: 0.6rem; font-weight: 700;
          box-shadow: 0 2px 6px rgba(0,0,0,0.15);
        }

        .tr-deadline {
          display: flex; align-items: center; gap: 10px;
          padding: 12px 14px; border-radius: 14px;
        }
        .tr-dl-label { font-size: 0.65rem; opacity: 0.7; font-weight: 700; }
        .tr-dl-text { font-size: 0.85rem; font-weight: 800; }

        .tr-meta-row {
          display: flex; justify-content: space-between;
          font-size: 0.68rem; opacity: 0.65;
        }
        .tr-meta-row span { display: inline-flex; align-items: center; gap: 3px; }

        .tr-cta {
          display: inline-flex; align-items: center; justify-content: center; gap: 6px;
          padding: 10px 16px; border: 1.5px solid;
          border-radius: 12px; background: transparent;
          font-weight: 800; font-size: 0.82rem; cursor: pointer;
          align-self: center; margin-top: 6px;
        }
      `}</style>
    </div>
  );
}

window.CekPesananScreen = CekPesananScreen;
window.TrackingScreen = TrackingScreen;
window.MI = MI;
