/* =====================================================
   TMS Logistics PWA — Mobile-first stylesheet
   ===================================================== */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #1565c0;
  --primary-dk: #003c8f;
  --accent:     #ff6f00;
  --bg:         #f0f4f8;
  --surface:    #ffffff;
  --text-main:  #1a202c;
  --text-sub:   #718096;
  --border:     #e2e8f0;
  --success:    #2e7d32;
  --warning:    #e65100;
  --info:       #0277bd;
  --radius:     12px;
  --shadow:     0 2px 8px rgba(0,0,0,.10);
  --nav-h:      64px;
  --header-h:   56px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text-main);
  overflow: hidden; /* prevent body scroll; each view scrolls independently */
}

/* ---------- App shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  /* iOS safe-area (notch / Dynamic Island / home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--surface);
  position: relative;
  overflow: hidden;
}

/* ---------- Top header ---------- */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.app-header .header-icon { font-size: 22px; }
.app-header h1 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.app-header .header-actions { display: flex; gap: 8px; }
.app-header button {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.app-header button:hover { background: rgba(255,255,255,.28); }

/* ---------- View container ---------- */
#view-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Views ---------- */
.view { display: none; padding: 0 0 8px; }
.view.active { display: block; }

/* ---------- Bottom navigation ---------- */
.bottom-nav {
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  color: var(--text-sub);
  padding: 6px 0;
  transition: color .2s;
  position: relative;
}

.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn span { line-height: 1; }

.nav-btn.active {
  color: var(--primary);
}
.nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border: 1px solid var(--border);
}

/* ---------- Section header ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.section-header h2 { font-size: 0.95rem; font-weight: 700; color: var(--text-main); }
.section-header a,
.section-header .link-btn {
  font-size: 0.8rem;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

/* =====================================================
   DASHBOARD VIEW
   ===================================================== */

/* Greeting banner */
.dashboard-banner {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dk) 100%);
  color: #fff;
  padding: 20px 16px 28px;
  position: relative;
  overflow: hidden;
}
.dashboard-banner::after {
  content: '🚚';
  font-size: 72px;
  position: absolute;
  right: -8px; top: 4px;
  opacity: .18;
  pointer-events: none;
}
.dashboard-banner .greeting { font-size: 0.85rem; opacity: .85; }
.dashboard-banner .greeting-name { font-size: 1.25rem; font-weight: 700; }
.dashboard-banner .date-line { font-size: 0.78rem; opacity: .7; margin-top: 2px; }

/* KPI strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 12px;
  margin-top: -18px;
}
.kpi-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 6px;
  text-align: center;
  border-top: 3px solid transparent;
}
.kpi-card:nth-child(1) { border-color: #1565c0; }
.kpi-card:nth-child(2) { border-color: #2e7d32; }
.kpi-card:nth-child(3) { border-color: #e65100; }
.kpi-card:nth-child(4) { border-color: #6a1b9a; }
.kpi-card .kpi-value { font-size: 1.3rem; font-weight: 800; }
.kpi-card .kpi-label { font-size: 0.62rem; color: var(--text-sub); margin-top: 2px; line-height: 1.2; }

/* Quick action buttons */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 0 16px;
}
.qa-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.qa-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.qa-btn span { font-size: 0.68rem; color: var(--text-sub); }

/* Recent shipments list */
.shipment-list { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }

.shipment-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.shipment-icon-wrap {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.shipment-info { flex: 1; min-width: 0; }
.shipment-id { font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shipment-route { font-size: 0.72rem; color: var(--text-sub); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shipment-eta { font-size: 0.7rem; color: var(--text-sub); margin-top: 2px; }

.badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-success { background: #e8f5e9; color: var(--success); }
.badge-warning { background: #fff3e0; color: var(--warning); }
.badge-info    { background: #e3f2fd; color: var(--info); }
.badge-grey    { background: #f5f5f5; color: #757575; }

/* =====================================================
   SHIPMENTS VIEW
   ===================================================== */

.filter-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-sub);
  transition: all .2s;
}
.filter-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.search-bar {
  padding: 0 16px 12px;
}
.search-bar input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  background: var(--bg);
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.search-bar input:focus { border-color: var(--primary); background-color: var(--surface); }

.shipment-full-list { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; }

.shipment-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 14px;
  cursor: pointer;
  transition: box-shadow .2s;
}
.shipment-card:active { box-shadow: 0 4px 16px rgba(0,0,0,.15); }

.shipment-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.shipment-card-id { font-size: 0.85rem; font-weight: 700; }
.shipment-card-date { font-size: 0.72rem; color: var(--text-sub); }

.shipment-route-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  margin-bottom: 10px;
}
.route-dot { width: 8px; height: 8px; border-radius: 50%; }
.route-dot.origin { background: var(--primary); }
.route-dot.dest   { background: var(--accent); }
.route-line { flex: 1; height: 2px; background: var(--border); position: relative; }
.route-line::after {
  content: '▶';
  font-size: 8px;
  color: var(--text-sub);
  position: absolute;
  top: -5px; right: 0;
}

.shipment-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.shipment-weight { font-size: 0.72rem; color: var(--text-sub); }
.shipment-driver { font-size: 0.72rem; color: var(--text-sub); }

/* =====================================================
   DRIVERS VIEW
   ===================================================== */

.driver-list { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; }

.driver-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.driver-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.driver-info { flex: 1; min-width: 0; }
.driver-name { font-size: 0.9rem; font-weight: 700; }
.driver-phone { font-size: 0.75rem; color: var(--text-sub); }
.driver-status-line { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.available { background: #2e7d32; }
.status-dot.on-route  { background: #e65100; }
.status-dot.offline   { background: #9e9e9e; }
.driver-status-text { font-size: 0.72rem; }
.driver-vehicle { font-size: 0.72rem; color: var(--text-sub); margin-left: auto; text-align: right; }

/* =====================================================
   ROUTES VIEW
   ===================================================== */

.route-list { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; }

.route-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 14px;
}
.route-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.route-card-name { font-size: 0.9rem; font-weight: 700; }

.route-stops { list-style: none; position: relative; padding-left: 20px; }
.route-stops::before {
  content: '';
  position: absolute;
  left: 6px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--border);
}
.route-stop {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  position: relative;
}
.route-stop:last-child { margin-bottom: 0; }
.stop-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  flex-shrink: 0;
  margin-top: 3px;
  position: absolute;
  left: -17px;
  box-shadow: 0 0 0 2px var(--border);
}
.stop-dot.done  { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.stop-dot.active { background: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.stop-dot.pending { background: var(--border); }

.stop-addr { flex: 1; }
.stop-time { font-size: 0.7rem; color: var(--text-sub); }

.route-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-sub);
}

/* =====================================================
   UTILITIES
   ===================================================== */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

.offline-banner {
  background: #b71c1c;
  color: #fff;
  text-align: center;
  font-size: 0.78rem;
  padding: 6px;
  display: none;
}
.offline-banner.visible { display: block; }

/* Scrollbar styling (desktop) */
#view-container::-webkit-scrollbar { width: 4px; }
#view-container::-webkit-scrollbar-track { background: transparent; }
#view-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Desktop: hiển thị dạng khung điện thoại trong browser */
@media (min-width: 480px) and (display-mode: browser) {
  body { background: #c5cae9; display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow: auto; }
  #app { height: min(100dvh, 820px); max-width: 420px; border-radius: 24px; overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,.35); }
}

/* Khi cài app (standalone / fullscreen): luôn full màn hình, không khung */
@media (display-mode: standalone),
       (display-mode: fullscreen) {
  html, body { overflow: hidden; }
  #app {
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}
