/* ============================================================
   style.css - 契約管理システム スタイルシート
   ============================================================ */

/* ---------- CSS変数 ---------- */
:root {
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.125rem;
  --font-size-xl:   1.25rem;
  --font-family:    'Noto Sans JP', sans-serif;
  --radius-sm:  8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --bg-base:       #f1f5f9;
  --bg-surface:    #ffffff;
  --text-primary:  #0f172a;
  --text-secondary:#64748b;
  --border:        #e2e8f0;
  --accent:        #3bb8eb;
  --color-success: #10b981;
  --color-danger:  #ef4444;
}
:root[data-theme="dark"] {
  --bg-base: #0f172a; --bg-surface: #1e293b;
  --text-primary: #f8fafc; --text-secondary: #94a3b8;
  --border: #334155; --accent: #6366f1;
}
:root[data-theme="ocean"] {
  --bg-base: #082f49; --bg-surface: #0c4a6e;
  --text-primary: #f0f9ff; --text-secondary: #7dd3fc;
  --border: #0369a1; --accent: #0ea5e9;
}

/* ---------- ベース ---------- */
* { box-sizing: border-box; }
body {
  font-family: var(--font-family);
  background: var(--bg-base);
  color: var(--text-primary);
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.container {
  max-width: 1400px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  width: 100%;
}

/* ---------- ログイン ---------- */
#view-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}
.login-card {
  background: var(--bg-surface);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 25px rgba(0,0,0,0.05);
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--border);
  text-align: center;
}
.login-card .material-icons { font-size: 48px; color: var(--accent); margin-bottom: 16px; }
.login-card h1 { margin: 0 0 24px 0; color: var(--text-primary); font-size: 1.5rem; }
.login-card .input-group { text-align: left; margin-bottom: 16px; }
.login-card button { width: 100%; padding: 12px; font-size: 1.1rem; margin-top: 16px; }

/* ---------- ヘッダー ---------- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 24px;
  border: 1px solid var(--border);
}
.header__brand { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.header__logo  { color: var(--accent); display: flex; align-items: center; font-size: 2rem; }
.header__title { font-size: var(--font-size-xl); font-weight: 700; letter-spacing: 1px; }
.header__user  {
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-base);
  padding: 6px 12px;
  border-radius: 20px;
}
.logout-btn {
  background: transparent;
  border: none;
  color: var(--color-danger);
  cursor: pointer;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: 0.2s;
}
.logout-btn:hover { background: #fee2e2; }

/* ---------- 共通ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  gap: 4px;
  transition: 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; box-shadow: 0 2px 4px rgba(59,184,235,0.3); }
.btn--primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn--ghost   { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn--ghost:hover { background: rgba(0,0,0,0.05); }
.btn--success { background: #d1fae5; color: var(--color-success); border: 1px solid #a7f3d0; }
.btn--danger  { background: #fee2e2; color: var(--color-danger);  border: 1px solid #fecaca; }

/* ---------- テーブル ---------- */
.table-container {
  overflow-x: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.data-table { width: 100%; border-collapse: collapse; text-align: left; font-size: var(--font-size-sm); }
.data-table th, .data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap; /* 基本はnowrap、個別セルでnormalに上書き */
}
/* 折り返しを許可するセル */
.data-table td.wrap { white-space: normal; }
.data-table th { background: rgba(0,0,0,0.02); color: var(--text-secondary); font-weight: 700; }
.data-table tbody tr { transition: background 0.2s; }
.data-table tbody tr:hover { background: rgba(59,184,235,0.03); }

.prop-type-badge {
  display: inline-block;
  background: #e2e8f0;
  color: #475569;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
  margin-bottom: 4px;
}

/* ---------- テーブル内ステッパー ---------- */
.table-stepper { display: flex; align-items: center; justify-content: center; width: fit-content; margin: 0 auto; }
.ts-step {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: bold;
  position: relative; z-index: 2;
  border: 2px solid var(--bg-surface);
  transition: 0.3s;
}
.ts-step.active    { background: var(--accent); box-shadow: 0 0 0 2px rgba(59,184,235,0.3); }
.ts-step.completed { background: var(--color-success); }
.ts-step.cancelled { background: #e5e7eb; color: #9ca3af; }
.ts-line           { height: 3px; width: 16px; background: #e2e8f0; margin: 0 -2px; z-index: 1; transition: 0.3s; }
.ts-line.completed { background: var(--color-success); }

/* ---------- 統合リストパネル（タイトル＋検索を一体化） ---------- */
.list-panel {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 16px;
  overflow: hidden;
}
/* タイトル行 */
.list-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-surface);
}
.list-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.list-panel-title h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}
.list-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* 検索ボックス行 */
.list-panel-search {
  padding: 14px 20px;
}
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.search-input-wrapper .material-icons {
  position: absolute;
  left: 14px;
  color: var(--text-secondary);
  pointer-events: none;
  font-size: 20px;
}
.search-input-wrapper input {
  width: 100%;
  padding-left: 46px;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  transition: 0.2s;
  background: var(--bg-base);
  color: var(--text-primary);
}
.search-input-wrapper input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,184,235,0.15);
  background: var(--bg-surface);
}
/* フィルタトグルボタン */
.filter-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-base);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  white-space: nowrap;
  height: 38px;
}
.filter-toggle-btn:hover { background: rgba(59,184,235,0.08); border-color: var(--accent); color: var(--accent); }
.filter-toggle-btn.active { background: rgba(59,184,235,0.1); border-color: var(--accent); color: var(--accent); }
.filter-toggle-btn .material-icons { font-size: 17px; }
.filter-toggle-btn.active .filter-arrow { transform: rotate(180deg); }
.filter-active-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 0 5px;
}
/* 折りたたみフィルタ領域 */
.search-filters-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.search-filters-panel.open {
  max-height: 320px;
  border-top: 1px solid var(--border);
}
.search-filters-inner {
  padding: 14px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-base);
}
.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.filter-row select {
  flex: 1;
  min-width: 130px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  padding: 0 10px;
  color: var(--text-primary);
  background: var(--bg-surface);
  cursor: pointer;
  transition: 0.2s;
}
.filter-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,184,235,0.15); }
.filter-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  background: var(--bg-surface);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.filter-clear-btn {
  font-size: 12px;
  color: var(--color-danger);
  background: transparent;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.2s;
  font-weight: 600;
  height: 36px;
}
.filter-clear-btn:hover { background: #fee2e2; }
/* 結果カウント帯 */
.search-result-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: var(--bg-base);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.search-result-count { font-weight: 700; color: var(--text-primary); }
/* ---- 入金予定モーダル ---- */
#payment-schedule-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 7000;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.payment-schedule-modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 820px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
  margin: auto;
}
.psm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.psm-header h3 { margin: 0; font-size: 1.1rem; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.psm-body { padding: 20px 24px; }
.psm-month-card { border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 12px; overflow: hidden; }
.psm-month-header {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--bg-base); cursor: pointer; user-select: none; transition: 0.15s;
}
.psm-month-header:hover { background: rgba(59,184,235,0.06); }
.psm-month-label { font-size: 1rem; font-weight: 700; color: var(--text-primary); flex: 1; }
.psm-month-count { font-size: 12px; background: #e0f2fe; color: #0369a1; padding: 2px 10px; border-radius: 12px; font-weight: 600; }
.psm-month-fee { font-size: 1rem; font-weight: 700; color: var(--accent); font-family: 'BIZ UDPGothic', monospace; }
.psm-month-fee span { font-size: 11px; font-weight: 400; color: var(--text-secondary); margin-left: 2px; }
.psm-month-arrow { font-size: 18px; color: var(--text-secondary); transition: transform 0.2s; }
.psm-month-arrow.open { transform: rotate(180deg); }
.psm-contracts { display: none; }
.psm-contracts.open { display: block; }
.psm-contract-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-top: 1px solid var(--border); font-size: 13px;
}
.psm-contract-row:hover { background: rgba(59,184,235,0.03); }
.psm-contract-name { flex: 1; font-weight: 600; color: var(--accent); }
.psm-contract-date { color: var(--text-secondary); white-space: nowrap; }
.psm-contract-fee  { font-family: 'BIZ UDPGothic', monospace; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.psm-total-bar {
  background: linear-gradient(135deg, #e0f2fe, #bae6fd);
  border-radius: var(--radius-md); padding: 16px 20px; margin-bottom: 16px;
  display: flex; gap: 24px; flex-wrap: wrap; align-items: center;
}
.psm-total-item { text-align: center; }
.psm-total-item .label { font-size: 11px; color: #0369a1; font-weight: 600; }
.psm-total-item .value { font-size: 1.25rem; font-weight: 700; color: #0c4a6e; font-family: 'BIZ UDPGothic', monospace; }

/* ---------- ビューヘッダー ---------- */
.view-header-card {
  background: var(--bg-surface);
  padding: 16px 24px;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
}
.view-header-card h2 { margin: 0; font-size: 1.5rem; color: var(--accent); display: flex; align-items: center; gap: 8px; }

/* ---------- タブ ---------- */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--border);
}
.tab-btn {
  padding: 12px 24px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: bold;
  font-size: 1rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: 0.2s;
  border-radius: 8px 8px 0 0;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--bg-surface); }
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- フォーム ---------- */
.form-section {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  border: 1px solid var(--border);
}
.form-section h3 {
  font-size: 1.1rem;
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section h3::before {
  content: '';
  display: block;
  width: 4px;
  height: 1.2em;
  background: var(--accent);
  border-radius: 2px;
}
.form-grid        { display: grid; grid-template-columns: 1fr 1fr;           gap: 20px 24px; margin-bottom: 20px; }
.form-grid.full   { grid-template-columns: 1fr; }
.form-grid.triple { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.quad   { grid-template-columns: 1fr 1fr 1fr 1fr; }

.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-secondary);
}
input:not([type="checkbox"]), select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px;
  transition: 0.2s;
}
input:not([type="checkbox"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(59,184,235,0.2);
}
input:read-only, input:disabled, select:disabled, textarea:disabled {
  background: #e2e8f0;
  color: #475569;
  border-style: dashed;
  cursor: not-allowed;
}
input.num-input {
  text-align: right;
  font-family: 'BIZ UDPGothic', monospace, sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}
.input-with-unit { display: flex; align-items: center; gap: 8px; }
.input-with-unit input { flex: 1; }

/* ---------- サービス行 ---------- */
.service-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.service-row:last-child { border-bottom: none; }
.service-row label { width: 180px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.service-row input[type="text"] { flex: 1; background: transparent; border: 1px dashed var(--border); padding: 8px; }

/* ---------- フォームアクション（固定フッター） ---------- */
.form-actions-fixed {
  position: sticky;
  bottom: 16px;
  background: var(--bg-surface);
  padding: 16px 24px;
  border-radius: var(--radius-md);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
  border: 1px solid var(--border);
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  gap: 16px;
}

/* ---------- アコーディオン ---------- */
details summary {
  padding: 16px;
  background: rgba(0,0,0,0.02);
  border-radius: 8px;
  font-weight: bold;
  color: var(--accent);
  cursor: pointer;
  outline: none;
  border: 1px solid var(--border);
}
.advanced-content {
  padding: 24px;
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}
.sub-accordion { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 16px; }
.sub-accordion summary {
  padding: 10px 16px;
  background: rgba(0,0,0,0.03);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  margin: 0;
}
.sub-accordion .sub-content {
  padding: 16px;
  background: var(--bg-surface);
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.flex-container { display: flex; gap: 24px; margin-bottom: 24px; }

/* ---------- ロックバッジ ---------- */
.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fee2e2;
  color: #dc2626;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid #fecaca;
}

/* ---------- ローディング ---------- */
#global-loader {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s;
}
#global-loader.show { opacity: 1; visibility: visible; }
.loader-spinner {
  width: 60px; height: 60px;
  border: 5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}
.loader-text { font-size: 1.25rem; font-weight: bold; color: var(--text-primary); letter-spacing: 1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- トースト ---------- */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  padding: 16px 24px;
  border-radius: 8px;
  color: #fff;
  font-weight: bold;
  opacity: 0;
  transition: 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show    { opacity: 1; }
.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-danger); }
.toast.info    { background: var(--accent); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 768px) {
  .container { padding: 8px; }
  .header { flex-direction: column; align-items: flex-start; gap: 12px; padding: 12px; margin-bottom: 16px; }
  .view-header-card { flex-direction: column; align-items: flex-start; gap: 12px; padding: 12px; }
  .view-header-card button { width: 100%; justify-content: center; }
  .list-panel-header { flex-direction: column; align-items: flex-start; }
  .list-panel-actions { width: 100%; flex-wrap: wrap; }
  .list-panel-actions .btn, .list-panel-actions .filter-toggle-btn { flex: 1; justify-content: center; }
  .form-section { padding: 16px; margin-bottom: 16px; }
  .form-grid.triple, .form-grid.quad, .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-actions-fixed { flex-direction: column; padding: 12px; }
  .form-actions-fixed button { width: 100%; justify-content: center; margin: 0; }
  .flex-container { flex-direction: column; gap: 16px; }
  .tab-btn { padding: 10px 12px; font-size: 0.9rem; }
}