:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e2e5ea;
  --primary: #1d4e89;
  --primary-hover: #163d6c;
  --red: #c62828;
  --amber: #b26a00;
  --green: #1b7a3d;
  --radius: 8px;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.6; }
a { color: var(--primary); }
h1 { font-size: 20px; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 12px; }
input, select, textarea {
  font: inherit; padding: 7px 9px; border: 1px solid #cfd4db; border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--primary); }
label { display: block; font-size: 13px; color: #374151; }
label > input, label > select, label > textarea, label > .row { margin-top: 4px; }
label.inline { display: inline-flex; gap: 4px; align-items: center; }
label.inline input { width: auto; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.r { text-align: right; }
.c { text-align: center; }
.pad { padding: 12px 16px; margin: 0; }
.req { background: var(--red); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 3px; margin-left: 6px; }
.row { display: flex; gap: 8px; }
.row select { width: 110px; flex: none; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd4db; background: #fff; color: var(--text);
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f1f3f6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { color: var(--red); border-color: #efc4c4; background: #fff; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 10px; margin-top: 8px; }

/* ヘッダー */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px;
  background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { height: 28px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { white-space: nowrap; padding: 6px 12px; border-radius: 6px; color: #374151; text-decoration: none; }
.topbar nav a:hover { background: #f1f3f6; }
.topbar nav a.active { background: #e6eef8; color: var(--primary); font-weight: 600; }
.me { white-space: nowrap; display: flex; gap: 10px; align-items: center; font-size: 13px; }
.me a { color: #374151; text-decoration: none; }

/* ページ */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page.narrow { max-width: 560px; }
.page.wide { max-width: 1000px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
#results.card { padding: 0; overflow-x: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid h2 { margin: 0; }
.align-end { display: flex; align-items: flex-end; }
.info { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }
.alert.red { background: #fdecec; color: var(--red); }
.alert.amber { background: #fff6e0; color: #7a4a00; }

/* 一覧 */
.search { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search input[name=q] { flex: 1 1 280px; }
.search select { width: auto; }
.search .range { display: inline-flex; align-items: center; gap: 4px; }
.search .range input { width: 150px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th { background: #f8f9fb; font-weight: 600; font-size: 12px; color: #4b5563; white-space: nowrap; }
table.list th.r, table.list td.r { text-align: right; }
table.list tbody tr[data-id] { cursor: pointer; }
#results tbody tr:hover { background: #f5f8fc; }
table.list tr.inactive td { opacity: 0.5; }
table.list select { width: auto; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: #eceef1; color: #4b5563; }
.badge.amber { background: #fff1d1; color: var(--amber); }
.badge.green { background: #dcf3e4; color: var(--green); }
.badge.red { background: #fde2e2; color: var(--red); }
.badge.blue { background: #e0ecfa; color: var(--primary); }
.count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.block-link { display: block; text-decoration: none; }
.text-red { color: var(--red); }
.btn.big { padding: 11px 22px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .hanko { vertical-align: middle; }

/* 押印パネル */
.stamp-panel { display: grid; grid-template-columns: auto 1fr; gap: 18px 28px; align-items: start; }
.stamp-slots { display: flex; gap: 14px; }
.stamp-slot { width: 128px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stamp-label { font-size: 12px; color: var(--muted); }
.stamp-box { width: 72px; height: 72px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; background: #fcfcfd; }
.stamp-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.stamp-actions .request { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stamp-actions .request select { width: auto; }
.issue-box { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 14px; }
.issue-box p { margin: 6px 0 0; }
.link-panel .row input { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
@media (max-width: 720px) { .stamp-panel { grid-template-columns: 1fr; } }

/* 明細入力 */
.table-wrap { overflow-x: auto; }
table.items-edit { width: 100%; border-collapse: collapse; margin-bottom: 10px; min-width: 860px; }
table.items-edit th { font-size: 12px; color: #4b5563; font-weight: 600; text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.items-edit th.r { text-align: right; }
table.items-edit td { padding: 4px; border-bottom: 1px solid #f0f2f5; }
table.items-edit .w-num { width: 80px; }
table.items-edit .w-unit { width: 70px; }
table.items-edit .w-price { width: 120px; }
table.items-edit select { width: 84px; }
table.items-edit td.amount { white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 100px; }
.row-ops { white-space: nowrap; }
.row-ops button { border: none; background: none; cursor: pointer; color: var(--muted); padding: 4px 5px; font-size: 14px; }
.row-ops button:hover { color: var(--text); }
.row-ops button[data-op=del]:hover { color: var(--red); }
.totals { margin-left: auto; width: 360px; max-width: 100%; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--text); margin-top: 4px; padding-top: 8px; font-size: 17px; }

/* 認証 */
.auth-card { max-width: 380px; margin: 10vh auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 32px; text-align: center; }
.auth-card form { text-align: left; display: grid; gap: 12px; margin: 20px 0 12px; }
.auth-logo { max-height: 60px; max-width: 200px; margin-bottom: 8px; }

/* 設定 */
.img-field .label { font-size: 13px; color: #374151; margin-bottom: 6px; display: flex; flex-direction: column; }
.img-preview { height: 110px; border: 1px dashed #cfd4db; border-radius: 6px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; background: repeating-conic-gradient(#f5f5f5 0 25%, #fff 0 50%) 0 0/16px 16px; }
.img-preview img { max-height: 96px; max-width: 90%; }
.img-field input[type=file] { width: auto; border: none; padding: 0; }
.account { display: flex; gap: 16px; align-items: center; }
.account .big { font-size: 18px; font-weight: 700; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2328; color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.error { background: var(--red); }

/* ================= 見積書（A4） ================= */
.sheet-wrap { overflow-x: auto; background: #e5e7eb; padding: 24px; border-radius: var(--radius); }
.sheet {
  width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; padding: 16mm 15mm 14mm;
  position: relative; color: #111; font-size: 10pt; line-height: 1.5;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "MS Mincho", serif;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.watermark {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg);
  font-size: 54pt; color: rgba(198, 40, 40, 0.13); font-weight: 700; white-space: nowrap; pointer-events: none;
  border: 6px solid rgba(198, 40, 40, 0.13); padding: 4mm 10mm; border-radius: 6mm;
}
.doc-title { text-align: center; font-size: 22pt; letter-spacing: 0.5em; font-weight: 700; padding-bottom: 2mm; border-bottom: 3px double #111; width: 90mm; margin: 0 auto 4mm; text-indent: 0.5em; }
.doc-meta { text-align: right; font-size: 9.5pt; margin-bottom: 4mm; }
.doc-head { display: flex; justify-content: space-between; gap: 8mm; margin-bottom: 6mm; }
.doc-left { flex: 1; }
.to { font-size: 15pt; font-weight: 700; border-bottom: 1px solid #111; padding-bottom: 1mm; display: inline-block; min-width: 85mm; }
.to .hon { margin-left: 4mm; font-size: 12pt; }
.to-person { margin-top: 1mm; }
.lead { margin: 4mm 0 3mm; font-size: 9.5pt; }
table.kv { border-collapse: collapse; font-size: 9.5pt; margin-bottom: 4mm; }
table.kv th { text-align: left; font-weight: normal; padding: 0.6mm 4mm 0.6mm 0; white-space: nowrap; vertical-align: top; }
table.kv td { padding: 0.6mm 0; border-bottom: 1px dotted #999; min-width: 60mm; }
.grand-box { display: flex; align-items: baseline; gap: 5mm; border: 2px solid #111; padding: 2.5mm 5mm; width: fit-content; min-width: 95mm; }
.grand-box span { font-size: 11pt; }
.grand-box b { font-size: 18pt; letter-spacing: 0.02em; font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif; }
.grand-box small { font-size: 9pt; }
.doc-right { width: 72mm; flex: none; font-size: 9pt; display: flex; flex-direction: column; align-items: flex-end; }
.doc-logo { max-width: 50mm; max-height: 16mm; margin-bottom: 2mm; object-fit: contain; }
.company { position: relative; text-align: right; line-height: 1.55; min-height: 22mm; padding-right: 2mm; }
.company .cname { font-size: 12.5pt; font-weight: 700; margin-bottom: 1mm; }
.company .oname { font-weight: 700; }
.seal { position: absolute; right: -2mm; top: -3mm; width: 22mm; height: 22mm; object-fit: contain; mix-blend-mode: multiply; opacity: 0.92; }
table.stamps { border-collapse: collapse; margin-top: 3mm; }
table.stamps th { border: 1px solid #333; font-weight: normal; font-size: 8pt; padding: 0.5mm; width: 19mm; background: #f3f3f3; }
table.stamps td { border: 1px solid #333; height: 19mm; text-align: center; vertical-align: middle; }
table.stamps .hanko { display: block; margin: 0 auto; }
.hanko { opacity: 0.9; }
.tanto { font-size: 8.5pt; margin-top: 1mm; }

table.items { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
table.items th { background: #ebedf0; border: 1px solid #555; padding: 1.5mm 2mm; font-weight: 600; text-align: center; }
table.items td { border: 1px solid #555; border-top-color: #bbb; border-bottom-color: #bbb; padding: 1.4mm 2mm; vertical-align: top; }
table.items tbody tr:last-child td { border-bottom-color: #555; }
table.items td.r { text-align: right; white-space: nowrap; font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif; }
table.items td.c { text-align: center; }
table.items .no { width: 9mm; }
table.items tr.blank td { height: 7mm; }
table.items .spec { font-size: 8.5pt; color: #444; }
table.items .mark { font-size: 8.5pt; }
.doc-bottom { display: flex; gap: 6mm; margin-top: 4mm; align-items: flex-start; }
.notes { flex: 1; font-size: 9pt; }
.notes-box { border: 1px solid #555; padding: 2mm 3mm; min-height: 26mm; margin-top: 1mm; }
.notes-label { font-weight: 700; margin-bottom: 1mm; }
.doc-footnote { margin-top: 5mm; font-size: 7.5pt; color: #555; }
.muted-print { color: #555; }
.bank { margin-top: 2mm; padding-top: 2mm; border-top: 1px dotted #999; }
table.sum { border-collapse: collapse; width: 72mm; font-size: 9.5pt; }
table.sum th { text-align: left; font-weight: normal; border: 1px solid #555; background: #f3f3f3; padding: 1.2mm 2.5mm; }
table.sum th .small { font-size: 7.5pt; color: #555; }
table.sum td { text-align: right; border: 1px solid #555; padding: 1.2mm 2.5mm; font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif; white-space: nowrap; }
table.sum tr.grand th, table.sum tr.grand td { font-weight: 700; font-size: 11pt; background: #e6e8ec; }

@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .topbar, .toast { display: none !important; }
  .page { padding: 0; max-width: none; }
  .sheet-wrap { padding: 0; background: none; overflow: visible; }
  .sheet { box-shadow: none; margin: 0; zoom: 1 !important; }
}

@media (max-width: 1000px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; justify-content: space-between; }
  .topbar nav { order: 3; width: 100%; flex: none; overflow-x: auto; }
}
@media (max-width: 720px) {
  .sheet-wrap { padding: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .page { padding: 16px 12px 40px; }
}

/* お客様用ページ */
.alert.green { background: #e3f5ea; color: #145c2e; }
.order-form h2 { font-size: 17px; }
.order-form .agree { margin: 18px 0 12px; font-size: 14px; }
.qty-table .w-num { width: 100px; }
.qty-table td, .qty-table th { padding: 8px 10px; }
body.customer .topbar { justify-content: center; }

/* ================= works ================= */
.works-logo { font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif; font-weight: 800; letter-spacing: -0.02em; color: var(--primary); font-size: 20px; }
.works-logo.big { font-size: 44px; line-height: 1.1; margin-bottom: 4px; }
.brand #brand-name { font-weight: 500; color: var(--muted); font-size: 13px; }
.subnav { display: flex; align-items: center; gap: 4px; padding: 6px 20px; background: #f8f9fb; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }
.subnav-title { font-weight: 700; font-size: 13px; margin-right: 12px; }
.subnav a { padding: 5px 12px; border-radius: 6px; color: #374151; text-decoration: none; font-size: 13px; }
.subnav a:hover { background: #eef1f5; }
.subnav a.active { background: #e6eef8; color: var(--primary); font-weight: 600; }
.hero { text-align: center; padding: 48px 0 32px; }
.hero .btn { margin-top: 12px; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.app-tile { position: relative; display: flex; gap: 14px; align-items: flex-start; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.app-tile:hover { border-color: #9cc0ea; box-shadow: 0 2px 10px rgba(29, 78, 137, .08); }
.app-icon { font-size: 30px; line-height: 1; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: #f1f5fa; border-radius: 10px; flex: none; }
.app-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.app-name { font-weight: 700; font-size: 15px; }
.app-desc { font-size: 12px; color: var(--muted); }
.app-tile .vis { position: absolute; top: 10px; right: 10px; font-size: 10px; padding: 1px 6px; border-radius: 4px; background: #e3f5ea; color: #145c2e; }
.app-tile .vis.admin { background: #eceef1; color: #4b5563; }
.app-icon-cell { font-size: 22px; width: 40px; }
.notice-list { display: grid; gap: 8px; margin-bottom: 18px; }
.notice-list .alert { margin: 0; }
h2 { margin-top: 8px; }
.works-icon { width: 26px; height: 26px; border-radius: 6px; }
.works-icon.big { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 10px; box-shadow: 0 4px 14px rgba(29, 78, 137, .25); }
/* アプリとして起動したとき（ブラウザの枠なし）は上部を少し詰める */
@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
