/* ==========================================================
   請求書管理  スタイル
   方針: 装飾を足さない。線と余白と文字だけで構造を出す。
   ========================================================== */

:root{
  --radius:    6px;   /* パネル・モーダルなどの面 */
  --radius-sm: 4px;   /* ボタン・入力欄などの部品 */
  --bg:        #f1f1ee;
  --surface:   #ffffff;
  --line:      #dcdcd6;
  --line-mid:  #c4c4bd;
  --line-dark: #9a9a92;
  --text:      #1b1b19;
  --text-sub:  #5f5f58;
  --text-mute: #8a8a82;
  --ink:       #1d3444;
  --ink-hover: #26445a;
  --danger:    #96302c;
  --ok:        #2f6b46;
  --warn:      #8a5a12;
  --row-alt:   #fafaf8;
  --head:      #eeeee9;
}

*{ box-sizing:border-box; }

/* display を持つ要素にも hidden 属性を効かせる */
[hidden]{ display:none !important; }

html,body{ height:100%; }

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
              "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  font-size:13px;
  line-height:1.65;
  -webkit-font-smoothing:antialiased;
}

h1,h2,h3,h4{ margin:0; font-weight:600; }

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

button{ font:inherit; }

input,select,textarea{
  font:inherit;
  color:var(--text);
  background:#fff;
  border:1px solid var(--line-mid);
  border-radius:var(--radius-sm);
  padding:5px 7px;
  width:100%;
}
input:focus,select:focus,textarea:focus{
  outline:none;
  border-color:var(--ink);
  box-shadow:inset 0 0 0 1px var(--ink);
}
input[readonly]{ background:#f5f5f2; color:var(--text-sub); }
textarea{ resize:vertical; line-height:1.6; }
select{ appearance:auto; }

.num{ text-align:right; font-variant-numeric:tabular-nums; }

/* ---------- ログイン / 接続設定 ---------- */
.gate{
  min-height:100%;
  display:flex; align-items:center; justify-content:center;
  padding:32px 16px;
}
.gate-box{
  width:100%; max-width:380px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius);
  padding:28px 26px 24px;
}
.gate-title{ font-size:17px; letter-spacing:.04em; }
.gate-lead{ margin:6px 0 20px; color:var(--text-sub); font-size:12px; }
.gate-error{
  margin:0 0 12px; padding:7px 9px;
  background:#fbf0ef; border:1px solid #e0c3c1; color:var(--danger); font-size:12px;
  border-radius:var(--radius-sm);
}
.field{ display:block; margin-bottom:14px; }
.field > span{ display:block; margin-bottom:4px; font-size:12px; color:var(--text-sub); }

/* ---------- ボタン ---------- */
.btn{
  display:inline-block;
  padding:5px 14px;
  border:1px solid var(--line-dark);
  border-radius:var(--radius-sm);
  background:#fff;
  color:var(--text);
  cursor:pointer;
  white-space:nowrap;
}
.btn:hover{ background:#f4f4f1; }
.btn-primary{ background:var(--ink); border-color:var(--ink); color:#fff; }
.btn-primary:hover{ background:var(--ink-hover); border-color:var(--ink-hover); }
.btn-danger{ color:var(--danger); border-color:#c9a7a5; }
.btn-danger:hover{ background:#fbf3f2; }
.btn-block{ display:block; width:100%; padding:7px; margin-top:4px; }
.btn-sm{ padding:2px 8px; font-size:12px; }
.btn:disabled{ opacity:.5; cursor:default; }

.linkbtn{
  background:none; border:none; padding:0; margin-top:14px;
  color:var(--text-mute); font-size:12px; text-decoration:underline; cursor:pointer;
}
.linkbtn:hover{ color:var(--text); }

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

.sidebar{
  width:186px; flex:0 0 186px;
  background:#26313a;
  color:#c9d2d8;
  display:flex; flex-direction:column;
  position:sticky; top:0; height:100vh;
}
.brand{
  padding:16px 18px 14px;
  font-size:13px; letter-spacing:.12em; color:#fff;
  border-bottom:1px solid #33404a;
}
.nav{ padding:8px 0; flex:1; overflow-y:auto; }
.nav a{
  display:block; padding:7px 18px;
  color:#c1cbd2; text-decoration:none; font-size:13px;
  border-left:3px solid transparent;
}
.nav a:hover{ background:#2d3941; color:#fff; }
.nav a.active{ background:#31404a; color:#fff; border-left-color:#7fa4bb; }
.nav .nav-sep{ height:1px; background:#33404a; margin:8px 14px; }

.sidebar-foot{ padding:12px 18px 16px; border-top:1px solid #33404a; }
.user-email{ font-size:11px; color:#8b9aa5; word-break:break-all; }
.sidebar-foot .linkbtn{ margin-top:6px; color:#8b9aa5; }
.sidebar-foot .linkbtn:hover{ color:#fff; }

.main{ flex:1; min-width:0; display:flex; flex-direction:column; }
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 24px; background:var(--surface); border-bottom:1px solid var(--line);
  position:sticky; top:0; z-index:5;
}
.page-title{ font-size:15px; }
.page-actions{ display:flex; gap:8px; align-items:center; }
.view{ padding:20px 24px 56px; }

/* ---------- パネル ---------- */
.panel{ background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; margin-bottom:18px; }
.panel-head{
  padding:9px 14px; border-bottom:1px solid var(--line);
  background:#f7f7f4; font-size:12px; font-weight:600; letter-spacing:.03em;
  display:flex; justify-content:space-between; align-items:center; gap:10px;
}
.panel-body{ padding:14px; }
.panel-body.tight{ padding:0; }

/* ---------- テーブル ---------- */
table.grid{ width:100%; border-collapse:collapse; }
table.grid th{
  background:var(--head); text-align:left; font-weight:600; font-size:12px;
  padding:7px 10px; border-bottom:1px solid var(--line-mid); white-space:nowrap;
}
table.grid td{
  padding:7px 10px; border-bottom:1px solid var(--line); vertical-align:middle;
}
table.grid tbody tr:hover{ background:#f6f6f3; }
table.grid td.num, table.grid th.num{ text-align:right; font-variant-numeric:tabular-nums; }
table.grid tr.rowclick{ cursor:pointer; }
table.grid .rowlink{ color:var(--ink); text-decoration:none; }
table.grid .rowlink:hover{ text-decoration:underline; }
.empty{ padding:26px 14px; text-align:center; color:var(--text-mute); font-size:12px; }

/* 明細編集テーブル */
table.items{ width:100%; border-collapse:collapse; }
table.items th{
  background:var(--head); font-size:12px; font-weight:600; text-align:left;
  padding:6px 8px; border:1px solid var(--line-mid);
}
table.items td{ padding:3px 4px; border:1px solid var(--line); }
table.items input{ border-color:transparent; background:transparent; }
table.items input:focus{ background:#fff; border-color:var(--ink); }
table.items td.amount{ text-align:right; padding-right:9px; font-variant-numeric:tabular-nums; }
.rowbtn{
  border:none; background:none; color:var(--text-mute); cursor:pointer;
  padding:2px 6px; font-size:14px; line-height:1;
}
.rowbtn:hover{ color:var(--danger); }

/* ---------- フォーム配置 ---------- */
.form-grid{ display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:12px 18px; }
.form-grid .col-2{ grid-column:span 2; }
@media (max-width:820px){
  .form-grid{ grid-template-columns:1fr; }
  .form-grid .col-2{ grid-column:span 1; }
}

/* ---------- 集計・小物 ---------- */
.stats{ display:grid; grid-template-columns:repeat(4, minmax(0,1fr)); gap:12px; margin-bottom:18px; }
@media (max-width:900px){ .stats{ grid-template-columns:repeat(2,minmax(0,1fr)); } }
.stat{ background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:12px 14px; }
.stat-label{ font-size:11px; color:var(--text-sub); }
.stat-value{ font-size:20px; font-variant-numeric:tabular-nums; margin-top:2px; }
.stat-sub{ font-size:11px; color:var(--text-mute); }

.tag{
  display:inline-block; padding:1px 7px; font-size:11px;
  border:1px solid var(--line-mid); background:#f5f5f2; color:var(--text-sub);
  border-radius:var(--radius-sm); white-space:nowrap;
}
.tag-ok{ border-color:#b6cdbf; background:#eef5f0; color:var(--ok); }
.tag-warn{ border-color:#dbc8a4; background:#faf5ea; color:var(--warn); }
.tag-danger{ border-color:#dcbab8; background:#fbf1f0; color:var(--danger); }

.totals{ margin-left:auto; width:290px; }
.totals div{ display:flex; justify-content:space-between; padding:4px 0; border-bottom:1px solid var(--line); }
.totals div:last-child{ border-bottom:none; border-top:2px solid var(--line-dark); margin-top:4px; padding-top:7px; font-size:15px; }
.totals span:last-child{ font-variant-numeric:tabular-nums; }

.toolbar{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:14px; }
.toolbar label{ font-size:12px; color:var(--text-sub); display:flex; align-items:center; gap:5px; }
.toolbar input, .toolbar select{ width:auto; min-width:130px; }
.spacer{ flex:1; }
.hint{ font-size:11px; color:var(--text-mute); margin-top:4px; }
.note-block{ background:#f7f7f4; border:1px solid var(--line); border-radius:var(--radius-sm); padding:10px 12px; font-size:12px; color:var(--text-sub); }
.inline-check{ display:flex; align-items:center; gap:6px; font-size:12px; }
.inline-check input{ width:auto; min-width:0; }   /* .toolbar input の min-width を打ち消す */

/* ---------- 月次損益表（月を横に取る） ---------- */
.pl-wrap{ overflow-x:auto; }
.pl{ min-width:1040px; }
.pl th, .pl td{ white-space:nowrap; font-variant-numeric:tabular-nums; }
.pl thead th{ text-align:right; }
.pl .pl-item{
  position:sticky; left:0; z-index:2;
  text-align:left; font-weight:400; color:var(--text-sub);
  background:var(--surface); border-right:1px solid var(--line);
  min-width:190px;
}
.pl thead .pl-item{ background:var(--head); color:var(--text); }
.pl .pl-total-head{ background:var(--head); border-left:1px solid var(--line-mid); }
.pl tbody td:last-child{ border-left:1px solid var(--line-mid); background:var(--row-alt); }
.pl .pl-line th, .pl .pl-line td{ font-weight:600; color:var(--text); }
.pl .pl-rule th, .pl .pl-rule td{ border-top:2px solid var(--line-mid); }
.pl .pl-line .pl-item{ color:var(--text); }
.pl .pl-strong{ font-weight:600; }
.pl .pl-minus{ color:var(--danger); }
.pl .pl-blank{ color:var(--warn); font-weight:400; font-size:11px; }

/* 内訳が出るセルと、その内訳ポップアップ */
.pl .pl-has-detail{ cursor:default; }
.pl .pl-has-detail:hover, .pl .pl-has-detail:focus{
  outline:none; background:var(--head); box-shadow:inset 0 0 0 1px var(--line-mid);
}
.pl .pl-now{ background:var(--row-alt); }
.pl-tip{ font-size:11px; font-weight:400; color:var(--text-mute); margin-left:10px; }

.pl-pop{
  position:fixed; z-index:40; min-width:210px; max-width:420px;
  background:var(--surface); border:1px solid var(--line-dark);
  border-radius:var(--radius-sm); box-shadow:0 2px 8px rgba(27,27,25,.14);
  padding:8px 10px; font-size:12px;
  pointer-events:none;   /* 読むだけ。下のセルへのホバーを邪魔しない */
}
.pl-pop-head{
  font-size:11px; color:var(--text-sub); padding-bottom:5px; margin-bottom:5px;
  border-bottom:1px solid var(--line);
}
.pl-pop table{ width:100%; border-collapse:collapse; }
.pl-pop td{ padding:2px 0; vertical-align:top; }
.pl-pop td.num{ text-align:right; padding-left:14px; white-space:nowrap; font-variant-numeric:tabular-nums; }
.pl-pop tfoot td{ border-top:1px solid var(--line); padding-top:4px; font-weight:600; }
.pl-pop-n{ color:var(--text-mute); font-size:11px; margin-left:5px; }

/* ---------- トースト / モーダル ---------- */
.toast{
  position:fixed; left:50%; bottom:28px; transform:translateX(-50%);
  background:#26313a; color:#fff; padding:8px 18px; font-size:13px; z-index:100;
  border-radius:var(--radius);
}
.toast.error{ background:var(--danger); }

/* 一覧からの帳票プレビュー */
.sheet-modal{ position:fixed; inset:0; z-index:70; overflow:auto; padding:28px 16px; }
.sheet-modal-backdrop{ position:fixed; inset:0; background:rgba(20,20,18,.42); }
.sheet-modal-box{
  position:relative; width:828px; max-width:100%; margin:0 auto;
  background:var(--surface); border:1px solid var(--line-mid);
  border-radius:var(--radius); overflow:hidden;
}
.sheet-modal-head{
  padding:8px 12px; border-bottom:1px solid var(--line); background:#f7f7f4;
  display:flex; justify-content:space-between; align-items:center; gap:10px;
  font-size:12px; font-weight:600;
}
.sheet-modal-actions{ display:flex; gap:8px; align-items:center; }
.sheet-modal-body{ padding:16px; overflow-x:auto; background:#ecece9; }
.sheet-modal-body .sheet{ border:1px solid #d0d0c8; margin:0 auto; }

.modal{ position:fixed; inset:0; z-index:80; display:flex; align-items:center; justify-content:center; padding:20px; }
.modal-backdrop{ position:absolute; inset:0; background:rgba(20,20,18,.42); }
.modal-box{
  position:relative; background:#fff; border:1px solid var(--line-mid);
  border-radius:var(--radius); overflow:hidden;
  width:100%; max-width:460px; max-height:88vh; display:flex; flex-direction:column;
}
.modal-head{
  padding:10px 14px; border-bottom:1px solid var(--line); background:#f7f7f4;
  font-weight:600; font-size:13px; display:flex; justify-content:space-between; align-items:center;
}
.modal-x{ border:none; background:none; font-size:18px; line-height:1; cursor:pointer; color:var(--text-mute); }
.modal-body{ padding:16px 14px; overflow:auto; }
.modal-foot{ padding:10px 14px; border-top:1px solid var(--line); display:flex; justify-content:flex-end; gap:8px; }

/* ==========================================================
   A4 帳票（PDF / 印刷用）
   html2canvas で画像化するため、変数を使わず実値で指定する
   ========================================================== */
.sheet-host{
  position:absolute; left:-10000px; top:0; width:794px;
}
.sheet-host.visible{
  position:static; left:auto; margin:0 auto 24px; width:794px; max-width:100%;
}

.sheet{
  width:794px; min-height:1123px;
  background:#ffffff;
  color:#111111;
  padding:56px 60px 64px;
  font-family:"Hiragino Kaku Gothic ProN","Hiragino Sans","Yu Gothic","Meiryo",sans-serif;
  font-size:12px;
  line-height:1.6;
  box-sizing:border-box;
}
.sheet-host.visible .sheet{ border:1px solid #d0d0c8; }

.sheet .s-title{
  text-align:center; font-size:24px; letter-spacing:.5em;
  text-indent:.5em; font-weight:600; margin:0 0 30px;
}
.sheet .s-head{ display:flex; justify-content:space-between; gap:28px; }
.sheet .s-left{ width:56%; }
.sheet .s-right{ width:42%; text-align:right; }
.sheet .s-partner{
  font-size:16px; font-weight:600; border-bottom:1px solid #111111;
  padding-bottom:5px; margin-bottom:10px;
}
.sheet .s-meta{ font-size:11px; color:#333333; }
.sheet .s-meta div{ display:flex; }
.sheet .s-meta .k{ width:76px; color:#555555; }
.sheet .s-lead{ font-size:13px; font-weight:600; margin:26px 0 14px; }
.sheet table.s-docmeta{ border-collapse:collapse; }
.sheet table.s-docmeta th{
  border:1px solid #d4d4cc; background:#ffffff; padding:5px 14px;
  font-size:11px; font-weight:600; text-align:center; white-space:nowrap;
}
.sheet table.s-docmeta td{
  border:1px solid #d4d4cc; padding:5px 14px; font-size:11px; min-width:150px;
}
.sheet .s-issuer{ font-size:11px; line-height:1.75; position:relative; }
.sheet .s-issuer .name{ font-size:14px; font-weight:600; display:inline-block; position:relative; }
/* 社印は会社名の最後の文字に重ねる（印影が文字の上にくる）。
   下の行（登録番号）にはかからない高さに置く */
.sheet .s-issuer .seal{
  position:absolute; left:calc(100% - 38px); top:-38px;
  width:62px; height:62px; object-fit:contain; z-index:1;
}
.sheet .s-logo{ max-height:40px; max-width:200px; margin-bottom:8px; }

.sheet .s-amountbox{
  margin:28px 0 22px; background:#eeeeea; padding:14px 18px;
  display:flex; align-items:baseline; gap:16px;
  width:50%;
}
.sheet .s-amountbox .lbl{ font-size:13px; font-weight:600; letter-spacing:.14em; }
.sheet .s-amountbox .val{ font-size:22px; font-weight:600; margin-left:auto; }

/* 明細は縦線を引かず、薄い横罫線だけで見せる */
.sheet table.s-items{ width:100%; border-collapse:collapse; margin-top:6px; }
.sheet table.s-items th{
  background:#eeeeea; border:none;
  border-top:1px solid #d4d4cc; border-bottom:1px solid #d4d4cc;
  padding:8px 10px; font-size:11px; font-weight:600; text-align:center;
}
.sheet table.s-items td{
  border:none; border-bottom:1px solid #d4d4cc;
  padding:7px 10px; font-size:11.5px; vertical-align:top;
}
.sheet table.s-items td.r{ text-align:right; }
.sheet table.s-items td.c{ text-align:center; }
.sheet table.s-items td.spec{ font-size:10px; color:#555555; padding-top:0; border-top:none; }

.sheet .s-bottom{ display:flex; gap:28px; margin-top:24px; }
.sheet .s-bottom .left{ flex:1; }
.sheet .s-bottom .right{ width:300px; }

.sheet table.s-sum{ width:100%; border-collapse:collapse; }
.sheet table.s-sum th{
  border:1px solid #d4d4cc; background:#f4f4f0; padding:6px 11px;
  font-size:11.5px; font-weight:normal; text-align:left; width:44%;
}
.sheet table.s-sum td{
  border:1px solid #d4d4cc; padding:6px 11px; font-size:11.5px; text-align:right;
}
.sheet table.s-sum tr.total th{ font-weight:600; background:#e9e9e4; }
.sheet table.s-sum tr.total td{ font-weight:600; font-size:14px; }

.sheet .s-box{ border:1px solid #d4d4cc; padding:10px 12px; font-size:11px; }
.sheet .s-box .bt{ font-weight:600; margin-bottom:4px; font-size:11px; }
.sheet .s-box + .s-box{ margin-top:12px; }
.sheet .s-pre{ white-space:pre-wrap; }
.sheet .s-page{ text-align:right; font-size:10px; color:#777777; margin-top:14px; }

/* ---------- 画面が狭いとき ---------- */
#items-wrap{ overflow-x:auto; }
#items-wrap table.items{ min-width:720px; }

@media (max-width:760px){
  .app{ flex-direction:column; }
  .sidebar{ width:auto; flex:none; height:auto; position:static; }
  .brand{ padding:10px 14px; }
  .nav{ display:flex; flex-wrap:wrap; padding:2px 8px; }
  .nav a{ padding:5px 10px; border-left:none; border-bottom:2px solid transparent; }
  .nav a.active{ border-left-color:transparent; border-bottom-color:#7fa4bb; background:none; }
  .nav .nav-sep{ display:none; }
  .sidebar-foot{ display:flex; justify-content:space-between; align-items:center; padding:6px 14px; }
  .sidebar-foot .linkbtn{ margin-top:0; }
  .topbar{ padding:10px 14px; flex-wrap:wrap; }
  .view{ padding:14px 12px 48px; }
  .panel-body{ padding:12px 10px; }
  .panel-body.tight{ overflow-x:auto; }
  .stats{ grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  .stat-value{ font-size:17px; }
  .totals{ width:100%; }
  .sheet-host.visible{ width:100%; overflow-x:auto; }
}

/* ---------- 印刷 ---------- */
@media print{
  body{ background:#fff; }
  .app,.gate,.toast,.modal{ display:none !important; }
  .sheet-host, .sheet-host.visible{
    position:static !important; left:auto !important; margin:0 !important; width:auto !important;
  }
  .sheet{ border:none !important; width:auto; min-height:0; padding:14mm 14mm; }
  @page{ size:A4; margin:0; }
}
