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

:root {
  --navy:      #1F4E79;
  --navy-mid:  #2E6DA4;
  --navy-light:#BDD7EE;
  --green:     #375623;
  --green-lt:  #EBF1DE;
  --blue:      #4472C4;
  --blue-lt:   #DBE5F1;
  --alt:       #EBF3FB;
  --white:     #FFFFFF;
  --gray-50:   #F5F7FA;
  --gray-100:  #E8ECF0;
  --gray-300:  #C4CBD4;
  --gray-500:  #7A8698;
  --gray-800:  #2D3748;
  --danger:    #C53030;
  --warning:   #D69E2E;
  --success:   #276749;
  --sidebar-w: 220px;
  --header-h:  56px;
  --font:      'Hiragino Sans', 'Yu Gothic', 'Meiryo', sans-serif;
}

html, body { height: 100%; font-family: var(--font); font-size: 13px; color: var(--gray-800); background: var(--gray-50); }

a { color: var(--navy-mid); text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); font-size: 13px; }

/* ============================================================
   Login
   ============================================================ */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 100%);
}
.login-card {
  background: var(--white); border-radius: 12px; padding: 48px 40px;
  width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card .logo {
  text-align: center; margin-bottom: 28px;
}
.login-card .logo h1 {
  font-size: 18px; font-weight: 700; color: var(--navy); line-height: 1.4;
}
.login-card .logo p {
  font-size: 11px; color: var(--gray-500); margin-top: 4px;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-500); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--gray-100);
  border-radius: 6px; font-size: 14px; transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--blue);
}
.btn-primary {
  width: 100%; padding: 12px; background: var(--navy); color: var(--white);
  border: none; border-radius: 6px; font-size: 14px; font-weight: 600;
  margin-top: 8px; transition: background .2s;
}
.btn-primary:hover { background: var(--navy-mid); }
.login-error { color: var(--danger); font-size: 12px; margin-top: 10px; text-align: center; display: none; }

/* ============================================================
   App Layout
   ============================================================ */
#app { display: none; flex-direction: row; height: 100vh; }

/* Sidebar：全幅で固定、スライドイン/アウト共通 */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100%;
  width: var(--sidebar-w);
  background: var(--navy); color: var(--white);
  display: flex; flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,0.18);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
#sidebar.open {
  transform: translateX(0);
}
.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo h2 { font-size: 13px; font-weight: 700; line-height: 1.5; }
.sidebar-logo p  { font-size: 10px; opacity: .6; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background .15s; color: rgba(255,255,255,0.8);
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.nav-item.active {
  background: rgba(255,255,255,0.14); color: var(--white);
  border-left-color: var(--navy-light);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11px; opacity: .7;
}
.sidebar-user { font-weight: 600; }
.btn-logout {
  width: 100%; margin-top: 8px; padding: 7px; background: rgba(255,255,255,0.1);
  color: var(--white); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px; font-size: 12px; transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.2); }

/* Main：サイドバー開閉に合わせてマージンをアニメーション */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-left: 0;
  transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
}
#app.sidebar-open #main {
  margin-left: var(--sidebar-w);
}

/* Top bar */
#topbar {
  height: var(--header-h); background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; flex-shrink: 0;
}
#topbar h2 { font-size: 16px; font-weight: 700; color: var(--navy); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* Content */
#content { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  padding: 7px 16px; border-radius: 5px; font-size: 12px; font-weight: 600;
  border: none; transition: all .15s; display: inline-flex; align-items: center; gap: 5px;
}
.btn-add    { background: var(--navy); color: var(--white); }
.btn-add:hover { background: var(--navy-mid); }
.btn-green  { background: var(--green); color: var(--white); }
.btn-green:hover { opacity: .88; }
.btn-ghost  { background: transparent; color: var(--gray-500); border: 1.5px solid var(--gray-300); }
.btn-ghost:hover { border-color: var(--navy); color: var(--navy); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { opacity: .88; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-icon { padding: 5px 8px; background: none; border: none; font-size: 15px; color: var(--gray-500); border-radius: 4px; }
.btn-icon:hover { background: var(--gray-100); color: var(--navy); }

/* ============================================================
   Filter bar
   ============================================================ */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  background: var(--white); border: 1px solid var(--gray-100);
  border-radius: 8px; padding: 12px 16px; margin-bottom: 14px;
}
.filter-bar select, .filter-bar input {
  padding: 6px 10px; border: 1.5px solid var(--gray-100); border-radius: 5px;
  font-size: 12px; background: var(--gray-50); transition: border-color .2s;
}
.filter-bar select:focus, .filter-bar input:focus {
  outline: none; border-color: var(--blue);
}
.filter-bar label { font-size: 11px; color: var(--gray-500); font-weight: 600; align-self: center; }

/* ============================================================
   Table
   ============================================================ */
.table-wrap {
  background: var(--white); border-radius: 8px;
  border: 1px solid var(--gray-100); overflow: auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
table { border-collapse: collapse; width: max-content; min-width: 100%; }
thead tr { background: var(--navy); position: sticky; top: 0; z-index: 2; }
thead th {
  color: var(--white); font-size: 11px; font-weight: 600;
  padding: 10px 10px; text-align: center; white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.1);
  vertical-align: bottom;
}
thead th small { display: block; font-size: 9px; opacity: .7; margin-top: 2px; }

tbody tr { transition: background .1s; }
tbody tr:nth-child(even) { background: var(--alt); }
tbody tr:hover { background: var(--blue-lt) !important; }
tbody td {
  padding: 7px 9px; border-bottom: 1px solid var(--gray-100);
  border-right: 1px solid var(--gray-100);
  font-size: 12px; vertical-align: top;
}
.td-center { text-align: center; }
.td-nowrap  { white-space: nowrap; }
.td-text    { max-width: 220px; line-height: 1.5; }
.td-textarea { max-width: 280px; max-height: 80px; overflow-y: auto; white-space: pre-wrap; line-height: 1.5; }
.td-actions { text-align: center; white-space: nowrap; }
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 99px;
  font-size: 10px; font-weight: 700;
}
.badge-blue   { background: var(--blue-lt);  color: var(--blue); }
.badge-green  { background: var(--green-lt); color: var(--green); }
.badge-navy   { background: var(--navy-light); color: var(--navy); }
.badge-gray   { background: var(--gray-100); color: var(--gray-500); }
.check-done   { color: var(--success); font-size: 16px; }
.check-star   { color: var(--warning); font-size: 14px; }

.cid-link { color: var(--blue); font-weight: 600; cursor: pointer; }
.cid-link:hover { text-decoration: underline; }

.empty-row td { text-align: center; color: var(--gray-500); padding: 40px; }

/* ============================================================
   Customer Master
   ============================================================ */
.master-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px; margin-top: 4px;
}
.customer-card {
  background: var(--white); border: 1px solid var(--gray-100);
  border-radius: 8px; padding: 16px; transition: box-shadow .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.customer-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.card-id { font-size: 11px; font-weight: 700; color: var(--blue); background: var(--blue-lt); padding: 2px 8px; border-radius: 99px; }
.card-company { font-size: 14px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.card-contact { font-size: 12px; color: var(--gray-500); }
.card-attrs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.card-count { font-size: 11px; color: var(--gray-500); margin-top: 8px; }
.card-count span { font-weight: 700; color: var(--navy); }

/* ============================================================
   Stats
   ============================================================ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.stats-card {
  background: var(--white); border-radius: 8px;
  border: 1px solid var(--gray-100); overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.stats-card-header {
  background: var(--navy); color: var(--white);
  padding: 10px 16px; font-size: 13px; font-weight: 700;
}
.stats-card-header.green  { background: var(--green); }
.stats-card-header.blue   { background: var(--blue); }
.stats-list { padding: 0; }
.stats-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px; border-bottom: 1px solid var(--gray-100);
  font-size: 12px;
}
.stats-row:last-child { border-bottom: none; }
.stats-row:nth-child(even) { background: var(--alt); }
.stats-bar-wrap { display: flex; align-items: center; gap: 8px; }
.stats-bar { background: var(--gray-100); border-radius: 99px; height: 6px; width: 80px; overflow: hidden; }
.stats-bar-fill { height: 100%; border-radius: 99px; background: var(--blue); transition: width .5s; }
.stats-count { font-weight: 700; color: var(--navy); min-width: 28px; text-align: right; }
.stats-pct   { color: var(--gray-500); font-size: 11px; min-width: 40px; text-align: right; }
.stats-total-card {
  background: var(--navy); color: var(--white);
  border-radius: 8px; padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.stats-total-card .big { font-size: 40px; font-weight: 800; }
.stats-total-card .label { font-size: 13px; opacity: .8; }
.stats-total-card .sub { font-size: 12px; opacity: .6; margin-top: 4px; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white); border-radius: 10px;
  width: 100%; max-width: 860px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { transform: translateY(-20px); opacity: 0; } }
.modal-header {
  background: var(--navy); color: var(--white);
  padding: 16px 24px; border-radius: 10px 10px 0 0;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--white); font-size: 20px; cursor: pointer; opacity: .7; line-height: 1; }
.modal-close:hover { opacity: 1; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--gray-100);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* Form grid inside modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .col3  { grid-column: span 1; }
.fg label { display: block; font-size: 11px; font-weight: 700; color: var(--gray-500); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .3px; }
.fg input, .fg select, .fg textarea {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--gray-100);
  border-radius: 5px; font-size: 13px; transition: border-color .2s;
  background: var(--gray-50);
}
.fg input:focus, .fg select:focus, .fg textarea:focus {
  outline: none; border-color: var(--blue); background: var(--white);
}
.fg textarea { resize: vertical; min-height: 80px; }
.fg .hint { font-size: 10px; color: var(--gray-500); margin-top: 3px; }
.form-section-title {
  grid-column: 1 / -1; font-size: 11px; font-weight: 800; color: var(--navy);
  text-transform: uppercase; letter-spacing: .5px;
  padding-bottom: 6px; border-bottom: 2px solid var(--navy-light);
  margin-top: 6px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--navy); }

/* 相談メモ 詳細ボタン */
.btn-detail {
  background: none;
  border: 1.5px solid var(--gray-100);
  border-radius: 5px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  color: var(--navy);
}
.btn-detail:hover {
  background: var(--navy-light);
  border-color: var(--navy);
}

/* 相談メモ 詳細モーダル */
.detail-modal-inner {
  max-width: 780px;
  width: 95vw;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.detail-section-title {
  grid-column: 1 / -1;
  background: var(--navy-light);
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 14px;
  margin: 10px 0 0;
  border-radius: 4px;
  letter-spacing: 0.05em;
}
.detail-section-title:first-child { margin-top: 0; }
.detail-row {
  display: flex;
  flex-direction: column;
  padding: 8px 14px;
  border-bottom: 1px solid #f0f0f0;
  gap: 3px;
}
.detail-row.full {
  grid-column: 1 / -1;
}
.detail-label {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-value {
  font-size: 14px;
  color: var(--gray-700);
  font-weight: 500;
  word-break: break-all;
}
.detail-empty { color: var(--gray-300); font-size: 13px; }
.detail-textarea {
  background: var(--gray-50);
  border-radius: 5px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--gray-700);
  min-height: 48px;
  white-space: pre-wrap;
  word-break: break-all;
}
.flag-on  { color: var(--navy); font-weight: 700; font-size: 13px; }
.flag-off { color: var(--gray-300); font-size: 13px; text-decoration: line-through; }

/* 顧客マスタ 表示切替ボタン */
.view-toggle-group {
  display: flex;
  border: 1.5px solid var(--gray-100);
  border-radius: 6px;
  overflow: hidden;
}
.view-toggle-btn {
  background: #fff;
  border: none;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--gray-500);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-right: 1px solid var(--gray-100);
}
.view-toggle-btn:last-child { border-right: none; }
.view-toggle-btn:hover { background: var(--navy-light); color: var(--navy); }
.view-toggle-btn.active { background: var(--navy); color: #fff; }

/* 並び替えヘッダー */
th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th[data-sort]:hover {
  background: #16395e;
}
th[data-sort].sort-active {
  background: #0d2540;
  color: #ffd700;
}

/* 顧客同時登録チェックボックス */
.also-register-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1.5px solid var(--green);
  border-radius: 6px;
  background: #f1f8ee;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--green);
  letter-spacing: 0;
  text-transform: none;
  transition: background 0.15s;
  user-select: none;
}
.also-register-label:hover { background: #e0f0d8; }
.also-register-label input[type=checkbox] {
  width: 16px; height: 16px;
  cursor: pointer;
  accent-color: var(--green);
}
.also-register-label.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--gray-100);
  background: var(--gray-50);
  color: var(--gray-400);
}

/* 対応者 複数選択チェックボックス */
.multi-check-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 8px 10px;
  border: 1.5px solid var(--gray-100);
  border-radius: 6px;
  background: #fff;
  min-height: 40px;
}
.multi-check-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  white-space: nowrap;
  color: var(--gray-700);
}
.multi-check-item input[type=checkbox] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--navy);
}
.customer-autofill {
  background: var(--green-lt); border: 1px solid var(--green);
  border-radius: 6px; padding: 10px 14px; grid-column: 1 / -1;
  font-size: 12px; color: var(--green);
}

/* ============================================================
   Realtime indicator
   ============================================================ */
.rt-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  display: inline-block; margin-right: 5px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.rt-label { font-size: 11px; color: var(--gray-500); }

/* ============================================================
   Toast
   ============================================================ */
#toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--gray-800); color: var(--white);
  padding: 10px 18px; border-radius: 6px; font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideIn .25s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }

/* ============================================================
   Utility
   ============================================================ */
.hidden  { display: none !important; }
.loading { text-align: center; padding: 48px; color: var(--gray-500); }
.sync-badge {
  background: rgba(255,255,255,0.15); color: var(--white);
  font-size: 10px; padding: 2px 8px; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 4px;
}

/* ============================================================
   ハンバーガーボタン
   ============================================================ */
.sidebar-toggle-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: 1.5px solid var(--gray-100);
  border-radius: 6px;
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.sidebar-toggle-btn:hover { background: var(--navy-light); }
.sidebar-toggle-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--navy);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
  transform-origin: center;
}
/* ✕ アニメーション */
.sidebar-toggle-btn.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-toggle-btn.active span:nth-child(2) { opacity: 0; }
.sidebar-toggle-btn.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   サイドバー オーバーレイ（SP用）
   ============================================================ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
  backdrop-filter: blur(1px);
}
#sidebar-overlay.show { display: block; }

/* ============================================================
   レスポンシブ（スマートフォン：～ 767px）
   ============================================================ */
@media (max-width: 767px) {

  /* PC版マージンをSPでは使わない（オーバーレイ方式） */
  #app.sidebar-open #main { margin-left: 0; }

  /* トップバー */
  #topbar { padding: 0 14px; }
  #topbar h2 { font-size: 14px; }
  .rt-label { display: none; }

  /* コンテンツパディング縮小 */
  #content { padding: 12px; }

  /* テーブル */
  .table-wrap { font-size: 12px; }

  /* フィルターバー */
  .filter-bar { flex-wrap: wrap; gap: 6px; }
  .filter-bar select { font-size: 12px; padding: 5px 6px; }

  /* モーダル */
  .modal { width: 96vw; max-height: 90vh; margin: 20px auto; }
  .detail-modal-inner { width: 96vw; }

  /* グリッド1列化 */
  .master-grid { grid-template-columns: 1fr; }
  .stats-grid  { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-row.full { grid-column: 1; }

  /* トースト */
  #toast-wrap { bottom: 12px; right: 12px; left: 12px; }
  .toast { font-size: 12px; }
}

/* ============================================================
   PC（768px以上）ではオーバーレイを非表示
   ============================================================ */
@media (min-width: 768px) {
  #sidebar-overlay { display: none !important; }
}
