:root{
  --bg:#0b0d12; --card:#121826; --line:#263042; --text:#e8eefc; --muted:#a7b3cc;
  --accent:#6ea8ff; --danger:#ff6e6e; --ok:#66d19e; --warn:#ffd66e;
  --field:#0f1422;
}
*{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }
body{
  margin:0;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background:linear-gradient(180deg, #080a10, var(--bg));
  color:var(--text);
}
input, select, textarea, button { font-size:16px; }

.wrap{ max-width:1050px; margin:0 auto; }
header{
  display:flex; align-items:center; justify-content:space-between;
  gap:12px; margin-bottom:12px; flex-wrap:wrap;
}
h1{ font-size:18px; margin:0; letter-spacing:.02em; }
.tabs{ display:flex; gap:10px; }
.tab{
  border:1px solid var(--line); background:transparent; color:var(--text);
  padding:10px 12px; border-radius:12px; cursor:pointer; font-weight:800;
}
.tab.active{ background:rgba(110,168,255,.12); border-color:rgba(110,168,255,.45); }
.card{
  background:rgba(18,24,38,.85);
  border:1px solid var(--line);
  border-radius:16px;
  padding:14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.grid{ display:grid; gap:12px; }
.grid.two{ grid-template-columns: 1fr 1fr; }
.hr{ height:1px; background:var(--line); margin:12px 0; }

@media (max-width: 560px){
  .grid.two{ grid-template-columns: 1fr; }
  .card{ padding:12px; border-radius:14px; }
}

label{ display:block; font-size:12px; color:var(--muted); margin-bottom:6px; }
input, select, textarea{
  width:100%;
  padding:12px 12px;
  border-radius:12px;
  border:1px solid var(--line);
  background:var(--field);
  color:var(--text);
  outline:none;
}
textarea{ min-height:96px; resize:vertical; }

.row{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.row > * { flex:1; min-width:160px; }
@media (max-width: 560px){
  .row > * { min-width: 0; }
}

.btn{
  width:auto;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--line);
  background:var(--field);
  color:var(--text);
  cursor:pointer;
  font-weight:900;
}
.btn.primary{ background:rgba(110,168,255,.16); border-color:rgba(110,168,255,.45); }
.btn.ok{ background:rgba(102,209,158,.12); border-color:rgba(102,209,158,.45); }
.btn.danger{ background:rgba(255,110,110,.12); border-color:rgba(255,110,110,.45); }
.small{ font-size:12px; color:var(--muted); }
.warn{ color: var(--warn); }

.pill{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:10px 12px; border-radius:14px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.03);
  font-weight:900;
}
.money{ font-variant-numeric: tabular-nums; font-feature-settings:"tnum"; }
.mono{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.hidden{ display:none !important; }

.session{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
  background:var(--field);
  margin-bottom:10px;
}
.session-head{
  display:flex; justify-content:space-between; align-items:center; gap:10px;
  margin-bottom:10px;
}
.session-title{ font-weight:900; }
.session-grid{
  display:grid; gap:10px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 560px){
  .session-grid{ grid-template-columns: 1fr; }
}

.optbox{
  border:1px solid rgba(255,255,255,.08);
  border-radius:12px;
  padding:10px;
  background: rgba(255,255,255,.02);
  display:flex; flex-direction:column; gap:8px;
}
.optitem{
  display:flex; gap:10px; align-items:center; justify-content:flex-start;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  padding:10px; border-radius:12px;
}
.optitem input{ width:auto; }
.optname{ font-weight:900; }

.summary-card{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
  background: rgba(255,255,255,.02);
  margin-top:12px;
}
.summary-title{
  font-weight:900;
  margin:0 0 10px 0;
  font-size:14px;
}
.summary-pill{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  font-weight:900;
  margin-top:8px;
}
.summary-big{
  padding:12px 14px;
  border-radius:16px;
  border:1px solid rgba(110,168,255,.45);
  background: rgba(110,168,255,.10);
  font-weight:900;
}
.checkline{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  margin-top:8px;
}
.checkline .left{
  display:flex; gap:10px; align-items:center;
  font-weight:900;
}
.checkline input{ width:auto; }

.breakdown{
  border:1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  border-radius:14px;
  padding:10px 12px;
}
.break-row{
  display:flex; justify-content:space-between; gap:10px;
  padding:8px 0;
  border-bottom:1px solid rgba(255,255,255,.06);
}
.break-row:last-child{ border-bottom:none; }
.break-left{ display:flex; gap:10px; align-items:center; }
.count{ color:var(--muted); font-size:12px; font-weight:900; }
.neg{ color: #ffb0b0; }
.pos{ color: #cfe0ff; }

.editor-card{
  border:1px solid var(--line);
  border-radius:14px;
  padding:12px;
  background: var(--field);
}
.amount-input{
  width: 170px;
  min-width: 170px;
  text-align:right;
  padding:12px 12px;
}
@media (max-width: 560px){
  .amount-input{ width: 180px; min-width: 180px; }
}


/* ===== iPhone向け コンパクト調整 ===== */
.main-topline{ display:block; }
.main-employee-row{
  display:flex;
  gap:10px;
  align-items:center;
}
.main-employee-row select{
  flex:1;
  min-width:0;
}
.main-rank{
  flex:0 0 auto;
  min-width:44px;
  text-align:center;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
  font-weight:1000;
  letter-spacing:.05em;
}

.session.compact{ padding:10px; border-radius:14px; margin-bottom:10px; }
.session-head{ margin-bottom:8px; }
.session-title{ font-size:13px; }
.session-body{ display:block; }

.session-line2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
@media (max-width: 560px){
  .session-line2{ grid-template-columns: 1fr 1fr; gap:8px; }
  .session.compact{ padding:10px; }
}

.pill-compact{ padding:10px 12px; border-radius:14px; }

/* オプション：2列・小さめ・省スペース */
.optbox.optgrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:8px;
  padding:8px;
}
.optbox.optgrid .optitem{
  padding:8px 8px;
  border-radius:12px;
}
.optbox.optgrid .optname{
  font-size:12px;
  font-weight:900;
  line-height:1.2;
}
.optbox.optgrid input[type="checkbox"]{
  transform: scale(0.95);
}

/* メイン全体のカード余白を少し詰める */
#viewMain.card{ padding:12px; }

/* 集計：iPhoneで見やすく */
.summary-title{ font-size:13px; }
.summary-pill, .checkline{ padding:10px 10px; }
.break-row{ padding:7px 0; }

/* 設定画面：横はみ出し対策（入力が潰れる/見切れるのを防止） */
#viewSettings .row > *{ min-width: 0; }
.amount-input{ width:100%; min-width:0; }
.editor-card{ padding:10px; }
textarea{ font-size:16px; } /* iOSズーム回避 */
@media (max-width: 560px){
  .card{ padding:12px; }
  .btn{ width:100%; }
  .tabs{ width:100%; }
  .tabs .tab{ flex:1; }
}


/* ===== 設定画面: iPhone はみ出し修正 ===== */
@media (max-width: 560px){
  /* 設定画面内は「横並び」をやめて縦積みにして確実に収める */
  #viewSettings .row{
    flex-direction: column;
    align-items: stretch;
  }
  #viewSettings .row > *{
    width: 100%;
    min-width: 0;
  }

  /* 価格表生成 / 保存ボタンも縦積み */
  #viewSettings .row button.btn{
    width: 100%;
  }

  /* オプション/従業員の1行（入力+削除）が横に収まらないので折り返し */
  #viewSettings .break-row{
    flex-wrap: wrap;
    align-items: flex-start;
    gap:10px;
  }

  /* inline style の width を !important で上書きして「潰れ」を防止 */
  #optionList .break-row > div:nth-child(1),
  #employeeList .break-row > div:nth-child(1){
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  #optionList .break-row > div:nth-child(2),
  #employeeList .break-row > div:nth-child(2){
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  #optionList .break-row > div:nth-child(3),
  #employeeList .break-row > div:nth-child(3){
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  #optionList .break-row > div:nth-child(3) .btn,
  #employeeList .break-row > div:nth-child(3) .btn{
    width: 100% !important;
  }

  /* label が縦に潰れるのを防ぐ（日本語ラベルは折り返してOK） */
  #viewSettings label{
    white-space: normal;
    word-break: keep-all;
  }

  /* セレクトの右端が切れることがあるので余白を少し確保 */
  select{
    padding-right: 34px;
  }
}
