/* ===== 基本 ===== */
* { box-sizing: border-box; }
:root {
  --accent: #0e7490;
  --accent-dark: #155e75;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #cbd5e1;
  --text: #1e293b;
  --internal-bg: #fff7ed;
}
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.error { color: #dc2626; min-height: 1.2em; }
a { color: var(--accent); }

/* ===== ログイン ===== */
#view-login { display: flex; justify-content: center; padding: 60px 16px; }
.login-box {
  background: var(--card); border-radius: 12px; padding: 32px; width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-box h1 { font-size: 20px; margin: 0; color: var(--accent-dark); text-align: center; }
.login-sub { text-align: center; margin: 4px 0 24px; color: #64748b; }
.login-box label { display: block; margin-bottom: 14px; font-weight: 600; }
.login-box select, .login-box input {
  width: 100%; margin-top: 4px; padding: 10px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
}
.login-note { font-size: 12px; color: #64748b; margin: 10px 0 0; }

/* ===== ヘッダー ===== */
#app-header {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--accent-dark); color: #fff; flex-wrap: wrap;
}
.header-title { font-weight: 700; }
#app-header nav { display: flex; gap: 8px; }
.nav-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff;
  padding: 6px 14px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.nav-btn.active { background: #fff; color: var(--accent-dark); font-weight: 700; }
.header-user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }

/* ===== 共通部品 ===== */
.view { padding: 16px; max-width: 1280px; margin: 0 auto; }
.btn {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-size: 14px; color: var(--text);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: #dc2626; }
.btn.wide { width: 100%; margin-top: 8px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 240px; }
.toolbar select { padding: 9px; border: 1px solid var(--line); border-radius: 8px; }
.sync-status { font-size: 12px; color: #64748b; margin-left: auto; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card h3, .card legend { font-size: 15px; color: var(--accent-dark); }
fieldset.card { border: 1px solid var(--line); }
.card label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.card input, .card select, .card textarea {
  width: 100%; margin-top: 3px; padding: 8px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox-line { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.checkbox-line input { width: auto; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 800px) { .editor-grid { grid-template-columns: 1fr; } .row2 { grid-template-columns: 1fr; } }

/* ===== 一覧 ===== */
.list-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.list-table th, .list-table td { padding: 9px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; font-size: 13px; }
.list-table thead th { background: #e2e8f0; font-size: 12px; }
.lt-cust { font-weight: 700; }
.empty { color: #94a3b8; padding: 24px; text-align: center; }

/* ===== 明細テーブル ===== */
.items-card { overflow: visible; }
.items-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; margin-bottom: 8px; }
#items-table { border-collapse: collapse; width: 100%; min-width: 900px; }
#items-table th, #items-table td { border: 1px solid var(--line); padding: 2px; font-size: 13px; }
#items-table thead th { background: #e0f2fe; font-size: 12px; padding: 6px 4px; white-space: nowrap; }
#items-table input { width: 100%; border: none; padding: 7px 6px; font-size: 13px; background: transparent; }
#items-table input:focus { outline: 2px solid var(--accent); background: #fff; }
#items-table input[type=number] { text-align: right; }
#items-table .calc { background: #f8fafc; padding: 7px 6px; color: #475569; white-space: nowrap; }
.c-no { width: 36px; } .c-qty { width: 64px; } .c-std, .c-price { width: 90px; }
.c-stdamt, .c-amt { width: 95px; } .c-del { width: 34px; }
.row-del { border: none; background: none; color: #dc2626; cursor: pointer; font-size: 15px; width: 100%; }
.internal { display: none; background: var(--internal-bg); }
.show-internal .internal { display: table-cell; }
.show-internal .internal-total.internal, .show-internal span.internal { display: inline; }
#items-table thead .internal { background: #ffedd5; }
.totals { display: flex; gap: 24px; justify-content: flex-end; align-items: baseline; flex-wrap: wrap; padding: 8px 4px; }
.totals .grand { font-size: 18px; font-weight: 700; color: var(--accent-dark); }
.totals span { font-weight: 700; }
.internal-total { color: #c2410c; }
.editor-toolbar { position: sticky; top: 0; background: var(--bg); z-index: 5; padding: 8px 0; }
.editor-status { color: #64748b; font-size: 12px; }

/* ===== モーダル ===== */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 12px; padding: 20px; width: 480px; max-width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.modal-box.wide { width: 860px; }
.modal-box h3 { margin-top: 0; color: var(--accent-dark); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-box label { display: block; font-size: 13px; font-weight: 600; margin-top: 10px; }
.modal-box input[type=text], .modal-box textarea {
  width: 100%; margin-top: 3px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
.mst-table { width: 100%; border-collapse: collapse; min-width: 900px; table-layout: fixed; }
.mst-table th, .mst-table td { border: 1px solid var(--line); padding: 2px; font-size: 13px; }
.mst-table thead th { background: #e0f2fe; font-size: 12px; padding: 6px 4px; white-space: nowrap; }
.mst-table input { width: 100%; border: none; padding: 7px 6px; font-size: 13px; background: transparent; box-sizing: border-box; }
.mst-table input:focus { outline: 2px solid var(--accent); background: #fff; }
.mst-table .c-bname { width: 17%; } .mst-table .c-baddr { width: 28%; }
.mst-table .c-btel, .mst-table .c-bfax { width: 14%; } .mst-table .c-bmgr { width: 17%; }
.mst-table .row-del { width: 34px; }
#branch-table { margin-bottom: 8px; }

#import-table { width: 100%; border-collapse: collapse; }
#import-table th, #import-table td { border: 1px solid var(--line); padding: 2px; font-size: 12px; }
#import-table thead th { background: #e0f2fe; padding: 6px; }
#import-table input { width: 100%; border: none; padding: 6px 4px; font-size: 12px; }
#import-table input[type=number] { text-align: right; width: 90px; }
#import-table input[type=checkbox] { width: auto; }
.import-wrap { max-height: 45vh; overflow-y: auto; margin-bottom: 8px; }
#import-progress { color: var(--accent-dark); font-weight: 600; min-height: 1.5em; }

/* ===== トースト ===== */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 22px; border-radius: 24px;
  z-index: 100; font-size: 14px; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
#toast.error-toast { background: #b91c1c; }

/* ===== PDF・印刷用（A4 = 794×1123px @96dpi） ===== */
#print-root { position: absolute; left: -10000px; top: 0; }
#print-root.rendering { left: -10000px; }
.sheet {
  width: 794px; height: 1123px; background: #fff; color: #1e293b;
  padding: 50px 55px; position: relative; overflow: hidden;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
}
/* 表紙 */
.cover-inner { text-align: center; padding-top: 70px; }
.cover-date { text-align: right; font-size: 13px; }
.cover-to {
  text-align: left; font-size: 22px; font-weight: 700;
  border-bottom: 2px solid #1e293b; display: inline-block; min-width: 60%;
  padding: 6px 8px; margin: 28px 0 10px;
}
.cover h1 { font-size: 40px; letter-spacing: 14px; margin: 46px 0 8px; color: #0f172a; }
.cover-title { font-size: 16px; margin: 18px 0 0; }
.cover-total-label { margin-top: 56px; font-size: 14px; color: #475569; }
.cover-total {
  font-size: 34px; font-weight: 700; margin: 6px auto 0;
  border-bottom: 3px double #1e293b; display: inline-block; padding: 4px 36px;
}
.cover-cond { margin: 48px auto 0; border-collapse: collapse; font-size: 14px; }
.cover-cond th, .cover-cond td { border: 1px solid #94a3b8; padding: 8px 18px; text-align: left; }
.cover-cond th { background: #f1f5f9; font-weight: 600; width: 140px; }
.cover-company { position: absolute; right: 55px; bottom: 70px; text-align: left; font-size: 13px; line-height: 1.7; }
.cover-co-name { font-size: 17px; font-weight: 700; margin-bottom: 2px; }

/* 明細ページ */
.detail h2 { font-size: 24px; letter-spacing: 8px; margin: 0 0 8px; }
.d-head { display: flex; justify-content: space-between; gap: 20px; }
.d-left { flex: 1; }
.d-to { font-size: 17px; font-weight: 700; border-bottom: 1.5px solid #1e293b; display: inline-block; padding: 2px 6px; margin: 4px 0; min-width: 280px; }
.d-msg { font-size: 12px; margin: 6px 0; }
.d-cond { border-collapse: collapse; font-size: 11.5px; margin-top: 4px; }
.d-cond th, .d-cond td { border: 1px solid #94a3b8; padding: 3px 8px; text-align: left; }
.d-cond th { background: #f1f5f9; width: 95px; font-weight: 600; }
.d-cond td { min-width: 220px; }
.d-right { width: 270px; font-size: 12px; line-height: 1.6; text-align: left; }
.d-date { text-align: right; }
.d-co { font-size: 14px; font-weight: 700; }
.d-total { border-collapse: collapse; width: 100%; margin-top: 8px; font-size: 13px; }
.d-total th, .d-total td { border: 1px solid #64748b; padding: 4px 8px; }
.d-total th { background: #f1f5f9; text-align: left; width: 45%; }
.d-total td { text-align: right; }
.d-total .grand th, .d-total .grand td { font-size: 15px; font-weight: 700; background: #e0f2fe; }
.d-items { border-collapse: collapse; width: 100%; margin-top: 14px; font-size: 11.5px; }
.d-items th, .d-items td { border: 1px solid #64748b; padding: 4px 5px; }
.d-items thead th { background: #e0f2fe; font-weight: 600; }
.d-items td { height: 22px; }
.d-items .small { font-size: 10px; }
.w-no { width: 28px; } .w-qty { width: 42px; } .w-num { width: 72px; } .w-rem { width: 90px; }
.d-items tfoot td { font-weight: 700; white-space: nowrap; }
.d-items tfoot .grand td { background: #e0f2fe; font-size: 13px; }
.foot-label { background: #f8fafc; }
.intn { background: #fff7ed; }
.internal-sheet h2 { color: #c2410c; }
.d-page { position: absolute; bottom: 24px; left: 0; right: 0; text-align: center; font-size: 11px; color: #64748b; }

/* ブラウザ印刷時はprint-rootのみ表示 */
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { position: static; left: 0; }
  body.printing { background: #fff; }
  .sheet { page-break-after: always; width: 210mm; height: 296mm; padding: 14mm 15mm; }
  @page { size: A4 portrait; margin: 0; }
}
