:root {
  --navy: #0f1f3d;
  --accent: #2f6fb3;
  --light-blue: #f3f6fb;
  --border: #dde4ec;
  --text: #0f1b2d;
  --muted: #5a6b80;
  --danger: #d73a49;
  --success: #1a7f37;
  --bg: #f6f8fb;
  --white: #ffffff;
  --shadow: 0 1px 3px rgba(15, 31, 61, 0.06);
  --radius: 12px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.admin-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
}

.login-card .logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--navy);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.04em;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 8px;
}

.login-card p {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 24px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button,
.btn {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  background: var(--navy);
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-card footer,
.app-footer {
  margin-top: 24px;
  font-size: 11px;
  color: var(--muted);
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar .logo {
  padding: 22px 20px 16px;
}

.sidebar .logo-text {
  color: var(--white);
}

.nav {
  list-style: none;
  margin: 0;
  padding: 0 12px;
}

.nav li {
  margin-bottom: 4px;
}

.nav button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
  cursor: pointer;
}

.nav button:hover,
.nav button.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.45);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  color: var(--navy);
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filters select,
.filters input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--white);
  color: var(--text);
}

.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.demo-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff3cd;
  color: #856404;
  font-size: 11px;
  font-weight: 600;
  margin-left: 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.kpi-card h3 {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.sparkline {
  width: 80px;
  height: 28px;
}

.change {
  font-weight: 600;
}

.change.up {
  color: var(--success);
}

.change.down {
  color: var(--danger);
}

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

.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 15px;
  margin: 0 0 16px;
  color: var(--navy);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
}

.bar-label {
  width: 120px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 18px;
  background: var(--light-blue);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--navy);
  border-radius: 4px;
}

.bar-value {
  width: 80px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.keyword-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.keyword-cloud .tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--light-blue);
  color: var(--navy);
  font-size: 13px;
}

.keyword-cloud .tag span {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--light-blue);
}

.chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--light-blue);
  color: var(--navy);
  font-size: 11px;
  margin-right: 4px;
  margin-bottom: 2px;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty p {
  margin: 0 0 8px;
}

.empty small {
  font-size: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  font-size: 13px;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-row input,
.search-row select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 27, 45, 0.4);
}

.drawer-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--white);
  height: 100%;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  font-size: 16px;
  margin: 0;
  color: var(--navy);
}

.drawer-close {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
}

.drawer-body {
  padding: 24px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.meta-item {
  font-size: 13px;
}

.meta-item .label {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.bubbles {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.bubble.agent {
  align-self: flex-start;
  background: var(--light-blue);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble .who {
  font-size: 10px;
  opacity: 0.8;
  margin-bottom: 4px;
}

.report-card p {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 16px;
}

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 12px;
  color: var(--muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #e9eef5 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Mobile */
@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 0 12px;
    overflow-x: auto;
  }

  .sidebar .logo {
    padding: 14px 8px;
  }

  .nav {
    display: flex;
    padding: 0;
    gap: 4px;
  }

  .nav li {
    margin: 0;
  }

  .nav button {
    white-space: nowrap;
    padding: 10px 12px;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 400px) {
  .content {
    padding: 16px;
  }

  .kpi-value {
    font-size: 22px;
  }
}

/* --- 2026-10-16 検証で追加: はみ出し・KPI --- */
html, body { overflow-x: hidden; }
.kpi-grid > *, .grid-2 > *, .grid-1 > * { min-width: 0; }
.card { min-width: 0; }
.kpi-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.spark { flex-shrink: 0; opacity: 0.9; }
.change.flat { color: var(--muted); font-weight: 400; }
.chart-wrap { position: relative; height: 260px; }
@media (max-width: 900px) {
  .filters { width: 100%; }
  .filters select, .filters input { flex: 1 1 140px; min-width: 0; }
  .spark { display: none; }
  .table-wrap { margin: 0 -4px; }
}

/* スマホの会話表: 設置場所と時間を隠し、要約を読める幅に */
@media (max-width: 600px) {
  .table-wrap table th:nth-child(2), .table-wrap table td:nth-child(2),
  .table-wrap table th:nth-child(5), .table-wrap table td:nth-child(5) { display: none; }
  .table-wrap table { table-layout: fixed; width: 100%; }
  .table-wrap table th:first-child, .table-wrap table td:first-child { width: 64px; font-size: 11px; line-height: 1.4; }
  .table-wrap table th:nth-child(4), .table-wrap table td:nth-child(4) { width: 92px; }
  .table-wrap table td { padding-left: 6px; padding-right: 6px; }
  .table-wrap .chip { display: inline-block; white-space: normal; font-size: 10px; margin: 0 0 4px; }
}

/* --- 納品版追加: ログイン・サイドバー・アカウント・操作履歴 --- */

.login-error,
.form-error {
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffe6e9;
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

.form-success {
  padding: 10px 12px;
  border-radius: 8px;
  background: #e6f4ea;
  color: var(--success);
  font-size: 13px;
  margin-bottom: 12px;
}

.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
  text-decoration: none;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 10px;
}

.user-email {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.9);
  word-break: break-all;
}

.user-role {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
}

.logout-btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
}

.report-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-secondary {
  background: var(--white);
  color: var(--navy);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--light-blue);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.drawer-actions {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.account-content {
  max-width: 640px;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.account-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

.account-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.account-email {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.privacy-card h2 {
  color: var(--navy);
  font-size: 15px;
  margin: 0 0 6px;
}

.privacy-card p {
  line-height: 1.6;
}

.privacy-card a {
  color: var(--accent);
  text-decoration: none;
}

/* スマホ: 1 段目 = ロゴ＋ログイン中/ログアウト、2 段目 = 横スクロールのタブ（10/17 修正） */
@media (max-width: 900px) {
  .sidebar {
    min-height: auto;
    flex-wrap: wrap;
    overflow-x: visible;
    padding: 0 12px;
  }
  .sidebar .logo { order: 1; flex: 1 1 auto; padding: 12px 4px; }
  .sidebar-footer {
    order: 2;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 8px 0;
    border-top: none;
    min-width: 0;
  }
  .sidebar-footer .user-info { margin: 0; min-width: 0; text-align: right; }
  .sidebar-footer .user-email { display: none; }
  .sidebar-footer .copyright { display: none; }
  .logout-btn { width: auto; padding: 6px 12px; }
  .sidebar .nav {
    order: 3;
    flex: 1 0 100%;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
}

@media (max-width: 400px) {
  .report-actions {
    flex-direction: column;
  }
  .report-actions .btn {
    width: 100%;
  }
}

.filters[hidden] { display: none; }
