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

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

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ===== ヘッダー ===== */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  color: #fff;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px 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: #e94560; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; color: #fff; letter-spacing: -1px;
  flex-shrink: 0;
}
.logo-text  { font-size: 17px; font-weight: 700; letter-spacing: .05em; color: #fff; }
.logo-sub   { font-size: 11px; color: rgba(255,255,255,.5); letter-spacing: .08em; }
.header-date { font-size: 13px; color: rgba(255,255,255,.55); }

/* ===== ヘッダーユーザーエリア（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,.75);
}
.btn-logout {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  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); }

/* 閲覧のみロール: .write-only 要素を非表示 */
body[data-role="readonly"] .write-only { display: none !important; }

/* 管理者専用: .admin-only 要素（デフォルト非表示、admin のみ表示） */
.admin-only { display: none !important; }
body[data-role="admin"] .admin-only { display: flex !important; }

/* ===== パンくず ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 32px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  font-size: 13px;
  color: #6b7280;
}
.breadcrumb a { color: #6366f1; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: #d1d5db; }

/* ===== メイン ===== */
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: #111827; }
.page-header-left p  { font-size: 13px; color: #6b7280; 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: #6366f1; color: #fff; }
.btn-secondary { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-danger    { background: #ef4444; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }

/* ===== フィルターパネル ===== */
.filter-panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.filter-group label { font-size: 12px; font-weight: 600; color: #6b7280; 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;
  font-family: inherit;
}
.input:focus, .select:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.input-search { min-width: 220px; padding-left: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 10px center; }

/* ===== テーブルラッパー ===== */
.table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #f3f4f6;
  flex-wrap: wrap;
  gap: 8px;
}
.table-count { font-size: 13px; color: #6b7280; }
.table-count strong { color: #111827; font-weight: 700; }

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

thead tr { background: #f9fafb; }
thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  letter-spacing: .06em;
  border-bottom: 1px solid #e5e7eb;
  text-transform: uppercase;
}
thead th.center { text-align: center; }

tbody tr { border-bottom: 1px solid #f3f4f6; transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
tbody td { padding: 12px 16px; font-size: 13px; color: #374151; vertical-align: middle; }
tbody td.center { text-align: center; }
tbody td.muted { color: #9ca3af; font-size: 12px; }

/* ===== バッジ ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  white-space: nowrap;
}
/* 物件ステータス */
.badge-normal      { background: #d1fae5; color: #065f46; }
.badge-maintenance { background: #fef3c7; color: #92400e; }
.badge-scheduled   { background: #ffedd5; color: #9a3412; }
/* 光の導入状況 */
.badge-contracted  { background: #dbeafe; color: #1e40af; }
.badge-cancelled   { background: #fee2e2; color: #991b1b; }
.badge-prospect    { background: #e0e7ff; color: #3730a3; }
.badge-individual  { background: #ede9fe; color: #5b21b6; }
/* 入居状況 */
.badge-vacant      { background: #f3f4f6; color: #6b7280; }
.badge-occupied    { background: #d1fae5; color: #065f46; }
.badge-leaving     { background: #ffedd5; color: #9a3412; }
.badge-construction{ background: #fef9c3; color: #854d0e; }
/* インターネット */
.badge-not-opened  { background: #f3f4f6; color: #6b7280; }
.badge-opened      { background: #d1fae5; color: #065f46; }
.badge-suspended   { background: #fef3c7; color: #92400e; }
/* 入居者ステータス */
.badge-resident    { background: #d1fae5; color: #065f46; }
.badge-pre-leave   { background: #ffedd5; color: #9a3412; }
.badge-left        { background: #f3f4f6; color: #6b7280; }
/* お問い合わせ対応状況 */
.badge-pending     { background: #fee2e2; color: #991b1b; }
.badge-inprogress  { background: #fef3c7; color: #92400e; }
.badge-resolved    { background: #d1fae5; color: #065f46; }
.badge-closed      { background: #f3f4f6; color: #6b7280; }
/* 優先度 */
.badge-low         { background: #f3f4f6; color: #6b7280; }
.badge-mid         { background: #dbeafe; color: #1e40af; }
.badge-high        { background: #ffedd5; color: #9a3412; }
.badge-urgent      { background: #fee2e2; color: #991b1b; }
/* オーナー種別 */
.badge-individual-owner { background: #dbeafe; color: #1e40af; }
.badge-corporate        { background: #ede9fe; color: #5b21b6; }
/* 物件種別 */
.badge-new-build        { background: #ccfbf1; color: #0f766e; }
.badge-existing         { background: #f3f4f6; color: #6b7280; }
/* 配線工事状態 */
.badge-wiring-done      { background: #d1fae5; color: #065f46; }
.badge-wiring-pending   { background: #ffedd5; color: #9a3412; }
/* 工事状態 */
.badge-construction-done    { background: #d1fae5; color: #065f46; }
.badge-construction-pending { background: #ffedd5; color: #9a3412; }
/* 月額料金 */
.badge-fee-free         { background: #f3f4f6; color: #6b7280; }
.badge-fee-paid         { background: #dbeafe; color: #1e40af; }
/* ルーター */
.badge-router-room      { background: #d1fae5; color: #065f46; }
.badge-router-none      { background: #f3f4f6; color: #6b7280; }
.badge-router-rental    { background: #dbeafe; color: #1e40af; }
.badge-router-embedded  { background: #ede9fe; color: #5b21b6; }
/* あり・なし汎用 */
.badge-yes              { background: #d1fae5; color: #065f46; }
.badge-no               { background: #f3f4f6; color: #6b7280; }
/* 入居者ランク */
.badge-rank-normal      { background: #f3f4f6; color: #6b7280; }
.badge-rank-caution     { background: #fef3c7; color: #92400e; }
.badge-rank-black       { background: #1f2937; color: #f9fafb; }
/* デバイス種別 */
.badge-device           { background: #e0e7ff; color: #3730a3; }
/* OS */
.badge-os               { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
/* 連絡手段 */
.badge-contact-phone    { background: #dbeafe; color: #1e40af; }
.badge-contact-email    { background: #d1fae5; color: #065f46; }
.badge-contact-form     { background: #ede9fe; color: #5b21b6; }
.badge-contact-chatbot  { background: #ccfbf1; color: #0f766e; }
.badge-contact-portal   { background: #e0e7ff; color: #3730a3; }
.badge-contact-other    { background: #f3f4f6; color: #6b7280; }
/* エスカレーション */
.badge-escalated        { background: #fee2e2; color: #991b1b; }
/* ルーター機器利用状況 */
.badge-router-active    { background: #d1fae5; color: #065f46; }
.badge-router-available { background: #dbeafe; color: #1e40af; }
.badge-router-broken    { background: #fee2e2; color: #991b1b; }
.badge-router-repair    { background: #fef3c7; color: #92400e; }
/* スイッチ機器利用状況 */
.badge-switch-active    { background: #d1fae5; color: #065f46; }
.badge-switch-available { background: #dbeafe; color: #1e40af; }
.badge-switch-broken    { background: #fee2e2; color: #991b1b; }
.badge-switch-repair    { background: #fef3c7; color: #92400e; }
.badge-switch-disposed  { background: #f3f4f6; color: #6b7280; }

/* ===== アクションボタン群 ===== */
.actions { display: flex; gap: 6px; align-items: center; }

/* ===== ページネーション ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 20px;
  border-top: 1px solid #f3f4f6;
}
.page-btn {
  min-width: 34px; height: 34px;
  border: 1px solid #e5e7eb; border-radius: 7px;
  background: #fff; color: #374151;
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; text-decoration: none;
}
.page-btn:hover   { border-color: #6366f1; color: #6366f1; }
.page-btn.active  { background: #6366f1; border-color: #6366f1; color: #fff; }
.page-btn.disabled{ opacity: .4; cursor: default; pointer-events: none; }

/* ===== フッター ===== */
footer {
  background: #1a1a2e;
  color: rgba(255,255,255,.4);
  text-align: center;
  padding: 16px;
  font-size: 12px;
  letter-spacing: .04em;
  margin-top: auto;
}

/* ===== 写真グリッド ===== */
.photo-section { padding: 20px; }

.photo-group { margin-bottom: 28px; }
.photo-group:last-child { margin-bottom: 0; }

.photo-group-label {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.photo-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  position: relative;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
}

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

.photo-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: #f3f4f6;
}

.photo-card-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #d1d5db;
  font-size: 28px;
}

.photo-card-placeholder span {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 600;
}

.photo-card-footer {
  padding: 6px 10px;
  font-size: 11px;
  color: #6b7280;
  border-top: 1px solid #f3f4f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-add-btn {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  aspect-ratio: 4/3;
  text-decoration: none;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 600;
}

.photo-add-btn:hover {
  border-color: #6366f1;
  background: #f5f3ff;
  color: #6366f1;
}

.photo-add-btn .add-icon { font-size: 24px; }

/* ===== 詳細ページ ===== */

/* カードパネル */
.detail-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
}

.detail-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #f3f4f6;
  background: #f9fafb;
}

.detail-card-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: #374151;
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-card-body { padding: 20px; }

/* フィールドグリッド */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0;
}

.detail-field {
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-field:last-child  { border-bottom: none; }
.detail-field.span-2      { grid-column: span 2; }
.detail-field.span-full   { grid-column: 1 / -1; }

.detail-field .field-label {
  font-size: 11px;
  font-weight: 700;
  color: #9ca3af;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.detail-field .field-value {
  font-size: 14px;
  color: #111827;
  font-weight: 500;
  word-break: break-all;
}

.detail-field .field-value.muted { color: #9ca3af; font-weight: 400; }

/* 対応履歴タイムライン */
.timeline { padding: 4px 0; }

.timeline-item {
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
}
.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #6366f1;
  flex-shrink: 0;
  margin-top: 5px;
}

.timeline-content { flex: 1; }

.timeline-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.timeline-responder { font-size: 13px; font-weight: 700; color: #111827; }
.timeline-date      { font-size: 12px; color: #9ca3af; }
.timeline-body      { font-size: 13px; color: #374151; line-height: 1.7; white-space: pre-wrap; }

/* エスカレーションタイムライン */
.escalation-arrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 4px;
}
.escalation-arrow .arrow { color: #ef4444; font-size: 15px; }
.escalation-reason { font-size: 12px; color: #6b7280; margin-top: 4px; }

/* ===== 詳細ページ 2カラムレイアウト ===== */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 0 20px;
  align-items: start;
}
.detail-layout-side {
  position: sticky;
  top: 80px;
}

/* ===== フォームページ ===== */
.form-wrap { max-width: 860px; }

.form-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}

.form-section-header {
  padding: 14px 20px;
  border-bottom: 1px solid #f3f4f6;
  background: #fafafa;
}
.form-section-header h2 { font-size: 14px; font-weight: 700; color: #374151; }

.form-body { padding: 20px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px 24px;
}

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.span-full { grid-column: 1 / -1; }

.form-label { font-size: 13px; font-weight: 600; color: #374151; }
.form-label .required { color: #ef4444; margin-left: 2px; }

.textarea {
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}
.textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

.form-select {
  height: auto;
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 13px;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  cursor: pointer;
}
.form-select:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

.radio-group, .check-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px 0 4px;
}
.radio-label, .check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
}

.form-hint { font-size: 11px; color: #9ca3af; margin-top: 2px; }

.form-actions {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}

/* ===== モーダル ===== */
dialog {
  border: none;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.22);
  padding: 0;
  width: 540px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow: auto;
  margin: auto;
}
dialog::backdrop {
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: #111827; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #9ca3af;
  padding: 0 2px;
}
.modal-close:hover { color: #374151; }

.modal-body { padding: 20px; }
.modal-body .form-grid { gap: 16px 20px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid #f3f4f6;
  background: #fafafa;
}

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
  header       { padding: 0 16px; }
  .breadcrumb  { padding: 10px 16px; }
  main         { padding: 20px 16px 40px; }
  .filter-panel{ flex-direction: column; }
  .filter-group{ min-width: 100%; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-layout-side { position: static; }
}
