/* Mobile & Tablet first responsive UI (touch friendly) */

:root{
  --bg: #ffffff;
  --text: #333333;
  --muted: #6b7280;
  --border: #cccccc;
  --panel: #ffffff;
  --overlay: rgba(0,0,0,.62);
  --radius: 14px;
  --shadow: 0 14px 40px rgba(0,0,0,.22);
  --tap: 48px;
  --gap: 12px;
  --max: 980px;
}

*{ box-sizing: border-box; }
html,body{ height: 100%; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", sans-serif;
  padding: 0px;
  -webkit-text-size-adjust: 100%;
}

body.is-modal-open {
  overflow: hidden;
  touch-action: none; /* iOS/Androidの余計なスクロール抑制 */
}

main{
  max-width: var(--max);
  margin: 0 auto;
}

h2{
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .02em;
}

input, select, button{
  font-size: 16px;
  line-height: 1.2;
}

button:disabled{
  opacity: 0.5;
}

input, select{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  outline: none;
}
input:focus, select:focus{
  border-color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(99,102,241,.20);
}

select{
   cursor: pointer;
   color: var(--text);
   overflow: hidden;
}

button{
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  /*background: #f9fafb;*/
  background: #eee;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
button:active{ transform: translateY(1px); }
button:focus{
  outline: none;
  box-shadow: 0 0 0 3px rgba(99,102,241,.20);
}
button.primary{
  background: #111827;
  border-color: #111827;
  color: #fff;
}
button.danger{
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
  /*display: none;*/
  margin-bottom:12px;
}

button#send-button{
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
  margin-bottom: 12px;
}

button#list-button{
  /*background: #f1fff4;
border-color: #c7f0d1;
color: #166534;*/
}

.select-wrap {
  /* select要素を囲むコンテナに相対配置を設定 */
  position: relative;

}

.select-wrap::after {
  content: "›"; /* 右向きの「くの字」文字を使用 */
  position: absolute;
  right: 15px; /* 右からの位置 */
  top: 50%;
  transform: translateY(-50%) rotate(90deg); /* 下向きのくの字にするため回転させる */
  pointer-events: none; /* 矢印のクリックイベントを無視し、select要素に伝える */
  color: #555;
  font-size: 1.6em;
}

#count{ 
  margin: 12px 0;
  font-weight: 800;
  font-size: 14px; 
  text-align: center;
}

/* Layout blocks */
.field{
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.row-actions{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 10px;
}
.row-actions.three{
  grid-template-columns: 1fr;
}
.row-actions.three > *{ width: 100%; }

@media (min-width: 640px){
  body{ padding: 0px; }
  h2{ font-size: 17px; }
  .field.inline{
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .field.inline button{ width: auto; }
  .row-actions.three{
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.wrapper{
  display: flex;
  flex-direction: column;
  height: 100%;
}

.content{
  flex-grow: 1;
  padding: 20px 20px 0 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.forms{
  
}

.content-nav{
  padding: 20px 20px 20px 20px;
  background: #eee;
}

.content-nav button{
  width: 100%;
}

button#next-button{
  background: #333;
  color: #fff;
  font-size: 20px;
  min-height: 60px;
}

.head-nav{
  padding: 20px;
  text-align: right;
}

.form-layout{
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.form-layout .title{
width: 80px;
min-width: 80px;
}

.form-layout .form{
flex-grow: 1;
}

.form-layout .sub{
  width: 58px;
  padding-left: 10px;
}

#camera-button{
  width: 48px;
}

#camera-button img{
  width: 1.2em;
}


.scanner-title{
  text-align: center;
}


/* Overlay / Modal */
.overlay{
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}
.overlay.is-open{ display: flex; }
.panel{
  width: min(560px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.panel h3{
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
}
.panel .actions{
  /*display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  */
  margin-top: 22px;
}
.panel .actions button{ width: 100%; }

@media (min-width: 640px){
  .panel{ padding: 16px; }
  .panel h3{ font-size: 18px; }
}
@media (min-width: 900px){
  .panel{ width: min(720px, 100%); }
}

/* Scanner viewport (Quagga injects video/canvas) */
.scanner-viewport{
  width: 100%;
  /* Smartphone-friendly: taller preview */
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.scanner-viewport video,
.scanner-viewport canvas{
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

/* Add simple guide frame */
.scanner-viewport::after{
  content:"";
  position:absolute;
  inset: 18% 10%;
  border: 2px solid rgba(255,255,255,.75);
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.20) inset;
  pointer-events:none;
}
@media (min-width: 640px){
  .scanner-viewport{ aspect-ratio: 16 / 9; }
  .scanner-viewport::after{ inset: 28% 16%; }
}

/* Sending modal */
#sending-modal .panel{ text-align: center; width: min(480px, 100%); }
#sending-modal .msg{ font-size: 18px; font-weight: 900; padding: 14px 0 6px; }

/* List modal */
/*#list-modal .panel{ width: min(980px, 100%); }
.table-wrap{
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  -webkit-overflow-scrolling: touch;
}*/
/* List modal: full-height panel + table-only vertical scroll */
#list-modal{
  /* 端末の表示領域いっぱいに使う（overlay自体はそのまま） */
  align-items: stretch; /* center → stretch にしてもOK。centerのままでも下のheightで成立します */
}

#list-modal .panel{
  width: min(980px, 100%);
  /* 画面いっぱい（overlay padding 16px×2 を引く） */
  height: calc(85dvh - 32px);
  max-height: calc(85dvh - 32px);

  /* dvh未対応ブラウザ用フォールバック */
  height: calc(85vh - 32px);
  max-height: calc(85vh - 32px);

  display: flex;
  flex-direction: column;
}

/* タイトル・ボタンは固定、真ん中だけ伸縮させる */
#list-container{
  flex: 1 1 auto;
  min-height: 0; /* これがないと子要素のoverflowが効かない事があります */
}

/* テーブル領域だけ縦横スクロール */
#list-container .table-wrap{
  height: 100%;
  max-height: 100%;
  overflow: auto; /* 横スクロールも縦スクロールも維持 */
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
}

/* 下のボタンエリアは縮まない（常に見える） */
#list-modal .actions{
  flex: 0 0 auto;
  margin-top: 12px; /* 既存の22pxより詰めたい場合だけ */
}
table{
  border-collapse: collapse;
  width: 100%;
  min-width: 720px;
}
th,td{
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
  white-space: nowrap;
  font-size: 12px;
  border-left: 1px solid var(--border);
}
th:first-child,
td:first-child{
  border-left:none;
}
th:last-child,
td:last-child{
  width: 66px;
}
th{
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 12px;
  color: #111827;
}


button.row-delete{
  font-size: 12px;
  min-height: 20px;
}

.empty{
  padding: 14px;
  background: #f9fafb;
  /*border: 1px solid var(--border);
  border-radius: 14px;*/
  font-size: 12px;
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce){
  button:active{ transform: none; }
}

/* Loader (sending) */
.loader{
  width: 44px;
  height: 44px;
  margin: 10px auto 2px;
  border-radius: 50%;
  border: 4px solid rgba(17,24,39,.15);
  border-top-color: rgba(17,24,39,.85);
  animation: spin 0.9s linear infinite;
  display: none;
}
#sending-modal.is-open .loader.is-active{ display: block; }

#sending-sub{
  text-align: center;
  margin: 6px 0 0;
  color: var(--muted, #6b7280);
  display: none;
}
#sending-modal.is-open #sending-sub.is-active{ display: block; }

@keyframes spin{
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce){
  .loader{ animation: none; }
}

/* Required error style */
.is-error{
  /*border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239,68,68,.18) !important;*/
}
