/* 星の杜中学校高等学校 保護者の会 経費申請・会計管理システム */
:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e8f0fe;
  --secondary: #3f83f8;
  --bg: #f0f4ff;
  --surface: #ffffff;
  --border: #d1daf5;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
}

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

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* === ログイン === */
#loginOverlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-md);
}
.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
  margin-bottom: 8px;
}
.login-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; font-size: 15px; }
.login-logo {
  text-align: center;
  font-size: 40px;
  margin-bottom: 12px;
}

/* === ヘッダー === */
#appHeader {
  background: var(--primary-dark);
  color: white;
  padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
#appHeader h1 { font-size: 18px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 14px; opacity: 0.9; }
.btn-logout {
  background: rgba(255,255,255,0.15);
  color: white; border: 1px solid rgba(255,255,255,0.3);
  padding: 5px 12px; border-radius: 4px;
  cursor: pointer; font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* === タブバッジ === */
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: #ef4444; color: white;
  font-size: 11px; font-weight: 800;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  margin-left: 5px;
  vertical-align: middle;
  animation: badgePop 0.2s ease;
}
@keyframes badgePop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* === タブナビ === */
.tab-nav {
  background: var(--primary);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }
.tab-btn {
  color: rgba(255,255,255,0.75);
  border: none; background: none;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}
.tab-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.tab-btn.active { color: white; border-bottom-color: white; }

/* === メインコンテンツ === */
#appContent { padding: 20px; max-width: 1200px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === カード === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-light);
}

/* === フォーム === */
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }
label { display: block; font-size: 14px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
label .req { color: var(--danger); margin-left: 2px; }
input[type="text"], input[type="password"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 16px;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.15);
}
input[readonly] { background: #f8fafc; color: var(--text-muted); }
textarea { resize: vertical; min-height: 60px; }

/* === ボタン === */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: none; border-radius: 6px;
  padding: 9px 18px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline {
  background: white; color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { display: flex; width: 100%; }

/* === テーブル === */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
thead th {
  background: var(--primary-dark);
  color: white;
  padding: 11px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky; top: 0;
}
tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:hover { background: var(--primary-light); }
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
.no-data { text-align: center; padding: 40px; color: var(--text-muted); font-size: 15px; }

/* === ステータスバッジ === */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-submitted { background: #dbeafe; color: #1d4ed8; }
.badge-paid      { background: var(--warning-bg); color: #92400e; }
.badge-received  { background: var(--success-bg); color: #14532d; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
.badge-active    { background: var(--success-bg); color: #14532d; }
.badge-closed    { background: #f1f5f9; color: #64748b; }
.badge-reopened  { background: var(--warning-bg); color: #92400e; }
.badge-income    { background: #dbeafe; color: #1d4ed8; }
.badge-expense   { background: #fce7f3; color: #9d174d; }

/* === フィルターバー === */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar .form-group { margin-bottom: 0; min-width: 120px; }
.filter-bar label { font-size: 13px; }

/* === 現在残高バー === */
.balance-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: white; border: 1px solid var(--border);
  padding: 10px 16px; border-radius: var(--radius);
  margin-bottom: 12px;
}
.balance-bar .balance-label { font-size: 14px; color: var(--text-muted); }
.balance-bar .balance-amount { font-size: 22px; font-weight: 800; color: var(--primary); letter-spacing: 0.02em; }

/* === モーダル === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px;
  z-index: 3000;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%; max-width: 800px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  margin: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 16px; font-weight: 700; color: var(--primary-dark); }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--text-muted); line-height: 1;
  padding: 4px;
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* === 明細テーブル（申請フォーム内） === */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 8px 8px;
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
}
.items-table td { padding: 5px; vertical-align: top; }
.items-table input, .items-table select { font-size: 15px; padding: 8px; }
.item-amount-display { text-align: right; font-weight: 600; color: var(--primary); }

/* === 合計表示 === */
.total-section {
  display: flex; justify-content: flex-end; align-items: center; gap: 12px;
  padding: 12px 0; margin-top: 8px;
  border-top: 2px solid var(--primary-light);
}
.total-label { font-weight: 700; font-size: 18px; }
.total-amount { font-size: 32px; font-weight: 800; color: var(--primary); }

/* === 残高表示 === */
.balance-positive { color: var(--success); }
.balance-negative { color: var(--danger); }

/* === トースト通知 === */
#toastContainer {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  color: white;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  min-width: 200px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === スピナー === */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000;
}

/* === アクション行 === */
.action-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}

/* === 決算書 === */
.closing-report-table th { background: var(--primary-dark); }
.closing-report-total {
  font-weight: 800;
  background: var(--primary-light) !important;
}

/* === 操作ログ === */
.log-action { font-size: 11px; font-family: monospace; }

/* === エラー表示 === */
.error-msg { color: var(--danger); font-size: 12px; margin-top: 4px; }
.alert {
  padding: 12px 16px; border-radius: 6px;
  margin-bottom: 12px; font-size: 13px;
}
.alert-warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fde68a; }
.alert-danger { background: var(--danger-bg); color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: var(--success-bg); color: #14532d; border: 1px solid #86efac; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #bfdbfe; }

/* === 印刷スタイル === */
@media print {
  #appHeader, .tab-nav, .action-bar, .filter-bar, .btn,
  .modal-footer, #toastContainer, .no-print { display: none !important; }
  body { background: white; font-size: 11px; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  table { font-size: 11px; }
  thead th { background: #eee !important; color: black !important; print-color-adjust: exact; }
  .tab-panel { display: block !important; }
}

/* === レスポンシブ === */
@media (max-width: 640px) {
  #appContent { padding: 12px; }
  .card { padding: 14px; }
  .modal { max-width: 100%; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 12px 12px 0 0; }
  .form-row { flex-direction: column; }
  .form-row .form-group { min-width: 0; }
  .total-amount { font-size: 26px; }
}

/* === 領収書プレビュー === */
.receipt-thumb {
  width: 80px; height: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.receipt-preview-large {
  max-width: 100%; max-height: 500px;
  display: block; margin: 0 auto;
  border-radius: 4px;
}

/* === 数値入力 === */
input[type="number"] { text-align: right; }

/* === ページタイトル === */
.page-title {
  font-size: 18px; font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.page-title-icon { font-size: 22px; }

/* === グリッド === */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-card-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.summary-card-value { font-size: 24px; font-weight: 800; color: var(--primary); }
.summary-card-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
