* { box-sizing: border-box; }
body { margin: 0; font-family: "Hiragino Sans","Yu Gothic",Meiryo,sans-serif; background: #f4f6f8; color: #222; }
.hidden { display: none !important; }

/* 認証 */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; padding: 28px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.1); width: 360px; }
.auth-card h1 { font-size: 20px; text-align: center; margin: 0 0 18px; }
.auth-tabs { display: flex; margin-bottom: 16px; }
.atab { flex: 1; border: none; background: #eee; padding: 10px; cursor: pointer; font-size: 14px; }
.atab:first-child { border-radius: 6px 0 0 6px; } .atab:last-child { border-radius: 0 6px 6px 0; }
.atab.active { background: #2e7d32; color: #fff; font-weight: bold; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
.auth-form input { padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; }
.err { color: #c62828; font-size: 13px; margin: 0; }

/* 共通 */
.topbar { background: #2e7d32; color: #fff; padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; }
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.tabs { display: flex; gap: 4px; background: #fff; border-bottom: 1px solid #e0e0e0; padding: 0 12px; }
.tab { border: none; background: none; padding: 14px 16px; font-size: 14px; cursor: pointer; border-bottom: 3px solid transparent; color: #555; }
.tab.active { color: #2e7d32; border-bottom-color: #2e7d32; font-weight: bold; }
main { max-width: 860px; margin: 0 auto; padding: 20px; }
.panel { display: none; } .panel.active { display: block; }
h2 { font-size: 18px; } h3 { font-size: 15px; margin-top: 20px; }
.count { font-size: 13px; color: #666; font-weight: normal; }
.hint { font-size: 13px; color: #666; }

label { font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 6px; }
main label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: bold; color: #444; }
main input, main select, main textarea { padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; font-family: inherit; font-weight: normal; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

button.primary { background: #2e7d32; color: #fff; border: none; padding: 11px 28px; border-radius: 6px; font-size: 15px; cursor: pointer; }
button.ghost { background: #eee; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.form-head { display: flex; justify-content: space-between; align-items: center; }
.form-actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; }

table.grid, table.items { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; background: #fff; }
table.grid th, table.grid td, table.items th, table.items td { border: 1px solid #e0e0e0; padding: 8px 10px; }
table.grid th, table.items th { background: #f5f5f5; text-align: left; }
.r { text-align: right; }
.ops button, .i-del { border: none; background: #eef; padding: 5px 10px; border-radius: 5px; cursor: pointer; margin-right: 4px; font-size: 12px; }
.ops .del, .i-del { background: #fdecea; color: #c62828; }
.items input, .items select { width: 100%; padding: 6px; }
.items .i-name { min-width: 160px; }

.totals { margin: 14px 0; text-align: right; font-size: 14px; line-height: 1.9; }
.totals .grand { font-size: 18px; border-top: 2px solid #333; margin-top: 6px; padding-top: 6px; }
.totals b { margin-left: 10px; }

#toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; }
.toast { background: #333; color: #fff; padding: 11px 18px; border-radius: 8px; margin-top: 8px; font-size: 14px; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.toast.success { background: #2e7d32; } .toast.error { background: #c62828; }

/* 招待コード */
.code-issue { display: flex; gap: 10px; margin: 12px 0; }
.code-issue input { flex: 1; padding: 9px 10px; border: 1px solid #ccc; border-radius: 6px; }
.ok-text { color: #2e7d32; font-weight: bold; }
table.grid code { background: #eef1f4; padding: 2px 8px; border-radius: 4px; font-size: 14px; letter-spacing: 1px; }

/* 状態バッジ（下書き/提出済み）・提出ボタン・固定日付表示 */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: bold; white-space: nowrap; }
.badge.draft { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }
.badge.submitted { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
button.submit-btn { background: #1565c0; color: #fff; border: none; padding: 11px 28px; border-radius: 6px; font-size: 15px; cursor: pointer; }
.ops .submit-mini { background: #e3f0fb; color: #1565c0; }
.fixed-dates { background: #f0f4f8; border: 1px solid #d7e0ea; border-radius: 6px; padding: 10px 12px; font-size: 13px; line-height: 1.9; }
.fixed-dates strong { font-size: 14px; }
@media (max-width: 640px) { button.submit-btn { width: 100%; padding: 13px; font-size: 16px; } }

.fixed-recipient { background: #eef7ed; border: 1px solid #cfe8cc; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.fixed-recipient strong { font-size: 15px; }
#recipient-card { margin-top: 26px; border-top: 1px dashed #ccc; padding-top: 16px; }

/* ===================== スマホ対応 ===================== */
@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }

  /* タブは横スクロール（潰れ防止） */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { flex: 0 0 auto; padding: 12px 12px; font-size: 13px; }

  /* 入力はiOSの自動ズーム防止に16px */
  main input, main select, main textarea, .auth-form input, .code-issue input { font-size: 16px; }

  /* ログインカードを画面幅に追従 */
  .auth { padding: 16px; }
  .auth-card { width: 100%; max-width: 380px; padding: 22px; }

  /* 明細テーブル → 1件ずつのカードに積み替え */
  table.items thead { display: none; }
  table.items, table.items tbody, table.items tr, table.items td { display: block; width: 100%; }
  table.items tr {
    border: 1px solid #d9d9d9; border-radius: 10px; background: #fff;
    padding: 6px 10px; margin-bottom: 14px;
  }
  table.items td {
    border: none; border-bottom: 1px dashed #eee;
    display: flex; align-items: center; gap: 10px; padding: 9px 2px;
  }
  table.items td:last-child { border-bottom: none; }
  table.items td::before {
    content: attr(data-label); flex: 0 0 84px; color: #666; font-weight: bold; font-size: 13px;
  }
  table.items td input, table.items td select { flex: 1; min-width: 0; }
  .items .i-name { min-width: 0; }
  table.items td.i-amount { justify-content: flex-end; font-weight: bold; font-size: 16px; }
  table.items td.i-amount::before { flex: 1; }
  .i-del { width: 100%; padding: 10px; }

  /* 一覧テーブル（請求書一覧・ゲストコード）→ 1件ずつカードに積み替え */
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { border: 1px solid #d9d9d9; border-radius: 10px; background: #fff; padding: 6px 12px; margin-bottom: 14px; }
  table.grid td {
    border: none; border-bottom: 1px dashed #eee; white-space: normal;
    display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 2px;
  }
  table.grid td:last-child { border-bottom: none; }
  table.grid td::before { content: attr(data-label); flex: 0 0 auto; color: #666; font-weight: bold; font-size: 13px; }
  table.grid td.ops { flex-wrap: wrap; gap: 8px; padding-top: 10px; }
  table.grid td.ops::before { display: none; }
  table.grid td.ops button { flex: 1; min-width: 90px; padding: 11px 8px; font-size: 14px; margin: 0; }

  /* 操作ボタンを押しやすく */
  button.primary { width: 100%; padding: 13px; font-size: 16px; }
  .form-actions { flex-direction: column; align-items: stretch; }
  #add-item { width: 100%; padding: 12px; }
}

.tax-mode { margin: 8px 0 4px; font-size: 14px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.tax-mode label { font-weight: normal; display: inline-flex; align-items: center; gap: 4px; margin: 0; color: #333; }
.tax-mode .sep { color: #ccc; }
.tax-mode select { padding: 5px 8px; border: 1px solid #ccc; border-radius: 6px; }
