/* ===== 案件管理ダッシュボード / ダークテーマ ===== */

:root {
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #21252f;
  --line: #2c313d;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #5b8cff;
  --accent-dim: #2f4a8f;
  --green: #3ecf8e;
  --amber: #f0b34a;
  --red: #ff5f5f;
  --radius: 10px;
  --font: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ===== ログイン画面 ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 18px; margin: 0 0 6px; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-card input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  text-align: center;
  letter-spacing: 2px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button { width: 100%; margin-top: 14px; }
.login-err { color: var(--red); font-size: 13px; min-height: 20px; margin-top: 10px; }

/* ===== レイアウト ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}
.brand { font-size: 15px; font-weight: 600; padding: 0 10px 18px; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  background: none;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.nav button:hover { background: var(--panel-2); color: var(--text); }
.nav button.active { background: var(--accent-dim); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; }
.sidebar-foot button {
  background: none; border: none; color: var(--muted);
  font-size: 12px; cursor: pointer; font-family: inherit; padding: 0;
}
.sidebar-foot button:hover { color: var(--text); }

.main { flex: 1; padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; margin: 0; font-weight: 600; }
.view { display: none; }
.view.active { display: block; }

/* ===== 部品 ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h3 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -.01em; }
.kpi .note { color: var(--muted); font-size: 11px; margin-top: 2px; }
.kpi.green .value { color: var(--green); }
.kpi.amber .value { color: var(--amber); }

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.12); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover { background: var(--panel-2); filter: none; }
button:disabled { opacity: .45; cursor: default; filter: none; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
.pill.s-未着手 { color: #9aa4bd; }
.pill.s-編集中 { color: var(--accent); border-color: var(--accent-dim); }
.pill.s-確認待ち { color: var(--amber); }
.pill.s-修正中 { color: var(--amber); }
.pill.s-納品済 { color: var(--green); }

.overdue { color: var(--red) !important; font-weight: 600; }
.soon { color: var(--amber); }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 28px 10px; text-align: center; font-size: 13px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] { min-width: 220px; }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; }
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px; }
  .nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0 8px; }
  .main { padding: 16px; }
}

/* 新規追加フォーム */
.addform { display: none; margin-bottom: 16px; }
.addform.open { display: block; }
.addform .rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.addform .actions { margin-top: 14px; display: flex; gap: 10px; }

/* 行の編集ボタン */
.edit-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 3px 9px; border-radius: 6px; font-size: 13px; line-height: 1.4;
}
.edit-btn:hover { background: var(--panel-2); color: var(--text); filter: none; }

/* 編集パネル */
.modal {
  display: none;
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 9, 13, .72);
  align-items: center; justify-content: center; padding: 24px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%; max-width: 720px;
  max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-head .x {
  background: none; border: none; color: var(--muted);
  font-size: 22px; line-height: 1; padding: 0 4px; cursor: pointer;
}
.modal-head .x:hover { color: var(--text); filter: none; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-body .rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 13px; }
.modal-body .rows .wide { grid-column: 1 / -1; }
.modal-body textarea { resize: vertical; min-height: 62px; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.modal-actions { display: flex; gap: 10px; margin-left: auto; }
.stepper { display: flex; gap: 6px; }
.stepper input { flex: 1; min-width: 0; }
.stepper button { padding: 0 12px; }

/* トースト */
#toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 11px 16px; border-radius: 8px; font-size: 13px;
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
#toast.err { border-left-color: var(--red); }

.chartbox { position: relative; height: 260px; }

/* ===== 請求書（Invoy風レイアウト / 画面のダークテーマを持ち込まない） ===== */
.inv-picker { margin-bottom: 18px; }

.invoice {
  background: #fff;
  color: #111;
  border-radius: 8px;
  padding: 38px 42px 44px;
  max-width: 820px;
  margin-top: 18px;
  font-size: 13px;
  line-height: 1.6;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}
.invoice * { color: #111; }

.iv-meta { text-align: right; font-size: 12px; line-height: 1.6; }
.iv-title {
  text-align: center; font-size: 25px; font-weight: 700;
  letter-spacing: .32em; margin: 10px 0 30px; text-indent: .32em;
}

.iv-parties { display: flex; align-items: flex-start; gap: 24px; }
.iv-to { flex: 1 1 auto; min-width: 0; }
.iv-toname { font-size: 19px; font-weight: 700; margin-bottom: 5px; }
.iv-line { font-size: 12px; line-height: 1.75; }
.iv-from { flex: 0 0 250px; text-align: center; padding-top: 24px; }
.iv-fromname { font-size: 14px; }
.iv-fromsub { font-size: 10.5px; line-height: 1.6; margin-top: 5px; color: #333; }

.iv-amount {
  display: flex; justify-content: space-between; align-items: baseline;
  width: 330px; background: #ececec; padding: 9px 16px; margin: 26px 0 0;
  font-size: 13px;
}
.iv-amount strong { font-size: 17px; font-weight: 700; }
.iv-limit { font-size: 12px; margin: 14px 0 24px; }

.invoice table { border-collapse: collapse; }
.invoice td.c, .invoice th.c { text-align: center; }
.invoice td.r, .invoice th.r { text-align: right; }

.iv-items { width: 100%; font-size: 12px; table-layout: fixed; }
.iv-items th {
  background: #767676; color: #fff !important; font-weight: 600;
  border: 1px solid #767676; padding: 6px 8px; text-align: center;
}
.iv-items td { border: 1px solid #b8b8b8; padding: 5px 9px; height: 14px; }
.iv-items .w-qty { width: 74px; }
.iv-items .w-amt { width: 116px; }
.invoice tbody tr:hover { background: none; }

.iv-sumwrap { display: flex; justify-content: flex-end; margin-top: -1px; }
.iv-sums { width: 306px; font-size: 12px; }   /* = 数量74 + 単価116 + 金額116 */
.iv-sums td { border: 1px solid #b8b8b8; padding: 5px 9px; }
.iv-sums td:first-child { width: 190px; }   /* = 数量74 + 単価116 → 左端が数量列に揃う */
.iv-sums tr.grand td { font-weight: 700; }

.iv-taxbreak { width: 430px; margin: 16px 0 0 auto; font-size: 12px; }
.iv-taxbreak td { padding: 5px 10px; border-bottom: 1px solid #c9c9c9; }
.iv-taxbreak tr:first-child td { border-top: 1px solid #c9c9c9; }

.iv-banklabel { font-size: 12px; margin: 28px 0 6px; }
.iv-bank { background: #ececec; padding: 11px 16px; font-size: 12px; }
.iv-remark { font-size: 11.5px; margin-top: 12px; white-space: pre-line; }
.iv-note { font-size: 10px; color: #555 !important; margin-top: 18px; }

/* ===== 印刷（A4 1枚・白地黒字） ===== */
@media print {
  /* margin:0 にするとブラウザ既定の印刷ヘッダー/フッター（日付・タイトル・URL・ページ番号）が出ない。
     紙の余白は .invoice の padding で作る。 */
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; }
  .sidebar, .page-head, .inv-picker, #toast, .modal, .noprint { display: none !important; }
  .app { display: block; }
  .main { padding: 0 !important; }
  .view { display: none !important; }
  .view.active { display: block !important; }
  .invoice {
    max-width: none; margin: 0; padding: 13mm 14mm;
    border-radius: 0; font-size: 11.5px;
  }
  .iv-title { font-size: 22px; margin: 6px 0 24px; }
  .iv-amount, .iv-bank { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .iv-items th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .invoice, .iv-items, .iv-sums, .iv-taxbreak { page-break-inside: avoid; }
}
