*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{margin:0;height:100%;overflow:hidden}
body{background:#f2f4f1;color:#18201c;font:16px/1.4 system-ui,-apple-system,"Apple SD Gothic Neo","Malgun Gothic","Noto Sans KR",sans-serif}
button,input,select,textarea{font:inherit;color:inherit}
button{min-height:40px;padding:0 12px;border:1px solid #1f5c46;border-radius:9px;background:#fff;color:#1f5c46;font-weight:600;cursor:pointer;white-space:nowrap}
button:disabled{opacity:.35;cursor:default}
button.primary,button.on{background:#1f5c46;color:#fff}
button.danger{border-color:#a12622;color:#a12622}
input,select{width:100%;min-width:0;min-height:40px;padding:0 9px;border:1px solid #9aa8a0;border-radius:8px;background:#fff}
a{color:#1f5c46;font-weight:700}
h2{font-size:17px;margin:0}
p{margin:0}
label{display:flex;flex-direction:column;gap:2px;font-size:13px;color:#44504a;min-width:0}
.row{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.row.nowrap{flex-wrap:nowrap}
.warn{background:#fff0d1;color:#663700;padding:6px 10px;border-radius:8px;font-size:14px}

#login{height:100%;display:grid;place-items:center;padding:16px}
#loginForm{width:min(100%,340px);background:#fff;border-radius:16px;padding:20px;display:flex;flex-direction:column;gap:10px;text-align:center}
#loginForm h1{margin:0;font-size:21px}
#pin{text-align:center;font-size:30px;letter-spacing:14px;height:58px}
#loginMsg{color:#a12622;min-height:1.4em}

#app{height:100vh;height:100dvh;display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr) auto;grid-template-areas:"brand actions" "main main" "nav nav"}
.brand,.actions{background:#1f5c46;color:#fff;display:flex;align-items:center;padding:max(6px,env(safe-area-inset-top)) 10px 6px}
.brand{grid-area:brand;flex-direction:column;align-items:flex-start;justify-content:center;white-space:nowrap;overflow:hidden}
.brand strong{font-size:15px}
.brand span{font-size:13px}
.actions{grid-area:actions;gap:5px}
.actions button{border-color:#fff;font-size:14px;padding:0 9px}
.actions .ghost{background:transparent;color:#fff}
nav{grid-area:nav;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));background:#fff;border-top:1px solid #cdd5cf;padding-bottom:env(safe-area-inset-bottom)}
nav button{min-height:50px;padding:0;border:0;border-radius:0;border-top:4px solid transparent;color:#4d5952;font-size:14px}
nav button[aria-current=page]{color:#1f5c46;border-color:#1f5c46;background:#e3f0e9}
main{grid-area:main;min-height:0;padding:6px}

.view{height:100%;display:flex;flex-direction:column;gap:6px;min-height:0}
.panel-box{display:flex;flex-direction:column;gap:5px;min-width:0;min-height:0}
.grow1{flex:1 1 0}.grow2{flex:2 1 0}.grow3{flex:3 1 0}
.side{flex:0 0 auto}
.head{display:flex;align-items:center;gap:5px;min-height:40px}
.head h2{margin-right:auto;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
[data-view=cal] .head h2,[data-view=staff] .head h2{margin:0}
[data-view=cal] .panel-box:last-child .head h2{margin-right:auto}
[data-view=cal] [data-jump="0"]{margin-left:auto}
.pager{display:flex;align-items:center;gap:5px;font-size:14px}
.pager:empty{display:none}
.pager button{min-width:40px;padding:0}

.list{flex:1 1 0;min-height:0;overflow:hidden;display:grid;grid-auto-rows:58px;gap:5px;align-content:start}
.list.tall{grid-auto-rows:66px}
.empty{color:#56615b;padding:8px;grid-column:1/-1}
.item{display:flex;align-items:stretch;gap:6px;background:#fff;border-radius:10px;padding:5px;min-width:0}
.item.off{background:#e1e5e2;color:#56615b}
.item>.open{flex:1;min-width:0;display:flex;align-items:center;gap:10px;border:0;background:transparent;color:inherit;padding:0 5px;text-align:left;font-weight:400;min-height:0}
.item .time{font-size:20px;font-weight:700;white-space:nowrap}
.tall .item .time{font-size:25px}
.item .text{display:flex;flex-direction:column;min-width:0;flex:1}
.item .text>*{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.item .text b{font-size:16px}
.tall .item .text b{font-size:19px}
.item .text span{font-size:14px;color:#44504a}
.item>button:not(.open){align-self:center;min-height:44px}
.badge{align-self:center;background:#e3f0e9;color:#143d2e;border-radius:20px;padding:2px 9px;font-size:13px;font-weight:700;white-space:nowrap}
.badge.alert{background:#fff0d1;color:#663700}

.stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px}
.stats div{background:#fff;border-radius:10px;padding:3px 9px}
.stats span{display:block;font-size:12px;color:#56615b}
.stats b{font-size:21px}
.note{background:#fff;border-radius:9px;padding:5px 10px;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:0 0 auto}

.calendar{flex:1 1 0;min-height:0;display:grid;grid-template-columns:repeat(7,minmax(0,1fr));grid-template-rows:18px;grid-auto-rows:minmax(0,1fr);gap:2px}
.calendar .dow{text-align:center;font-weight:700;font-size:12px}
.calendar button{min-height:0;min-width:0;padding:1px;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;line-height:1.15;border:1px solid #cdd5cf;border-radius:6px;color:#18201c;font-weight:400;font-size:12px;overflow:hidden}
.calendar button>*{max-width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.calendar button.has{background:#e3f0e9}
.calendar button.now b{background:#1f5c46;color:#fff;border-radius:8px;padding:0 5px}
.calendar button.sel{border:3px solid #1f5c46}
.calendar button.leave{background:#1f5c46;color:#fff}
.calendar button.leave small{color:#fff}
.calendar small{color:#7a4400;font-size:11px}

.search{display:grid;grid-template-columns:minmax(0,1fr) 92px auto;gap:5px}
.chips{display:flex;flex-wrap:wrap;gap:5px}
.chips:empty{display:none}
.check{flex-direction:row;align-items:center;gap:7px;font-size:14px}
.check input{width:20px;min-height:20px}

dialog{width:min(100% - 12px,520px);max-height:calc(100vh - 8px);max-height:calc(100dvh - 8px);padding:0;border:0;border-radius:14px;overflow:auto}
dialog::backdrop{background:rgba(0,0,0,.55)}
#matches{flex-wrap:nowrap;overflow:hidden}
#matches button{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;font-size:13px}
.panel>*{min-width:0}
.panel{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;align-items:end;padding:12px;background:#fff}
.panel>h2{grid-column:1/-1}
.wide{grid-column:1/-1}
.sheet{display:flex;flex-direction:column;gap:8px;padding:14px}
.sheet h2{font-size:22px}
.sheet .line{overflow-wrap:anywhere}
.states{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:4px}
.states button{padding:0;min-height:46px}
textarea{width:100%;padding:8px;border:1px solid #9aa8a0;border-radius:8px;margin:4px 0}
summary{min-height:36px;cursor:pointer;color:#1f5c46;font-weight:600;display:list-item;padding-top:6px}
label.file{min-height:46px;display:flex;flex-direction:row;align-items:center;justify-content:center;border:1px solid #1f5c46;border-radius:10px;color:#1f5c46;font-size:16px;font-weight:700;cursor:pointer;position:relative}
label.file.primary{background:#1f5c46;color:#fff}
label.file input{position:absolute;opacity:0;width:1px;height:1px}
label.file:focus-within{outline:3px solid #e0a100}
#scanPreview{width:100%;max-height:24vh;object-fit:contain}
#resPhoto{width:100%;max-height:14vh;object-fit:contain}
pre{margin:0;white-space:pre-wrap;font-family:inherit;font-size:13px;background:#f2f4f1;border-radius:8px;padding:6px 8px;max-height:16vh;overflow:auto}
.source{display:flex;flex-direction:column;gap:4px}
#resRaw{max-height:9vh}
.scan{display:flex;flex-direction:column;gap:6px;border:1px solid #cdd5cf;border-radius:10px;padding:9px}
#scanList:empty,#scanMsg:empty{display:none}
#toast{position:fixed;left:12px;right:12px;bottom:64px;z-index:10;margin:auto;max-width:480px;background:#18201c;color:#fff;border-radius:10px;padding:10px 14px;text-align:center;pointer-events:none}

/* 가로 화면 (POS·태블릿·PC) */
@media (orientation:landscape) and (min-width:700px) and (min-height:500px){
  #app{grid-template-columns:auto minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr);grid-template-areas:"brand nav actions" "main main main"}
  nav{background:#1f5c46;border:0;padding:6px 4px;gap:3px;align-items:center}
  nav button{min-height:42px;background:transparent;color:#fff;border:0;border-radius:8px}
  nav button[aria-current=page]{background:#fff;color:#1f5c46}
  .split{flex-direction:row;gap:10px}
  .side{flex:0 0 min(300px,34%);gap:10px}
  dialog{width:min(100% - 16px,680px)}
  .panel{grid-template-columns:repeat(4,minmax(0,1fr))}
  .panel>label{grid-column:span 2}
  #guestForm>.wide,#resForm>.wide{grid-column:1/-1}
  #guestForm>button,#resForm>button{grid-column:span 2}
  .panel>.file{grid-column:span 2}
  #resSource{display:grid;grid-template-columns:1fr 1fr;align-items:center}
  #resSource>p{grid-column:1/-1}
  #toast{bottom:16px}
}
@media (orientation:landscape) and (min-width:700px) and (min-height:500px) and (max-width:899px){
  .brand strong{display:none}
  nav button{font-size:13px}
  .actions button{font-size:13px;padding:0 6px}
}
@media (min-width:1280px) and (min-height:800px){
  body{font-size:18px}
  .list{grid-auto-rows:66px}
  .list.tall{grid-auto-rows:78px}
  .calendar button{font-size:15px}
  .calendar small{font-size:13px}
}

/* 휴대폰: 위아래로 스크롤 (app.js의 FIT 조건과 맞출 것) */
@media (max-width:699.98px), (max-height:499.98px){
  html,body{height:auto;overflow:visible}
  #login{height:auto;min-height:100dvh}
  #app{height:auto;min-height:100dvh;grid-template-rows:auto 1fr;grid-template-areas:"brand actions" "main main"}
  nav{position:fixed;left:0;right:0;bottom:0;z-index:5}
  main{padding:8px 8px calc(66px + env(safe-area-inset-bottom))}
  .view{height:auto;gap:12px}
  .grow1,.grow2,.grow3{flex:0 0 auto}
  .list{flex:none;overflow:visible}
  .calendar{flex:none;grid-auto-rows:minmax(54px,auto)}
}

/* 낮은 PC·POS 화면: 입력창이 스크롤 없이 들어가게 줄인다 */
@media (min-width:700px) and (min-height:500px) and (max-height:599.98px){
  .panel{gap:4px;padding:8px 12px}
  .panel input,.panel button{min-height:36px}
  .panel h2{font-size:15px}
  .warn{padding:3px 8px;font-size:13px}
  #resPhoto{max-height:11vh}
}
