/**
 * main.css — 足場（工程1）のベーススタイル
 * 0.1秒の操作感・ダークテーマ・モバイルファースト。
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* --- ヘッダー --- */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header .logo {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
}
.app-header .title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.app-header .env-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
}

/* --- コンテンツ --- */
main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: var(--sp-4); }

.card h2 {
  font-size: 16px;
  margin-bottom: var(--sp-3);
}
.card p { color: var(--text-secondary); line-height: 1.7; font-size: 14px; }

/* --- 接続ステータス --- */
.status-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface-2);
  border-radius: var(--radius-md);
}
.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex: none;
}
.status-dot.ok { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
.status-dot.ng { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,77,79,0.16); }
.status-label { font-size: 13px; color: var(--text-secondary); }
.status-label b { color: var(--text-primary); }

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text-tertiary);
  word-break: break-all;
}

/* --- トースト --- */
#toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0) + 20px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 1000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 88vw;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- アカウントバー & タブ --- */
.account-bar {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-1); margin-bottom: var(--sp-3);
}
.acct-item { font-size: 13px; color: var(--text-secondary); }
.acct-item b { color: var(--text-primary); }
.account-bar .btn-ghost { margin-left: auto; height: 34px; }
.tabbar {
  display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border-subtle); overflow-x: auto;
}
.tab-btn {
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  color: var(--text-secondary); background: transparent; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* 選択肢リスト管理 */
.optlist-box { margin-top: var(--sp-3); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border-subtle); }
.optlist-title { font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-bottom: var(--sp-2); }
.optlist-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-2); }
.optlist-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 3px 4px 3px 10px; border-radius: var(--radius-pill);
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle); color: var(--text-primary);
}
.optlist-del {
  width: 18px; height: 18px; border-radius: 50%; line-height: 1; font-size: 12px;
  background: transparent; color: var(--text-tertiary); border: none; cursor: pointer;
}
.optlist-del:hover { color: var(--danger); }
.optlist-add { display: flex; gap: var(--sp-2); align-items: center; }
.optlist-add .field-inline { flex: 1 1 auto; max-width: 240px; }

/* --- フォーム（ログイン等） --- */
.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin: var(--sp-3) 0 var(--sp-1);
}
.field {
  width: 100%;
  height: 46px;
  padding: 0 var(--sp-3);
  font-size: 16px; /* iOS のズーム防止に16px以上 */
  color: var(--text-primary);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
}
.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.btn-primary {
  width: 100%;
  height: 48px;
  margin-top: var(--sp-5);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-on-accent);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost {
  height: 40px;
  padding: 0 var(--sp-4);
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-tertiary); }
.form-note {
  min-height: 18px;
  margin-top: var(--sp-3);
  font-size: 13px;
  color: var(--text-secondary);
}
.form-note.error { color: var(--danger); }

/* --- マスタ確認パネル（工程3） --- */
.master-block { margin-top: var(--sp-4); }
.master-h3 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
  font-weight: 600;
}
.tree-store {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.tree-store-name { font-weight: 700; font-size: 14px; min-width: 100px; }
.tree-depts, .cat-line { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.cat-line { margin-bottom: var(--sp-2); }
.chip {
  display: inline-block;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--border-subtle);
}
.cat-tag {
  font-size: 11px;
  color: var(--text-tertiary);
  min-width: 44px;
}
.alloc-row { font-size: 13px; color: var(--text-primary); padding: 2px 0; }
.muted { color: var(--text-tertiary); font-size: 13px; }
.tax-form { display: flex; gap: var(--sp-3); align-items: flex-end; flex-wrap: wrap; margin-top: var(--sp-3); }
.tax-form label { display: flex; flex-direction: column; font-size: 11px; color: var(--text-tertiary); gap: 2px; }
.tax-form input {
  height: 38px; width: 92px; padding: 0 8px; font-size: 15px;
  background: var(--bg-surface-2); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
}
.tax-form input[type="date"] { width: 150px; }

/* --- 日報入力（工程5） --- */
.dr-toolbar {
  display: flex; align-items: center; gap: var(--sp-3);
  flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.dr-store, .dr-store-fixed {
  font-weight: 700; font-size: 15px;
  padding: 8px 12px; border-radius: var(--radius-md);
  background: var(--bg-surface-2); color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.dr-datenav { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }
.dr-datenav button {
  width: 40px; height: 40px; font-size: 16px;
  background: var(--bg-surface-2); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); cursor: pointer;
}
.dr-datenav input[type="date"] {
  height: 40px; padding: 0 8px; font-size: 15px;
  background: var(--bg-surface-2); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
}
.dept-block {
  margin-top: var(--sp-4); padding: var(--sp-3);
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.dept-block.party { border-color: var(--accent-dim); }
.dept-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); flex-wrap: wrap; }
.dept-title { font-weight: 700; font-size: 15px; }
.dept-total { font-size: 13px; color: var(--text-secondary); }
.dept-total b { color: var(--accent); font-size: 15px; font-variant-numeric: tabular-nums; }
.dept-head .status-pick { margin-left: auto; }
.status-pick { font-size: 12px; color: var(--text-secondary); }
.status-pick select {
  margin-left: 4px; background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 4px 6px;
}
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 4px; text-align: center; }
table.grid thead th { font-size: 11px; color: var(--text-tertiary); font-weight: 600; }
table.grid tbody th { font-size: 12px; color: var(--text-secondary); text-align: left; width: 56px; }
.grid-num {
  width: 100%; height: 40px; text-align: right; padding: 0 8px;
  font-size: 16px; color: var(--text-primary);
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm); outline: none;
}
.grid-num:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.grid-sub { font-size: 11px; color: var(--text-tertiary); margin: var(--sp-2) 0 4px; }
.goods-row, .traffic-row { display: flex; gap: var(--sp-2); margin-top: 4px; }
.goods-cell, .tf-cell { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.goods-cell span, .tf-cell span { font-size: 11px; color: var(--text-tertiary); }
.traffic-row { margin-top: var(--sp-2); }
.dr-foot { margin-top: var(--sp-4); display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.reporter { font-size: 13px; color: var(--text-secondary); }
.field-inline {
  margin-left: 4px; height: 36px; padding: 0 8px; font-size: 15px;
  background: var(--bg-surface-2); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
}
.dr-save { width: auto; min-width: 120px; margin-top: 0; }
.form-note.ok { color: var(--accent); }

/* 総合計バー */
.dr-grandbar {
  font-size: 15px; font-weight: 700; margin-bottom: var(--sp-3);
  color: var(--text-primary);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-surface-2); border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}
.dr-grandbar span { color: var(--accent); font-size: 19px; margin-left: 6px; }

/* マトリクス表（紙日報準拠） */
.grid-wrap { overflow-x: auto; }
table.grid2 { width: 100%; border-collapse: collapse; min-width: 460px; }
table.grid2 th, table.grid2 td { padding: 3px; text-align: center; border: 1px solid var(--border-subtle); }
table.grid2 thead th { font-size: 11px; color: var(--text-tertiary); font-weight: 600; background: var(--bg-elevated); padding: 6px 3px; }
table.grid2 .c-type { width: 52px; font-size: 12px; color: var(--text-secondary); }
table.grid2 .c-sub { width: 74px; }
table.grid2 tbody th.c-type { color: var(--text-secondary); font-weight: 600; }
table.grid2 .grid-num { height: 40px; border-radius: var(--radius-sm); text-align: right; }
.cell-sub, .cell-coltotal, .cell-deptgrand {
  font-size: 13px; font-variant-numeric: tabular-nums;
  color: var(--text-secondary); background: var(--bg-surface); text-align: right; padding-right: 8px;
}
.cell-sub { color: var(--text-primary); font-weight: 600; }
table.grid2 tfoot td, table.grid2 tfoot th {
  background: var(--bg-elevated); font-weight: 700; color: var(--text-primary);
}
table.grid2 tfoot .cell-coltotal, table.grid2 tfoot .cell-deptgrand { color: var(--accent); }

/* 部門別合計サマリ（八） */
.dept-summary {
  margin-top: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface-2); border: 1px solid var(--accent-dim);
  border-radius: var(--radius-md);
}
.sum-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0; border-bottom: 1px solid var(--border-subtle);
}
.sum-row:last-child { border-bottom: none; }
.sum-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.cell-summary { font-size: 16px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 明細台帳（疎行） */
.ledger { margin-top: var(--sp-5); }
table.ledger-tbl { width: 100%; border-collapse: collapse; min-width: 520px; }
table.ledger-tbl th { font-size: 11px; color: var(--text-tertiary); font-weight: 600; padding: 4px; text-align: left; }
table.ledger-tbl td { padding: 3px; }
.led-in {
  width: 100%; height: 38px; padding: 0 8px; font-size: 15px;
  color: var(--text-primary); background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); outline: none;
}
.led-in:focus { border-color: var(--accent); }
.led-num { text-align: right; }
.led-delcell { width: 34px; text-align: center; }
.led-del {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-tertiary);
  border: 1px solid var(--border-subtle); cursor: pointer; font-size: 15px; line-height: 1;
}
.led-del:hover { color: var(--danger); border-color: var(--danger); }

/* 現金残高ボックス */
.cashbox { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.cash-cell { flex: 1 1 140px; display: flex; flex-direction: column; gap: 2px; }
.cash-cell span { font-size: 11px; color: var(--text-tertiary); }
.cash-cell input {
  height: 40px; padding: 0 8px; font-size: 16px; text-align: right;
  color: var(--text-primary); background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
}

footer.app-footer {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 11px;
  padding: var(--sp-5);
}
