/* ========================================================
   styles.css — サポートデスク 問い合わせ管理
   ======================================================== */

:root {
  --primary: #0f62fe;
  --primary-dark: #0043ce;
  --primary-light: #e8f0fe;
  --danger: #dc3545;
  --success: #198754;
  --warning: #fd7e14;
  --bg: #f4f6f9;
  --sidebar-bg: #1a1a2e;
  --sidebar-w: 220px;
  --header-h: 56px;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --card-bg: #fff;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.1);
}

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

body {
  font-family: "Segoe UI", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

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

#loginScreen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 3rem 2.5rem;
  width: 360px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.3rem;
}

.login-card p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
}

.login-card .login-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* ========================================================
   アプリ本体レイアウト
   ======================================================== */

#appScreen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ヘッダー */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}

.header-user {
  font-size: 0.85rem;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

/* サイドバー + コンテンツ */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* サイドナビ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  flex-shrink: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 1.5rem;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 0.95rem;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
}

.nav-icon { font-size: 1.1rem; }
.sidebar-spacer { flex: 1; }

/* メインコンテンツ */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.view { display: none; }

/* ========================================================
   共通コンポーネント
   ======================================================== */

/* カード */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-light);
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #e9ecef; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.15s;
}
.btn-icon:hover { background: #f0f0f0; }
.btn-icon.btn-danger:hover { background: #fde8e8; }

/* バッジ */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-cat {
  background: #4e79a7;
}
.badge-sub {
  display: inline-block;
  font-size: 0.73rem;
  color: #555;
  background: #f0f0f0;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  margin-top: 3px;
}

/* フォーム */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
}
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
  background: #fff;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 100px; }

.form-row {
  display: flex;
  gap: 1rem;
}
.form-row .form-group { flex: 1; }

/* ========================================================
   問い合わせ一覧
   ======================================================== */

.filter-bar {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.filter-grid .form-group { margin-bottom: 0; }

.filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.list-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.table-wrap {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: #f8f9fa;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
  font-size: 0.88rem;
}

.list-row:hover td { background: var(--primary-light); cursor: pointer; }

#listLoading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  display: none;
}

/* ========================================================
   フォーム画面
   ======================================================== */

.form-view-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form-view-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  flex: 1;
}

.form-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-width: 800px;
}

.form-footer {
  display: flex;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

/* ========================================================
   詳細画面
   ======================================================== */

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1rem;
}

.detail-item label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  display: block;
}
.detail-item .detail-val {
  font-size: 0.95rem;
  margin-top: 0.15rem;
}
.detail-item.full { grid-column: 1 / -1; }

.history-item {
  padding: 0.75rem;
  border-left: 3px solid var(--primary);
  background: #f8f9fa;
  border-radius: 0 6px 6px 0;
  margin-bottom: 0.75rem;
}
.history-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.history-content { font-size: 0.9rem; }

.note-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-top: 1rem;
}
.note-form textarea {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  min-height: 60px;
}
.note-form textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* ========================================================
   レポート画面
   ======================================================== */

.report-controls {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  text-align: center;
}

.kpi-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.kpi-value.danger { color: var(--danger); }
.kpi-value.success { color: var(--success); }

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* 棒グラフ */
.chart-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.chart-label {
  width: 170px;
  font-size: 0.82rem;
  text-align: right;
  flex-shrink: 0;
}
.chart-bar-wrap {
  flex: 1;
  height: 22px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}
.chart-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 2px;
}
.chart-val {
  width: 110px;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.rpt-list-table {
  font-size: 0.85rem;
}

/* ========================================================
   トースト通知
   ======================================================== */

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ========================================================
   グローバルローディング
   ======================================================== */

#globalLoading {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  flex-direction: column;
  gap: 0.75rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================
   長期未更新アラートブロック
   ======================================================== */

.stale-alert-block {
  border-radius: var(--radius);
  border: 2px solid #dc3545;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 16px rgba(220,53,69,0.2);
  overflow: hidden;
  animation: stale-pulse 2s ease-in-out infinite;
}

@keyframes stale-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(220,53,69,0.2); }
  50%       { box-shadow: 0 4px 24px rgba(220,53,69,0.45); }
}

.stale-alert-header {
  background: linear-gradient(135deg, #dc3545, #c0392b);
  color: #fff;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stale-badge {
  background: #fff;
  color: #dc3545;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 0.1rem 0.6rem;
  border-radius: 20px;
}

.stale-days {
  color: #dc3545;
  font-weight: 700;
  white-space: nowrap;
}

.stale-alert-block .list-row:hover td {
  background: #fff5f5;
}

/* ========================================================
   ダッシュボード
   ======================================================== */

.dash-kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.dash-kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.dash-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.dash-kpi-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.dash-kpi-value {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}

/* 経過日数の色 */
.days-warn { color: #fd7e14; font-weight: 600; }
.days-alert { color: #dc3545; font-weight: 700; }

/* 担当者リスト */
.staff-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: .9rem;
}
.staff-item:last-child { border-bottom: none; }
.staff-item:hover { background: var(--primary-light); }

/* 管理番号バッジ */
.mgmt-no {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}

/* ========================================================
   印刷（PDF出力）用スタイル
   ======================================================== */

@media print {
  .sidebar, .app-header, .report-controls, #generateReportBtn,
  .nav-btn, .btn, #toast, #globalLoading { display: none !important; }

  body { overflow: visible; font-size: 11pt; }
  .app-body { display: block; }
  .main-content { padding: 0; overflow: visible; }
  .view { display: block !important; }

  /* レポート以外の画面を非表示 */
  #view-dashboard, #view-list, #view-form, #view-detail,
  #view-search, #view-staff, #view-customers,
  #view-customerForm { display: none !important; }
  #view-report { display: block !important; }

  .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
  .charts-row { display: grid; grid-template-columns: 1fr 1fr; }
  .kpi-card { border: 1px solid #ddd; }
  table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  th, td { border: 1px solid #ccc; padding: 4px 6px; }
  th { background: #1a1a2e !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  @page { margin: 15mm; size: A4 landscape; }
}

/* ========================================================
   スクロールバー
   ======================================================== */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
