/* ------------------------------------------------------------------
   丸元 商談ボード / 業務用の管理画面スタイル
   ・白背景・高密度・文字は 14px を基準（小さくしすぎない）
   ・PC での一覧性を最優先。装飾は状態が分かる部分だけに使う
------------------------------------------------------------------ */

:root {
  color-scheme: light;

  --bg:        #ffffff;
  --bg-soft:   #f5f7f9;
  --bg-head:   #1e2b38;
  --line:      #d9dee4;
  --line-soft: #eceff2;

  --ink:   #16202a;
  --ink-2: #46535f;
  --ink-3: #7b8794;

  --accent:      #1361a8;
  --accent-soft: #e8f0f8;
  --accent-line: #b9d3e9;

  --danger: #b3261e;
  --warn:   #9a5b05;

  --st-inquiry-fg: #4b5866; --st-inquiry-bg: #eef1f4; --st-inquiry-bd: #dbe1e7;
  --st-await-fg:   #0f6b6b; --st-await-bg:   #e2f2f1; --st-await-bd:   #bfe0dd;
  --st-inspect-fg: #1361a8; --st-inspect-bg: #e4eff9; --st-inspect-bd: #c3dcf0;
  --st-quote-fg:   #4c3fa8; --st-quote-bg:   #ecebfa; --st-quote-bd:   #d4cff2;
  --st-qtodo-fg:   #4c3fa8; --st-qtodo-bg:   #ffffff; --st-qtodo-bd:   #b5adea;
  --st-order-fg:   #9a5b05; --st-order-bg:   #fbf0dc; --st-order-bd:   #f0ddb8;
  --st-payment-fg: #b3261e; --st-payment-bg: #fbe9e7; --st-payment-bd: #f3cdc9;
  --st-done-fg:    #1d7a4c; --st-done-bg:    #e4f4ec; --st-done-bd:    #c4e6d5;
  --st-lost-fg:    #7b8794; --st-lost-bg:    #f7f8f9; --st-lost-bd:    #dbe1e7;

  --radius: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
          "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
table { border-collapse: collapse; }
input, select, textarea, button { font-family: inherit; font-size: 14px; color: inherit; }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--bg-head);
  color: #fff;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius);
  padding: 2px 6px;
  margin-left: -6px;
}
a.brand:hover { background: rgba(255, 255, 255, .12); }
a.brand:focus-visible { outline: 2px solid #9fc5e8; outline-offset: 1px; }
.brand-mark {
  font-size: 13px; font-weight: 700; letter-spacing: .14em;
  padding: 2px 7px; border: 1px solid rgba(255,255,255,.45); border-radius: 3px;
}
.brand-name { font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.tag-proto {
  font-size: 12px; color: #b9c6d3;
  padding: 1px 7px; border: 1px dashed rgba(255,255,255,.35); border-radius: 3px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #0f5490; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.4); color: #d7e1ea; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-red { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-red:hover { background: #97201a; }
.btn-danger { color: var(--danger); border-color: #e7c4c1; background: #fff; }
.btn-danger:hover { background: #fbe9e7; }
.btn-link {
  border: 0; background: none; padding: 0; color: var(--accent);
  cursor: pointer; font-size: 14px;
}
.btn-link:hover { text-decoration: underline; }

/* ---------- ページ ---------- */
.page {
  padding: 18px 20px 64px;
  padding-inline: max(20px, env(safe-area-inset-left, 0px));
  max-width: 1440px;
  margin: 0 auto;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
}
.page-title { font-size: 18px; }
.page-sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.crumb {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--accent); background: none; border: 0;
  padding: 0; margin-bottom: 10px; cursor: pointer;
}
.crumb:hover { text-decoration: underline; }

/* ---------- 検索・絞り込み ---------- */
.toolbar {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  margin-bottom: 12px;
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field > label { font-size: 12px; color: var(--ink-2); }
.input, .select, .textarea {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  min-width: 0;
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent-line); outline-offset: -1px; border-color: var(--accent);
}
.input-search { width: 280px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); padding-bottom: 6px; }
.toolbar-spacer { flex: 1 1 auto; }
.result-count { font-size: 13px; color: var(--ink-2); padding-bottom: 6px; white-space: nowrap; }

/* ---------- テーブル ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; min-width: 900px; background: #fff; }
.tbl th, .tbl td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}
.tbl thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
.tbl thead th.sortable { cursor: pointer; user-select: none; }
.tbl thead th.sortable:hover { background: #eceff3; }
.sort-mark { color: var(--accent); font-size: 11px; margin-left: 3px; }
.tbl tbody tr.row-click { cursor: pointer; }
.tbl tbody tr.row-click:hover { background: var(--accent-soft); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.model { font-weight: 600; white-space: nowrap; }
.serial { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.muted { color: var(--ink-3); }
.memo-cell {
  max-width: 220px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mail-cell { white-space: nowrap; color: var(--ink-2); }
.nowrap { white-space: nowrap; }
.empty {
  padding: 40px 20px; text-align: center; color: var(--ink-3);
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--bg-soft);
}

/* ---------- 進捗バッジ ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid;
  font-size: 12.5px;
  line-height: 1.7;
  white-space: nowrap;
}
.badge-row { display: flex; flex-wrap: wrap; gap: 4px; }
.st-inquiry { color: var(--st-inquiry-fg); background: var(--st-inquiry-bg); border-color: var(--st-inquiry-bd); }
.st-await   { color: var(--st-await-fg);   background: var(--st-await-bg);   border-color: var(--st-await-bd); }
.st-inspect { color: var(--st-inspect-fg); background: var(--st-inspect-bg); border-color: var(--st-inspect-bd); }
.st-quote,
.st-quote_done { color: var(--st-quote-fg); background: var(--st-quote-bg); border-color: var(--st-quote-bd); }
.st-quote_todo { color: var(--st-qtodo-fg); background: var(--st-qtodo-bg); border-color: var(--st-qtodo-bd); font-weight: 600; }
.st-order   { color: var(--st-order-fg);   background: var(--st-order-bg);   border-color: var(--st-order-bd); }
.st-payment { color: var(--st-payment-fg); background: var(--st-payment-bg); border-color: var(--st-payment-bd); font-weight: 600; }
.st-done    { color: var(--st-done-fg);    background: var(--st-done-bg);    border-color: var(--st-done-bd); }
.st-lost    { color: var(--st-lost-fg);    background: var(--st-lost-bg);    border-color: var(--st-lost-bd); border-style: dashed; }

/* 進捗プルダウン（表の中で直接変更する） */
.status-select {
  padding: 3px 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  max-width: 130px;
}
.status-select.st-inquiry, .status-select.st-await, .status-select.st-inspect,
.status-select.st-quote_todo, .status-select.st-quote_done, .status-select.st-order,
.status-select.st-payment, .status-select.st-done, .status-select.st-lost { font-weight: 600; }
.status-select { max-width: 160px; }

/* ---------- 経過日数 ---------- */
.stale { color: var(--warn); font-weight: 600; }
.stale::before { content: "● "; font-size: 10px; vertical-align: 1px; }

/* ---------- 商品カード ---------- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.card-title { font-size: 20px; font-weight: 700; letter-spacing: .01em; }
.card-serial { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card-note { font-size: 12px; color: var(--ink-3); margin-left: auto; }
.grid-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px 16px;
}
.grid-fields.cols-2 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin: 18px 0 8px;
}
.section-title h2 { font-size: 15px; }

/* 一覧と同じ並びで直接直せる入力欄 */
.inline-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-soft);
}
.inline-input:hover { border-color: var(--line); background: #fff; }
.inline-input:focus { border-color: var(--accent); background: #fff; outline: 2px solid var(--accent-line); outline-offset: -1px; }

/* ---------- 新規登録フォーム ---------- */
.form-wrap { max-width: 880px; }
.form-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  background: #fff;
}
.form-section > h2 {
  font-size: 14px;
  padding: 9px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}
.form-body { padding: 14px; }
.req { color: var(--danger); font-size: 12px; margin-left: 2px; }
.url-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 4px; }
.url-row .field { flex: 1 1 340px; }
.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 6px; }
.hint-ok { color: var(--st-done-fg); }
.hint-warn { color: var(--warn); }
.divider-or {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink-3); font-size: 12.5px; margin: 14px 0;
}
.divider-or::before, .divider-or::after {
  content: ""; flex: 1; height: 1px; background: var(--line-soft);
}
.form-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-top: 4px;
}
.form-actions .hint { margin: 0 0 0 auto; }
.form-error {
  color: var(--danger); font-size: 13px; background: #fbe9e7;
  border: 1px solid #f3cdc9; border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 12px;
}

/* ---------- 案件詳細パネル ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(22, 32, 42, .28);
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 41;
  width: min(520px, 100vw);
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(22, 32, 42, .12);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.drawer-head {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 17px; }
.drawer-head .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.drawer-close {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--ink-3); padding: 2px 6px;
}
.drawer-close:hover { color: var(--ink); }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 24px; }
.drawer-foot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; border-top: 1px solid var(--line); background: var(--bg-soft);
  font-size: 12.5px; color: var(--ink-3);
}
.drawer-foot .btn { margin-left: auto; }
.drawer-status { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.drawer-status .field { flex: 1 1 180px; }
.sub-head {
  font-size: 12px; color: var(--ink-3); letter-spacing: .08em;
  border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; margin: 18px 0 10px;
}
.sub-head:first-child { margin-top: 0; }
.textarea { width: 100%; min-height: 76px; resize: vertical; }
.field-full { grid-column: 1 / -1; }

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60;
  background: #16202a; color: #fff;
  padding: 8px 16px; border-radius: 16px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(22,32,42,.25);
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .16s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }
}

/* ---------- 画面が狭いとき ---------- */
@media (max-width: 640px) {
  .page { padding: 14px 16px 48px; }
  .input-search { width: 100%; }
  .field { flex: 1 1 100%; }
}

/* ---------- 本番用：保存の状態・お知らせ・ログイン ---------- */
.save-state {
  font-size: 12.5px;
  color: #b9c6d3;
  min-width: 72px;
  text-align: right;
}
.save-state.is-saving { color: #ffd88a; }
.save-state.is-saved  { color: #9fdcb8; }
.save-state.is-error  { color: #ff9e95; font-weight: 600; }

.banner {
  background: #fbe9e7;
  border-bottom: 1px solid #f3cdc9;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 20px;
}

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 24px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
}
.login-brand .brand-mark {
  color: var(--ink);
  border-color: var(--line);
}
.login-lead {
  font-size: 13px;
  color: var(--ink-2);
  margin: 10px 0 18px;
}
.login-card .field > label { font-size: 12px; color: var(--ink-2); }
.login-card .input { width: 100%; padding: 9px 10px; }
