/* ==========================================================================
   KurokoLab Invoice & Receipt Builder Stylesheet
   石原 準也 公式請求書・領収書デザイン 完全準拠
   ========================================================================== */

:root {
  /* UIテーマ（操作画面）: ビジネスダーク＆スマートブルー */
  --bg-app: #0f172a;
  --bg-pane: #1e293b;
  --bg-card: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --accent-blue: #2563eb;
  --accent-blue-hover: #1d4ed8;
  --accent-blue-light: #60a5fa;
  
  --border-light: rgba(255, 255, 255, 0.1);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.3);

  /* A4書類カラー（洗練されたグレー＆ホワイト・モノトーン仕様） */
  --a4-width: 210mm;
  --a4-height: 297mm;
  --doc-dark: #0f172a;       /* タイトル・主要文字色（深みのあるチャコールブラック） */
  --doc-slate: #334155;      /* 見出しバー・重要アクセント（上品なスレートグレー） */
  --doc-gray-sub: #f8fafc;   /* 金額ボックス等の背景（清潔な極薄グレー） */
  --doc-border: #cbd5e1;     /* テーブル・枠線（均整の取れたライトグレー） */
  --doc-th-bg: #f1f5f9;      /* 表ヘッダー背景（洗練された明るいグレー） */
  --hanko-red: #d9383a;      /* 公式印影・朱肉色 */
}

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

body {
  font-family: 'Noto Sans JP', 'Plus Jakarta Sans', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  word-break: auto-phrase;
}

/* --------------------------------------------------------------------------
   App Header (操作画面)
   -------------------------------------------------------------------------- */
.app-header {
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1.5rem;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1800px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  font-size: 2rem;
  color: var(--accent-blue-light);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.app-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

/* ボタン共通 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue-hover);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  background: var(--accent-blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--border-light);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-danger-soft {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger-soft:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent-blue-light);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --------------------------------------------------------------------------
   Main Layout
   -------------------------------------------------------------------------- */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 61px);
}

/* エディタペイン (左) */
.editor-pane {
  width: 500px;
  background: var(--bg-pane);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* 請求書 / 領収書 切替タブ */
.doc-type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(15, 23, 42, 0.6);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.type-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.type-tab.active {
  background: var(--accent-blue);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.form-sections {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-card {
  background: rgba(51, 65, 85, 0.4);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1.25rem;
}

.form-card .card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.form-card .card-header-flex .card-title {
  margin-bottom: 0;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title i {
  color: var(--accent-blue-light);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

label .required {
  color: #f87171;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  color: #ffffff;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

textarea {
  resize: vertical;
}

/* 明細リスト編集 */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-row-edit {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.75rem;
}

.item-row-edit .item-row-top {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.item-row-edit .item-row-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr auto;
  gap: 0.5rem;
  align-items: center;
}

.item-row-edit .btn-remove-item {
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  padding: 0.25rem;
}

.item-row-edit .btn-remove-item:hover {
  color: #ef4444;
}

/* 電子印鑑ラジオボタングループ */
.stamp-controls {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.file-input-hidden {
  display: none;
}

.form-checkbox-group {
  margin-top: 0.75rem;
}

.form-checkbox-group .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: #cbd5e1;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Preview Pane (右側：A4リアルタイムプレビュー)
   -------------------------------------------------------------------------- */
.preview-pane {
  flex: 1;
  background: #0b1120;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-toolbar {
  width: var(--a4-width);
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* A4用紙ラッパー */
.a4-wrapper {
  perspective: 1000px;
}

.a4-document {
  width: var(--a4-width);
  height: 295mm;
  max-height: 295mm;
  box-sizing: border-box;
  background: #ffffff;
  color: #111827;
  padding: 16mm 20mm 14mm 20mm;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transform-origin: top center;
  transition: transform 0.2s ease;
  font-size: 9.2pt;
  line-height: 1.55;
  overflow: hidden;
}

/* 1. タイトル ＆ 下線ライン (公式PDF再現) */
.doc-top-bar {
  text-align: center;
  margin-bottom: 28px;
}

.doc-center-title {
  font-size: 24pt;
  font-weight: 700;
  letter-spacing: 0.5em;
  color: var(--doc-dark);
  margin-bottom: 10px;
}

.doc-title-line {
  width: 100%;
  height: 2px;
  background-color: var(--doc-dark);
}

/* 2. ヘッダー2カラムレイアウト */
.doc-header-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 26px;
  margin-bottom: 24px;
}

/* 左カラム：宛名・挨拶・金額 */
.header-col-left {
  display: flex;
  flex-direction: column;
}

.recipient-area {
  margin-bottom: 14px;
}

.recipient-name {
  font-size: 15pt;
  font-weight: 700;
  color: var(--doc-dark);
}

.recipient-honorific {
  font-size: 12.5pt;
  font-weight: 600;
  margin-left: 8px;
}

.greeting-text {
  font-size: 8.5pt;
  color: #4b5563;
  line-height: 1.65;
  margin-bottom: 14px;
}

/* ご請求・ご領収金額ボックス（純粋なグレー＆ホワイトの洗練モノトーン） */
.amount-box {
  background: var(--doc-gray-sub);
  border: 1px solid var(--doc-border);
  border-radius: 4px;
  padding: 13px 18px;
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}

.amount-main-row {
  display: flex;
  align-items: baseline;
}

.amount-title {
  font-size: 9.5pt;
  font-weight: 700;
  color: var(--doc-slate);
  margin-right: 18px;
}

.amount-symbol {
  font-size: 14.5pt;
  font-weight: 700;
  color: var(--doc-dark);
  margin-right: 4px;
}

.amount-number {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 20.5pt;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--doc-dark);
}

.amount-hyphen {
  font-size: 14.5pt;
  font-weight: 700;
  color: var(--doc-dark);
  margin: 0 4px;
}

.amount-tax-tag {
  font-size: 8.5pt;
  color: #64748b;
  margin-left: 6px;
}

/* 領収書時の一体化メタ情報（但し書き・支払方法） */
.receipt-meta-box {
  border-top: 1px dashed var(--doc-border);
  padding-top: 8px;
  margin-top: 8px;
  font-size: 8.5pt;
}

.receipt-meta-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.receipt-meta-row:last-child {
  margin-bottom: 0;
}

.rm-label {
  font-weight: 700;
  color: var(--doc-slate);
  white-space: nowrap;
  min-width: 68px;
}

.rm-value {
  color: var(--doc-dark);
  font-weight: 500;
}

/* 右カラム：メタ情報 ＆ 発行者（石原 準也） */
.header-col-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.meta-data-list {
  font-size: 8.5pt;
  margin-bottom: 14px;
}

.meta-item {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  line-height: 1.7;
}

.meta-label {
  color: #4b5563;
}

.meta-value {
  color: #111827;
  font-weight: 600;
}

/* 発行者情報ボックス ＆ 印鑑配置 */
.issuer-info-box {
  font-size: 8.5pt;
  color: #374151;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.issuer-name-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 8px;
  position: relative;
}

.issuer-brand {
  font-size: 11pt;
  font-weight: 700;
  color: #1e3a8a;
  margin-right: -2px;
}

.issuer-name {
  font-size: 15pt;
  font-weight: 700;
  color: #111827;
  letter-spacing: 0.12em;
}

/* 印鑑コンテナ（名前のすぐ横にリアルに押印） */
.stamp-container {
  width: 44px;
  height: 44px;
  position: relative;
  display: inline-block;
  vertical-align: middle;
}

.stamp-circle-hanko {
  width: 44px;
  height: 44px;
}

.hanko-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-3deg);
}

.custom-stamp-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  transform: rotate(-3deg);
}

.issuer-contact-lines {
  line-height: 1.55;
  color: #4b5563;
}

/* 3. 明細セクション (公式PDF再現) */
.items-section {
  margin-bottom: 22px;
}

.section-badge-title {
  font-size: 9.5pt;
  font-weight: 700;
  color: #111827;
  margin-bottom: 8px;
}

.details-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.details-table th {
  background-color: var(--doc-th-bg);
  border-top: 1px solid var(--doc-border);
  border-bottom: 1px solid var(--doc-border);
  border-left: none;
  border-right: none;
  padding: 8px 10px;
  font-weight: 700;
  color: var(--doc-dark);
}

.details-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--doc-border);
  color: var(--doc-dark);
  vertical-align: top;
}

.col-no { width: 5%; text-align: center; }
.col-desc { width: 53%; text-align: left; }
.col-qty { width: 8%; text-align: center; }
.col-unit { width: 8%; text-align: center; }
.col-price { width: 13%; text-align: right; }
.col-amount { width: 13%; text-align: right; }

.td-no, .td-qty, .td-unit { text-align: center; }
.td-price, .td-amount { 
  text-align: right; 
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 600;
}

.item-main-title {
  font-size: 9pt;
  font-weight: 700;
  color: #111827;
}

.item-sub-desc {
  font-size: 8pt;
  color: #6b7280;
  margin-top: 3px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* 4. 税計算・合計ブロック (公式PDF再現) */
.calculation-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 24px;
  margin-bottom: 22px;
}

.tax-breakdown-left {
  font-size: 8.5pt;
  color: #374151;
}

.cb-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.cb-row {
  display: flex;
  justify-content: space-between;
  width: 200px;
  line-height: 1.8;
}

.tax-totals-right {
  display: flex;
  flex-direction: column;
  font-size: 8.5pt;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  line-height: 1.8;
  color: #374151;
}

.calc-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 600;
}

.calc-grand-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 11pt;
  font-weight: 700;
  color: #111827;
  border-top: 1.5px solid #111827;
  border-bottom: 1.5px solid #111827;
  padding: 6px 0;
  margin-top: 5px;
}

.gt-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13pt;
}

/* 5. お振込先口座情報 & 領収書お支払確認情報 */
.bank-section,
.receipt-section {
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  margin-bottom: 22px;
}

.bank-header-bar,
.receipt-header-bar {
  background-color: var(--doc-slate);
  color: #ffffff;
  font-size: 8.5pt;
  font-weight: 700;
  padding: 6px 12px;
}

.bank-table-container,
.receipt-table-container {
  padding: 8px 12px;
}

.bank-info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.bank-info-table td {
  padding: 5px 8px;
  line-height: 1.5;
}

.b-lbl {
  width: 15%;
  color: #4b5563;
  font-weight: 500;
}

.b-val {
  width: 35%;
  color: #111827;
  font-weight: 600;
}

.bank-notes {
  padding: 6px 12px 7px 12px;
  font-size: 7.5pt;
  color: #6b7280;
  line-height: 1.55;
  border-top: 1px dashed #e2e8f0;
}

/* 6. 備考欄 (公式PDF再現) */
.remarks-section {
  border: 1px solid #e2e8f0;
  border-radius: 3px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 8pt;
  color: #4b5563;
  line-height: 1.6;
}

.rem-title {
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 4px;
}

.rem-content {
  white-space: pre-wrap;
}

/* 7. フッター */
.doc-bottom-footer {
  display: flex;
  justify-content: space-between;
  font-size: 8pt;
  color: #6b7280;
  border-top: 1px solid #f1f5f9;
  padding-top: 8px;
  margin-top: auto;
}

/* --------------------------------------------------------------------------
   Modal Styles (履歴一覧)
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-card {
  background: var(--bg-pane);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-soft);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #ffffff;
}

.modal-header h2 i {
  color: var(--accent-blue-light);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close-btn:hover {
  color: #ffffff;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.history-actions {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.search-input {
  max-width: 300px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th {
  background: rgba(15, 23, 42, 0.6);
  padding: 0.75rem 1rem;
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
}

.history-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
}

.history-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-invoice {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(37, 99, 235, 0.4);
}

.badge-receipt {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

/* --------------------------------------------------------------------------
   @media print (A4 1ページ完全出力設定)
   -------------------------------------------------------------------------- */
@media print {
  .no-print {
    display: none !important;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }

  html, body {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    overflow: hidden !important;
  }

  .main-layout {
    height: auto !important;
    display: block !important;
    overflow: visible !important;
  }

  .preview-pane {
    background: #ffffff !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  .a4-wrapper {
    perspective: none !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .a4-document {
    width: 210mm !important;
    height: 295mm !important;
    max-height: 295mm !important;
    box-shadow: none !important;
    padding: 16mm 20mm 14mm 20mm !important;
    margin: 0 auto !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-after: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
}
