 :root{
  --primary:#4a90e2;
  --primary-dark:#3a79c9;
  --bg:#f7f9fc;
  --fg:#1a1a1a;
  --muted:#666;
  --line:#e0e0e0;
  --card-bg:#fff;
  --radius:10px;
  --spacing:16px;
  --ok-bg:#e6f0ff;
  --ok-bd:#bfdbfe;
  --ok-fg:#2563eb;
  --ng-bg:#fee2e2;
  --ng-bd:#fecdd3;
  --ng-fg:#e11d48;
}

*{box-sizing:border-box}

html,body{
  margin:0;
  background:var(--bg);
  color:var(--fg);
  font-family:'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;
}

header{
  position:sticky;
  top:0;
  background:var(--card-bg);
  border-bottom:1px solid var(--line);
  padding:10px var(--spacing);
  z-index:10;
}

.app-title{
  margin:0;
  font-size:14px;
  font-weight:700;
  letter-spacing:.3px;
  text-align:center;
}

.app-title .shoku{color:#e11d48}

main{
  padding:var(--spacing);
  max-width:720px;
  margin:0 auto;
}

.card{
  background:var(--card-bg);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:var(--spacing);
  box-shadow:0 4px 6px rgba(0,0,0,.05);
  margin:0 0 12px;
}

.row{
  display:flex;
  gap:10px;
  align-items:center;
}

.row-between{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}

.wrap{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

input,button,textarea,select{
  font-size:16px;
  padding:12px;
  border-radius:8px;
  border:1px solid var(--line);
  width:100%;
  margin:8px 0;
}

textarea{
  min-height:120px;
  resize:vertical;
}

button{
  background:var(--primary);
  color:#fff;
  border:none;
  font-weight:600;
  cursor:pointer;
}

button:hover{background:var(--primary-dark)}

button.ghost{
  background:#f1f5f9;
  color:var(--fg);
  border:1px solid var(--line);
}

input:focus,
select:focus,
textarea:focus,
button:focus{
  outline:none;
  border-color:var(--primary);
  box-shadow:0 0 0 2px rgba(74,144,226,0.30);
}

.list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(140px,1fr));
  gap:10px;
}

.item{
  background:#fff;
  border:1px solid var(--line);
  border-radius:8px;
  padding:12px;
  transition:border-color .12s ease,box-shadow .12s ease,transform .05s ease,background-color .12s ease;
}

.shop-card{
  cursor:pointer;
  transition:border-color .15s ease,box-shadow .15s ease,background-color .15s ease,transform .06s ease;
}

.shop-card.clicked{
  border-color:var(--primary);
  box-shadow:0 0 0 2px rgba(74,144,226,0.35);
  background:#f5f9ff;
  transform:scale(0.97);
}

.menu-card{
  position:relative;
  cursor:pointer;
}

.menu-card.selected{
  border-color:var(--primary);
  box-shadow:0 0 0 2px rgba(74,144,226,0.35);
  background:#f5f9ff;
}

.menu-card-badge{
  position:absolute;
  top:6px;
  right:6px;
  min-width:20px;
  padding:2px 6px;
  border-radius:999px;
  font-size:11px;
  font-weight:700;
  text-align:center;
  color:#fff;
  background:var(--primary);
  box-shadow:0 2px 4px rgba(15,23,42,.25);
}

.muted{
  color:var(--muted);
  font-size:12px;
}

.price{
  font-variant-numeric:tabular-nums;
  font-weight:600;
  color:var(--primary-dark);
}

.tag{
  display:inline-block;
  background:#e6f0ff;
  color:var(--primary-dark);
  border-radius:999px;
  padding:4px 10px;
  font-size:12px;
  margin-left:8px;
}

.hidden{display:none !important}
.center{text-align:center}

#loading-overlay{
  position:fixed;
  inset:0;
  background:rgba(255,255,255,.8);
  z-index:9999;
  display:flex;
  justify-content:center;
  align-items:center;
  flex-direction:column;
  font-size:20px;
  color:var(--primary-dark);
  font-weight:bold;
}

.spinner{
  border:4px solid #f3f3f3;
  border-top:4px solid var(--primary);
  border-radius:50%;
  width:40px;
  height:40px;
  margin-bottom:10px;
  animation:spin 1s linear infinite;
}

@keyframes spin{
  to{transform:rotate(360deg)}
}

/* 営業情報 */
.status-grid{
  display:grid;
  grid-template-columns:1fr 64px 64px 64px;
  gap:10px;
  align-items:center;
}

.status-header{
  font-weight:700;
  color:#555;
}

.status-header span{
  display:inline-block;
  width:100%;
  text-align:center;
  font-size:11px;
}

.badge-ok{
  background:var(--ok-bg);
  color:var(--ok-fg);
  border:1px solid var(--ok-bd);
  border-radius:8px;
  padding:6px 0;
  text-align:center;
  font-weight:800;
}

.badge-ng{
  background:var(--ng-bg);
  color:var(--ng-fg);
  border:1px solid var(--ng-bd);
  border-radius:8px;
  padding:6px 0;
  text-align:center;
  font-weight:800;
}

.shop-chip{
  display:grid;
  grid-template-columns:28px 1fr;
  align-items:center;
  gap:8px;
  min-width:0;
}

.shop-avatar{
  width:28px;
  height:28px;
  border-radius:8px;
  background:#e6f0ff;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  color:#3a79c9;
}

.shop-name{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

/* vendor 品目別 */
.vendor-byitem-table{
  width:100%;
  border-collapse:collapse;
}

.vendor-byitem-table th:nth-child(1),
.vendor-byitem-table td:nth-child(1){
  width:auto;
  max-width:calc(100% - 130px);
  white-space:normal;
  word-break:break-word;
  line-height:1.3;
}

.vendor-byitem-table th:nth-child(2),
.vendor-byitem-table td:nth-child(2){
  width:40px;
  min-width:40px;
  text-align:right;
  white-space:nowrap;
}

.vendor-byitem-table th:nth-child(3),
.vendor-byitem-table td:nth-child(3){
  width:90px;
  min-width:90px;
  text-align:right;
  white-space:nowrap;
}

/* vendor 注文詳細 */
.vendor-rows th:nth-child(1),
.vendor-rows td:nth-child(1){
  width:80px;
  min-width:80px;
  white-space:nowrap;
}

.vendor-rows th:nth-child(2),
.vendor-rows td:nth-child(2){
  width:auto;
  max-width:calc(100% - 170px);
  white-space:normal;
  word-break:break-word;
  line-height:1.3;
}

.vendor-rows th:nth-child(3),
.vendor-rows td:nth-child(3){
  width:60px;
  min-width:60px;
  text-align:right;
  white-space:nowrap;
}

.vendor-rows th:nth-child(4),
.vendor-rows td:nth-child(4){
  width:90px;
  min-width:90px;
  text-align:right;
  white-space:nowrap;
}

/* お知らせ */
.notice-title{
  font-weight:700;
  cursor:pointer;
}

.notice-body{
  margin-top:6px;
  font-size:14px;
  line-height:1.6;
  display:none;
  white-space:pre-wrap;
}

.notice-item{
  border-left:4px solid #e6f0ff;
  padding-left:8px;
}

body.show-login header{display:none}
#view-vendor #vendor-sub{display:none}
main section.hidden{display:none !important}

/* vendor メニュー編集 */
.menu-edit-list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.menu-row{
  border:1px solid var(--line);
  border-radius:12px;
  padding:8px 10px;
  background:var(--card-bg);
  box-shadow:0 2px 4px rgba(0,0,0,.04);
  transition:border-color .12s ease,box-shadow .12s ease,background-color .12s ease;
}

.menu-row:focus-within{
  border-color:var(--primary);
  box-shadow:0 0 0 2px rgba(74,144,226,0.30);
  background:#f5f9ff;
}

.menu-field{
  margin-bottom:6px;
}

.menu-field-label{
  font-size:11px;
  color:var(--muted);
  margin-bottom:2px;
}

.menu-field input{
  width:100%;
}

.menu-row-inline{
  display:flex;
  gap:10px;
}

.menu-row-inline .menu-field{
  flex:1;
  margin-bottom:0;
}

.menu-row-inline input{
  text-align:right;
}

.menu-row-footer{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:8px;
  margin-top:4px;
}

.menu-enabled-wrap{
  display:flex;
  align-items:center;
  gap:6px;
  font-size:14px;
}

.menu-enabled-wrap span{
  white-space:nowrap;
}

.menu-row-footer .btn-menu-del{
  font-size:13px;
}

#btn-menu-add{
  white-space:nowrap;
  min-width:130px;
}

/* メニュー画面上部 */
.menu-header-sticky{
  position:sticky;
  top:0;
  z-index:9;
  background:var(--bg);
  padding:4px 8px 8px;
}

.current-shop-row{
  margin:4px 0 0 0;
  align-items:center;
}

.current-shop-text{
  display:flex;
  flex-direction:column;
  gap:2px;
}

.current-shop-label{
  font-size:13px;
  color:var(--muted);
  line-height:1.2;
}

.current-shop-name{
  font-size:17px;
  font-weight:600;
  color:#111;
  line-height:1.25;
}

/* 営業カレンダー */
.shop-calendar-box{
  border:1px solid #e0e0e0;
  border-radius:8px;
  padding:8px;
  background:#fff;
  flex:0 0 calc(50% - 6px);
  min-width:0;
}

.shop-calendar-title{
  font-size:13px;
  font-weight:700;
  margin-bottom:4px;
}

.shop-calendar-grid{
  display:grid;
  grid-template-columns:repeat(7,1fr);
  gap:4px;
}

.shop-calendar-grid .dow{
  font-size:10px;
  color:#94a3b8;
  text-align:center;
}

.shop-cal-day,
.shop-cal-empty{
  font-size:11px;
  text-align:center;
  padding:3px 0;
  border-radius:4px;
}

.shop-cal-day.open{
  background:#e0edff;
  color:#1f2937;
}

.shop-cal-day.closed{
  background:#fee2e2;
  color:#b91c1c;
  font-weight:600;
}

#shop-calendars{
  display:grid !important;
  grid-template-columns:repeat(2, 1fr);
  gap:12px;
}

#shop-calendars .shop-calendar-box{
  min-width:0;
  width:100%;
}

/* モーダル */
#confirm-overlay.hidden,
#pw-change-overlay.hidden{
  display:none !important;
}

#confirm-overlay,
#pw-change-overlay{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
}

#confirm-overlay{z-index:10000}
#pw-change-overlay{z-index:10001}

#confirm-overlay .confirm-backdrop,
#pw-change-overlay .confirm-backdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.45);
}

#confirm-overlay .confirm-card,
#pw-change-overlay .confirm-card{
  position:relative;
  width:min(92vw, 420px);
  background:#fff;
  border-radius:14px;
  padding:16px;
  box-shadow:0 12px 30px rgba(0,0,0,.18);
  z-index:1;
}

#pw-change-overlay input{
  width:100%;
}

#pw-change-overlay .row{
  justify-content:flex-end;
}

/* ===== 売上集計カード ===== */
#vendor-sales-card{
  overflow:hidden;
}

#vendor-sales-card .sales-title{
  margin:0 0 12px 0;
  font-size:20px;
}

#vendor-sales-card .sales-form{
  display:flex;
  flex-direction:column;
  gap:14px;
  width:100%;
}

#vendor-sales-card .sales-field{
  display:block;
  width:100%;
  margin:0;
  padding:0;
}

#vendor-sales-card .sales-label{
  display:block;
  color:var(--muted);
  font-size:14px;
  margin:0 0 6px 0;
}

#vendor-sales-card input[type="date"],
#vendor-sales-card select{
  display:block;
  width:100%;
  max-width:100%;
  margin:0;
  padding:12px 16px;
  border:1px solid var(--line);
  border-radius:16px;
  background:#fff;
  font-size:16px;
  box-sizing:border-box;
}

#vendor-sales-card .sales-actions{
  display:flex;
  gap:10px;
  align-items:center;
  margin-top:12px;
  flex-wrap:wrap;
}

#vendor-sales-card .sales-actions button{
  width:auto;
  min-width:120px;
  margin:0;
  flex:0 0 auto;
}

#vendor-sales-card .sales-help{
  margin-top:12px;
}

#vendor-sales-card .sales-result{
  margin-top:12px;
}

#vendor-sales-card .sales-meta{
  margin-bottom:10px;
  line-height:1.5;
}

.sales-kpi-grid{
  display:grid;
  grid-template-columns:repeat(3, minmax(0, 1fr));
  gap:10px;
  margin-bottom:12px;
}

.sales-kpi-card{
  padding:12px;
}

.sales-kpi-value{
  font-size:24px;
  font-weight:900;
  line-height:1.2;
}

.sales-block-title{
  margin:0 0 8px 0;
}

.sales-table{
  width:100%;
  border-collapse:collapse;
  table-layout:fixed;
  font-size:14px;
}

.sales-table th,
.sales-table td{
  border-bottom:1px solid var(--line);
  padding:8px 6px;
  vertical-align:top;
}

.sales-table th{
  background:#f8fafc;
  font-size:12px;
  color:var(--muted);
  text-align:left;
}

.sales-table td{
  word-break:break-word;
}

.sales-table th:nth-child(n+2),
.sales-table td:nth-child(n+2){
  text-align:right;
  white-space:nowrap;
}

.sales-table th:first-child,
.sales-table td:first-child{
  white-space:normal;
}

#sales-by-day td:nth-child(1),
.sales-table thead tr th:nth-child(1){
  width:auto;
}

#sales-by-item td:nth-child(1){
  white-space:normal;
  word-break:break-word;
}

@media print{
  @page{
    size:A4 portrait;
    margin:10mm;
  }

  html,
  body{
    background:#fff !important;
    margin:0 !important;
    padding:0 !important;
    width:auto !important;
    height:auto !important;
    overflow:visible !important;
  }

  body > *{
    display:none !important;
  }

  main{
    display:block !important;
    margin:0 !important;
    padding:0 !important;
    max-width:none !important;
  }

  #view-vendor{
    display:block !important;
    margin:0 !important;
    padding:0 !important;
  }

  #view-vendor > *{
    display:none !important;
  }

  #vendor-sales-card{
    display:block !important;
    margin:0 !important;
    padding:0 !important;
    border:none !important;
    box-shadow:none !important;
    background:#fff !important;
    width:100% !important;
    max-width:none !important;
  }

  #vendor-sales-card .sales-form,
  #vendor-sales-card .sales-actions,
  #sales-report-empty{
    display:none !important;
  }

  #sales-report-result{
    display:block !important;
    margin-top:0 !important;
  }

  #vendor-sales-card .sales-meta{
    font-size:10px !important;
    line-height:1.4 !important;
    margin:0 0 10px 0 !important;
    color:#333 !important;
  }

  .sales-kpi-grid{
    grid-template-columns:repeat(3, 1fr) !important;
    gap:8px !important;
    margin:0 0 12px 0 !important;
  }

  .sales-kpi-card{
    border:1px solid #ccc !important;
    box-shadow:none !important;
    background:#fff !important;
  }

  .sales-kpi-value{
    font-size:18px !important;
  }

  .sales-print-block{
    display:block !important;
    margin:0 0 12px 0 !important;
    padding:0 !important;
    border:none !important;
    box-shadow:none !important;
    break-inside:avoid !important;
    page-break-inside:avoid !important;
    background:#fff !important;
  }

  .sales-block-title{
    font-size:12px !important;
    margin:0 0 6px 0 !important;
    line-height:1.3 !important;
    color:#111 !important;
  }

  .sales-table{
    width:100% !important;
    border-collapse:collapse !important;
    table-layout:fixed !important;
    font-size:11px !important;
    margin:0 !important;
  }

  .sales-table th,
  .sales-table td{
    border:1px solid #bbb !important;
    padding:5px 6px !important;
    line-height:1.35 !important;
    vertical-align:middle !important;
    color:#111 !important;
    background:#fff !important;
  }

  .sales-table th{
    background:#f5f5f5 !important;
    font-size:10px !important;
    font-weight:700 !important;
  }

  .sales-table th:nth-child(1),
  .sales-table td:nth-child(1){
    width:46% !important;
    text-align:left !important;
    white-space:normal !important;
    word-break:break-word !important;
  }

  .sales-table th:nth-child(2),
  .sales-table td:nth-child(2),
  .sales-table th:nth-child(3),
  .sales-table td:nth-child(3),
  .sales-table th:nth-child(4),
  .sales-table td:nth-child(4){
    width:18% !important;
    text-align:right !important;
    white-space:nowrap !important;
  }

  #sales-by-item td:nth-child(1){
    width:64% !important;
  }

  #sales-by-item td:nth-child(2),
  #sales-by-item td:nth-child(3){
    width:18% !important;
  }
}

/* 売上集計ボタン（スマホ時） */
@media (max-width: 600px){
  #vendor-sales-card .sales-actions{
    display:flex;
    flex-direction:row;
    align-items:center;
    justify-content:flex-start;
    gap:12px;
    width:100%;
    flex-wrap:nowrap;
  }

  #vendor-sales-card .sales-actions button{
    width:calc((100% - 12px) / 2);
    max-width:none;
    min-width:0;
    margin:0;
    flex:1 1 0;
  }

  .sales-kpi-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:12px;
    margin-bottom:12px;
  }

  .sales-kpi-grid .sales-kpi-card:nth-child(3){
    grid-column:1 / -1;
  }

  .sales-kpi-value{
    font-size:22px;
  }

  .sales-table{
    font-size:13px;
  }

  .sales-table th,
  .sales-table td{
    padding:7px 5px;
  }
}
