// Secondary main screens: Find, Service, Notifications, Profile
// Plus aux flow: Splash, Onboarding (3 steps), Pair vehicle

const t2 = THEMES.c;

// ─────────────────────────────────────────────────────────────
// FIND MY CAR — Hanoi map with horn/flash feedback
// ─────────────────────────────────────────────────────────────
function FindScreen() {
  const nav = useRouter();
  const { tw } = useApp();
  const L = STRINGS[tw.lang];
  const v = VEHICLES[tw.model];

  // Bottom sheet drag
  const [sheetY, setSheetY] = React.useState(0);   // 0 = expanded, +N = collapsed
  const startY = React.useRef(null);
  const startSheetY = React.useRef(0);
  const onSheetDown = (e) => {
    startY.current = (e.touches ? e.touches[0].clientY : e.clientY);
    startSheetY.current = sheetY;
  };
  const onSheetMove = (e) => {
    if (startY.current == null) return;
    const y = e.touches ? e.touches[0].clientY : e.clientY;
    const dy = y - startY.current;
    setSheetY(Math.max(0, Math.min(160, startSheetY.current + dy)));
  };
  const onSheetUp = () => {
    if (startY.current == null) return;
    startY.current = null;
    setSheetY(sheetY > 80 ? 160 : 0);
  };

  return (
    <div style={{ width: '100%', height: '100%', position: 'relative' }}>
      {/* Map */}
      <HanoiMap/>
      <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(50% 30% at 52% 46%, rgba(212,165,116,0.18), transparent 70%)', pointerEvents: 'none' }}/>

      {/* POIs near the car */}
      <POI left="38%" top="36%" kind="fuel" label="Petrolimex"/>
      <POI left="68%" top="56%" kind="service" label="Thaco LB"/>
      <POI left="58%" top="78%" kind="park" label=""/>

      {/* Top bar */}
      <div style={{ position: 'absolute', top: 72, left: 16, right: 16, display: 'flex', gap: 10 }}>
        <GlassC padding={0} radius={28} intensity={tw.glass} style={{ flex: 1 }}>
          <div style={{ display: 'flex', alignItems: 'center', padding: '0 14px', height: 44, gap: 12 }}>
            <div onClick={nav.back} style={{ cursor: 'pointer' }}>
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke={t2.text} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M15 18l-6-6 6-6"/></svg>
            </div>
            <Icons.search size={16}/>
            <div style={{ flex: 1, fontSize: 13 }}>Vincom Bà Triệu, Hà Nội</div>
          </div>
        </GlassC>
        <GlassC padding={0} radius={22} intensity={tw.glass} style={{ width: 44, height: 44, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <Icons.signal size={18}/>
        </GlassC>
      </div>

      {/* Concentric range rings + car pin */}
      <div style={{ position: 'absolute', top: '46%', left: '52%', transform: 'translate(-50%,-50%)' }}>
        {[200, 150, 100].map((s, i) => (
          <div key={i} style={{ position: 'absolute', top: -s/2, left: -s/2, width: s, height: s, borderRadius: s/2,
                                border: `1px solid rgba(212,165,116,${0.10 + i * 0.12})`,
                                animation: `c-pulse-strong ${2 + i * 0.4}s ease-out infinite`,
                                animationDelay: (i * 0.5) + 's' }}/>
        ))}
        <div style={{ position: 'absolute', top: -28, left: -28, width: 56, height: 56, borderRadius: 28, background: t2.accent,
                      display: 'flex', alignItems: 'center', justifyContent: 'center', color: t2.accentInk,
                      boxShadow: '0 8px 24px rgba(212,165,116,0.5)' }}>
          <Icons.car size={28}/>
        </div>
        <div style={{ position: 'absolute', top: 32, left: -50, width: 100, textAlign: 'center', fontSize: 10, fontFamily: t2.mono, color: t2.text, letterSpacing: 1 }}>
          {v.plate}
        </div>
      </div>

      {/* User dot */}
      <div style={{ position: 'absolute', top: '62%', left: '34%' }}>
        <div style={{ width: 16, height: 16, borderRadius: 8, background: t2.accent2, border: '3px solid #fff', boxShadow: '0 0 0 6px rgba(124,183,255,0.3)' }}/>
      </div>

      {/* Bottom sheet — draggable */}
      <div style={{
        position: 'absolute', bottom: 0, left: 0, right: 0,
        transform: `translateY(${sheetY}px)`,
        transition: startY.current ? 'none' : 'transform .3s cubic-bezier(.4,0,.2,1)',
        padding: 16, paddingBottom: 36,
      }}>
        <GlassC padding={0} radius={26} intensity={Math.max(1, tw.glass)} style={{ background: 'rgba(20,25,30,0.85)' }}>
          {/* drag handle */}
          <div onMouseDown={onSheetDown} onMouseMove={onSheetMove} onMouseUp={onSheetUp} onMouseLeave={onSheetUp}
               onTouchStart={onSheetDown} onTouchMove={onSheetMove} onTouchEnd={onSheetUp}
               style={{ padding: '10px 0', display: 'flex', justifyContent: 'center', cursor: 'grab' }}>
            <div style={{ width: 36, height: 4, borderRadius: 2, background: 'rgba(255,255,255,0.25)' }}/>
          </div>
          <div style={{ padding: '0 18px 18px' }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 14 }}>
              <div>
                <div style={{ fontSize: 11, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1 }}>{L.parkedAt.toUpperCase()}</div>
                <div style={{ fontSize: 20, fontWeight: 500, marginTop: 4, letterSpacing: -0.3 }}>Vincom Bà Triệu</div>
                <div style={{ fontSize: 12, color: t2.textDim, marginTop: 2 }}>{T(tw.lang, 'P3 · Slot B-142 · Hanoi', 'Tầng 3 · Chỗ B-142 · Hà Nội')}</div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontSize: 28, fontWeight: 500, fontVariantNumeric: 'tabular-nums', letterSpacing: -0.6 }}>0.4</div>
                <div style={{ fontSize: 11, color: t2.textDim }}>{L.distance}</div>
              </div>
            </div>
            <div style={{ display: 'flex', gap: 10 }}>
              <button onClick={() => nav.openSheet('navigate', { to: 'Vincom Bà Triệu', distance: '0.4 km', dur: '6 min' })}
                      style={{ flex: 1, height: 48, border: 'none', borderRadius: 24, background: t2.accent, color: t2.accentInk, fontSize: 14, fontWeight: 600, fontFamily: t2.font, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, cursor: 'pointer' }}>
                <Icons.arrow size={16}/> {L.navigate}
              </button>
              <button onClick={() => nav.openSheet('hornFeedback')}
                      style={{ width: 48, height: 48, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 24, background: 'rgba(255,255,255,0.04)', color: t2.text, cursor: 'pointer' }}>
                <Icons.horn size={18}/>
              </button>
              <button onClick={() => nav.openSheet('flashFeedback')}
                      style={{ width: 48, height: 48, border: '1px solid rgba(255,255,255,0.1)', borderRadius: 24, background: 'rgba(255,255,255,0.04)', color: t2.text, cursor: 'pointer' }}>
                <Icons.flash size={18}/>
              </button>
            </div>

            {/* extra info — visible when expanded */}
            <div style={{ marginTop: 16, paddingTop: 16, borderTop: '1px solid rgba(255,255,255,0.06)', opacity: 1 - sheetY / 160, transition: 'opacity .2s' }}>
              <div style={{ fontSize: 10, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1, marginBottom: 8 }}>{T(tw.lang, 'NEARBY', 'GẦN ĐÂY')}</div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
                {[
                  { i: 'fuel', n: 'Petrolimex Bà Triệu', d: T(tw.lang, '120 m · RON95 21,340₫', '120 m · RON95 21.340₫') },
                  { i: 'wrench', n: 'Mazda Thaco Long Biên', d: T(tw.lang, '3.2 km · Authorized', '3,2 km · Chính hãng') },
                ].map((p, i) => {
                  const I = Icons[p.i];
                  return (
                    <div key={i} onClick={() => nav.openSheet('navigate', { to: p.n, distance: p.d.split(' · ')[0], dur: T(tw.lang, '2 min', '2 phút') })}
                         style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '8px 0', cursor: 'pointer' }}>
                      <div style={{ width: 28, height: 28, borderRadius: 14, background: 'rgba(255,255,255,0.05)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                        <I size={14}/>
                      </div>
                      <div style={{ flex: 1 }}>
                        <div style={{ fontSize: 12, fontWeight: 500 }}>{p.n}</div>
                        <div style={{ fontSize: 10, color: t2.textDim, marginTop: 1 }}>{p.d}</div>
                      </div>
                      <div style={{ color: t2.textMute }}><Icons.chev size={14}/></div>
                    </div>
                  );
                })}
              </div>
            </div>
          </div>
        </GlassC>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// SERVICE
// ─────────────────────────────────────────────────────────────
function ServiceScreen() {
  const nav = useRouter();
  const { tw } = useApp();
  const L = STRINGS[tw.lang];
  const v = VEHICLES[tw.model];
  const [selectedDealer, setDealer] = React.useState(0);
  const [selectedDate, setDate] = React.useState(2);
  const [time, setTime] = React.useState('09:30');

  const dealers = [
    { n: 'Thaco Long Biên', a: T(tw.lang, '15 Nguyễn Văn Cừ · Hanoi', '15 Nguyễn Văn Cừ · Hà Nội'), d: '3.2', stars: 4.8 },
    { n: 'Thaco Lê Văn Lương', a: T(tw.lang, 'Trung Hòa District · Hanoi', 'KĐT Trung Hòa · Hà Nội'), d: '5.8', stars: 4.7 },
    { n: 'Thaco Phạm Văn Đồng', a: T(tw.lang, 'Bắc Từ Liêm · Hanoi', 'Bắc Từ Liêm · Hà Nội'), d: '8.1', stars: 4.9 },
  ];
  const dates = ['T2 19', 'T3 20', 'T4 21', 'T5 22', 'T6 23', 'T7 24'];
  const times = ['08:00', '09:30', '11:00', '13:30', '15:00', '16:30'];

  // The vehicle reports its own due service — we show that and book it as a slot;
  // the dealer assesses on arrival to finalize the work + price.
  const suggested = T(tw.lang, '10,000 km maintenance', 'Bảo dưỡng 10,000 km');
  const estimate = 1850000;

  return (
    <ScreenShell>
      <div style={{ padding: '6px 18px 20px' }} className="c-stagger">
        <div style={{ marginBottom: 18 }}>
          <div style={{ fontSize: 11, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1 }}>{L.bookService.toUpperCase()}</div>
          <div style={{ fontSize: 26, fontWeight: 400, letterSpacing: -0.5, marginTop: 2 }}>{T(tw.lang, 'Schedule service', 'Đặt lịch hẹn')}</div>
        </div>

        {/* Service summary card — what the dealer will work on */}
        <GlassC padding={16} radius={24} intensity={tw.glass} style={{ marginBottom: 12 }} accentLine>
          <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
            <div style={{ width: 44, height: 44, borderRadius: 14, background: 'rgba(212,165,116,0.14)', color: t2.accent, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
              <Icons.wrench size={22}/>
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 11, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1 }}>{T(tw.lang, 'SUGGESTED', 'ĐỀ XUẤT')}</div>
              <div style={{ fontSize: 16, fontWeight: 500, marginTop: 2 }}>{suggested}</div>
              <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>{T(tw.lang, 'Due in 2,300 km · ~ 90 min', 'Còn 2,300 km · ~ 90 phút')}</div>
            </div>
          </div>
          <div style={{ marginTop: 14, paddingTop: 12, borderTop: '1px solid rgba(255,255,255,0.06)',
                        display: 'flex', gap: 10, alignItems: 'flex-start' }}>
            <div style={{ fontSize: 10, fontFamily: t2.mono, color: t2.accent2, letterSpacing: 1.5, paddingTop: 1, flexShrink: 0 }}>{T(tw.lang, 'NOTE', 'LƯU Ý')}</div>
            <div style={{ flex: 1, fontSize: 11, color: t2.textDim, lineHeight: 1.5 }}>
              {T(tw.lang, 'Final cost and any extra work confirmed at the dealer on arrival.', 'Báo giá cuối cùng và các hạng mục bổ sung sẽ được xác nhận tại đại lý khi xe đến.')}
            </div>
          </div>
        </GlassC>

        <GlassC padding={16} radius={24} intensity={tw.glass} style={{ marginBottom: 12 }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
            <div style={{ fontSize: 10, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1 }}>01 · {L.chooseDealer.toUpperCase()}</div>
            <div onClick={() => nav.go('dealer')} style={{ fontSize: 11, color: t2.accent, cursor: 'pointer' }}>{T(tw.lang, 'Map →', 'Bản đồ →')}</div>
          </div>
          {dealers.map((d, i) => (
            <div key={i} onClick={() => setDealer(i)}
                 style={{ padding: '12px 0', display: 'flex', alignItems: 'center', gap: 14, cursor: 'pointer',
                          borderTop: i ? '1px solid rgba(255,255,255,0.06)' : 'none' }}>
              <div style={{ width: 20, height: 20, borderRadius: 10, border: `2px solid ${selectedDealer === i ? t2.accent : 'rgba(255,255,255,0.2)'}`,
                            display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'all .15s' }}>
                {selectedDealer === i && <div style={{ width: 10, height: 10, borderRadius: 5, background: t2.accent }}/>}
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 14, fontWeight: 500 }}>{d.n}</div>
                <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>{d.a}</div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontSize: 11, color: t2.accent }}>★ {d.stars}</div>
                <div style={{ fontSize: 11, color: t2.textDim, fontVariantNumeric: 'tabular-nums', marginTop: 2 }}>{d.d} km</div>
              </div>
            </div>
          ))}
        </GlassC>

        <GlassC padding={16} radius={24} intensity={tw.glass} style={{ marginBottom: 12 }}>
          <div style={{ fontSize: 10, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1, marginBottom: 12 }}>02 · {L.chooseDate.toUpperCase()}</div>
          <div style={{ display: 'flex', gap: 6, marginBottom: 14 }}>
            {dates.map((d, i) => (
              <div key={d} onClick={() => setDate(i)}
                   style={{ flex: 1, padding: '12px 0', textAlign: 'center', borderRadius: 12, cursor: 'pointer',
                            background: selectedDate === i ? t2.accent : 'rgba(255,255,255,0.05)',
                            color: selectedDate === i ? t2.accentInk : t2.text, transition: 'all .15s' }}>
                <div style={{ fontSize: 9, opacity: 0.7, fontFamily: t2.mono, letterSpacing: 1 }}>{d.split(' ')[0]}</div>
                <div style={{ fontSize: 16, fontWeight: 600, marginTop: 3 }}>{d.split(' ')[1]}</div>
              </div>
            ))}
          </div>
          <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
            {times.map((tm) => (
              <div key={tm} onClick={() => setTime(tm)}
                   style={{ flex: '1 0 30%', padding: '10px 0', textAlign: 'center', borderRadius: 12, cursor: 'pointer',
                            border: `1px solid ${time === tm ? t2.accent : 'rgba(255,255,255,0.08)'}`,
                            background: time === tm ? 'rgba(212,165,116,0.14)' : 'transparent',
                            color: time === tm ? t2.accent : t2.text, fontSize: 13, fontWeight: 500, fontFamily: t2.mono }}>
                {tm}
              </div>
            ))}
          </div>
          <div style={{ marginTop: 14, padding: '10px 12px', borderRadius: 12, background: 'rgba(212,165,116,0.08)',
                        fontSize: 11, color: t2.textDim, display: 'flex', alignItems: 'center', gap: 8 }}>
            <div style={{ color: t2.accent }}>※</div>
            {L.holidayBadge}: {T(tw.lang, '29 Jan – 6 Feb closed for Tết', '29/01 – 6/02 nghỉ Tết Nguyên Đán')}
          </div>
        </GlassC>

        <button onClick={() => nav.openSheet('serviceSuccess', { total: estimate, dealer: dealers[selectedDealer], time, date: dates[selectedDate], suggested })}
                style={{
          width: '100%', height: 56, border: 'none', borderRadius: 28,
          background: t2.accent, color: t2.accentInk,
          fontSize: 14, fontWeight: 600, fontFamily: t2.font, cursor: 'pointer',
          display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 24px',
          transition: 'all .15s',
        }}>
          <span>{L.confirm}</span>
          <span style={{ fontVariantNumeric: 'tabular-nums', fontWeight: 500, opacity: 0.85 }}>~ {fmtVND(estimate)}</span>
        </button>
      </div>
    </ScreenShell>
  );
}

// ─────────────────────────────────────────────────────────────
// NOTIFICATIONS — swipe to dismiss + timeline animation
// ─────────────────────────────────────────────────────────────
// Notification data is bilingual; render layer picks tl[lang] / body[lang].
const SEED_NOTIFICATIONS = (lang) => [
  { id: 'mx5', day: 'today', ic: 'car',
    tl: T(lang, 'New: Mazda MX-5 2026', 'Mới ra mắt: Mazda MX-5 2026'),
    body: T(lang, 'Now in Vietnam · from 1.49 tỷ', 'Đã có mặt tại Việt Nam · từ 1,49 tỷ'),
    tm: '16:20', alert: false, promo: true },
  { id: 'n1', day: 'today', ic: 'lock',
    tl: T(lang, 'Vehicle unlocked', 'Xe đã mở khóa'),
    body: T(lang, 'Vincom Bà Triệu · 10 min ago', 'Vincom Bà Triệu · 10 phút trước'),
    tm: '14:32', alert: true },
  { id: 'n2', day: 'today', ic: 'wrench',
    tl: T(lang, 'Service due soon', 'Bảo dưỡng sắp đến hạn'),
    body: T(lang, 'In 2,300 km', 'Còn 2,300 km'),
    tm: '08:10' },
  { id: 'n3', day: 'yesterday', ic: 'fuel',
    tl: T(lang, 'Fuel level low', 'Nhiên liệu thấp'),
    body: T(lang, 'At 18% · 115 km left', 'Còn 18% · ~ 115 km'),
    tm: '18:44' },
  { id: 'n4', day: 'yesterday', ic: 'signal',
    tl: T(lang, 'Software v3.2 ready', 'Cập nhật v3.2 đã sẵn sàng'),
    body: T(lang, 'New features inside', 'Tính năng mới đã có'),
    tm: '12:01' },
  { id: 'n5', day: 'week', ic: 'pin',
    tl: T(lang, 'Trip complete', 'Chuyến đi hoàn tất'),
    body: 'Hà Nội → Hải Phòng · 102 km · 1h 48m',
    tm: T(lang, 'Tue', 'T3') },
  { id: 'n6', day: 'week', ic: 'car',
    tl: T(lang, 'Long press detected', 'Phát hiện ấn giữ cửa'),
    body: T(lang, 'Driver door · 02:14', 'Cửa tài · 02:14'),
    tm: T(lang, 'Mon', 'T2') },
];

function NotificationsScreen() {
  const nav = useRouter();
  const { tw } = useApp();
  const L = STRINGS[tw.lang];
  const [items, setItems] = React.useState(tw.emptyInbox ? [] : SEED_NOTIFICATIONS(tw.lang));
  // Re-seed when language flips so titles/bodies stay localized.
  React.useEffect(() => {
    setItems(tw.emptyInbox ? [] : SEED_NOTIFICATIONS(tw.lang));
  }, [tw.lang, tw.emptyInbox]);

  const groups = ['today', 'yesterday', 'week'];
  const groupLabels = {
    today:     T(tw.lang, 'TODAY',     'HÔM NAY'),
    yesterday: T(tw.lang, 'YESTERDAY', 'HÔM QUA'),
    week:      T(tw.lang, 'THIS WEEK', 'TUẦN NÀY'),
  };

  if (!items.length) {
    return (
      <ScreenShell>
        <div style={{ padding: '6px 18px 20px' }}>
          <BackHeader title={L.notifications}/>
          <EmptyState
            icon="bell"
            title={T(tw.lang, 'All caught up', 'Đã xem hết')}
            body={T(tw.lang, 'No new notifications. Pull down to refresh, or check back later.', 'Không có thông báo mới. Kéo xuống để làm mới, hoặc kiểm tra lại sau.')}
          />
        </div>
      </ScreenShell>
    );
  }

  return (
    <ScreenShell>
      <div style={{ padding: '6px 18px 20px' }}>
        <BackHeader title={L.notifications}
                    action={<div style={{ fontSize: 12, color: t2.accent, cursor: 'pointer' }} onClick={() => setItems([])}>{L.markAllRead}</div>}/>

        {groups.map((g) => {
          const rows = items.filter((it) => it.day === g);
          if (!rows.length) return null;
          return (
            <div key={g} style={{ marginBottom: 16 }}>
              <div style={{ fontSize: 10, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1, marginBottom: 10, padding: '0 4px' }}>{groupLabels[g]}</div>
              <GlassC padding={4} radius={20} intensity={tw.glass}>
                {rows.map((n, i) => (
                  <NotificationRow key={n.id} n={n} first={i === 0}
                    onDismiss={() => setItems((cur) => cur.filter((x) => x.id !== n.id))}/>
                ))}
              </GlassC>
            </div>
          );
        })}
      </div>
    </ScreenShell>
  );
}

function NotificationRow({ n, first, onDismiss }) {
  const I = Icons[n.ic];
  const nav = useRouter();
  const sw = useSwipeDismiss(120, onDismiss);
  const swiping = sw.dx < -1;
  const onTap = (e) => {
    // Suppress click if a swipe was in progress.
    if (sw.dx < -3) return;
    nav.openSheet('notifDetail', { id: n.id });
  };
  return (
    <div style={{ position: 'relative', overflow: 'hidden', borderTop: first ? 'none' : '1px solid rgba(255,255,255,0.05)' }}>
      {/* Delete background — only painted while a swipe is in progress, so the
          row sits flat against the GlassC card the rest of the time. */}
      {swiping && (
        <div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'flex-end',
                      padding: '0 24px', background: 'rgba(232,72,72,0.18)' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, fontWeight: 600, color: '#E84848' }}>
            Dismiss
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 6h18M8 6V4a2 2 0 012-2h4a2 2 0 012 2v2M5 6l1 14a2 2 0 002 2h8a2 2 0 002-2l1-14"/></svg>
          </div>
        </div>
      )}
      <div {...sw.bind} onClick={onTap} style={{ ...sw.bind.style, position: 'relative',
                                 padding: '14px 14px',
                                 display: 'flex', gap: 12, alignItems: 'flex-start', cursor: 'pointer' }}>
        <div style={{ width: 36, height: 36, borderRadius: 18, flexShrink: 0,
                      background: n.alert ? 'rgba(232,184,114,0.14)' : 'rgba(255,255,255,0.06)',
                      color: n.alert ? t2.warn : t2.text,
                      display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <I size={18}/>
        </div>
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', gap: 8 }}>
            <div style={{ fontSize: 14, fontWeight: 500 }}>{n.tl}</div>
            <div style={{ fontSize: 11, color: t2.textDim, fontFamily: t2.mono, flexShrink: 0 }}>{n.tm}</div>
          </div>
          <div style={{ fontSize: 12, color: t2.textDim, marginTop: 2 }}>{n.body}</div>
        </div>
      </div>
    </div>
  );
}

function EmptyState({ icon = 'bell', title, body }) {
  const I = Icons[icon];
  return (
    <div style={{ padding: '60px 24px 30px', textAlign: 'center', animation: 'c-fade-in .5s' }}>
      <div style={{ width: 80, height: 80, borderRadius: 40, background: 'rgba(255,255,255,0.04)',
                    display: 'flex', alignItems: 'center', justifyContent: 'center', margin: '0 auto 22px',
                    border: '1px solid rgba(255,255,255,0.06)' }}>
        <I size={32} stroke={1.2}/>
      </div>
      <div style={{ fontSize: 18, fontWeight: 500, marginBottom: 8, letterSpacing: -0.3 }}>{title}</div>
      <div style={{ fontSize: 13, color: t2.textDim, lineHeight: 1.5, maxWidth: 280, margin: '0 auto' }}>{body}</div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// PROFILE
// ─────────────────────────────────────────────────────────────
function ProfileScreen() {
  const nav = useRouter();
  const { tw, setTweak } = useApp();
  const L = STRINGS[tw.lang];

  return (
    <ScreenShell>
      <div style={{ padding: '6px 18px 20px' }} className="c-stagger">
        <div style={{ marginBottom: 16 }}>
          <div style={{ fontSize: 11, fontFamily: t2.mono, color: t2.textDim, letterSpacing: 1 }}>{L.profile.toUpperCase()}</div>
          <div style={{ fontSize: 26, fontWeight: 400, letterSpacing: -0.5, marginTop: 2 }}>{T(tw.lang, 'Account', 'Tài khoản')}</div>
        </div>

        <GlassC padding={18} radius={26} intensity={tw.glass} style={{ marginBottom: 14, display: 'flex', alignItems: 'center', gap: 16, cursor: 'pointer' }} accentLine
                onClick={() => nav.go('profileInfo')}>
          <div style={{ width: 62, height: 62, borderRadius: 31, background: 'conic-gradient(from 180deg, #D4A574, #7CB7FF, #D4A574)', padding: 2 }}>
            <div style={{ width: '100%', height: '100%', borderRadius: '50%', background: t2.bg, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 20, fontWeight: 500, color: t2.text }}>AN</div>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 17, fontWeight: 600 }}>An Nguyễn</div>
            <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>+84 912 84 02 19</div>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 4, marginTop: 6, padding: '3px 10px', borderRadius: 999,
                          background: 'rgba(212,165,116,0.14)', color: t2.accent, fontSize: 10, fontWeight: 600, letterSpacing: 0.5 }}>
              <div style={{ width: 5, height: 5, borderRadius: 3, background: t2.accent }}/>
              PREMIUM · 02Y
            </div>
          </div>
          <Icons.chev size={16}/>
        </GlassC>

        {/* Vehicle card */}
        <GlassC padding={16} radius={24} intensity={tw.glass} style={{ marginBottom: 14, display: 'flex', alignItems: 'center', gap: 14, cursor: 'pointer' }}
                onClick={() => nav.tab('drive')}>
          <CarSideModel model={tw.model} width={120} color={VEHICLES[tw.model].color}/>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 500 }}>{VEHICLES[tw.model].name}</div>
            <div style={{ fontSize: 11, color: t2.textDim, fontFamily: t2.mono, marginTop: 2 }}>{VEHICLES[tw.model].plate}</div>
            <div style={{ fontSize: 11, color: t2.textDim, marginTop: 4 }}>{fmtKm(12480)} km · {T(tw.lang, 'Updated 3m ago', 'Cập nhật 3 phút trước')}</div>
          </div>
          <Icons.chev size={16}/>
        </GlassC>

        {/* + Add vehicle */}
        <GlassC padding={14} radius={22} intensity={tw.glass} style={{ marginBottom: 14, display: 'flex', alignItems: 'center', gap: 12, cursor: 'pointer', border: `1px dashed rgba(212,165,116,0.4)` }}
                onClick={() => nav.go('pair')}>
          <div style={{ width: 36, height: 36, borderRadius: 18, background: 'rgba(212,165,116,0.14)', color: t2.accent, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
            <Icons.plus size={20}/>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 500 }}>{T(tw.lang, 'Pair another vehicle', 'Ghép nối xe khác')}</div>
            <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>{T(tw.lang, 'Scan QR or enter VIN', 'Quét QR hoặc nhập số VIN')}</div>
          </div>
        </GlassC>

        <GlassC padding={4} radius={22} intensity={tw.glass} style={{ marginBottom: 14 }}>
          {[
            { i: 'doc',    l: L.documents, s: T(tw.lang, 'Insurance · inspection · VIN', 'Bảo hiểm · đăng kiểm · VIN'), tap: () => nav.go('documents') },
            { i: 'wallet', l: L.payment,   s: 'Visa •• 4029 · Momo',                                                                  tap: () => nav.go('payment') },
            { i: 'qmark',  l: L.help,      s: T(tw.lang, 'Owner\u2019s manual · how-to', 'Sách hướng dẫn · hỏi đáp'),                tap: () => nav.go('manual') },
            { i: 'wrench', l: T(tw.lang, 'Dealers', 'Đại lý'), s: T(tw.lang, 'Locator · Thaco network', 'Bản đồ · mạng lưới Thaco'), tap: () => nav.go('dealer') },
            { i: 'gear',   l: L.settings,  s: T(tw.lang, 'Notifications · privacy · language', 'Thông báo · riêng tư · ngôn ngữ'),   tap: () => nav.go('settings') },
          ].map((it, i, arr) => {
            const I = Icons[it.i];
            return (
              <div key={i} onClick={it.tap}
                   style={{ padding: '14px 12px', display: 'flex', alignItems: 'center', gap: 14,
                            borderTop: i ? '1px solid rgba(255,255,255,0.05)' : 'none', cursor: it.tap ? 'pointer' : 'default' }}>
                <div style={{ width: 36, height: 36, borderRadius: 12, background: 'rgba(255,255,255,0.05)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                  <I size={18}/>
                </div>
                <div style={{ flex: 1 }}>
                  <div style={{ fontSize: 14, fontWeight: 500 }}>{it.l}</div>
                  <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>{it.s}</div>
                </div>
                {it.right || <div style={{ color: t2.textMute }}><Icons.chev size={14}/></div>}
              </div>
            );
          })}
        </GlassC>

        {/* SOS */}
        <GlassC padding={16} radius={22} intensity={tw.glass} style={{ background: 'linear-gradient(135deg, rgba(232,72,72,0.22), rgba(232,72,72,0.06))', display: 'flex', alignItems: 'center', gap: 14 }}>
          <div style={{ width: 44, height: 44, borderRadius: 22, background: '#E84848', color: '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative' }}>
            <div style={{ position: 'absolute', inset: 0, borderRadius: 22, border: '1px solid #E84848', animation: 'c-pulse-strong 2s infinite' }}/>
            <Icons.sos size={22}/>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 600 }}>{L.sos}</div>
            <div style={{ fontSize: 11, color: t2.textDim, marginTop: 2 }}>{L.sosLine}</div>
          </div>
          <button onClick={() => nav.openSheet('sos')}
                  style={{ padding: '8px 14px', borderRadius: 16, border: 'none', background: '#E84848', color: '#fff', fontSize: 12, fontWeight: 600, fontFamily: t2.font, cursor: 'pointer' }}>{T(tw.lang, 'Call', 'Gọi')}</button>
        </GlassC>
      </div>
    </ScreenShell>
  );
}

function LangSwitch({ lang, onChange }) {
  return (
    <div style={{ display: 'flex', padding: 2, borderRadius: 12, background: 'rgba(255,255,255,0.06)' }}>
      {['vi', 'en'].map((k) => (
        <div key={k} onClick={() => onChange(k)} style={{ padding: '4px 10px', borderRadius: 10, fontSize: 11, fontWeight: 600,
                                                            background: lang === k ? t2.accent : 'transparent',
                                                            color: lang === k ? t2.accentInk : t2.textDim, cursor: 'pointer', transition: 'all .15s' }}>
          {k.toUpperCase()}
        </div>
      ))}
    </div>
  );
}

window.FindScreen = FindScreen;
window.ServiceScreen = ServiceScreen;
window.NotificationsScreen = NotificationsScreen;
window.ProfileScreen = ProfileScreen;
window.EmptyState = EmptyState;
