/* ============================================================
   Sunny Net 管理システム — 共通スタイル
   ============================================================ */

/* ===== リセット・基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f0f4f8;
  color: #1e293b;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ===== ヘッダー ===== */
header {
  background: linear-gradient(135deg, #0d3b6e 0%, #1565c0 60%, #0288d1 100%);
  color: #fff;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.logo-icon {
  width: 36px; height: 36px;
  background: #00b4d8;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 900; color: #fff;
  flex-shrink: 0;
}
.logo-text { font-size: 17px; font-weight: 700; letter-spacing: .04em; color: #fff; }
.logo-sub  { font-size: 11px; color: rgba(255,255,255,.55); letter-spacing: .06em; }

/* ===== ヘッダーユーザーエリア（auth-check.js が動的注入） ===== */
.header-user-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.header-operator { font-size: 13px; color: rgba(255,255,255,.8); }
.btn-logout {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background .2s;
}
.btn-logout:hover { background: rgba(255,255,255,.22); }

/* ─── 言語切替ボタン ─── */
.lang-switch {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,.1);
  border-radius: 6px;
  padding: 2px;
}
.lang-switch button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.7);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-switch button:hover  { background: rgba(255,255,255,.15); color: #fff; }
.lang-switch button.lang-active { background: rgba(255,255,255,.25); color: #fff; font-weight: 700; }

/* ロール制御 */
body[data-role="readonly"] .write-only { display: none !important; }
.admin-only { display: none !important; }
body[data-role="admin"]  .admin-only { display: flex !important; }
body[data-role="admin"]  .nav-group.admin-only { display: block !important; }
/* staff-only: hide when role is NOT staff or admin; let natural display apply when visible */
body:not([data-role="staff"]):not([data-role="admin"]) .staff-only { display: none !important; }

/* ===== パンくず ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 32px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
  color: #64748b;
}
.breadcrumb a { color: #1565c0; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: #cbd5e1; }

/* ===== メイン ===== */
main {
  flex: 1;
  padding: 28px 32px 60px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===== ページヘッダー ===== */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header-left h1 { font-size: 22px; font-weight: 700; color: #0f172a; }
.page-header-left p  { font-size: 13px; color: #64748b; margin-top: 3px; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: opacity .15s, transform .1s;
  letter-spacing: .02em;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn-primary   { background: #1565c0; color: #fff; }
.btn-secondary { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-danger    { background: #ef4444; color: #fff; }
.btn-success   { background: #16a34a; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }

/* ===== フィルターパネル ===== */
.filter-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.search-input {
  flex: 1;
  min-width: 200px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  border-color: #1565c0;
  box-shadow: 0 0 0 3px rgba(21,101,192,.1);
}
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.filter-group label { font-size: 12px; font-weight: 600; color: #64748b; letter-spacing: .04em; }

.input, .select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus {
  border-color: #1565c0;
  box-shadow: 0 0 0 3px rgba(21,101,192,.1);
}
.input.input-lg { height: 40px; font-size: 14px; padding: 0 14px; }

/* ===== テーブル ===== */
.table-wrap {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #e2e8f0;
  gap: 12px;
  flex-wrap: wrap;
}
.table-toolbar-left  { display: flex; align-items: center; gap: 8px; }
.table-toolbar-right { display: flex; align-items: center; gap: 8px; }
.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.text-link { color: #1565c0; text-decoration: none; font-weight: 600; }
.text-link:hover { text-decoration: underline; }

/* ===== バッジ ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
/* 顧客ステータス */
.badge-pending    { background: #fef9c3; color: #854d0e; }
.badge-active     { background: #dcfce7; color: #166534; }
.badge-suspended  { background: #fef2f2; color: #991b1b; }
.badge-cancelled  { background: #f1f5f9; color: #475569; }
/* チケット・メール共通ステータス */
.badge-status-pending    { background: #fef9c3; color: #854d0e; }
.badge-status-active     { background: #dbeafe; color: #1d4ed8; }
.badge-status-suspended  { background: #fff7ed; color: #9a3412; }
.badge-status-resolved   { background: #dcfce7; color: #166534; }
.badge-status-cancelled  { background: #f1f5f9; color: #475569; }
/* 顧客ランク */
.badge-rank-normal    { background: #f0f9ff; color: #0369a1; }
.badge-rank-caution   { background: #fff7ed; color: #9a3412; }
.badge-rank-blacklist { background: #1e293b; color: #f8fafc; }
/* 連絡方法 */
.badge-contact-email { background: #eff6ff; color: #1d4ed8; }
.badge-contact-chat  { background: #f0fdf4; color: #15803d; }
.badge-contact-phone { background: #faf5ff; color: #7e22ce; }
/* 汎用 */
.badge-yes { background: #dcfce7; color: #166534; }
.badge-no  { background: #f1f5f9; color: #64748b; }

/* ===== 詳細カード ===== */
.detail-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}
.detail-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.detail-card-header h2 { font-size: 14px; font-weight: 700; color: #0f172a; }
.detail-card-body { padding: 20px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.detail-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  letter-spacing: .05em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.detail-field p {
  font-size: 14px;
  color: #0f172a;
  word-break: break-word;
}
.detail-field p.empty { color: #94a3b8; font-style: italic; }

/* ===== 2カラム詳細レイアウト ===== */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}
.detail-layout-side { position: sticky; top: 80px; }
@media (max-width: 960px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-layout-side { position: static; }
}

/* ===== フォーム ===== */
.form-wrap {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 28px;
  max-width: 760px;
}
.form-section { margin-bottom: 28px; }
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #1565c0;
  padding-bottom: 10px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 18px;
  letter-spacing: .02em;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-label {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  letter-spacing: .03em;
}
.form-label .required { color: #ef4444; margin-left: 3px; }
.form-input, .form-select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus {
  border-color: #1565c0;
  box-shadow: 0 0 0 3px rgba(21,101,192,.1);
}
.textarea {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  resize: vertical;
  min-height: 90px;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.textarea:focus { border-color: #1565c0; box-shadow: 0 0 0 3px rgba(21,101,192,.1); }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e2e8f0;
}

/* ===== モーダル ===== */
dialog {
  border: none;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 0;
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  margin: auto;
  /* display は dialog[open] で制御 — ここでは指定しない */
}
dialog:not([open]) { display: none !important; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; color: #0f172a; }
.modal-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: #94a3b8; line-height: 1; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: #f1f5f9; color: #374151; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
}

/* ===== サマリーウィジェット ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.summary-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .18s, transform .18s;
}
.summary-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); transform: translateY(-2px); }
.summary-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.summary-body { min-width: 0; }
.summary-value { font-size: 24px; font-weight: 800; color: #0f172a; line-height: 1; }
.summary-label { font-size: 12px; color: #64748b; margin-top: 3px; }
.summary-card.active .summary-icon { background: #dcfce7; }
.summary-card.pending .summary-icon { background: #fef9c3; }
.summary-card.suspended .summary-icon { background: #fef2f2; }
.summary-card.cancelled .summary-icon { background: #f1f5f9; }
.summary-card.total .summary-icon { background: #eff6ff; }

/* ===== ページネーション ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 16px;
}
.page-btn {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.page-btn:hover { background: #f1f5f9; }
.page-btn.active { background: #1565c0; color: #fff; border-color: #1565c0; }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ===== タイムライン ===== */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 12px; position: relative; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: 15px; top: 28px;
  width: 2px;
  bottom: 0;
  background: #e2e8f0;
}
.timeline-item:last-child::before { display: none; }
.timeline-dot {
  width: 32px; height: 32px; border-radius: 50%;
  background: #eff6ff; border: 2px solid #bfdbfe;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; margin-top: 2px;
}
.timeline-content { flex: 1; padding-bottom: 20px; }
.timeline-meta { font-size: 11px; color: #94a3b8; margin-top: 4px; }

/* ===== ローディング ===== */
.loading-row td { text-align: center; padding: 40px; color: #94a3b8; }

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  header { padding: 0 16px; }
  main   { padding: 16px 16px 40px; }
  .filter-panel { gap: 8px; }
  .form-wrap { padding: 16px; }
  .detail-grid { grid-template-columns: 1fr; }
}
