:root {
  --bg: #f4f6f8; --panel: #fff; --line: #d9dee3; --text: #1f2933; --muted: #6b7680;
  --primary: #1f5fa8; --primary-d: #174a85; --danger: #c0392b; --ok: #2e7d32; --warn: #b26a00;
  --radius: 6px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", "Hiragino Sans", sans-serif; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 14px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px; }

/* ヘッダー */
.topbar { display: flex; align-items: center; gap: 18px; background: #1b2a41; color: #fff; padding: 0 18px; height: 52px; }
.topbar .brand { color: #fff; font-weight: 700; white-space: nowrap; }
.topbar .brand span { font-weight: 400; opacity: .75; margin-left: 8px; font-size: .85rem; }
.topbar .nav { display: flex; gap: 2px; flex: 1; }
.topbar .nav a { color: #d9e2ec; padding: 6px 12px; border-radius: 4px; }
.topbar .nav a.active, .topbar .nav a:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.topbar .userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.topbar .userbox a { color: #fff; }
.main { max-width: 1280px; margin: 0 auto; padding: 20px 18px 60px; }
.main-plain { max-width: 420px; margin: 60px auto; padding: 0 16px; }

/* パネル・フォーム */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 10px 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=date], input[type=number], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #b9c2cc; border-radius: 4px; font: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.req::after { content: " *"; color: var(--danger); }
.field { margin-bottom: 8px; }
.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline > * { flex: 0 0 auto; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.actions .spacer { flex: 1; }

/* ボタン */
.btn { display: inline-block; padding: 8px 16px; border: 1px solid #b9c2cc; border-radius: 4px; background: #fff; color: var(--text); font: inherit; cursor: pointer; line-height: 1.3; text-decoration: none; }
.btn:hover { background: #f0f3f6; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary-d); }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { color: var(--danger); border-color: #e3a8a1; }
.btn-danger:hover { background: #fdecea; }
.btn-lg { padding: 11px 22px; font-size: 1.05rem; }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: default; }

/* テーブル */
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 8px 8px; text-align: left; vertical-align: middle; }
table.list th { background: #eef2f6; font-weight: 600; font-size: .85rem; color: #3e4c59; white-space: nowrap; }
table.list tr:hover td { background: #f7f9fb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.center { text-align: center; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .78rem; background: #e5e9ee; color: #3e4c59; white-space: nowrap; }
.badge-draft { background: #e5e9ee; } .badge-sent { background: #dbeafe; color: #1e40af; } .badge-won { background: #dcfce7; color: #166534; }
.badge-lost { background: #fee2e2; color: #991b1b; } .badge-unsent { background: #fef3c7; color: #92400e; } .badge-paid { background: #dcfce7; color: #166534; }

/* 明細編集テーブル */
table.edit { width: 100%; border-collapse: collapse; background: #fff; font-size: .92rem; }
table.edit th, table.edit td { border: 1px solid var(--line); padding: 3px 4px; }
table.edit th { background: #eef2f6; font-weight: 600; font-size: .8rem; text-align: center; white-space: nowrap; }
table.edit input, table.edit select { padding: 5px 6px; font-size: .92rem; }
table.edit input.num { text-align: right; }
table.edit td.calc { text-align: right; background: #f7f9fb; padding-right: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.edit td.drag { text-align: center; color: #9aa5b1; cursor: grab; width: 24px; }
table.edit tr.dragging { opacity: .4; }
table.edit td.rm { text-align: center; width: 34px; }
.rm-btn { background: none; border: 0; color: #9aa5b1; cursor: pointer; font-size: 1.1rem; }
.rm-btn:hover { color: var(--danger); }
.totals { display: flex; justify-content: flex-end; gap: 30px; margin-top: 10px; font-size: 1.02rem; }
.totals div span { display: block; font-size: .78rem; color: var(--muted); }
.totals div b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.profitbox { background: #fffbeb; border: 1px dashed #f0c36d; padding: 8px 14px; border-radius: 4px; display: inline-flex; gap: 24px; font-size: .92rem; }
.profitbox b { font-variant-numeric: tabular-nums; }

/* デモバナー */
.demo-bar { background: #fff4d6; color: #7a4b00; border-bottom: 1px solid #f0c36d; padding: 7px 18px; font-size: .88rem; text-align: center; }

/* フラッシュ */
.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; border: 1px solid; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ダッシュボード */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.card span { display: block; font-size: .8rem; color: var(--muted); }
.card b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: .7rem; color: var(--muted); }
.bars .bar i { display: block; width: 70%; background: #9cc0ea; border-radius: 3px 3px 0 0; }
.bars .bar i.won { background: var(--primary); }
.muted { color: var(--muted); font-size: .88rem; }
.hint { font-size: .82rem; color: var(--muted); }
.filterbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.filterbar label { margin: 0; }
.login-box h1 { text-align: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs a.active { background: #fff; border-color: var(--line); color: var(--text); font-weight: 600; }
datalist { display: none; }
/* ---------- レスポンシブ ---------- */
.panel { overflow-x: auto; }
.menu-btn { display: none; background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 4px; padding: 6px 10px; font: inherit; cursor: pointer; }
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 > [style*="span 3"], .grid-4 > [style*="span 4"] { grid-column: span 2 !important; }
  .cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  html { font-size: 15px; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .topbar .brand span { display: none; }
  .menu-btn { display: inline-block; margin-left: auto; }
  .topbar .nav { display: none; flex-basis: 100%; flex-direction: column; gap: 0; border-top: 1px solid rgba(255,255,255,.15); padding-top: 6px; }
  .topbar .nav.open { display: flex; }
  .topbar .nav a { padding: 10px 8px; border-radius: 0; border-bottom: 1px solid rgba(255,255,255,.08); }
  .topbar .userbox { flex-basis: 100%; justify-content: space-between; font-size: .85rem; }
  .main { padding: 14px 10px 50px; }
  h1 { font-size: 1.15rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid > [style*="grid-column"] { grid-column: auto !important; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card b { font-size: 1.15rem; }
  .filterbar { gap: 6px; }
  .filterbar > div { flex: 1 1 45%; }
  .filterbar input[type=text], .filterbar select { width: 100%; }
  .filterbar .btn, .actions .btn, .actions form { flex: 1 1 auto; }
  .actions .btn { text-align: center; }
  .actions form .btn { width: 100%; }
  .actions .spacer { display: none; }
  .totals { flex-wrap: wrap; gap: 14px 20px; justify-content: space-between; }
  .profitbox { flex-wrap: wrap; gap: 8px 16px; }
  input[type=text], input[type=date], input[type=number], input[type=password], input[type=email], select, textarea { font-size: 16px; }
  table.list th, table.list td { padding: 7px 6px; font-size: .9rem; }
  table.edit { min-width: 900px; }
  .bars { height: 100px; }
  .main-plain { margin: 24px auto; }
}
@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
  .filterbar > div { flex-basis: 100%; }
}

/* 実績グラフ（入金済み／未入金の積み上げ） */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: .85rem; margin: -4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sum { display: inline; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw-paid, .bars-paid .stack i.paid { background: #2f7d55; }
.sw-unpaid, .bars-paid .stack i.unpaid { background: #b9dcc8; }
.bars.bars-paid { height: 170px; }
.bars-paid .bar .val { font-size: .68rem; color: var(--text, #333); white-space: nowrap; min-height: 1.1em; margin-bottom: 2px; }
.bars-paid .stack { width: 70%; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.bars-paid .stack i { display: block; width: 100%; min-height: 2px; }
.bars-paid .stack i:first-child { border-radius: 4px 4px 0 0; }
@media (max-width: 760px) { .bars.bars-paid { height: 130px; } .bars-paid .bar .val { font-size: .55rem; } .bars-paid .bar { white-space: nowrap; font-size: .6rem; } .legend .sum { flex-basis: 100%; } }

/* ===== 見積 Excel方式の入力画面 ===== */
.main-wide { max-width: none; }
.xl-in, .xl-in-sample { background: #fde9d9 !important; }
.xl-in-sample { display: inline-block; width: 14px; height: 12px; border: 1px solid #e9b48c; vertical-align: -1px; }
.xl-head { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 6px 40px; padding: 12px 18px; }
.xl-head input, .xl-head select { padding: 5px 8px; }
.xl-head input, .xl-head select { width: 100%; }
.xl-to { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; } .xl-to select { max-width: 340px; }
.xl-name { display: flex; gap: 6px; align-items: center; border-bottom: 1px solid #333; padding-bottom: 4px; }
.xl-name .xl-big { font-size: 1.25rem; font-weight: 600; } .xl-name select { width: 90px; flex: none; }
.xl-addr { display: grid; grid-template-columns: 140px 1fr; gap: 6px; margin: 6px 0; }
.xl-row { display: grid; grid-template-columns: 90px 1fr; gap: 8px; align-items: center; margin: 3px 0; }
.xl-row label { color: var(--muted); font-size: .85rem; margin: 0; }
.xl-note { margin: 8px 0 2px; color: var(--muted); font-size: .9rem; }
.xl-amount { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 3px double #333; padding: 4px 2px; margin: 4px 0 8px; }
.xl-amount b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.xl-ro { background: #f3f4f6; }
.xl-company { margin: 8px 0; font-size: .88rem; line-height: 1.5; color: #333; }
.xl-cover summary { cursor: pointer; color: var(--muted); }
.xl-cover-chk { font-size: .9rem; color: var(--text); white-space: normal; }
.xl-cover-chk input { width: auto !important; }
.xl-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 1500px) { .xl-grid { grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); } }
.xl-pane { padding: 10px 12px; }
.xl-pane-h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.xl-pane-h h2 { margin: 0; border: 0; padding: 0; color: var(--text); }
.xl-pane-h .spacer { flex: 1; }
.xl-chk { display: inline-flex; gap: 4px; align-items: center; margin: 0; font-size: .85rem; white-space: nowrap; }
.xl-scroll { max-height: calc(100vh - 230px); min-height: 420px; overflow: auto; border: 1px solid var(--line); }
.xl-table { font-size: .86rem; }
.xl-table thead th { position: sticky; top: 0; z-index: 2; }
.xl-table input { width: 100%; padding: 3px 5px; font-size: .86rem; border-radius: 0; }
.xl-table td { padding: 1px 2px; }
.xl-table .c-no { width: 30px; } .xl-table .c-item { min-width: 230px; } .xl-table .c-spec { width: 80px; }
.xl-table .c-qty { width: 58px; } .xl-table .c-unit { width: 46px; } .xl-table .c-price { width: 112px; } .xl-table .c-amt { width: 92px; }
.xl-table .c-note { min-width: 110px; } .xl-table .c-ritem { min-width: 190px; } .xl-table .c-content { min-width: 110px; }
.xl-table .c-rprice { width: 82px; } .xl-table .c-pct { width: 46px; } .xl-table .c-adj { width: 80px; }
.pwrap { display: flex; } .pwrap input { flex: 1; min-width: 0; }
.l-price { background: #f7f9fb; color: #374151; } .l-price.manual { background: #fff3b0 !important; color: #000; }
.l-reset { border: 0; background: none; color: #9aa5b1; cursor: pointer; padding: 0 3px; visibility: hidden; }
.l-price.manual + .l-reset { visibility: visible; } tr.is-mat .l-reset { visibility: hidden !important; }
.manual-sample { background: #fff3b0; padding: 0 4px; }
#lTable tr.is-mat .l-item { box-shadow: inset 3px 0 0 #2f7d55; }
#lTable tr.warn td.l-amt { color: var(--danger); }
#lTable tr.empty td.l-amt { background: #fff; }
#lTable tfoot td { background: #f2f5f8; font-weight: 600; text-align: center; }
#lTable tfoot td.calc { text-align: right; } #lTable tfoot .xl-total td { font-size: 1rem; }
#dTable tr.grp td { border-top: 2px solid #c4ccd5; }
#dTable td.d-item-td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; font-size: .82rem; }
#dTable td.d-content-td { font-size: .82rem; white-space: nowrap; }
#dTable .ditto { color: #b0b8c1; padding-left: 1em; }
#dTable td.c-fix { background: #f3f4f6; color: #374151; }
#dTable td.c-fixnote { font-size: .8rem; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
#dTable tr.custom .rm-btn { padding: 0 4px; flex: none; }
#dTable tr.filled td { background: #f0faf3; } #dTable tr.filled input:not(.xl-in) { background: #f0faf3; }
#dTable tr.hl td:first-child, #dTable tr.hl td:nth-child(2) { background: #dbeafe; }
.xl-sticky { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; background: #1b2a41; color: #fff; padding: 8px 14px; border-radius: 6px 6px 0 0; margin-top: 8px; font-size: .92rem; }
.xl-sticky b { font-size: 1.1rem; font-variant-numeric: tabular-nums; margin-left: 4px; }
.xl-sticky .spacer { flex: 1; }
.xl-warn { color: #ffd479; font-size: .85rem; } .xl-warn b { color: #fff; } .xl-warn .btn { margin-left: 6px; }
@media (max-width: 900px) {
  .xl-head { grid-template-columns: 1fr; }
  .xl-scroll { max-height: 70vh; min-height: 0; }
  #lTable { min-width: 780px; } #dTable { min-width: 980px; }
  .xl-sticky { gap: 10px; font-size: .82rem; } .xl-sticky b { font-size: .95rem; }
}
