/* =====================================================================
   SmartTruckCall PWA — giao diện người gọi
   Tông: cabin tối, accent cam an toàn (safety-orange). Nút lớn, gọn, nhanh.
   Dùng font hệ thống -> không phụ thuộc web font -> load tức thì trên 4G.
   ===================================================================== */
:root {
  --bg:        #0c0f14;
  --bg-soft:   #141922;
  --panel:     #1a212c;
  --line:      #2a3340;
  --text:      #eef2f7;
  --muted:     #8a97a8;
  --accent:    #ff7a18;   /* safety orange */
  --accent-2:  #ffb066;
  --ok:        #2ecc71;
  --danger:    #ff4757;
  --ring:      rgba(255,122,24,.35);
  --radius:    18px;
  --tap:       72px;      /* chiều cao tối thiểu nút bấm (ngón tay người lớn tuổi) */
  font-size: 17px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background:
    radial-gradient(120% 90% at 50% -10%, #1b2330 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 22px 8px;
}
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), #c2410c);
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(255,122,24,.28);
}
.brand .logo svg { width: 22px; height: 22px; }
.brand b { font-size: 1.05rem; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: .72rem; font-weight: 500; }

/* ---- Card / screens ---- */
.screen { flex: 1; display: none; flex-direction: column; padding: 14px 22px 26px; }
.screen.active { display: flex; }

.callee-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 22px;
  text-align: center;
  margin: 10px 0 26px;
  position: relative;
  overflow: hidden;
}
.callee-card::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(80% 60% at 50% 0, rgba(255,122,24,.10), transparent 70%);
  pointer-events: none;
}
.avatar {
  width: 96px; height: 96px; border-radius: 50%;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, #2a3340, #1a212c);
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-size: 2.4rem; font-weight: 700; color: var(--accent-2);
}
.callee-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.callee-card .sub { color: var(--muted); font-size: .9rem; }
.role-chip {
  display: inline-block; margin-top: 12px;
  padding: 5px 14px; border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  background: rgba(255,122,24,.12); color: var(--accent-2);
  border: 1px solid rgba(255,122,24,.25);
}

/* ---- Big buttons ---- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; min-height: var(--tap);
  border: none; border-radius: 16px;
  font-size: 1.18rem; font-weight: 700; letter-spacing: .2px;
  cursor: pointer; user-select: none;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 26px; height: 26px; }
.btn-call   { background: linear-gradient(135deg, var(--ok), #1e9e57); color: #fff;
              box-shadow: 0 10px 26px rgba(46,204,113,.30); }
.btn-end    { background: linear-gradient(135deg, var(--danger), #c0392b); color: #fff;
              box-shadow: 0 10px 26px rgba(255,71,87,.30); }
.btn-ghost  { background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 14px; }
.btn-row .btn { flex: 1; }

/* ---- Install banner ---- */
.install {
  display: none; align-items: center; gap: 12px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 16px;
  font-size: .86rem; color: var(--muted);
}
.install.show { display: flex; }
.install button {
  margin-left: auto; background: var(--accent); color: #fff; border: none;
  padding: 9px 14px; border-radius: 10px; font-weight: 700; cursor: pointer;
}

/* ---- In-call ---- */
.video-stage {
  position: relative; flex: 1; border-radius: var(--radius);
  overflow: hidden; background: #000; margin-bottom: 16px; min-height: 50vh;
}
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background:#000; }
#localVideo {
  position: absolute; right: 12px; bottom: 12px;
  width: 96px; height: 130px; border-radius: 12px; object-fit: cover;
  border: 2px solid rgba(255,255,255,.18); background:#111;
  transform: scaleX(-1);
}
.call-status {
  position: absolute; top: 12px; left: 12px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  padding: 7px 13px; border-radius: 999px; font-size: .82rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 rgba(46,204,113,.6); animation: pulse 1.6s infinite; }
.dot.warn { background: var(--accent); }
@keyframes pulse { 70%{box-shadow:0 0 0 9px rgba(46,204,113,0);} 100%{box-shadow:0 0 0 0 rgba(46,204,113,0);} }

.call-controls { display: flex; gap: 14px; }
.icon-btn {
  flex: 1; min-height: 64px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); cursor: pointer;
  display: grid; place-items: center; font-size: .72rem; gap: 4px; font-weight:600;
}
.icon-btn.off { background: rgba(255,71,87,.14); border-color: rgba(255,71,87,.4); color: var(--accent-2); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: #fff; color: #111; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; font-size: .9rem; opacity: 0; pointer-events: none;
  transition: all .25s ease; max-width: 90%; text-align:center; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.25);
           border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hint { color: var(--muted); font-size: .82rem; text-align: center; line-height: 1.5; }
.footer { padding: 14px 22px 22px; color: #4a566a; font-size: .72rem; text-align: center; }

/* ---- Driver status badge (home) ---- */
.driver-status {
  margin-top: 10px; padding: 6px 14px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; display: inline-block;
}
.driver-status.ok  { background: rgba(46,204,113,.14); color: var(--ok); }
.driver-status.off { background: rgba(255,71,87,.14);  color: var(--danger); }
.driver-status:empty { display: none; }

/* ---- Secondary button ---- */
.btn-secondary {
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line);
  padding: 14px 18px; border-radius: 14px; font-weight: 600; font-size: .95rem;
  cursor: pointer; min-height: 52px; width: 100%;
}
.btn-secondary:hover { background: var(--panel); }

/* ---- Driver picker (multi-driver) ---- */
.driver-list { display: flex; flex-direction: column; gap: 10px; padding: 0 22px 12px; }
.driver-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); cursor: pointer; text-align: left; width: 100%;
  transition: background .15s ease, border-color .15s ease;
}
.driver-card:hover { background: var(--panel); border-color: var(--accent); }
.driver-card.inactive { opacity: .6; }
.driver-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #c2410c);
  color: white; font-weight: 700; font-size: 1.05rem;
  display: grid; place-items: center; flex-shrink: 0;
}
.driver-info { flex: 1; min-width: 0; }
.driver-name { font-weight: 600; font-size: 1rem; }
.driver-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px; font-size: .78rem; color: var(--muted);
  flex-wrap: wrap;
}
.driver-meta .plate {
  background: var(--panel); padding: 2px 8px; border-radius: 6px;
  font-family: ui-monospace, monospace; font-size: .72rem;
}
.driver-meta .badge {
  padding: 2px 8px; border-radius: 999px; font-size: .7rem; font-weight: 600;
}
.driver-meta .badge.active { background: rgba(46,204,113,.16); color: var(--ok); }
.driver-meta .badge.off    { background: rgba(255,71,87,.14);  color: var(--danger); }
.driver-meta .online-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal.show { display: flex; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; max-width: 360px; width: 100%;
  text-align: center;
}
.modal-box h2 { font-size: 1.1rem; color: var(--accent-2); margin-bottom: 10px; }
.modal-box p { color: var(--text); font-size: .95rem; line-height: 1.5; margin-bottom: 20px; }
