/* ============================================================
   EcoLens — giao diện mobile-first cho học sinh
   Chữ to, màu tươi, thao tác 1 tay trên điện thoại dọc
   ============================================================ */

:root {
  --green: #0e9f6e;
  --green-dark: #057a55;
  --bg: #f0faf4;
  --ink: #14332a;
  --ink-soft: #4b6b5e;
  --card: #ffffff;
  --radius: 20px;
  --shadow: 0 6px 24px rgba(20, 83, 45, .10);
  --score-colors: #66bb6a, #9ccc65, #ffca28, #ff7043, #e53935;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at 50% -10%, #d2f5e3 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ---------- Thanh trên ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 18px 10px;
  max-width: 560px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  font-size: 30px; background: #fff; border-radius: 14px;
  width: 48px; height: 48px; display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.brand-name { font-size: 22px; font-weight: 800; letter-spacing: -.3px; color: var(--green-dark); }
.brand-sub { font-size: 12.5px; color: var(--ink-soft); }
.stats-link {
  font-size: 24px; text-decoration: none; background: #fff;
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; box-shadow: var(--shadow);
}

/* ---------- Khung chính ---------- */
#app { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 8px 16px 24px; }
.screen { display: flex; flex-direction: column; gap: 14px; animation: fadein .35s ease; }
/* QUAN TRỌNG: display:flex ở trên sẽ đè thuộc tính hidden của HTML,
   nên phải ép màn hình có hidden thật sự biến mất */
.screen[hidden] { display: none !important; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}

/* ---------- Hero + nút chụp ---------- */
.hero { text-align: center; padding: 28px 20px 24px; }
.hero-emoji { font-size: 56px; margin-bottom: 6px; }
.hero h1 { font-size: 26px; font-weight: 800; letter-spacing: -.4px; line-height: 1.25; }
.hero-sub { color: var(--ink-soft); font-size: 15.5px; margin: 8px 0 20px; }

.btn-capture {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 18px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff; font-size: 20px; font-weight: 800; letter-spacing: .2px;
  border-radius: 18px; box-shadow: 0 8px 20px rgba(14, 159, 110, .35);
  transition: transform .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-capture:active { transform: scale(.97); }
.btn-capture-icon { font-size: 24px; }

.btn-gallery {
  display: block; margin-top: 12px; color: var(--green-dark);
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: underline;
}

/* ---------- 3 bước ---------- */
.steps { display: flex; flex-direction: column; gap: 12px; font-size: 15.5px; }
.step { display: flex; align-items: center; gap: 12px; }
.step-n {
  flex: 0 0 30px; height: 30px; border-radius: 50%;
  background: #d9f3e6; color: var(--green-dark);
  font-weight: 800; display: grid; place-items: center;
}

/* ---------- Chú giải 3 thùng ---------- */
.bins-legend h2, .pick-title { font-size: 16px; margin-bottom: 12px; }
.bin-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; margin-bottom: 8px;
  background: color-mix(in srgb, var(--bin) 10%, white);
  font-size: 15px;
}
.bin-row b { color: var(--bin); }
.bin-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--bin); flex: 0 0 14px; }
.bin-eg { color: var(--ink-soft); font-size: 13.5px; margin-left: auto; text-align: right; }

/* ---------- Camera trong trang ---------- */
.camera-card { padding: 12px; }
#cam-video {
  width: 100%; max-height: 62vh; object-fit: cover;
  border-radius: 14px; background: #0b1512; display: block;
}
.cam-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px 8px;
}
.shutter {
  width: 74px; height: 74px; border-radius: 50%; cursor: pointer;
  background: #fff; border: 6px solid var(--green);
  box-shadow: 0 4px 16px rgba(14, 159, 110, .35);
  transition: transform .1s ease;
  -webkit-tap-highlight-color: transparent;
}
.shutter:active { transform: scale(.88); background: #d9f3e6; }
.cam-close {
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: #eef4f0; color: var(--ink); font-size: 18px; font-weight: 700;
}
.cam-gallery { font-size: 30px; cursor: pointer; width: 48px; text-align: center; }
.cam-hint { text-align: center; font-size: 13.5px; color: var(--ink-soft); padding: 4px 0 8px; }

/* ---------- Màn hình phân tích ---------- */
.loading-card { position: relative; overflow: hidden; text-align: center; padding: 14px; }
.preview { width: 100%; border-radius: 14px; max-height: 55vh; object-fit: cover; }
.scan-line {
  position: absolute; left: 6%; right: 6%; height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, transparent, #2ee6a8, transparent);
  animation: scan 1.6s ease-in-out infinite; top: 20px;
  box-shadow: 0 0 14px #2ee6a8;
}
@keyframes scan { 0%,100% { top: 8%; } 50% { top: 82%; } }
.loading-row { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 0 6px; }
.loading-row p { font-size: 16.5px; font-weight: 600; color: var(--ink-soft); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #d9f3e6; border-top-color: var(--green);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Kết quả ---------- */
.mock-badge {
  background: #fff7e0; color: #8a6100; border: 1px solid #ffe08a;
  border-radius: 12px; padding: 10px 14px; font-size: 13.5px; font-weight: 600;
}
.result-photo-card { padding: 12px; }
.result-img { width: 100%; border-radius: 14px; display: block; }
.result-time { text-align: right; font-size: 12px; color: var(--ink-soft); padding: 6px 4px 0; }

.det-card {
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); background: #fff; margin-top: 2px;
}
.det-head {
  padding: 18px 20px; color: #fff;
  background: linear-gradient(135deg, var(--bin), color-mix(in srgb, var(--bin) 70%, black));
}
.det-obj { font-size: 14px; opacity: .9; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.det-title { font-size: 24px; font-weight: 800; line-height: 1.25; margin-top: 2px; }
.det-conf {
  display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 700;
  background: rgba(255,255,255,.22); border-radius: 999px; padding: 4px 12px;
}
.det-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.det-guide { font-size: 16.5px; font-weight: 600; }
.det-fact { font-size: 14px; color: var(--ink-soft); background: #f2f8f4; border-radius: 12px; padding: 10px 14px; }

/* Thanh điểm ô nhiễm 1–5 */
.score-wrap { display: flex; flex-direction: column; gap: 6px; }
.score-label { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); display: flex; justify-content: space-between; }
.score-bar { display: flex; gap: 5px; }
.score-seg { flex: 1; height: 12px; border-radius: 6px; background: #e6efe9; }
.score-seg.on-1 { background: #66bb6a; } .score-seg.on-2 { background: #9ccc65; }
.score-seg.on-3 { background: #ffca28; } .score-seg.on-4 { background: #ff7043; }
.score-seg.on-5 { background: #e53935; }
.score-text { font-weight: 800; }

.btn-again { margin-top: 6px; }

/* ---------- Không nhận ra / lỗi ---------- */
.empty-card { text-align: center; padding: 28px 20px; }
.empty-card h2 { font-size: 22px; margin: 6px 0; }
.empty-card p { color: var(--ink-soft); font-size: 15.5px; margin-bottom: 18px; }
.pick-bin {
  border-left: 6px solid var(--bin);
  background: color-mix(in srgb, var(--bin) 8%, white);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-size: 14.5px;
}
.pick-bin b { color: var(--bin); }

/* ---------- Chân trang ---------- */
.footer {
  text-align: center; font-size: 12.5px; color: var(--ink-soft);
  padding: 10px 0 max(16px, env(safe-area-inset-bottom));
}

/* ---------- Trang thống kê ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-tile { text-align: center; padding: 18px 10px; }
.stat-num { font-size: 32px; font-weight: 800; color: var(--green-dark); }
.stat-cap { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.chart-card h2 { font-size: 16px; margin-bottom: 10px; }
.chart-box { position: relative; width: 100%; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--green-dark); font-weight: 700; text-decoration: none; font-size: 15px;
}

/* Màn hình rộng (máy tính): giữ khung điện thoại ở giữa */
@media (min-width: 640px) {
  body { background: linear-gradient(160deg, #e8f7ee, #d3ecf5); }
  #app, .topbar { max-width: 480px; }
}

/* ---------- Băng trạng thái tải AI (bản chạy trong trình duyệt) ---------- */
.ai-status {
  background: #fff7e0; color: #8a6100; border: 1px solid #ffe08a;
  border-radius: 12px; padding: 10px 14px; margin-bottom: 12px;
  font-size: 13.5px; font-weight: 600; text-align: center;
}
.ai-status.ok { background: #e5f7ee; color: #0b7a4b; border-color: #a7e3c6; }

/* Chú giải nhỏ + bảng cho trang thống kê */
.bins-mini-legend { display:flex; gap:14px; flex-wrap:wrap; margin-bottom:10px; }
.bins-mini-legend span { display:inline-flex; align-items:center; gap:6px; font-size:12.5px; font-weight:700; color:var(--ink-soft); }
.bins-mini-legend i { width:10px; height:10px; border-radius:3px; display:inline-block; }
.table-view { margin-top:12px; font-size:13.5px; }
.table-view summary { cursor:pointer; color:var(--green-dark); font-weight:700; }
.table-view table { width:100%; border-collapse:collapse; margin-top:8px; }
.table-view td, .table-view th { padding:6px 8px; border-bottom:1px solid #e6efe9; text-align:left; }
.table-view td:last-child, .table-view th:last-child { text-align:right; }
