:root {
  --bg: #f6f2ea;
  --paper: rgba(255, 253, 248, 0.9);
  --paper-strong: #fffdfa;
  --line: rgba(70, 58, 44, 0.14);
  --line-strong: rgba(70, 58, 44, 0.22);
  --text: #342a22;
  --muted: #6f655c;
  --accent: #9c5d33;
  --accent-soft: rgba(156, 93, 51, 0.1);
  --shadow: 0 18px 40px rgba(52, 42, 34, 0.06);
  --radius-xl: 26px;
  --radius-lg: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic", "BIZ UDPGothic", sans-serif;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0)),
    linear-gradient(180deg, #fbf8f2 0%, #f2ece2 100%);
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.page-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  gap: 28px;
  padding: 28px;
}

.page-shell.admin-locked {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.hidden {
  display: none !important;
}

.sidebar, .reader-demo { align-self: start; position: sticky; top: 24px; }

.sidebar,
.reader-demo,
.hero,
.metric-card,
.panel,
.status-card,
.timeline-card,
.processing-card,
.upload-dropzone,
.preview-card,
.code-card,
.qr-card,
.lead-list,
.lead-detail,
.chart-card,
.conversation-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 26px 20px;
  min-height: calc(100vh - 56px);
}

.sidebar-logout {
  width: 100%;
  margin-bottom: 14px;
}

.brand-block,
.panel-header,
.reader-header,
.preview-header,
.processing-head,
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand-block { align-items: center; margin-bottom: 30px; }

.locale-switcher {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 18px;
}

.locale-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.locale-button.active {
  background: #efe6da;
  border-color: rgba(156, 93, 51, 0.18);
  color: var(--accent);
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #efe3d4;
  border: 1px solid rgba(156, 93, 51, 0.14);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8d7d6d;
}

.sidebar h1,
.hero h2,
.panel h3,
.reader-demo h3,
.timeline-card h4,
.chart-card h4 {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "BIZ UDPMincho", serif;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
  margin-bottom: 26px;
}

.nav-item,
.tab-button {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-item.active,
.nav-item:hover,
.tab-button.active,
.tab-button:hover {
  background: #efe6da;
  color: var(--accent);
}

.status-card {
  padding: 18px;
  background: #f8f3ec;
}

.status-label {
  margin: 0 0 8px;
  font-weight: 600;
}

.status-copy {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.8;
  font-size: 0.95rem;
}

.main-content { display: grid; gap: 22px; }

.hero {
  padding: 34px 36px;
  display: flex;
  justify-content: space-between;
  gap: 30px;
  background: linear-gradient(180deg, rgba(255,253,248,0.98), rgba(249,244,237,0.96));
}

.hero-copy {
  max-width: 780px;
  color: var(--muted);
  line-height: 1.95;
  font-size: 0.98rem;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
}

.button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.button:hover { transform: translateY(-1px); }

.button.primary {
  background: var(--accent);
  color: #fffdf8;
}

.button.ghost {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  border-color: var(--line);
}

.button.fluid { width: 100%; }

.inline-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f5efe6;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.stats-grid,
.timeline-grid,
.analytics-grid {
  display: grid;
  gap: 16px;
}

.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric-card {
  padding: 22px;
  background: rgba(255, 253, 248, 0.84);
}

.metric-card p,
.metric-card span { margin: 0; }

.metric-card strong {
  display: block;
  margin: 10px 0 8px;
  font-size: 1.9rem;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "BIZ UDPMincho", serif;
  font-weight: 500;
}

.metric-card span,
.timeline-card p,
.processing-meta p,
.qr-card p,
.topic-list span,
.lead-meta,
.lead-note {
  color: var(--muted);
}

.support-note,
.analytics-note,
.preview-helper {
  color: var(--muted);
  line-height: 1.8;
  font-size: 0.92rem;
}

.metric-card.accent {
  background: linear-gradient(180deg, #f6ede2, #fffdf9);
}

.content-panels { display: grid; gap: 18px; }

.panel {
  display: none;
  padding: 28px;
}

.panel.active { display: block; }

.timeline-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.timeline-card {
  padding: 22px;
  background: rgba(255,255,255,0.48);
}

.timeline-card span {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #efe3d4;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 14px;
}

.upload-grid,
.brand-grid,
.embed-grid,
.lead-layout {
  display: grid;
  gap: 18px;
}

.upload-grid,
.embed-grid,
.lead-layout {
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
}

.brand-grid { grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr); }

.brand-form {
  display: grid;
  gap: 14px;
}

.brand-form label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
}

.brand-form input[type="text"],
.brand-form input[type="color"],
.brand-form textarea,
.brand-form select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.88);
  color: var(--text);
}

.brand-form input[type="color"] {
  min-height: 48px;
  padding: 6px;
}

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

.processing-note {
  margin-top: 18px;
}

.book-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.book-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line);
}

.book-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.material-action {
  padding: 8px 12px;
}

.book-row strong,
.book-row small {
  display: block;
}

.book-row small {
  margin-top: 6px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f5efe6;
  color: var(--accent);
  border: 1px solid rgba(156, 93, 51, 0.14);
  font-size: 0.88rem;
  white-space: nowrap;
}

.preview-shell {
  padding: 22px;
  border-radius: 24px;
  background: #fbf8f2;
  color: var(--text);
}

.preview-avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #efe3d4;
  color: var(--accent);
  font-weight: 700;
}

.preview-name,
.preview-sub {
  margin: 0;
}

.preview-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.preview-bubble {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.8;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
}

.preview-bubble.user {
  background: var(--accent-soft);
}

.preview-helper {
  margin: 12px 2px 4px;
}

.qr-visual {
  display: grid;
  place-items: center;
  margin: 18px 0;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
}

.qr-visual img {
  display: block;
  width: min(220px, 100%);
  height: auto;
}

.admin-auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(52, 42, 34, 0.18);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.auth-card {
  width: min(100%, 420px);
  padding: 28px;
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-card h2,
.auth-copy,
.auth-error {
  margin: 0;
}

.auth-copy {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.8;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.auth-form label {
  display: grid;
  gap: 8px;
}

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.88);
}

.auth-error {
  min-height: 1.4em;
  color: #9f3f2a;
  font-size: 0.92rem;
}

.topic-list {
  display: grid;
  gap: 10px;
}

.topic-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line);
}

.upload-dropzone,
.processing-card,
.preview-card,
.code-card,
.qr-card,
.lead-list,
.lead-detail,
.chart-card,
.conversation-card {
  padding: 22px;
}

.upload-dropzone {
  border: 1px dashed var(--line-strong);
  min-height: 280px;
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(247,242,234,0.9));
}

.upload-icon {
  margin: 0;
  font-size: 2.2rem;
  color: var(--accent);
}

.upload-dropzone input[type="file"] {
  margin-top: 12px;
  max-width: 100%;
}

.material-config {
  display: grid;
  gap: 10px;
  width: min(100%, 320px);
  margin-top: 14px;
}

.material-config label {
  display: grid;
  gap: 6px;
  text-align: left;
  font-size: 0.92rem;
  color: var(--muted);
}

.material-config select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.pill {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  background: #edf1ea;
  color: #5e7352;
}

.progress-line {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #eee6db;
  overflow: hidden;
}

.progress-line.large {
  height: 12px;
  margin: 16px 0 12px;
}

.progress-line span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c08b61, var(--accent));
}

.check-list { margin: 18px 0 0; padding-left: 18px; line-height: 1.9; color: var(--muted); }

.book-list { margin-top: 16px; display: grid; gap: 10px; }

.book-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.56);
}

.book-row small { color: var(--muted); }

.brand-form { display: grid; gap: 14px; }

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

.brand-form label { display: grid; gap: 8px; font-weight: 600; }

.brand-form input[type="text"],
.brand-form textarea,
.brand-form select,
.chat-form input,
#leadCaptureForm input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.brand-form input[type="range"] { width: 100%; }

.preview-card {
  background: #f4ede4;
  color: var(--text);
}

.preview-shell {
  border-radius: 18px;
  padding: 18px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(70, 58, 44, 0.08);
}

.preview-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e8d9c7;
  color: var(--accent);
  font-weight: 700;
}

.preview-name { margin: 0; font-weight: 700; }
.preview-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }

.preview-bubble {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.8;
}

.preview-bubble.ai { background: rgba(255,255,255,0.82); }
.preview-bubble.user { background: #efe6da; }

.tab-row { display: flex; gap: 8px; margin-bottom: 14px; }

pre {
  margin: 0 0 14px;
  padding: 18px;
  border-radius: 18px;
  background: #faf6f0;
  border: 1px solid var(--line);
  color: var(--text);
  overflow: auto;
  min-height: 240px;
}

.qr-card { text-align: center; }
.qr-visual { padding: 16px 0 20px; display: grid; place-items: center; }

.qr-frame {
  width: 180px;
  height: 180px;
  border-radius: 24px;
  background:
    linear-gradient(90deg, #53473a 12%, transparent 12% 18%, #53473a 18% 26%, transparent 26% 32%, #53473a 32% 38%, transparent 38% 44%, #53473a 44% 52%, transparent 52% 58%, #53473a 58% 68%, transparent 68% 74%, #53473a 74% 82%, transparent 82%),
    linear-gradient(180deg, #53473a 12%, transparent 12% 18%, #53473a 18% 26%, transparent 26% 32%, #53473a 32% 38%, transparent 38% 44%, #53473a 44% 52%, transparent 52% 58%, #53473a 58% 68%, transparent 68% 74%, #53473a 74% 82%, transparent 82%);
  background-color: #fffdfa;
  position: relative;
  box-shadow: inset 0 0 0 12px #fffdfa;
}

.qr-core {
  position: absolute;
  inset: 26px;
  border: 12px solid #53473a;
  border-radius: 16px;
}

.lead-list { display: grid; gap: 12px; }

.lead-row {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
  background: rgba(255,255,255,0.58);
}

.lead-row:hover,
.lead-row.active {
  border-color: rgba(156, 93, 51, 0.32);
  transform: translateY(-1px);
}

.lead-row strong,
.lead-detail h4 { display: block; margin-bottom: 6px; }

.lead-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.92rem;
}

.lead-detail { min-height: 380px; }

.detail-score {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  background: #efe6da;
  color: var(--accent);
  margin-bottom: 14px;
}

.detail-topics,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}

.topic-chip,
.action-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: #eef1ec;
  color: #5e7352;
}

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

.conversation-list { display: grid; gap: 12px; }

.conversation-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.62);
}

.conversation-item strong,
.conversation-item p { margin: 0; }

.conversation-item p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.7;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  min-height: 240px;
  padding-top: 18px;
}

.bar-column { display: grid; gap: 8px; justify-items: center; }

.bar {
  width: 100%;
  border-radius: 18px 18px 8px 8px;
  background: linear-gradient(180deg, #caa17f, var(--accent));
}

.bar-label,
.bar-value { font-size: 0.86rem; color: var(--muted); }

.topic-list { display: grid; gap: 14px; }

.topic-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.reader-demo {
  padding: 22px;
  background: rgba(255,253,248,0.92);
}

.chat-thread {
  min-height: 420px;
  max-height: 420px;
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 14px 0;
}

.chat-message { display: grid; gap: 6px; }
.message-role { font-size: 0.8rem; color: var(--muted); }

.message-bubble {
  padding: 13px 15px;
  border-radius: 18px;
  line-height: 1.75;
  background: rgba(255,255,255,0.82);
  border: 1px solid var(--line);
}

.chat-message.user .message-bubble {
  background: #efe6da;
  border-color: rgba(156, 93, 51, 0.16);
}

.chat-form,
#leadCaptureForm { display: grid; gap: 10px; }

.chat-form {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 8px;
}

.lead-gate {
  margin-top: 14px;
  padding: 16px;
  border-radius: 20px;
  background: #f5ece1;
  border: 1px solid rgba(156, 93, 51, 0.14);
}

.hidden { display: none; }

@media (max-width: 1320px) {
  .page-shell { grid-template-columns: 240px minmax(0, 1fr); }
  .reader-demo { position: static; grid-column: 1 / -1; }
}

@media (max-width: 960px) {
  .page-shell { grid-template-columns: 1fr; }
  .sidebar, .reader-demo { position: static; min-height: auto; }
  .hero,
  .stats-grid,
  .timeline-grid,
  .upload-grid,
  .brand-grid,
  .embed-grid,
  .lead-layout,
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  .hero { flex-direction: column; }
  .chat-form { grid-template-columns: 1fr; }
}
