:root {
  --clr-brand: #f79321;
  --clr-bg: #f7f5f0;
  --clr-card1: #8d7051;
  --clr-card2: #7b7e74;
  --clr-text-white: #ffffff;
  --clr-btn1: #bac7e5;
  --clr-btn2: #f2a51e;

  --clr-text-dark: #2f2a26;
  --clr-text-muted: #6b635b;
  --clr-border: rgba(0, 0, 0, 0.08);
  --clr-white: #ffffff;

  --shadow: 0 8px 30px rgba(141, 112, 81, 0.1);
  --radius-lg: 20px;
  --radius-md: 12px;
}

html {
  touch-action: manipulation;
}

body {
  touch-action: manipulation;
  background-color: var(--clr-bg);
  color: var(--clr-text-dark);
  padding-top: calc(64px + 18px *2);

  box-sizing: border-box;
}

h1,
h2,
h3,
p {
  color: inherit;
}

header {
  background-color: var(--clr-card1);
  color: var(--clr-text-white);
}

button {
  border: none;
  transition: opacity 0.2s, transform 0.2s;
}

button:disabled {
  opacity: 0.5;
}

textarea {
  border: 1px solid var(--clr-border);
  background-color: var(--clr-bg);
}

a {
  color: var(--clr-brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

textarea:focus,
input:focus {
  outline: 2px solid var(--clr-brand);
  border-color: transparent;
}

::selection {
  background-color: var(--clr-brand);
  color: var(--clr-text-white);
}

.test-mode-badge {
  position: fixed;
  right: 14px;
  bottom: 12px;
  z-index: 1200;
  display: none;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid rgba(146, 117, 83, 0.24);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.86);
  color: #7d6345;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 12px rgba(58, 47, 34, 0.1);
  pointer-events: none;
}

.test-mode-badge.show {
  display: inline-flex;
}

.common-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  z-index: 1000;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo .logo-icon {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.brand-name {
  display: flex;
  flex-direction: column;
}

.brand-name p {
  font-size: 12px;
  margin: 0;
  letter-spacing: 0.05em;
}

.brand-name h1 {
  font-size: 24px;
  margin: 0;
  letter-spacing: 0.05em;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  text-align: right;
}

.user-email {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

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

.role-badge {
  display: none;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.18);
  color: var(--clr-text-white);
  font-size: 12px;
  font-weight: 700;
}

.btn-admin-page,
.btn-logout {
  padding: 2px 12px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  background-color: transparent;
  color: var(--clr-text-white);
  border: 1px solid rgba(255, 255, 255, 0.5);
  transition: all 0.2s;
}

.btn-admin-page {
  display: none;
}

.btn-admin-page:hover,
.btn-logout:hover {
  background-color: rgba(255, 255, 255, 0.25);
}

@media screen and (max-width: 768px) {
  body {
    background-color: var(--clr-bg);
    color: var(--clr-text-dark);
    padding-top: calc(56px);
  }

  .common-header {
    height: 56px;
    padding: 0 12px;
  }

  .brand-logo {
    gap: 8px;
  }

  .brand-logo .logo-icon {
    width: 40px;
    height: 40px;
  }

  .brand-logo h1 {
    font-size: 18px;
  }

  .user-info {
    gap: 2px;
  }

  .user-email {
    font-size: 10px;
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .account-actions {
    gap: 5px;
  }

  .role-badge,
  .btn-admin-page,
  .btn-logout {
    padding: 1px 8px;
    font-size: 10px;
  }
}

.scroll-none {
  height: 100dvh;
  /* height: 100vh; */
  overflow: hidden;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.mt-20 {
  margin-top: 20px;
}

.mb-20 {
  margin-bottom: 20px;
}

.p-40 {
  padding: 40px;
}

.split-card-container {
  display: flex;
  width: 100%;
  max-width: 1000px;
  min-height: 600px;
  border-radius: 32px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  margin: 40px auto;
}

.split-card-left {
  flex: 1;
  padding: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background-color: var(--clr-card1);
  color: var(--clr-text-white);
}

.split-card-left h2 {
  font-size: 32px;
  line-height: 1.4;
  margin-bottom: 24px;
}

.split-card-left p {
  font-size: 16px;
  line-height: 1.8;
}

.split-card-right {
  flex: 1;
  padding: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--clr-text-white);
}

.form-inner {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

@media screen and (max-width: 768px) {
  .split-card-container {
    flex-direction: column;
    margin: 20px auto;
    width: 95%;
    min-height: auto;
    border-radius: 24px;
  }

  .split-card-left {
    padding: 5px 20px;
    text-align: center;
  }

  .split-card-left h2 {
    font-size: 24px;
    margin-bottom: 16px;
  }

  .split-card-right {
    padding: 5px 20px;
    background-color: var(--clr-text-white);
  }

  .form-inner {
    max-width: 100%;
  }

  /* ログインカードオンリー対応 */
  /* .split-card-left { display: none; } */

}

.container-card {
  display: flex;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.btn-main {
  background-color: var(--clr-btn2);
  color: var(--clr-text-white);
  cursor: pointer;
}

.btn-sub {
  background-color: var(--clr-btn1);
  color: var(--clr-text-dark);
  cursor: pointer;
}

.badge-admin {
  background-color: var(--clr-brand);
  color: var(--clr-text-white);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
}

.copy-button {
  border: 1px solid #d6c8b7;
  background: #f4eee7;
  color: var(--clr-text-white);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 16px;
  line-height: 1.2;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(91, 81, 72, 0.12);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.copy-button img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  filter: brightness(0) saturate(100%) invert(33%) sepia(12%) saturate(732%) hue-rotate(350deg) brightness(89%) contrast(86%);
}

.copy-button.is-morphing img {
  animation: iconMorph 180ms ease-out;
}

.copy-button:hover:not(:disabled) {
  background: #eadfd2;
  border-color: #c8b69f;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(91, 81, 72, 0.16);
}

.copy-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.copy-button.copied {
  background: #e6f1eb;
  color: #2f7b57;
  border-color: #a8cdbb;
}

.copy-button.copied img {
  filter: brightness(0) saturate(100%) invert(39%) sepia(35%) saturate(650%) hue-rotate(95deg) brightness(88%) contrast(89%);
}

.copy-button.failed {
  background: #f5e7e5;
  color: #9a3f3f;
  border-color: #dbb4ad;
}

.copy-button.is-pressed,
.source-open-button.is-pressed {
  animation: buttonTap 240ms ease-out;
}

.main-container {
  width: 100%;
  height: calc(100dvh - calc(64px + 18px * 2));
  display: flex;
  gap: 20px;
  box-sizing: border-box;
  min-height: 0;
}

.sorce-container {
  width: 0;
  height: 100%;
  overflow: hidden;
  transition: width 0.3s ease, border-left 0.3s ease;
  background-color: var(--clr-white);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  border-top-left-radius: 20px;
  border-bottom-left-radius: 20px;
}

.sorce-container.active {
  width: 400px;
  border-left: 1px solid #eee;
}

.container-header {
  font-size: 15px;
  display: flex;
  align-items: center;
  padding: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  background-color: var(--clr-card2);
  color: var(--clr-text-white);
  border-bottom: 1px solid #eee;
  border-top-left-radius: 20px;
}

.sorce-list {
  overflow-y: auto;
  padding: 5px 16px 16px 16px;
  overflow-y: scroll;
  height: 100%;
}

.source-open-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f4eee7;
  border: 1px solid #d6c8b7;
  color: #5b5148;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(91, 81, 72, 0.12);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.source-open-button img {
  width: 14px;
  height: 14px;
  object-fit: contain;
  filter: brightness(0) saturate(100%) invert(33%) sepia(12%) saturate(732%) hue-rotate(350deg) brightness(89%) contrast(86%);
}

.source-open-button:hover {
  background: #eadfd2;
  border-color: #c8b69f;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(91, 81, 72, 0.16);
}

.sorce-close {
  background-color: var(--clr-card2);
  color: var(--clr-text-white);
  font-size: 24px;
  padding: 10px;
}

@media screen and (max-width: 768px) {
  .main-container {
    height: calc(100dvh - 56px);
    max-height: calc(100dvh - 56px);
    gap: 0;
    padding: 0;
    position: relative;
    overflow: hidden;
  }

  .chat-pane {
    border-radius: 0;
    box-shadow: none;
  }

  .sorce-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    visibility: hidden;
  }

  .sorce-container.active {
    width: 100%;
    transform: translateX(0);
    visibility: visible;
  }

  .container-header {
    height: 60px;
    padding: 0 16px;
    border-top-left-radius: 0;
  }

  .sorce-list {
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
  }

  .message-block {
    max-width: 95%;
    gap: 8px;
  }

  .assistant-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .input-area {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .bubble-row {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

.chat-pane {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background-color: var(--clr-white);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: scroll;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.bubble-row {
  padding-top: 4px;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.bubble-text {
  padding: 14px 18px;
  line-height: 1.6;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-all;
}

.meta-row {
  font-size: 11px;
  color: var(--clr-text-muted);
}

.bubble.assistant>.bubble-text {
  align-self: flex-start;
  background-color: var(--clr-card2);
  color: var(--clr-text-white);
  border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
}

.assistant-icon {
  width: 48px;
  height: 48px;
  background-color: var(--clr-card2);
  color: var(--clr-text-white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  margin-top: 18px;
}

.assistant-name {
  font-size: 12px;
  color: var(--clr-text-muted);
  margin-left: 2px;
}

.bubble.user>.bubble-text {
  align-self: flex-end;
  flex-direction: row-reverse;
  background-color: var(--clr-btn1);
  color: var(--clr-text-dark);
  border-radius: var(--radius-md) 0 var(--radius-md) var(--radius-md);
}

.message-row.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.bubble.user .meta-row {
  text-align: right;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
  flex-wrap: wrap;
}

.message-block {
  max-width: 86%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.input-area {
  padding: 10px 12px;
  border-top: 1px solid var(--clr-border);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background-color: var(--clr-text-white);
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.input-hint {
  font-size: 11px;
  color: var(--clr-text-muted);
  padding-left: 4px;
  opacity: 0.8;
}

.input-textarea {
  flex: 1;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 16px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.btn-send {
  margin-top: 2px;
  width: 44px;
  height: 44px;
  background-color: #f4eee7;
  color: #5b5148;
  border: 1px solid #d6c8b7;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(91, 81, 72, 0.12);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.btn-send:hover:not(:disabled) {
  background-color: #eadfd2;
  border-color: #c8b69f;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(91, 81, 72, 0.16);
}

.btn-send:disabled {
  opacity: 0.48;
  cursor: default;
}

.btn-send img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: brightness(0) saturate(100%) invert(33%) sepia(12%) saturate(732%) hue-rotate(350deg) brightness(89%) contrast(86%);
}

@keyframes buttonTap {
  0% {
    transform: scale(1);
  }

  42% {
    transform: scale(0.92);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes iconMorph {
  0% {
    opacity: 0.2;
    transform: scale(0.55) rotate(-18deg);
  }

  70% {
    opacity: 1;
    transform: scale(1.1) rotate(3deg);
  }

  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 8px;
  vertical-align: middle;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #b9aea2;
  animation: blink 1.2s infinite ease-in-out;
  display: inline-block;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {

  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.35;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.source-section {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
}

.source-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.source-section-title {
  font-size: 16px;
  font-weight: bold;
  margin: 0;
  color: var(--clr-text-main);
}

.source-count {
  font-size: 12px;
  background: #f0f0f0;
  padding: 2px 8px;
  border-radius: 10px;
}

.source-folder-link {
  display: inline-block;
  font-size: 13px;
  color: #0066cc;
  text-decoration: none;
  margin-bottom: 10px;
}

.source-folder-link:hover {
  text-decoration: underline;
}

.source-item {
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.4;
}

.source-item-title {
  color: #333;
}

.external-link {
  color: #0066cc;
  text-decoration: none;
  font-weight: 500;
}

.source-item-url {
  font-size: 12px;
  color: #888;
  word-break: break-all;
}

.scroll-down-btn {
  width: 100%;
  background-color: rgba(247, 147, 33, 0.85);
  backdrop-filter: blur(4px);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  z-index: 10;

  display: none;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.scroll-down-btn.show {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

.scroll-down-btn:hover {
  background-color: rgba(247, 147, 33, 0.95);
}

.scroll-down-btn svg {
  animation: bounceDown 2s infinite;
}

@media screen and (max-width: 768px) {
  .scroll-down-btn {
    height: 50px;
  }
}


@keyframes bounceDown {

  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(4px);
  }

  60% {
    transform: translateY(2px);
  }
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s;
}

.loading-text {
  font-size: 3rem;
  font-weight: bold;
  font-family: 'Arial Black', sans-serif;
  color: #ccc;
  letter-spacing: 4px;
  animation: fillBrandColor 2s ease-in-out infinite alternate;
}

@keyframes fillBrandColor {
  0% {
    color: #ccc;
    text-shadow: 0 0 0px rgba(247, 147, 33, 0);
  }

  100% {
    color: var(--clr-brand);
    text-shadow: 0 0 15px rgba(247, 147, 33, 0.3);
  }
}

.loading-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}
