* { box-sizing: border-box; }
:root { --c: #1e3a5f; --a: #2563eb; --border: #d8dce3; --muted: #6b7280; --bg: #f3f4f6; }
body { margin: 0; font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; font-size: 15px;
       background: var(--bg); color: #111827; -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .spacer { flex: 1; }
.error { color: #dc2626; font-size: 13px; min-height: 1em; } .warn { color: #b45309; }
body.ext .staff-only, body.staff .ext-only { display: none !important; }

button, .button { font: inherit; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
                  cursor: pointer; color: inherit; text-decoration: none; display: inline-block; }
button.primary, .primary { background: var(--a); color: #fff; border-color: var(--a); }
button.danger { color: #dc2626; border-color: #fecaca; }
button.link { border: 0; background: none; color: var(--a); padding: 4px; }
button.icon { border: 0; background: none; font-size: 28px; padding: 0 8px; color: #fff; line-height: 1; }
.big { font-size: 17px; padding: 14px 18px; width: 100%; text-align: center; }
.wide { display: block; width: calc(100% - 24px); margin: 12px auto; }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
input[type=search] { flex: 1; min-width: 140px; }

/* 로그인 */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: #fff; padding: 28px 24px; border-radius: 14px; width: 100%; max-width: 360px;
             display: flex; flex-direction: column; gap: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.login-box h1 { margin: 0; text-align: center; } .login-box p { margin: 0 0 6px; text-align: center; font-size: 13px; }
.logo { font-size: 44px; text-align: center; }

/* 상단 */
header { position: sticky; top: 0; z-index: 5; background: var(--c); color: #fff; display: flex; align-items: center;
         gap: 6px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
header h1 { font-size: 18px; margin: 0; flex: 1; }
header .top-right { display: flex; gap: 8px; align-items: center; }
header .top-right .muted, header .link { color: #cbd5e1; font-size: 13px; }
header #accounts-btn { padding: 4px 10px; font-size: 13px; color: #111827; }

.view { max-width: 1100px; margin: 0 auto; padding: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.chk { font-size: 13px; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; margin-bottom: 10px; }
.tabs button { flex: 1; border-radius: 0; } .tabs button:first-child { border-radius: 8px 0 0 8px; }
.tabs button:last-child { border-radius: 0 8px 8px 0; border-left: 0; } .tabs .active { background: var(--c); color: #fff; }

/* 현장 목록 */
.site-list { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.site-list li { padding: 12px 14px; border-bottom: 1px solid #eef0f3; cursor: pointer; }
.site-list li:last-child { border-bottom: 0; } .site-list li:active, .site-list li:hover { background: #f1f5f9; }
.site-list.compact { max-height: 45vh; overflow: auto; margin: 8px 0; }
.sname { font-weight: 600; } .site-list .empty { color: var(--muted); cursor: default; }
.badge { font-size: 11px; background: #fef3c7; color: #92400e; padding: 1px 6px; border-radius: 8px; font-weight: normal; }
.badge.recent { background: #dbeafe; color: #1e40af; }

/* 현장 하나 */
.site-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.site-head > div:first-child { flex: 1; } .site-name { font-size: 19px; font-weight: bold; }
.site-actions { display: flex; gap: 6px; } .site-actions button { padding: 6px 10px; font-size: 13px; }
.upload-box { background: #fff; border-radius: 12px; padding: 12px; border: 1px solid var(--border); margin-bottom: 14px; }
.upload-btn { display: block; border-radius: 10px; cursor: pointer; }
details { margin-top: 10px; } summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0; }
details textarea { width: 100%; margin-top: 8px; } .field { display: block; margin-top: 8px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { padding: 6px 12px; border-radius: 16px; font-size: 14px; } .chip.on { background: var(--c); color: #fff; border-color: var(--c); }

#queue { margin-top: 8px; }
.qitem { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid #f1f5f9; }
.qthumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: #e5e7eb; flex: none; }
.qthumb.heic { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.qbody { flex: 1; min-width: 0; } .qname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin: 4px 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--a); transition: width .2s; }
.qitem.done .bar i { background: #16a34a; } .qitem.dup .bar i { background: #9ca3af; } .qitem.err .bar i { background: #dc2626; }
.qitem.err .qstate { color: #dc2626; } .qitem.done .qstate { color: #16a34a; }

/* 사진 목록 */
.gallery-bar select { padding: 6px 8px; }
h3.day { font-size: 14px; color: #374151; margin: 16px 0 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px; }
.tile { position: relative; aspect-ratio: 1; background: #e5e7eb; border-radius: 4px; overflow: hidden; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.sel { outline: 4px solid var(--a); outline-offset: -4px; } .tile.sel::after { content: "✓"; position: absolute; top: 4px; right: 6px;
  background: var(--a); color: #fff; border-radius: 50%; width: 22px; height: 22px; text-align: center; line-height: 22px; font-size: 13px; }
.tcat { position: absolute; left: 3px; bottom: 3px; background: rgba(0,0,0,.6); color: #fff; font-size: 10.5px; padding: 1px 5px; border-radius: 4px; }
.tmemo { position: absolute; right: 3px; bottom: 2px; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* 크게 보기 · 대화상자 */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.6); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal-box { background: #fff; border-radius: 12px; padding: 18px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto;
             display: flex; flex-direction: column; gap: 8px; }
.modal-box h2 { margin: 0 0 4px; font-size: 18px; } .wide-box { max-width: 1000px; }
.edit-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sim { display: block; width: 100%; text-align: left; margin-top: 4px; background: #fffbeb; border-color: #fde68a; }
#viewer { padding: 0; background: rgba(0,0,0,.92); }
.viewer-box { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; }
#viewer-img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer-info { background: #fff; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; max-height: 45vh; overflow: auto; }
.viewer-info textarea { width: 100%; }
#viewer .close { position: absolute; top: 10px; right: 10px; z-index: 2; background: rgba(0,0,0,.5); color: #fff; border: 0; font-size: 18px; }
#viewer .nav { position: absolute; top: 35%; z-index: 2; background: rgba(0,0,0,.4); color: #fff; border: 0; font-size: 34px; padding: 6px 12px; }
#viewer .prev { left: 6px; } #viewer .next { right: 6px; }

.acc-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.acc-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.acc-table th, .acc-table td { border-bottom: 1px solid #eef0f3; padding: 6px; text-align: left; }
.acc-table tr.off { color: #9ca3af; } .acc-table button { padding: 3px 8px; font-size: 12px; }

#toast { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: #111827;
         color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; font-size: 14px; }

@media (min-width: 800px) {
  .upload-box { display: grid; grid-template-columns: 260px 1fr; gap: 12px; align-items: start; }
  .upload-box details { margin-top: 0; } #queue { grid-column: 1 / -1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .viewer-box { flex-direction: row; } .viewer-info { width: 340px; max-height: none; }
}
.upload-box.drag { outline: 3px dashed var(--a); outline-offset: -3px; }
.upload-hint { display: block; font-size: 12px; opacity: .85; font-weight: normal; }

/* 지역 묶음 */
.site-list li.group { cursor: pointer; background: #f8fafc; font-weight: 600; user-select: none; }
.site-list li.group.sido { font-size: 16px; padding: 11px 14px; border-top: 1px solid var(--border); }
.site-list li.group.sigungu { padding: 8px 14px 8px 30px; font-size: 14.5px; background: #fff; }
.site-list li.group .arrow { display: inline-block; width: 14px; color: var(--muted); }
.site-list li.indent { padding-left: 46px; }

/* 휴대폰: 아이폰은 16px 보다 작은 입력칸을 누르면 화면을 확대하므로 16px 로 */
@media (max-width: 799px) {
  input, select, textarea { font-size: 16px; }
  button, .button { min-height: 40px; }                /* 손가락으로 누르기 쉽게 */
  .site-list li { padding-top: 13px; padding-bottom: 13px; }
  .toolbar input[type=search] { flex-basis: 100%; }
}
.tsrc { position: absolute; left: 3px; top: 3px; background: #0f766e; color: #fff; font-size: 10.5px; padding: 1px 5px; border-radius: 4px; }
.ro-note { background: #ecfdf5; color: #065f46; border-radius: 6px; padding: 6px 8px; }

/* 최근 현장 (목록과 분리된 카드) */
.box-title { font-size: 14px; font-weight: 700; color: #374151; margin: 4px 2px 8px; }
.recent-box { background: #eef4ff; border: 1px solid #c7d7f5; border-radius: 12px; padding: 10px 10px 12px; margin-bottom: 16px; }
.recent-box .box-title { color: #1e40af; margin-top: 0; }
.recent-cards { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scroll-snap-type: x proximity;
                -webkit-overflow-scrolling: touch; }
.recent-card { flex: 0 0 172px; scroll-snap-align: start; text-align: left; background: #fff; border: 1px solid #c7d7f5;
               border-left: 4px solid var(--a); border-radius: 10px; padding: 9px 10px; min-height: 0;
               display: flex; flex-direction: column; gap: 3px; box-shadow: 0 1px 2px rgba(30,64,175,.08); }
.recent-card:active { background: #f1f5ff; }
.rc-name { font-weight: 700; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2;
           -webkit-box-orient: vertical; overflow: hidden; }
.rc-sub { font-size: 12px; color: var(--muted); }
.rc-count { font-size: 12px; color: #1e40af; }
.list-title { margin-top: 2px; }
@media (min-width: 800px) {
  .recent-cards { flex-wrap: wrap; overflow: visible; }
  .recent-card { flex: 0 0 200px; }
}
.tsrc.nas { background: #7c3aed; } .badge.nas { background: #ede9fe; color: #5b21b6; }
.ro-note { white-space: pre-wrap; word-break: break-all; }

/* 폴더별 보기 */
.tabs { display: inline-flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; border-radius: 0; padding: 6px 12px; background: #fff; }
.tabs button.on { background: var(--c); color: #fff; }
.crumbs { margin: 4px 0 10px; line-height: 1.8; word-break: break-all; }
.crumbs a { color: var(--c); text-decoration: none; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.ftile { display: block; color: inherit; text-decoration: none; background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }
.ftile:hover { border-color: var(--c); }
.fcover { position: relative; aspect-ratio: 4 / 3; background: #f3f4f6 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23cbd5e1' d='M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8z'/%3E%3C/svg%3E") center / 40% no-repeat; }
.fcover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fkind { position: absolute; left: 4px; top: 4px; background: #2563eb; color: #fff; font-size: 10.5px; padding: 1px 5px; border-radius: 4px; }
.fkind.maint { background: #0f766e; } .fkind.nas { background: #7c3aed; }
.fcount { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.fname { padding: 6px 8px 0; font-size: 13.5px; font-weight: 600; word-break: break-all; }
.fdate { padding: 0 8px 6px; font-size: 11.5px; }
.ai { white-space: nowrap; display: inline-block; line-height: 1.4; background: #fef3c7; color: #92400e; font-size: 10.5px; padding: 0 4px; border-radius: 4px; font-weight: 600; }
.bundle-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
.bundle-input { width: 100%; margin-top: 8px; padding: 8px 10px; }
@media (max-width: 480px) { .fgrid { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
