:root {
  --bg: #f1f5f9; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #0f766e; --brand-2: #0d9488; --brand-dark: #115e59;
  --iqc: #2563eb; --pqc: #7c3aed; --oqc: #059669; --pack: #d97706;
  --ok: #059669; --warn: #d97706; --bad: #dc2626;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
.hidden { display: none !important; }

/* Auth Landing */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr; background: linear-gradient(135deg, #042f2e 0%, #0f766e 55%, #1d4ed8 100%); color: #fff; }
.auth-hero { padding: 48px; display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.auth-hero .pill { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); padding: 6px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; width: fit-content; }
.auth-hero h1 { margin: 0; font-size: 34px; line-height: 1.2; }
.auth-hero p { margin: 0; color: #ccfbf1; font-size: 15px; max-width: 560px; line-height: 1.6; }
.feat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 8px; }
.feat-box { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: 12px; padding: 12px 14px; font-size: 13px; }
.feat-box b { display: block; margin-bottom: 4px; color: #fff; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-card { width: 100%; max-width: 440px; background: #fff; color: var(--ink); border-radius: 20px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.tabs-auth { display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs-auth button { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tabs-auth button.active { background: #fff; color: var(--brand); box-shadow: 0 2px 6px rgba(15,23,42,.08); }
.fg { margin-bottom: 12px; } .fg label { display: block; font-size: 12px; font-weight: 700; color: #334155; margin-bottom: 4px; }
.fg input, .fg select, .fg textarea { width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 9px; font-size: 14px; outline: none; }
.fg input:focus, .fg select:focus, .fg textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 9px; padding: 9px 15px; font-weight: 700; cursor: pointer; font-size: 13px; transition: .15s; text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; } .btn-primary:hover { background: var(--brand-dark); }
.btn-demo { width: 100%; background: linear-gradient(90deg, #059669, #0284c7); color: #fff; padding: 11px; margin-top: 10px; }
.btn-out { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn-warn { background: #fffbeb; color: #b45309; border: 1px solid #f59e0b; }
.btn-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #ef4444; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.w100 { width: 100%; }

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 248px; background: #0f172a; color: #e2e8f0; display: flex; flex-direction: column; flex-shrink: 0; }
.sb-brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sb-brand .t { font-weight: 900; font-size: 17px; color: #2dd4bf; }
.sb-brand .c { font-size: 12px; color: #94a3b8; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-nav { padding: 12px 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sb-nav button { width: 100%; text-align: left; background: transparent; border: none; color: #cbd5e1; padding: 10px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 9px; }
.sb-nav button:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-nav button.active { background: var(--brand); color: #fff; }
.sb-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #94a3b8; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 22px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 18px; color: var(--ink); }
.content { padding: 20px 22px; flex: 1; max-width: 1380px; width: 100%; margin: 0 auto; }

/* Cards & Tables */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 15px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 700; }
.kpi .val { font-size: 26px; font-weight: 900; margin-top: 4px; color: var(--ink); }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 15px; color: var(--ink); }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; vertical-align: middle; }
th { background: #f8fafc; font-size: 11px; text-transform: uppercase; color: #475569; letter-spacing: .03em; }
tr:hover td { background: #f8fafc; }

/* Badges & Stage Colors */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.b-pass { background: #dcfce7; color: #166534; } .b-fail { background: #fee2e2; color: #991b1b; }
.b-pend { background: #fef3c7; color: #92400e; } .b-na { background: #e2e8f0; color: #475569; }
.b-draft { background: #e0f2fe; color: #075985; } .b-submitted { background: #ede9fe; color: #5b21b6; }
.b-approved { background: #dcfce7; color: #166534; } .b-void { background: #fee2e2; color: #991b1b; }
.stage-pill { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 800; color: #fff; }
.st-IQC { background: var(--iqc); } .st-PQC { background: var(--pqc); } .st-OQC { background: var(--oqc); } .st-PACK { background: var(--pack); }

/* Inspection Detail 4-Stage */
.stage-sec { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.stage-sec-h { padding: 10px 14px; font-weight: 800; color: #fff; display: flex; justify-content: space-between; align-items: center; }
.item-row { padding: 12px 14px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1.5fr 1fr 1.2fr; gap: 12px; align-items: center; }
.item-row.missing-photo { background: #fff7ed; border-left: 4px solid #ea580c; }
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-thumb { border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; width: 112px; background: #fff; font-size: 10px; }
.photo-thumb img { width: 100%; height: 74px; object-fit: cover; display: block; }
.photo-thumb .cap { padding: 3px 5px; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-box { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.ai-ok { background: #ecfdf5; border: 1px solid #10b981; color: #065f46; }
.ai-warn { background: #fffbeb; border: 1px solid #f59e0b; color: #92400e; }
.ai-item { font-size: 12px; margin-top: 6px; padding: 6px 9px; background: rgba(255,255,255,.75); border-radius: 7px; border-left: 3px solid #dc2626; }
.qr-panel { display: flex; gap: 16px; align-items: center; background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; flex-wrap: wrap; }
.qr-panel svg { width: 84px; height: 84px; background: #fff; padding: 4px; border-radius: 8px; border: 1px solid #cbd5e1; }

/* Modal & Toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; z-index: 90; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.toast { position: fixed; right: 18px; bottom: 18px; background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-weight: 600; z-index: 120; box-shadow: 0 10px 28px rgba(0,0,0,.25); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.embed-mode .sidebar { width: 196px; }

@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { padding: 28px 20px; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .sb-nav { flex-direction: row; flex-wrap: wrap; }
  .sb-nav button { width: auto; }
  .item-row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
