/* ============================================================
   N's factory — 見積請求領収システム スタイル
   ============================================================ */

:root {
  --color-primary:       #1D1D1F;
  --color-accent:        #A0785A;
  --color-accent-light:  #F3ECE4;
  --color-accent-dark:   #7A5540;
  --color-bg:            #FAFAF8;
  --color-bg-card:       #FFFFFF;
  --color-border:        #E8E8ED;
  --color-text:          #1D1D1F;
  --color-text-sub:      #636366;
  --color-text-mute:     #AEAEB2;
  --color-danger:        #C0392B;
  --color-success:       #27AE60;
  --color-info:          #2980B9;
  --shadow-sm:  0 2px 8px rgba(0,0,0,.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,.10);
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  font-family: 'Zen Old Mincho','Hiragino Mincho ProN','Yu Mincho',Georgia,serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
}

/* ---- ヘッダ ---- */
.site-header {
  background: var(--color-primary);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-header .brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-decoration: none;
  color: #fff;
}
.site-header nav { display: flex; gap: 4px; margin-left: auto; }
.site-header nav a {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background .2s, color .2s;
}
.site-header nav a:hover, .site-header nav a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
}

/* ---- メインコンテナ ---- */
.main-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---- ページタイトル ---- */
.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.page-title .badge {
  font-size: 12px;
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-weight: 400;
}

/* ---- タブ ---- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 24px;
}
.tabs .tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text-sub);
  transition: color .2s, border-color .2s;
  font-family: inherit;
}
.tabs .tab-btn.active {
  color: var(--color-accent-dark);
  border-bottom-color: var(--color-accent);
  font-weight: 700;
}
.tabs .tab-btn:hover { color: var(--color-text); }

/* ---- ツールバー ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  transition: opacity .2s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--color-accent); color: #fff; }
.btn-primary:hover  { background: var(--color-accent-dark); }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: #d0d0d5; }
.btn-danger   { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-ghost    { background: transparent; border: 1px solid var(--color-border); color: var(--color-text-sub); }
.btn-ghost:hover { background: var(--color-accent-light); color: var(--color-accent-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- カード ---- */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }

/* ---- テーブル ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  background: var(--color-primary);
  color: #fff;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--color-accent-light); }
.data-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.data-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

/* ---- ステータスバッジ ---- */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.status-draft   { background: #F0F0F5; color: #636366; }
.status-issued  { background: #E8F4FD; color: #1A6FA3; }
.status-paid    { background: #E8F8EF; color: #1A7A45; }

/* ---- フォーム ---- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-sub);
  margin-bottom: 5px;
  letter-spacing: .03em;
}
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--color-text);
  transition: border-color .2s, box-shadow .2s;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(160,120,90,.15);
}
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23636366' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

/* ---- 明細テーブル（エディタ） ---- */
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}
.detail-table td { padding: 4px; border-bottom: 1px solid var(--color-border); }
.detail-table input, .detail-table select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.detail-table input:focus { outline: none; border-color: var(--color-accent); }
.detail-table .btn-remove {
  background: none;
  border: none;
  color: var(--color-danger);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
}

/* ---- 小計ブロック ---- */
.subtotal-block {
  text-align: right;
  margin-top: 12px;
  font-size: 14px;
}
.subtotal-block .row { display: flex; justify-content: flex-end; gap: 20px; margin-top: 4px; }
.subtotal-block .label { color: var(--color-text-sub); }
.subtotal-block .amount { font-weight: 700; min-width: 90px; text-align: right; }
.subtotal-block .total-row { font-size: 18px; border-top: 2px solid var(--color-primary); margin-top: 8px; padding-top: 8px; }

/* ---- スピナー ---- */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- トースト ---- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--color-primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: slideIn .25s ease;
  max-width: 340px;
}
.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-danger); }
@keyframes slideIn { from { transform: translateX(40px); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ---- 空状態 ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-mute);
}
.empty-state .icon { font-size: 40px; display: block; margin-bottom: 12px; }

/* ---- レスポンシブ ---- */
@media (max-width: 700px) {
  .main-container { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 8px; }
  .site-header nav a span { display: none; }
}

/* ============================================================ */
/* 印刷専用エリア — 通常時は非表示、@media print時のみ表示       */
/* ============================================================ */
#print-area { display: none; }

@media print {
  /* 画面要素を全て非表示 */
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff !important; margin: 0; padding: 0; }

  /* 印刷エリアを表示 */
  #print-area {
    display: block !important;
    width: 100%;
    padding: 0;
    margin: 0;
    color: #000;
    font-family: 'Zen Old Mincho', 'Noto Sans JP', sans-serif;
    font-size: 11px;
    line-height: 1.6;
  }

  @page {
    size: A4 portrait;
    margin: 18mm 16mm 14mm 16mm;
  }
}

/* ---- 印刷エリア共通レイアウト（@media print 以外でも適用される
        スタイル：画面サイズではどのみち非表示なので影響なし） ---- */
#print-area .pa-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 2px solid #000;
  padding-bottom: 6mm;
  margin-bottom: 6mm;
  page-break-inside: avoid;
}
#print-area .pa-title {
  font-size: 22pt;
  font-weight: 700;
  letter-spacing: 0.4em;
  margin: 0;
}
#print-area .pa-meta {
  font-size: 9pt;
  text-align: right;
  line-height: 1.8;
}

#print-area .pa-grid {
  display: grid;
  grid-template-columns: 1fr 70mm;
  gap: 8mm;
  margin-bottom: 6mm;
}
#print-area .pa-customer-box {
  border-bottom: 1px solid #000;
  padding-bottom: 4mm;
  align-self: end;
}
#print-area .pa-customer-name {
  font-size: 14pt;
  font-weight: 700;
}
#print-area .pa-issuer-box {
  position: relative;
  font-size: 9pt;
  line-height: 1.8;
  padding-right: 17mm;
  min-height: 15mm;
}
#print-area .pa-issuer-name { font-weight: 700; font-size: 11pt; margin-bottom: 1mm; }
#print-area .pa-issuer-invoice { color: #666; font-size: 8pt; margin-top: 1mm; }
#print-area .pa-inkan {
  position: absolute;
  top: 0;
  right: 0;
  width: 15mm;
  height: 15mm;
  display: flex;
  align-items: center;
  justify-content: center;
}
#print-area .pa-inkan img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
/* 画像読込失敗時のフォールバック（テキスト印） */
#print-area .pa-inkan.pa-inkan-fallback {
  border: 1.5pt solid #b41e1e;
  color: #b41e1e;
  font-size: 11pt;
  font-weight: 700;
  border-radius: 50%;
  width: 18mm;
  height: 18mm;
}
#print-area .pa-inkan.pa-inkan-fallback::after {
  content: '印';
}

#print-area .pa-subject {
  font-size: 10pt;
  margin-bottom: 4mm;
}
#print-area .pa-total-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border: 1.5pt solid #000;
  padding: 4mm 6mm;
  margin-bottom: 6mm;
  background: #f5f0e8;
}
#print-area .pa-total-line > span:first-child {
  font-size: 11pt;
  font-weight: 700;
}
#print-area .pa-total-amount {
  font-size: 18pt;
  font-weight: 700;
}

#print-area .pa-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 5mm;
  font-size: 10pt;
}
#print-area .pa-table th {
  background: #50402b;
  color: #fff;
  padding: 2.5mm 3mm;
  text-align: left;
  font-weight: 700;
  font-size: 10pt;
  border: 0.5pt solid #50402b;
}
#print-area .pa-table td {
  padding: 2.5mm 3mm;
  border-bottom: 0.3pt solid #ccc;
  vertical-align: top;
}
#print-area .pa-table td:nth-child(2),
#print-area .pa-table td:nth-child(3),
#print-area .pa-table td:nth-child(4) { text-align: right; white-space: nowrap; }
#print-area .pa-table th:nth-child(1) { width: auto; }
#print-area .pa-table th:nth-child(2) { width: 16mm; text-align: right; }
#print-area .pa-table th:nth-child(3) { width: 24mm; text-align: right; }
#print-area .pa-table th:nth-child(4) { width: 26mm; text-align: right; }
#print-area .pa-table th:nth-child(5) { width: 32mm; }

#print-area .pa-summary {
  width: 80mm;
  margin-left: auto;
  font-size: 10pt;
  margin-bottom: 6mm;
}
#print-area .pa-summary > div {
  display: flex;
  justify-content: space-between;
  padding: 1.5mm 0;
  border-bottom: 0.3pt solid #ccc;
}
#print-area .pa-summary-total {
  font-weight: 700;
  font-size: 12pt;
  border-top: 1pt solid #000 !important;
  border-bottom: 1.5pt double #000 !important;
  margin-top: 1mm;
}

#print-area .pa-note {
  border: 0.5pt solid #999;
  padding: 3mm 4mm;
  margin-top: 4mm;
  page-break-inside: avoid;
}
#print-area .pa-note-title {
  font-weight: 700;
  font-size: 9pt;
  margin-bottom: 1.5mm;
  color: #555;
}
#print-area .pa-note pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 9pt;
  margin: 0;
  line-height: 1.7;
}

#print-area .pa-footer {
  text-align: center;
  font-size: 8pt;
  color: #999;
  margin-top: 8mm;
  padding-top: 2mm;
  border-top: 0.3pt solid #ccc;
}
