/* ─── Seique 基本スタイル ───
   フォント: Noto Sans JP（Google Fonts経由）
   配色: Misoca風のニュートラルなUI
*/

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #2c3e50;
  --text-muted: #6c7a89;
  --border: #e1e6ed;
  --border-strong: #cdd5df;
  --primary: #2980b9;
  --primary-dark: #1f6391;
  --primary-soft: #eaf3fa;
  --success: #1e7e34;
  --success-bg: #e8f8ee;
  --danger: #b03a3a;
  --danger-bg: #fde8e8;
  --warning-bg: #fff4d4;
  --sidebar-bg: #2c3e50;
  --sidebar-bg-active: #34495e;
  --sidebar-text: #ecf0f1;
  --sidebar-text-muted: #95a5a6;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.06);
  --radius: 6px;
  --radius-sm: 4px;
  --sidebar-width: 200px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Hiragino Sans", "ヒラギノ角ゴ ProN", "Yu Gothic", YuGothic, Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── サイドバー ─── */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}

.brand {
  padding: 20px 24px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, #3498db, #2980b9);
  color: white;
  font-weight: 700;
}
.brand-name { color: white; }

.sidebar nav { display: flex; flex-direction: column; padding: 8px 0; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-text-muted);
  padding: 10px 24px;
  font-size: 14px;
  border-left: 3px solid transparent;
  text-decoration: none;
  transition: all 0.1s;
}
.sidebar nav a:hover { background: var(--sidebar-bg-active); color: white; }
.sidebar nav a.active {
  background: var(--sidebar-bg-active);
  color: white;
  border-left-color: var(--primary);
  font-weight: 500;
}

.sidebar-footer { padding: 16px 24px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-footer .logout {
  color: var(--sidebar-text-muted);
  font-size: 13px;
}

/* ─── メイン領域 ─── */

.main {
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ─── カード ─── */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px 0; font-size: 16px; font-weight: 700; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

/* ─── ボタン ─── */

.btn-primary, .btn-secondary, button.btn-primary, button.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: #f8f9fa; text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; padding: 12px; }

.btn-link {
  background: transparent;
  border: 0;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  padding: 6px 8px;
}
.btn-link.btn-danger { color: var(--danger); }
.btn-link:hover { text-decoration: underline; }

.btn-icon {
  background: transparent;
  border: 0;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.btn-icon:hover { color: var(--danger); }

/* ─── フォーム ─── */

.form .card { padding: 24px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid label.col-3 { grid-column: span 1; }

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-grid label > span:first-child {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.form-grid label em {
  display: inline-block;
  font-size: 11px;
  background: #ff9800;
  color: white;
  padding: 1px 6px;
  border-radius: 2px;
  margin-left: 4px;
  font-style: normal;
}

input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], input[type=search],
select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
input[type=file] {
  font: inherit;
  font-size: 13px;
}
textarea { resize: vertical; min-height: 60px; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px 0;
}
.form-hint code {
  background: #f1f3f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.form-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .form-2col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}

.readonly-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 13px;
}
.readonly-list dt { color: var(--text-muted); }
.readonly-list dd { margin: 0; }

.image-preview { margin: 8px 0; }
.image-preview img { max-width: 200px; max-height: 80px; border: 1px solid var(--border); padding: 4px; background: white; }

/* ─── テーブル ─── */

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.list-table th {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.list-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.list-table tr:hover { background: #f9fafb; cursor: pointer; }
.list-table tr:last-child td { border-bottom: 0; }
.list-table th.num, .list-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.list-table th.actions, .list-table td.actions { text-align: right; white-space: nowrap; }
.list-table td.actions a { margin-right: 8px; }

.muted { color: var(--text-muted); }

/* ─── ホーム ─── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.1s;
}
.stat-card:hover { border-color: var(--primary); text-decoration: none; }
.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { font-size: 30px; font-weight: 700; margin-top: 4px; }
.stat-unit { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 6px; }

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .card-grid { grid-template-columns: 1fr; } .stats-grid { grid-template-columns: 1fr; } }

.empty {
  color: var(--text-muted);
  font-size: 13px;
  margin: 16px 0 4px 0;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: white;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-state p { margin-bottom: 16px; color: var(--text-muted); }

/* ─── 検索バー ─── */

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input { max-width: 360px; }

/* ─── フラッシュメッセージ ─── */

.flash {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #c3e6cb; }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f5c6cb; }

/* ─── ログイン画面 ─── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f0f4f8;
}
.login-card {
  background: white;
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.login-brand h1 { margin: 0; font-size: 28px; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin: 0 0 24px 0; }
.login-card label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.login-card .btn-primary { margin-top: 16px; }

/* ─── 明細編集 ─── */

.line-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.line-items th {
  background: #f5f7fa;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.line-items td {
  padding: 4px;
  border-bottom: 1px solid var(--border);
}
.line-items input, .line-items select {
  padding: 6px 8px;
  font-size: 13px;
}
.line-items td.num { text-align: right; padding: 8px 12px; font-variant-numeric: tabular-nums; }

.li-date  { width: 110px; }
.li-qty   { width: 70px; }
.li-unit  { width: 70px; }
.li-price { width: 100px; }
.li-tax   { width: 80px; }
.li-amount { width: 110px; text-align: right; }

.line-items-actions {
  margin: 12px 0;
}

.totals {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}
.totals table { border-collapse: collapse; min-width: 240px; }
.totals th { text-align: left; padding: 6px 16px 6px 0; font-weight: 500; color: var(--text-muted); }
.totals td { text-align: right; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals tr.total-row th { font-weight: 700; color: var(--text); font-size: 16px; padding-top: 10px; border-top: 1px solid var(--border); }
.totals tr.total-row td { font-weight: 700; font-size: 18px; padding-top: 10px; border-top: 1px solid var(--border); }

.client-picker { display: flex; gap: 8px; }
.client-picker select { flex: 1; }

.meta-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 16px;
  margin: 0 0 24px 0;
  font-size: 13px;
}
.meta-list dt { color: var(--text-muted); }
.meta-list dd { margin: 0; }

/* ─── ドキュメントプレビュー ───
   Misoca風のフォーマット
   .doc-paper は印刷時にA4一枚に収まることを意図
*/

.doc-frame {
  background: #eef3f7;
  padding: 24px;
  border-radius: var(--radius);
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

.doc-paper {
  background: white;
  width: 100%;
  max-width: 760px;
  padding: 48px 56px;
  font-family: 'Noto Sans JP', "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 12px;
  line-height: 1.6;
  color: #1a1a1a;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  position: relative;
}

.doc-meta {
  position: absolute;
  top: 32px;
  right: 56px;
  text-align: right;
  font-size: 11px;
}
.doc-meta-line { display: flex; gap: 12px; justify-content: flex-end; align-items: baseline; }
.doc-meta-label { color: #555; font-size: 10px; }

.doc-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-align: center;
  margin: 32px 0 36px 0;
  padding-bottom: 0;
}

.doc-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 32px;
  margin-bottom: 28px;
}

.doc-client-postal { font-size: 11px; color: #444; }
.doc-client-address { font-size: 11px; color: #444; margin-bottom: 4px; }
.doc-client-dept { font-size: 12px; }
.doc-client-name {
  font-size: 18px;
  font-weight: 700;
  margin: 4px 0 4px 0;
  padding-bottom: 6px;
  border-bottom: 1.5px solid #1a1a1a;
}
.doc-client-honorific { font-size: 16px; margin-left: 6px; }
.doc-client-contact { font-size: 12px; margin-bottom: 10px; }

.doc-subject { font-size: 12px; margin: 16px 0 6px 0; }
.doc-subject-label { color: #555; }
.doc-leadin { margin: 4px 0 12px 0; font-size: 12px; }

.doc-amount {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid #1a1a1a;
  padding-bottom: 6px;
  margin-top: 8px;
}
.doc-amount-label { font-size: 13px; font-weight: 700; }
.doc-amount-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.doc-due { margin-top: 8px; font-size: 12px; }

.doc-issuer {
  font-size: 11px;
  position: relative;
}
.doc-logo { margin-bottom: 12px; }
.doc-logo img { max-width: 200px; max-height: 50px; }
.doc-issuer-block {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.doc-issuer-info { flex: 1; }
.doc-issuer-company { font-size: 13px; font-weight: 700; }
.doc-issuer-rep { font-size: 11px; }
.doc-issuer-invreg { margin-top: 4px; font-size: 10px; color: #555; }
.doc-seal { width: 64px; flex-shrink: 0; }
.doc-seal img { width: 64px; height: 64px; object-fit: contain; mix-blend-mode: multiply; }

.doc-items {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.doc-items th, .doc-items td {
  border: 1px solid #1a1a1a;
  padding: 6px 8px;
}
.doc-items thead th {
  background: #f0f0f0;
  font-weight: 700;
  text-align: center;
}
.doc-items .col-desc { text-align: left; min-width: 200px; }
.doc-items .col-qty, .doc-items .col-unit { text-align: center; width: 60px; }
.doc-items .col-price, .doc-items .col-amount { text-align: right; width: 90px; }
.doc-items td.num { text-align: right; }

.doc-items tfoot th { text-align: right; font-weight: 500; background: #fafafa; }
.doc-items tfoot td { text-align: right; }
.doc-items tfoot tr.total-row th, .doc-items tfoot tr.total-row td {
  font-weight: 700;
  font-size: 13px;
  background: #fafafa;
}

.doc-notes {
  margin: 24px 0 8px 0;
  font-size: 11px;
  white-space: pre-wrap;
}

.doc-bank {
  margin-top: 24px;
  font-size: 11px;
}
.doc-bank-label { font-weight: 700; }
.doc-bank-info { white-space: pre-wrap; }
