/* BookLink mobile design system — sage green / ivory */
:root{
  --sage-900:#2c4435;--sage-700:#3f6250;--sage-600:#4d7360;--sage-300:#a9c1b0;--sage-100:#e6efe7;--sage-50:#f1f6f1;
  --ivory:#faf8f2;--paper:#fff;--ink:#222e27;--muted:#65756b;--line:#e3e8df;
  --amber-700:#8a5a0b;--amber-100:#fdf1d6;--amber-line:#ecd59a;--red-700:#a43b33;--red-100:#fbe9e7;
  --star:#d99a1d;--r-lg:16px;--r-md:12px;--r-sm:8px;
  --shadow-1:0 1px 2px rgba(34,46,39,.06),0 2px 8px rgba(34,46,39,.05);
  --shadow-2:0 8px 28px rgba(34,46,39,.16);
  --safe-b:env(safe-area-inset-bottom,0px);--safe-t:env(safe-area-inset-top,0px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--ivory);color:var(--ink);font:15px/1.55 "Pretendard","Noto Sans KR","Apple SD Gothic Neo","Malgun Gothic",system-ui,sans-serif;word-break:keep-all;overflow-wrap:anywhere}
h1,h2,h3,p{margin:0}
[hidden]{display:none!important}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;border:1px solid var(--line);background:var(--paper);border-radius:var(--r-md);padding:9px 14px;min-height:42px;display:inline-flex;align-items:center;justify-content:center;gap:6px;transition:background .12s,transform .06s}
button:active{transform:scale(.98)}
button:disabled{opacity:.5}
input,select,textarea{border:1px solid var(--line);border-radius:var(--r-md);padding:10px 12px;background:var(--paper);min-height:42px;width:auto}
input:focus-visible,select:focus-visible,textarea:focus-visible,button:focus-visible{outline:2px solid var(--sage-600);outline-offset:1px}
textarea{width:100%;resize:vertical}
.i{width:1.3em;height:1.3em;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
.i.big{width:30px;height:30px}
.i.fill{fill:currentColor;stroke:none}
.primary{background:var(--sage-600);border-color:var(--sage-600);color:#fff;font-weight:600}
.primary:active{background:var(--sage-700)}
.wide{width:100%;margin-top:12px}
.iconBtn{border:0;background:transparent;min-height:40px;width:40px;padding:0;border-radius:50%;color:var(--sage-700)}
.iconBtn:active{background:var(--sage-100)}
.link{border:0;background:transparent;color:var(--sage-700);min-height:36px;padding:6px 8px;font-size:14px;text-decoration:underline;text-underline-offset:3px}

/* header */
.top{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:8px;padding:calc(8px + var(--safe-t)) 16px 8px;background:rgba(250,248,242,.92);backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:8px;margin-right:auto;color:var(--sage-700)}
.brand b{font-size:19px;letter-spacing:-.4px;color:var(--ink)}
.chip{display:inline-flex;align-items:center;gap:6px;font-size:12px;padding:4px 10px;border-radius:999px;background:var(--sage-100);color:var(--sage-700);max-width:48vw;white-space:nowrap}
.chip>span{overflow:hidden;text-overflow:ellipsis}
.chip .dot{width:7px;height:7px;border-radius:50%;background:var(--sage-600);flex:none}
.chip[data-state=loading] .dot{background:var(--star);animation:pulse 1s infinite}
.chip[data-state=error]{background:var(--red-100);color:var(--red-700)}
.chip[data-state=error] .dot{background:var(--red-700)}
@keyframes pulse{50%{opacity:.25}}

main{max-width:880px;margin:0 auto;padding:14px 16px calc(92px + var(--safe-b))}
#status{font-size:13px;color:var(--muted);min-height:0}
#status.quiet,#status:empty{display:none}
#status.err{display:block;background:var(--red-100);color:var(--red-700);padding:10px 12px;border-radius:var(--r-md);margin-bottom:10px}

/* login */
#login{display:grid;gap:12px;max-width:380px;margin:28px auto}
.loginHead{text-align:center;margin-bottom:6px;color:var(--sage-700)}
.loginHead h2{font-size:22px;color:var(--ink);margin-top:8px}
.loginHead p{color:var(--muted);font-size:14px}
.check{display:flex;align-items:center;gap:8px;font-size:14px;color:var(--muted)}
.check input{min-height:0;width:18px;height:18px;accent-color:var(--sage-600)}

/* quick actions */
.quick{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:14px}
.quickBtn{justify-content:flex-start;text-align:left;padding:12px;background:var(--sage-50);border-color:var(--sage-100);color:var(--sage-900);align-items:center}
.quickBtn .i{width:24px;height:24px;color:var(--sage-600)}
.quickBtn b{display:block;font-size:14px}
.quickBtn small{display:block;color:var(--muted);font-size:12px;line-height:1.3}

/* scanner / check */
.actionGrid{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.tile{flex-direction:column;gap:2px;padding:16px 8px;min-height:104px;text-align:center}
.tile b{font-size:15px}
.tile small{font-size:12px;opacity:.85}
.tile.primary small{color:#e6f0e8}
.subActions{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:4px 12px;margin:6px 0}
.aiNotice{display:block;text-align:center;font-size:12px;color:var(--muted);margin-bottom:10px}
#video{width:100%;max-height:300px;object-fit:cover;background:#1d2621;border-radius:var(--r-lg);margin-top:8px}
#scanMessage{font-size:13px;color:var(--muted);text-align:center;margin:6px 0}
#scanMessage:empty{display:none}
#ocrPanel{margin:10px 0}
#ocrStatus:empty{display:none}
#ocrStatus{font-size:14px;color:var(--muted);padding:8px 0}
#ocrCandidates{display:grid;gap:8px;margin-top:8px}
#ocrCandidates button{justify-content:flex-start;text-align:left;white-space:normal}
details{font-size:14px}
summary{cursor:pointer;color:var(--muted);padding:8px 0}
#ocrText{margin:6px 0}
.aiActions{display:flex;flex-wrap:wrap;gap:8px;margin:6px 0}

/* result states */
.matchCard,.uncertainCard,.noneCard{padding:16px;border-radius:var(--r-lg);border:1px solid;margin-top:8px}
.matchCard{background:var(--sage-50);border-color:var(--sage-300)}
.uncertainCard{background:var(--amber-100);border-color:var(--amber-line)}
.noneCard{background:#f3f4f1;border-color:var(--line)}
.badge{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:700;padding:3px 10px;border-radius:999px;margin-bottom:8px}
.badge.ok{background:var(--sage-600);color:#fff}
.badge.warn{background:var(--amber-700);color:#fff}
.badge.none{background:#6b776f;color:#fff}
.matchCard h2,.uncertainCard h2,.noneCard h2{font-size:18px;margin:0 0 6px}
.matchCard h3{font-size:14px;margin:14px 0 4px;color:var(--sage-700)}
.matchCard p,.uncertainCard p,.noneCard p{margin:6px 0;font-size:14px}
.matchBook{display:flex;gap:12px;align-items:center;margin:12px 0}
.matchBook img,.matchBook .placeholder{width:64px;height:88px;flex:none;border-radius:6px;box-shadow:var(--shadow-1)}
.matchCard button{margin:6px 6px 0 0}
.matchCard button:last-child{background:var(--sage-600);color:#fff;border-color:var(--sage-600)}

/* search + filters */
.searchBox{display:flex;align-items:center;gap:8px;background:var(--paper);border:1px solid var(--line);border-radius:var(--r-lg);padding:0 12px;margin:2px 0 10px;box-shadow:var(--shadow-1);color:var(--muted)}
.searchBox input{border:0;flex:1;min-width:0;padding:11px 0;background:transparent;box-shadow:none;font-size:16px}
.searchBox:focus-within{border-color:var(--sage-600)}
.filterRow{display:flex;gap:8px;align-items:center}
.filters{display:flex;gap:6px;flex:1;min-width:0}
.filters select{flex:1;min-width:0;width:0;padding:7px 8px;min-height:38px;font-size:13px;border-radius:999px;background:var(--paper);text-overflow:ellipsis}
.seg{display:flex;background:var(--sage-100);border-radius:999px;padding:3px;flex:none}
.seg button{border:0;background:transparent;min-height:32px;width:34px;padding:0;border-radius:999px;color:var(--muted)}
.seg button.on{background:var(--paper);color:var(--sage-700);box-shadow:var(--shadow-1)}
.listHead{display:flex;justify-content:space-between;align-items:baseline;margin:16px 2px 10px}
#sectionTitle{font-weight:700;font-size:17px}
#count{font-size:13px;color:var(--muted)}

/* book grid */
#books{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px 12px}
.book{display:block;text-align:left;border:0;background:transparent;padding:0;min-height:0;border-radius:var(--r-md);transition:transform .12s}
.book:active{transform:scale(.97)}
.book img,.book .placeholder{display:block;width:100%;aspect-ratio:3/4;object-fit:cover;background:var(--sage-100);border-radius:var(--r-sm);box-shadow:0 2px 10px rgba(34,46,39,.18)}
.placeholder{display:grid;place-items:center;text-align:center;padding:8px;color:var(--muted);font-size:12px;background:linear-gradient(160deg,var(--sage-100),#eef1e8)!important}
.book .info{display:block;padding:8px 2px 0}
.book b{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-size:14px;line-height:1.35;font-weight:600}
.book small{display:block;color:var(--muted);font-size:12px;line-height:1.4;margin-top:2px}
.book .stars{display:inline-flex;align-items:center;gap:2px;color:var(--star);font-weight:600}
.book .stars .i{width:13px;height:13px}
#books.compact{grid-template-columns:repeat(3,minmax(0,1fr));gap:12px 8px}
#books.compact .book b{font-size:12px;-webkit-line-clamp:2}
#books.compact .book small{display:none}
#books.list{grid-template-columns:1fr;gap:0}
#books.list .book{display:grid;grid-template-columns:54px 1fr;gap:14px;align-items:center;padding:10px 2px;border-bottom:1px solid var(--line);border-radius:0}
#books.list .book img,#books.list .book .placeholder{width:54px;height:74px;font-size:10px;padding:2px}
#books.list .book .info{padding:0}
.empty{grid-column:1/-1;text-align:center;color:var(--muted);padding:40px 12px}
.stub{min-height:var(--stub-h,240px)}#books.list .stub{min-height:var(--stub-h,90px)}
.listSentinel{grid-column:1/-1;height:1px;pointer-events:none}
.listNavBtn{position:fixed;right:14px;z-index:7;width:44px;height:44px;min-height:0;padding:0;display:inline-flex;align-items:center;justify-content:center;border-radius:50%;background:var(--paper);border:1px solid var(--line);box-shadow:var(--shadow-2);color:var(--sage-700)}
.listNavBtn[hidden]{display:none}.listNavBtn .i{width:22px;height:22px}
.navTop{bottom:calc(136px + var(--safe-b))}.navBottom{bottom:calc(84px + var(--safe-b))}
.skeleton{grid-column:1/-1;display:grid;grid-template-columns:repeat(2,1fr);gap:12px}
.skeleton i{display:block;aspect-ratio:3/4;border-radius:var(--r-sm);background:linear-gradient(90deg,var(--sage-100),#f3f6f1,var(--sage-100));background-size:200% 100%;animation:sh 1.2s infinite}
@keyframes sh{to{background-position:-200% 0}}

/* bottom nav */
#bottom{position:fixed;left:0;right:0;bottom:0;z-index:6;display:flex;gap:2px;background:rgba(255,255,255,.96);backdrop-filter:blur(10px);border-top:1px solid var(--line);padding:6px 10px calc(6px + var(--safe-b))}
#bottom button{flex:1;flex-direction:column;gap:2px;border:0;background:transparent;color:var(--muted);min-height:50px;padding:4px;border-radius:var(--r-md)}
#bottom button small{font-size:11px;font-weight:600}
#bottom button.active{color:var(--sage-700);background:var(--sage-100)}

/* dialogs / sheets */
dialog{width:min(100%,560px);max-height:92vh;border:0;border-radius:20px;padding:0 18px 20px;box-shadow:var(--shadow-2);color:var(--ink);background:var(--ivory);overflow:auto}
dialog::backdrop{background:rgba(25,36,30,.5)}
.sheetHead{position:sticky;top:0;z-index:2;display:flex;align-items:center;justify-content:space-between;background:var(--ivory);padding:14px 0 8px;margin-bottom:4px}
.sheetHead h2{font-size:18px}
.card{background:var(--paper);border:1px solid var(--line);border-radius:var(--r-lg);padding:14px;margin-bottom:12px}
.card h3{font-size:15px;margin-bottom:6px}
.row{display:flex;flex-wrap:wrap;gap:8px;margin:8px 0}
.hint{font-size:13px;color:var(--muted);margin:6px 0 10px}
#syncInfo{font-size:14px;color:var(--muted)}
.advanced summary{font-weight:600;color:var(--ink)}
#testResult{white-space:pre-wrap;overflow-wrap:anywhere;max-height:36vh;overflow:auto;font-size:12px;background:var(--sage-50);padding:8px;border-radius:var(--r-sm)}
@media(max-width:600px){dialog{width:100%;max-width:100%;margin:auto 0 0;border-bottom-left-radius:0;border-bottom-right-radius:0;max-height:94vh;padding-bottom:calc(20px + var(--safe-b))}}

/* detail */
.detailHead{display:flex;gap:14px;align-items:flex-start;margin-bottom:12px}
.detailHead img,.detailHead .placeholder{width:96px;height:132px;flex:none;object-fit:cover;border-radius:var(--r-sm);box-shadow:0 3px 12px rgba(34,46,39,.22)}
.detailHead h2{font-size:19px;line-height:1.3;margin-bottom:4px}
.detailHead p{color:var(--muted);font-size:14px;margin:2px 0}
.tags{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}
.tag{font-size:12px;background:var(--sage-100);color:var(--sage-700);padding:2px 10px;border-radius:999px}
#content h3.sec{font-size:15px;margin:18px 0 8px;color:var(--sage-700)}
.noteCard{background:var(--paper);border:1px solid var(--line);border-radius:var(--r-md);padding:10px 12px;margin-bottom:8px}
.noteCard .who{display:flex;justify-content:space-between;align-items:center;font-weight:600}
.noteCard .state{font-size:12px;font-weight:600;color:var(--sage-700);background:var(--sage-100);padding:2px 9px;border-radius:999px}
.noteCard .memo{white-space:pre-wrap;font-size:14px;color:var(--muted);margin-top:4px}
.noteCard .stars{color:var(--star);display:inline-flex;gap:1px}
.noteCard .stars .i{width:15px;height:15px}
.loanItem{padding:8px 0;border-bottom:1px solid var(--line);font-size:14px}
.loanItem:last-child{border:0}
.loanItem small{display:block;color:var(--muted)}
.editor{background:var(--paper);border:1px solid var(--line);border-radius:var(--r-lg);padding:14px;margin-top:16px}
.editor h3{margin:0 0 6px;font-size:15px}
.editor label{display:block;font-size:13px;color:var(--muted);margin-top:10px}
.editor select,.editor input[type=date],.editor textarea{display:block;width:100%;margin-top:4px;color:var(--ink);font-size:15px}
.editor label.inline{display:flex;align-items:center;gap:8px;color:var(--ink)}
.editor label.inline input{min-height:0;width:18px;height:18px;accent-color:var(--sage-600)}
.editor .save{width:100%;margin-top:14px}
.editor .msg{font-size:13px;margin-top:8px;color:var(--sage-700)}
.starRow{display:inline-flex;gap:1px;vertical-align:middle}.starRow .i{width:13px;height:13px;fill:none;stroke:#c3cac2;stroke-width:1.6}.starRow .i.on{fill:var(--star);stroke:var(--star)}.ratings{margin-top:4px;display:flex;flex-direction:column;gap:2px}.rrow,.maxrow{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted)}.rrow .nm{max-width:6em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.maxrow{display:none}#books.compact .rrow{display:none}#books.compact .maxrow{display:flex}#books.compact .starRow .i{width:11px;height:11px}.noteCard .starRow{margin-top:3px}.noteCard .starRow .i{width:18px;height:18px}.editor .link:disabled{opacity:.4;text-decoration:none}.rating-stars{display:flex;gap:0;margin-top:4px;justify-content:space-between;max-width:300px}
.rating-stars button{border:0;background:transparent;min-height:52px;width:56px;padding:0;color:#c3cac2;border-radius:50%}
.rating-stars button .i{width:34px;height:34px}
.rating-stars button.rated{color:var(--star)}
.rating-stars button.rated .i{fill:currentColor}

/* receipt */
.steps{display:flex;gap:6px;list-style:none;padding:0;margin:4px 0 8px;counter-reset:s}
.steps li{flex:1;text-align:center;font-size:12px;color:var(--muted);padding:6px 0;border-bottom:3px solid var(--line);counter-increment:s}
.steps li::before{content:counter(s) ". "}
.steps li.on{color:var(--sage-700);border-color:var(--sage-600);font-weight:700}
.steps li.done{color:var(--sage-700);border-color:var(--sage-300)}
#receiptDialog label{display:block;margin:10px 0 0;font-size:13px;color:var(--muted)}
#receiptDialog label input,#receiptDialog label select{display:block;width:100%;margin-top:4px;color:var(--ink)}
#receiptDialog .two{display:grid;grid-template-columns:1fr 1fr;gap:10px}
#receiptDialog .actionGrid{margin:8px 0}
#receiptRows fieldset{margin:12px 0;border:1px solid var(--line);border-radius:var(--r-md);background:var(--paper);padding:4px 12px 12px}
#receiptRows fieldset button{margin-top:8px;color:var(--red-700)}
#receiptStatus,#receiptSaveStatus{font-size:14px;color:var(--sage-700);margin:8px 0}
#receiptStatus:empty,#receiptSaveStatus:empty{display:none}

/* toast */
#toast{position:fixed;left:50%;bottom:calc(76px + var(--safe-b));transform:translateX(-50%);z-index:20;max-width:min(92vw,420px);background:var(--sage-900);color:#fff;padding:10px 16px;border-radius:999px;font-size:14px;box-shadow:var(--shadow-2);display:flex;align-items:center;gap:8px}
#toast.err{background:var(--red-700)}

@media(min-width:700px){
  #books{grid-template-columns:repeat(auto-fill,minmax(150px,1fr))}
  #books.compact{grid-template-columns:repeat(auto-fill,minmax(110px,1fr))}
  #books.list{grid-template-columns:1fr}
}
@media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}

/* match candidates + returns dialog (mobile) */
.candList{display:grid;gap:8px;margin:10px 0}
.candRow{display:flex;gap:12px;align-items:flex-start;text-align:left;width:100%;padding:10px;border-radius:var(--r-md);background:var(--paper);min-height:0}
.candRow .placeholder,.candRow img{width:48px;height:66px;flex:none;border-radius:6px;object-fit:cover}
.candInfo{display:grid;gap:2px;min-width:0}.candInfo small{color:var(--muted)}
.lvChip{justify-self:start;font-size:11px;font-weight:700;padding:1px 8px;border-radius:999px;background:var(--sage-100);color:var(--sage-700)}
.lvChip.lv2,.lvChip.lv3{background:var(--amber-100);color:var(--amber-700)}
.reSearch{display:flex;gap:8px;margin:10px 0}.reSearch input{flex:1;min-width:0}
.dangerDialog .loanPick{max-height:46vh;overflow:auto;border:1px solid var(--line);border-radius:var(--r-md);background:var(--paper);margin:8px 0}
.dangerDialog .loanRow{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border-bottom:1px solid var(--line);font-size:14px;flex-wrap:wrap}
.dangerDialog .loanRow input[type=checkbox]{width:20px;height:20px;min-height:0;flex:none}
.dangerDialog .bulkRow{display:flex;gap:8px;flex-wrap:wrap;margin:6px 0}.dangerDialog .bulkRow select{flex:1;min-width:0}
.dangerDialog .actions{display:flex;gap:8px;margin:10px 0}.dangerDialog .dangerSummary{font-weight:700;margin:8px 0}
.dangerDialog .check{display:flex;gap:8px;align-items:center}
/* loan import entry */
.quick .importBtn{grid-column:1/-1}
.quick.single .importBtn{grid-column:auto}
