:root {
  --brand: #0a66c2;
  --brand-dark: #084d92;
  --accent: #f0a83b;
  --accent-ink: #3a2600;
  --ink: #0f172a;
  --muted: #5c6b7f;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --bg-soft: #f5f8fc;
  --ok: #1e8e3e;
  --ng: #c0392b;
  --radius: 16px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px -12px rgba(15, 23, 42, .12);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 17px;
  color: var(--ink);
  background:
    radial-gradient(1100px 420px at 50% -160px, rgba(10, 102, 194, .10), transparent 70%),
    var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }

/* ===== header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(226, 232, 240, .9);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-header .brand {
  font-weight: 800;
  color: var(--brand-dark);
  letter-spacing: .03em;
  display: flex;
  align-items: center;
  gap: 12px;
}
/* ロゴマーク（ブランド色のグラデーションタイル） */
.site-header .brand::before {
  content: "";
  flex: 0 0 34px;
  height: 34px;
  border-radius: 9px;
  background:
    linear-gradient(135deg, #0e7ad1 0%, var(--brand) 45%, var(--brand-dark) 100%);
  box-shadow: 0 4px 10px rgba(10, 102, 194, .35);
}
.site-header .brand small { display: block; font-weight: 500; font-size: .68em; color: var(--muted); letter-spacing: .05em; }
.site-header .header-right { display: flex; align-items: center; gap: 14px; font-size: .95em; }
.site-header .header-right .who { color: var(--muted); }
/* ヘッダーのボタンは押しやすいようやや大きめに */
.site-header .header-right .btn.small { padding: 10px 20px; font-size: .95em; border-radius: 10px; }

/* ===== layout ===== */
.wrap { max-width: 1200px; margin: 0 auto; padding: 32px 28px 64px; }
/* 管理画面は案件カード・一覧表が多いので横幅を広く使う */
body.admin .wrap { max-width: 1240px; }
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 28px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}
.card h2 { margin: 0 0 4px; font-size: 1.3em; color: var(--ink); letter-spacing: .01em; }
.card h3 { margin: 0 0 6px; font-size: 1.1em; letter-spacing: .01em; }
/* セクション見出しの左に短いアクセントバー */
.card h3::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: .95em;
  margin-right: 10px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--brand), #35a3ff);
  vertical-align: -2px;
}
.card .sub { color: var(--muted); margin: 0 0 20px; font-size: .93em; }

/* ===== 会員ダッシュボード：横幅活用レイアウト ===== */
.dash-hero-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}
.dash-hero-row .hero-text { flex: 1 1 260px; min-width: 240px; align-self: center; }
.dash-hero-row .hero-text .sub { margin-bottom: 0; }
.dash-hero-row .ticket-box { flex: 0 1 330px; max-width: 360px; margin: 0; justify-content: center; text-align: center; }

/* チケット追加購入パネル（残高カードから独立させたCTA） */
.buy-panel {
  flex: 0 1 360px;
  background: linear-gradient(180deg, #fff8ec 0%, #fff 90%);
  border: 1.5px solid #f0d9ab;
  border-radius: 14px;
  padding: 18px 22px 16px;
  box-shadow: 0 10px 24px -16px rgba(232, 161, 58, .5);
}
.buy-panel .buy-title { font-size: .82em; font-weight: 800; color: #a06a10; letter-spacing: .04em; }
.buy-panel .buy-price { margin: 2px 0 10px; color: var(--ink); }
.buy-panel .buy-price strong { font-size: 1.6em; font-weight: 900; letter-spacing: -.01em; }
.buy-panel .buy-price span { display: block; font-size: .8em; color: var(--muted); }
.buy-panel .buy-note { margin-top: 8px; font-size: .74em; color: var(--muted); }
@media (max-width: 1000px) {
  .dash-hero-row .ticket-box, .buy-panel { flex: 1 1 300px; max-width: none; }
}
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.dash-grid > .card { margin-bottom: 0; }
@media (max-width: 1000px) {
  .dash-grid { grid-template-columns: 1fr; }
}

/* 認証・承認待ちは中央のコンパクトなカードに */
#authView { max-width: 560px; margin: 32px auto 0; padding: 32px 34px; }
#pendingView { max-width: 640px; margin: 32px auto 0; }

/* ===== forms ===== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82em; font-weight: 700; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1em;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:hover { border-color: #c3d2e2; }
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 102, 194, .14); }
.field input[type="file"] { padding: 8px 10px; background: var(--bg-soft); }
.sel {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1em;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.sel:hover { border-color: #c3d2e2; }
.sel:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 102, 194, .14); }

/* 横幅があるときは項目を2列に並べる */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
}

/* ===== dropzone（大きなPDF投入ボックス・枠内どこでもドロップ）===== */
.dropzone {
  position: relative;
  border: 1.5px dashed #c3d2e2;
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfdff, var(--bg-soft));
  padding: 22px 18px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.dropzone:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 102, 194, .08); }
.dropzone.drag { border-color: var(--brand); background: #e8f2fd; }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: #f2fbf4; }
.dropzone-hint { color: var(--muted); font-size: .95em; font-weight: 700; pointer-events: none; }
.dropzone-hint span { display: block; font-weight: 500; font-size: .82em; margin-top: 4px; opacity: .8; }
.dropzone-files { margin-top: 8px; color: var(--ok); font-size: .9em; font-weight: 700; word-break: break-word; pointer-events: none; }
.dropzone input[type="file"] { display: inline-block; margin-top: 12px; max-width: 100%; cursor: pointer; }

/* ===== case cards ===== */
.case-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.case-item:hover { border-color: #bcd3e8; box-shadow: 0 4px 14px -6px rgba(15, 23, 42, .12); }
.case-item .case-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.case-item .case-title { font-weight: 700; }
.case-item .case-meta { color: var(--muted); font-size: .85em; margin-top: 4px; }
.case-item .case-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.badge.work { background: #e6f0fb; color: var(--brand); }
.badge.gray { background: #eef1f4; color: var(--muted); }

/* 工程ステップ別のボタングループ（資料 / 自動処理 / 手動差し替え / 仕上げ）*/
.case-groups { margin-top: 10px; }
.case-group { display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; border-top: 1px dashed var(--line); }
.case-group:first-child { border-top: none; padding-top: 4px; }
.case-group-label { flex: 0 0 92px; font-size: .78em; font-weight: 800; color: var(--muted); padding-top: 7px; letter-spacing: .02em; }
.case-group-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 auto; min-width: 0; }
.case-group .out-file { font-size: .82em; max-width: 220px; }
@media (max-width: 560px) {
  .case-group { flex-direction: column; gap: 6px; }
  /* 縦積み時は flex-basis:92px が「高さ92px」になってしまうので解除する */
  .case-group-label { padding-top: 0; flex: 0 0 auto; }
}

/* 詳細フレーム（過去案件の内容確認＋全ダウンロード）*/
.case-detail { margin-top: 12px; }
.case-detail > summary { cursor: pointer; font-weight: 700; color: var(--muted); font-size: .85em; list-style: none; }
.case-detail > summary::before { content: "▸ "; }
.case-detail[open] > summary::before { content: "▾ "; }
.case-detail .dl-grid { display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; margin: 10px 0 2px; font-size: .86em; align-items: baseline; }
.case-detail .dl-k { color: var(--muted); font-weight: 700; white-space: nowrap; }
.case-detail .dl-v { color: var(--ink); word-break: break-word; }
.case-detail .dl-v .btn { margin: 2px 4px 2px 0; }

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  font-family: inherit;
  font-size: 1em;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  padding: 11px 22px;
  border-radius: 10px;
  letter-spacing: .01em;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, filter .12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -6px rgba(10, 102, 194, .5); filter: brightness(1.05); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; filter: none; }
.btn.block { width: 100%; text-align: center; }
.btn.ghost { background: #fff; color: var(--brand); border: 1.5px solid #b9d2ea; }
.btn.ghost:hover { background: #eef6fe; border-color: var(--brand); box-shadow: none; }
.btn.accent { background: linear-gradient(135deg, #f5b34f 0%, #eda02a 100%); color: var(--accent-ink); }
.btn.accent:hover { box-shadow: 0 8px 18px -6px rgba(232, 161, 58, .6); }
.btn.small { padding: 7px 14px; font-size: .85em; border-radius: 8px; }
.btn.danger { background: #fff; color: var(--ng); border: 1px solid #e5b5ae; }
.btn.danger:hover { background: #fdf1ef; border-color: var(--ng); box-shadow: none; }

/* ===== tabs ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.tab:hover { color: var(--brand-dark); }
.tab.active { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }

/* ===== message ===== */
.msg { margin-top: 12px; font-size: .9em; min-height: 1.2em; }
.msg.ok { color: var(--ok); }
.msg.ng { color: var(--ng); }

/* ===== status badges ===== */
.badge {
  display: inline-block;
  font-size: .78em;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: 999px;
  letter-spacing: .02em;
}
.badge.wait { background: #fff3e0; color: #b26a00; }
.badge.ok { background: #e7f5e9; color: var(--ok); }
.badge.ng { background: #fdecea; color: var(--ng); }

/* ===== ticket ===== */
.ticket-box {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 20px;
  background: linear-gradient(120deg, #0b3e75 0%, var(--brand-dark) 45%, var(--brand) 100%);
  color: #fff;
  border-radius: 14px;
  padding: 22px 26px;
  box-shadow: 0 14px 30px -14px rgba(8, 77, 146, .55);
}
/* 光のアクセント（装飾） */
.ticket-box::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -40px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), transparent 70%);
  pointer-events: none;
}
.ticket-box .num { font-size: 2.8em; font-weight: 900; line-height: 1; letter-spacing: -.02em; }
.ticket-box .num small { font-size: .32em; font-weight: 700; opacity: .85; }
.ticket-box .label { font-size: .88em; opacity: .88; margin-top: 4px; }

/* ===== 案件コメント（顧客⇔管理者のチャット） ===== */
.case-chat { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.case-chat > summary { cursor: pointer; font-weight: 700; color: var(--brand); font-size: .88em; list-style: none; }
.case-chat > summary::before { content: "▸ "; }
.case-chat[open] > summary::before { content: "▾ "; }
.chat-thread {
  max-height: 320px;
  overflow-y: auto;
  padding: 12px 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty { color: var(--muted); font-size: .88em; padding: 6px 2px; }
.chat-msg { max-width: 78%; align-self: flex-start; }
.chat-msg.me { align-self: flex-end; text-align: right; }
.chat-bubble {
  display: inline-block;
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 14px 14px 14px 4px;
  font-size: .92em;
  line-height: 1.6;
  word-break: break-word;
}
.chat-msg.me .chat-bubble {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
}
.chat-meta { font-size: .74em; color: var(--muted); margin-top: 3px; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }
.chat-text {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: .95em;
  resize: vertical;
  min-height: 44px;
  background: #fff;
}
.chat-text:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 102, 194, .14); }

/* ===== notice ===== */
.notice {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: .93em;
  color: var(--ink);
}

/* ===== table (admin) ===== */
.tbl { width: 100%; border-collapse: collapse; font-size: .92em; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { color: var(--muted); font-size: .8em; background: var(--bg-soft); letter-spacing: .03em; }
.tbl tbody tr:hover td { background: #f8fbfe; }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 18px 4px; font-size: .92em; }

.hidden { display: none !important; }
.center { text-align: center; }
.mt { margin-top: 18px; }
.foot-note { color: var(--muted); font-size: .82em; text-align: center; margin-top: 32px; }

/* ============================================================
   スマホ対応（会員・管理共通）
   ============================================================ */
@media (max-width: 700px) {
  body { font-size: 16px; }

  /* ヘッダー：メールは省略表示、ボタンは折り返し可 */
  .site-header { padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .site-header .brand { gap: 8px; font-size: .95em; }
  .site-header .brand::before { flex: 0 0 26px; height: 26px; border-radius: 7px; }
  .site-header .header-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .site-header .header-right .who {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .site-header .header-right .btn.small { padding: 8px 14px; font-size: .85em; }

  /* 余白を詰めて画面を広く使う */
  .wrap { padding: 18px 12px 48px; }
  .card { padding: 20px 16px; border-radius: 12px; margin-bottom: 16px; }
  #authView { margin-top: 8px; padding: 22px 18px; }
  #pendingView { margin-top: 8px; }
  .dash-hero-row { gap: 14px; }
  .dash-grid { gap: 16px; }
  .ticket-box { padding: 18px 20px; }
  .ticket-box .num { font-size: 2.3em; }
  .buy-panel { padding: 16px 16px 14px; }
  .case-item { padding: 14px; }

  /* チャット：吹き出しを広く、入力は縦積み */
  .chat-msg { max-width: 92%; }
  .chat-form { flex-direction: column; align-items: stretch; }
  .chat-form .chat-send { align-self: flex-end; }

  /* テーブルは横スクロールで逃がす（管理画面） */
  .tbl { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  .btn { padding: 11px 18px; }
  .notice { padding: 12px 14px; }
}


/* ============================================================
   管理画面ダークテーマ（body.admin のみ・顧客ページはライトのまま）
   濁った紺ではなく、ニュートラルな黒基調＋高コントラストで見やすく
   ============================================================ */
body.admin {
  --ink: #e9eef5;
  --muted: #98a5b3;
  --line: #263040;
  --bg: #0d1117;
  --bg-soft: #161d27;
  background: #0d1117;
  color: var(--ink);
}
body.admin a { color: #58a6ff; }

/* ヘッダー：ブランド左・操作ボタンは中央寄せ */
body.admin .site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: rgba(13, 17, 23, .92);
  border-bottom: 1px solid #1f2733;
}
body.admin .site-header .brand { justify-self: start; color: #f0f6fc; }
body.admin .site-header .header-right { grid-column: 2; justify-self: center; }

body.admin .card {
  background: #141b24;
  border: 1px solid #232d3b;
  box-shadow: 0 16px 34px -22px rgba(0, 0, 0, .9);
}
body.admin .card h2 { color: #f0f6fc; }

/* ボタン：リンク下線なしのソリッドな操作ボタンに */
body.admin .btn.ghost {
  background: #1c2530;
  color: #d5dfe9;
  border: 1px solid #303c4c;
}
body.admin .btn.ghost:hover { background: #243040; border-color: #415062; color: #fff; box-shadow: none; }
body.admin .btn.danger { background: transparent; color: #f47067; border: 1px solid rgba(244, 112, 103, .4); }
body.admin .btn.danger:hover { background: rgba(244, 112, 103, .12); border-color: #f47067; box-shadow: none; }

/* 案件カード・工程グループ */
body.admin .case-item { background: #10161e; border-color: #232d3b; }
body.admin .case-item:hover { border-color: #3b4a5d; box-shadow: 0 6px 16px -8px rgba(0, 0, 0, .7); }
body.admin .case-group { border-top: 1px solid #1e2733; }
body.admin .case-group:first-child { border-top: none; }

/* テーブル */
body.admin .tbl th { background: #161d27; border-bottom: 1px solid #263040; }
body.admin .tbl td { border-bottom: 1px solid #1e2733; }
body.admin .tbl tbody tr:hover td { background: #161d27; }

/* バッジ：チップに薄い枠を付けてくっきり */
body.admin .badge { border: 1px solid transparent; }
body.admin .badge.wait { background: rgba(210, 153, 34, .14); color: #e3b341; border-color: rgba(210, 153, 34, .4); }
body.admin .badge.ok { background: rgba(63, 185, 80, .14); color: #56d364; border-color: rgba(63, 185, 80, .4); }
body.admin .badge.ng { background: rgba(248, 81, 73, .14); color: #f47067; border-color: rgba(248, 81, 73, .4); }
body.admin .badge.work { background: rgba(56, 139, 253, .15); color: #79b8ff; border-color: rgba(56, 139, 253, .4); }
body.admin .badge.gray { background: rgba(139, 148, 158, .14); color: #a5b1bd; border-color: rgba(139, 148, 158, .35); }

body.admin .notice { background: #161d27; border-color: #263040; }

/* フォーム・ドロップゾーン（PDF→JSON等で使用） */
body.admin .field input, body.admin .sel {
  background: #0d1117;
  color: var(--ink);
  border-color: #303c4c;
}
body.admin .field input:hover, body.admin .sel:hover { border-color: #415062; }
body.admin .dropzone { background: #10161e; border-color: #344050; }
body.admin .dropzone.drag { background: rgba(56, 139, 253, .1); }
body.admin .dropzone.has-file { background: rgba(63, 185, 80, .08); }
body.admin .dropzone-files { color: #56d364; }

body.admin .msg.ok { color: #56d364; }
body.admin .msg.ng { color: #f47067; }

/* チャット（ダーク） */
body.admin .case-chat { border-top-color: #1e2733; }
body.admin .case-chat > summary { color: #79b8ff; }
body.admin .chat-bubble { background: #1c2530; border-color: #303c4c; }
body.admin .chat-msg.me .chat-bubble { background: #1f6feb; border-color: #1f6feb; }
body.admin .chat-text { background: #0d1117; color: var(--ink); border-color: #303c4c; }
body.admin .chat-text:hover { border-color: #415062; }

/* 管理画面ヘッダー：狭い画面ではグリッド中央寄せをやめて折り返す
   （上の display:grid を上書きするため、ダークテーマ定義より後に置くこと） */
@media (max-width: 900px) {
  body.admin .site-header { display: flex; flex-wrap: wrap; }
  /* ブランド名が潰れて縦書きにならないよう1行占有させ、ボタン群は下の行に */
  body.admin .site-header .brand { flex: 1 1 100%; }
  body.admin .site-header .header-right { justify-content: flex-start; }
}
