:root{
  --bg:#f6f7f9;
  --card:#fff;
  --text:#111;
  --muted:#666;
  --line:#e8eaee;

  --pri:#111;
  --priText:#fff;
  --danger:#d33b3b;

  --dotGreen:#1aa251;
  --dotBlue:#2b6fff;
  --dotRed:#d33b3b;
  --dotGray:#b7bcc6;
}

*{ box-sizing:border-box; }

body{
  margin:0;
  font-family: system-ui, -apple-system, "Malgun Gothic", Arial, sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-text-size-adjust:100%;
}

.app{
  min-height:100dvh;
  height:100vh;
  height:100dvh;
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

/* ===== Top bar ===== */
.topbar{
  padding:14px 16px 8px;
  padding-top:calc(14px + env(safe-area-inset-top));
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  position:relative;
}
.title{
  display:flex;
  flex-direction:column;
  gap:2px;
  align-items:center;
  flex:1;
}
.h1{ font-size:18px; font-weight:800; }

.top-actions{
  display:flex;
  align-items:center;
  gap:8px;
  position:relative;
}

.iconBtn{
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}
.iconBtn svg{
  width:20px;
  height:20px;
  fill:none;
  stroke:#111;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.iconBtn:active{ filter:brightness(0.97); }

.menu{
  position:absolute;
  top:44px;
  right:0;
  width:160px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:12px;
  box-shadow:0 10px 30px rgba(0,0,0,0.08);
  overflow:hidden;
  z-index:20;
}
.menuItem{
  width:100%;
  text-align:left;
  padding:12px;
  background:#fff;
  border:0;
  border-bottom:1px solid var(--line);
  cursor:pointer;
  font-size:14px;
}
.menuItem:last-child{ border-bottom:0; }
.menuItem:active{ filter:brightness(0.97); }
.menuItem:disabled{ opacity:.45; cursor:not-allowed; }
.menuItem.danger{ color:var(--danger); }
.menuSep{ height:1px; background:var(--line); }

/* ===== Global sizing / scroll fix ===== */
html, body { height:100%; margin:0; padding:0; }
body { overflow:hidden; }
*, *::before, *::after { box-sizing:border-box; }

/* ===== Page layout ===== */
.root{ 
  padding:0 16px 16px;
  padding-bottom:calc(96px + env(safe-area-inset-bottom));
  flex:1;
  min-height:0;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
.footer{ display:none; }
.footStatus{ display:none; min-height:0; }

.card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  margin:10px 0;
  box-shadow:0 1px 0 rgba(0,0,0,0.02);
}

.row{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.row.space{ justify-content:space-between; }
.col{ display:flex; flex-direction:column; gap:6px; }
.label{ font-size:12px; color:var(--muted); }

.input,
select{
  width:100%;
  padding:12px;
  border:1px solid var(--line);
  border-radius:12px;
  font-size:15px;
  background:#fff;
}

.btn{
  border:1px solid var(--line);
  background:#fff;
  color:#111;
  padding:10px 12px;
  border-radius:10px;
  font-size:14px;
  cursor:pointer;
}
.btn.primary{ background:var(--pri); color:var(--priText); border-color:var(--pri); }
.btn.addSampleBtn{ min-height:44px; display:flex; align-items:center; justify-content:center; }
.addRow{ align-items:stretch; }
.btn.ghost{ background:transparent; }
.btn.small{ padding:7px 8px; font-size:13px; }
.btn.block{ width:100%; }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.btn.danger{ border-color:var(--danger); color:var(--danger); background:#fff; }

/* ===== Tabs & list ===== */
.tabs{ display:flex; gap:8px; flex-wrap:wrap; }
.tab{
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  font-size:13px;
}
.tab.active{ background:#fff; color:#111; border-color:#111; font-weight:800; }
.tabX{ margin-left:6px; font-weight:900; opacity:.5; cursor:pointer; }
.tabX:active{ opacity:.8; }

.list{ display:flex; flex-direction:column; gap:8px; }
.item{
  border:1px solid var(--line);
  background:#fff;
  border-radius:12px;
  padding:12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.item-title{ font-weight:800; }
.item-sub{ font-size:12px; color:var(--muted); margin-top:4px; }
.item.clickable{ cursor:pointer; }

.badge-new{
  font-size:11px;
  border:1px solid #111;
  padding:3px 8px;
  border-radius:999px;
  background:#111;
  color:#fff;
}

.chev{ font-size:22px; color:#999; line-height:1; padding-left:10px; }

/* ===== Status dot ===== */
.dot{
  width:10px;
  height:10px;
  border-radius:999px;
  background:var(--dotGray);
  border:1px solid rgba(0,0,0,.08);
}
.dot.green{ background:var(--dotGreen); }
.dot.red{ background:var(--dotRed); }
.dot.blue{ background:var(--dotBlue); }
.dot.blink{ animation:blink 1s infinite; }
@keyframes blink{ 0%,100%{opacity:1} 50%{opacity:.25} }

/* ===== Auth ===== */
.authTabs{ display:flex; gap:8px; margin-top:8px; }
.authCard{
  max-width:520px;
  margin:14px auto;
  padding:18px;
}
.gap-md{ gap:12px; }

/* ===== Date controls ===== */
.dateRow{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  margin:10px 0;
}
.dateControls{
  display:flex;
  align-items:stretch;
  gap:8px;
}
.dateControls .dateCol{ flex:1 1 auto; min-width:0; }
.dateControls .dateInput{
  width:150px;
  padding:8px 10px;
  font-size:13px;
  border-radius:10px;
}
.dateInput{
  width:150px;
  max-width:160px;
  padding:8px 10px;
  font-size:13px;
  border-radius:10px;
}
.dateControls > .btn{ flex:0 0 auto; width:auto; white-space:nowrap; }

/* ===== Sample row ===== */
.sampleRow{
  position:relative;
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  overflow:hidden;
}

.sampleLeft{ min-width:220px; flex:1; }
.sampleTitle{ font-weight:900; font-size:14px; line-height:1.2; display:flex; align-items:center; gap:8px; }
.sampleLocEdit{ flex:1 1 auto; min-width:120px; padding:8px 10px; border:1px solid var(--line); border-radius:10px; font-size:13px; background:#fff; }
.sampleMeta{
  margin-top:6px;
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:12px;
  color:var(--muted);
}
.metaLine{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

.timeInput{
  width:120px;
  padding:6px 8px;
  border:1px solid var(--line);
  border-radius:10px;
  font-size:13px;
  background:#fff;
}

.sampleRight{
  display:flex;
  gap:4px;
  align-items:flex-start;
  flex-wrap:wrap;
  justify-content:flex-end;
  margin-left:auto;
}

.slotMini{ display:flex; flex-direction:column; gap:6px; align-items:flex-end; }
.slotHead{ display:flex; align-items:center; justify-content:flex-end; gap:6px; font-size:12px; color:#666; }

.thumbMini{
  width:88px;
  height:54px;
  border-radius:10px;
  border:1px dashed var(--line);
  background:#fafbfc;
  overflow:hidden;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:11px;
  color:var(--muted);
}
.thumbMini img{ display:block; width:100%; height:100%; object-fit:cover; max-width:100%; max-height:100%; }

.slotBtns{ display:flex; gap:6px; }

/* ===== Photo layout by mode ===== */
.sampleRight.density,
.sampleRight.scatter{
  display:flex;
  align-items:flex-start;
  justify-content:flex-end;
  gap:12px;
}

.sampleRow.mode-scatter .sampleRight.scatter{ gap:10px; }
.sampleRow.mode-scatter .slotMini.scatter{ width:120px; }

.sampleRight.scatter{ flex-wrap:nowrap; }

/* 농도 slot inline 배치 고정 */
.slotInline{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  width:100%;
}

[hidden]{ display:none !important; }
.modal[hidden], .menu[hidden]{ display:none !important; }

/* ===== Modal ===== */
.modal{
  position:fixed;
  inset:0;
  z-index:50;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:16px;
}
.modal-backdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.45);
}
.modal-card{
  position:relative;
  width:min(520px, 100%);
  background:#fff;
  border:1px solid var(--line);
  border-radius:14px;
  box-shadow:0 20px 50px rgba(0,0,0,0.18);
  overflow:hidden;
}
.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:12px;
  border-bottom:1px solid var(--line);
}
.modal-title{ font-weight:900; }
.modal-body{ padding:12px; }
.modal-meta{ margin-top:8px; font-size:12px; color:var(--muted); }
.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:8px;
  padding:12px;
  border-top:1px solid var(--line);
}

.modal-preview{
  width:100%;
  height:auto;
  max-height:60vh;
  object-fit:contain;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
}

/* ===== Viewer modal ===== */
.viewer-card{ width:min(820px, 100%); }
.viewer-head-left{ display:flex; flex-direction:column; gap:2px; }
.viewer-label{ font-size:12px; color:var(--muted); }

.viewer-body{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  padding:10px;
  overflow:auto;
}
.viewer-img{
  max-width:100%;
  max-height:75vh;
  object-fit:contain;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
}
.viewer-img.zoom2{ transform:scale(2); transform-origin:center; }

.viewer-nav{
  width:40px;
  height:40px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  font-size:26px;
  line-height:38px;
}
.viewer-nav:disabled{ opacity:.45; cursor:not-allowed; }

/* ===== Choice cards (mode) ===== */
.choiceGrid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:12px;
  margin-top:12px;
}
.choiceCard{
  border:1px solid var(--line);
  background:#fff;
  border-radius:16px;
  padding:16px;
  text-align:center;
  cursor:pointer;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  min-height:84px;
}
.choiceCard:active{ filter:brightness(0.97); }
.choiceTitle{ font-size:18px; font-weight:900; }

/* 현재는 서브텍스트를 숨김(디자인 정책) */
.choiceSub{ display:none !important; }

/* ===== Swipe to delete ===== */
.swipeRow{ position:relative; overflow:hidden; border-radius:12px; background:#fff; }
.swipeActions{
  position:absolute;
  inset:0;
  display:flex;
  justify-content:flex-end;
  align-items:stretch;
  z-index:0;
  background:#fff;
}
.swipeDeleteBtn{
  width:92px;
  border:0;
  background:var(--danger);
  color:#fff;
  font-weight:900;
  font-size:14px;
  cursor:pointer;
}
.swipeContent{
  position:relative;
  z-index:1;
  touch-action:pan-y;
  transform:translateX(0px);
  background:#fff;
  border-radius:12px;
  overflow:hidden;
}
.swipeRow.dragging .swipeContent{ transition:none !important; }

.sectionLabel{ display:block; margin-bottom:10px; }

/* ===== Utilities ===== */
[hidden]{ display:none !important; }

/* ===== Responsive ===== */
@media (max-width: 520px){
  .root{ padding:0 12px 14px; }
  .topbar{ padding:12px 12px 8px; }
  .dateInput{ width:140px; max-width:140px; }

  .sampleLeft{ min-width:0; }
  .timeInput{ width:108px; }

  /* 비산(2칸): 오른쪽 사진영역을 같은 줄에 유지 */
  .sampleRow.mode-scatter{
    flex-wrap:nowrap;
    align-items:flex-start;
  }
  .sampleRow.mode-scatter .sampleLeft{ flex:1 1 auto; min-width:0; }
  .sampleRow.mode-scatter .sampleRight{ flex:0 0 auto; width:auto; }
  .sampleRow.mode-scatter .sampleRight.scatter{ flex-wrap:nowrap; gap:1px; }
  .sampleRow.mode-scatter .slotMini.scatter{ width:85px; }
  .sampleRow.mode-scatter .thumbMini{ width:86px; height:54px; }
  .sampleRow.mode-scatter .slotBtns{ gap:4px; }
  .sampleRow.mode-scatter .slotBtns .btn.small{ padding:6px 7px; font-size:12px; }

  /* 날짜 컨트롤: 한 줄 고정 */
  .dateControls{ flex-wrap:nowrap !important; }
  .dateControls .dateCol{ flex-basis:auto !important; }
  .dateControls > .btn{ width:auto !important; }

  /* 뷰어 버튼 */
  .viewer-nav{ width:34px; height:34px; font-size:22px; line-height:32px; }

  /* 현장 헤더 줄: 모바일에서 오른쪽 버튼/뱃지 줄바꿈 */
  .row.stack-mobile{ flex-direction:column; align-items:stretch; }
  .row.stack-mobile-right{ width:100%; justify-content:space-between; }
}

@media (max-width: 420px){
  .choiceGrid{ grid-template-columns:1fr; }
}


/* ===== Auth spacing patch ===== */
.gap-lg{ gap:16px; }
.authCardWide{ max-width:560px; margin:18px auto; padding:22px; }
.authFormStack{ margin-top:16px; }
.authInput{ min-height:52px; padding:14px 16px; font-size:16px; }
.authBtn{ min-height:48px; }
.secondaryAuthBtn{ background:#fff; }
@media (max-width: 520px){
  .authCardWide{ margin:12px auto; padding:20px 18px; }
  .authInput{ min-height:50px; }
}
