/* メモアプリと連続する、紙・墨・黄色の配色 */
:root {
  color-scheme: light;
  --bg: #f5f5f0;
  --surface: #ffffff;
  --field: #f1f1ec;
  --text: #1c1c1e;
  --text-muted: #68686d;
  --divider: #deded7;
  --accent: #ffd43b;
  --accent-ink: #312600;
  --success: #237a45;
  --warning: #8a5a00;
  --danger: #b42318;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* ヘッダー固定＋下部の入力バー固定で、間のスレッドだけスクロールさせる */
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ===== ヘッダー ===== */
.app-header {
  flex: 0 0 auto;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  padding: max(env(safe-area-inset-top), 10px) 16px 8px;
}

.app-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
  border-radius: 10px;
}

.icon-btn:active {
  background: var(--field);
}

/* ===== スレッド（チャット本体） ===== */
.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1rem;
}

.msg--user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-ink);
  border-bottom-right-radius: 5px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--bubble-ai);
  color: var(--bubble-ai-ink);
  border-bottom-left-radius: 5px;
}

/* 指示の状態（送信中／エラー）を小さく添える */
.msg__meta {
  display: block;
  margin-top: 3px;
  font-size: 0.7rem;
  opacity: 0.75;
  text-align: right;
}

.msg--error {
  background: var(--danger);
  color: #ffffff;
}

/* 秘書が処理中の「考え中…」表示 */
.typing {
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 4px 6px;
}

.thread__empty {
  margin: auto;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px;
}

/* ===== 入力バー ===== */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  background: var(--bg);
}

.composer__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 40vh;
  border: 1px solid var(--divider);
  border-radius: 20px;
  padding: 9px 14px;
  font: inherit;
  color: var(--text);
  background: var(--field);
}

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
}

.composer__send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.composer__send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ===== ロック画面 ===== */
.lock {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
}

.lock[hidden] {
  display: none;
}

.lock__card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock__title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
}

.lock__desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.lock__input {
  border: 1px solid var(--divider);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--field);
}

.lock__input:focus {
  outline: none;
  border-color: var(--accent);
}

.lock__btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--accent);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.lock__status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: var(--danger);
}

/* ===== トースト（軽い通知） ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 120;
  max-width: 90%;
  background: rgba(0, 0, 0, 0.82);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ===== 秘書メモ v2 ===== */
.app-shell {
  width: min(100%, 760px);
  margin-inline: auto;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--warning);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.12em;
}

.app-header {
  border-bottom: 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  padding: max(env(safe-area-inset-top), 14px) 16px 10px;
  backdrop-filter: blur(18px);
}

.app-header__row {
  align-items: flex-end;
}

.app-title {
  font-size: clamp(1.55rem, 5vw, 2rem);
  letter-spacing: -0.035em;
}

.header-actions,
.quiet-btn,
.connection,
.composer__footer,
.composer__send,
.confirmation-card__actions {
  display: flex;
  align-items: center;
}

.header-actions {
  gap: 8px;
}

.quiet-btn {
  min-height: 44px;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.connection {
  min-height: 32px;
  gap: 6px;
  border: 1px solid var(--divider);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.connection__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #929297;
}

.connection--online .connection__dot {
  background: var(--success);
}

.connection--offline .connection__dot {
  background: var(--danger);
}

.thread {
  padding: 14px 16px 24px;
  gap: 0;
}

.thread__empty {
  width: 100%;
  margin: auto;
  padding: 48px 24px;
}

.thread__empty-rule {
  display: block;
  width: 40px;
  height: 4px;
  margin: 0 auto 18px;
  border-radius: 999px;
  background: var(--accent);
}

.thread__empty h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.15rem;
}

.thread__empty p {
  margin: 6px 0 0;
}

.entry {
  position: relative;
  width: 100%;
  padding: 18px 18px 20px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}

.entry:first-child {
  border-radius: var(--radius) var(--radius) 0 0;
}

.entry:last-child {
  border-bottom: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

.entry--owner {
  border-left: 4px solid var(--accent);
  background: #fffdf5;
}

.entry__meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 7px;
}

.entry__author {
  font-size: 0.8rem;
  font-weight: 750;
}

.entry__time {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.entry__body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.7;
}

.status-badge {
  display: inline-flex;
  margin-top: 10px;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--field);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 650;
}

.status-badge--awaiting_confirmation,
.status-badge--approved {
  background: #fff2b8;
  color: var(--warning);
}

.status-badge--done {
  color: var(--success);
}

.status-badge--error,
.status-badge--rejected {
  color: var(--danger);
}

.confirmation-card {
  position: relative;
  width: calc(100% - 12px);
  margin: 14px 0 14px 12px;
  border: 1px solid #e6c13e;
  border-radius: var(--radius);
  padding: 18px;
  background: #fff7cf;
  color: var(--accent-ink);
  box-shadow: 0 8px 24px rgba(83, 66, 0, 0.08);
}

.confirmation-card::before {
  position: absolute;
  top: -1px;
  left: -9px;
  width: 18px;
  height: 42px;
  border-radius: 5px 0 0 5px;
  background: var(--accent);
  content: "";
}

.confirmation-card__eyebrow {
  margin: 0 0 4px;
  color: var(--warning);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.confirmation-card__title {
  margin: 0;
  font-size: 1.05rem;
}

.confirmation-card__text {
  margin: 10px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  line-height: 1.65;
}

.confirmation-card__actions {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.confirm-btn {
  min-height: 44px;
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.confirm-btn--approve {
  border: 1px solid var(--accent-ink);
  background: var(--accent-ink);
  color: #ffffff;
}

.confirm-btn--reject {
  border: 1px solid #d1b13b;
  background: transparent;
  color: var(--accent-ink);
}

.confirm-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.confirmation-card__result {
  margin: 14px 0 0;
  font-size: 0.8rem;
  font-weight: 700;
}

.activity {
  margin: 12px 4px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.activity::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
  animation: pulse 1.4s ease-in-out infinite;
}

.composer {
  border-top: 1px solid var(--divider);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(18px);
}

.composer__panel {
  display: block;
  border: 1px solid var(--divider);
  border-radius: 16px;
  padding: 10px 12px 10px 14px;
  background: var(--surface);
  box-shadow: 0 5px 20px rgba(25, 25, 20, 0.06);
}

.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.composer__input {
  display: block;
  width: 100%;
  min-height: 32px;
  max-height: 32vh;
  border: 0;
  border-radius: 0;
  padding: 2px 0;
  background: transparent;
  line-height: 1.55;
}

.composer__input:focus {
  border-color: transparent;
  outline: none;
}

.composer__footer {
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.composer__footer p {
  max-width: 440px;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.67rem;
  line-height: 1.4;
}

.composer__send {
  width: auto;
  min-width: 76px;
  height: 44px;
  justify-content: center;
  gap: 5px;
  border-radius: 12px;
  padding: 0 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 750;
}

.lock {
  background: var(--bg);
}

.lock__card {
  max-width: 390px;
  gap: 10px;
  border: 1px solid var(--divider);
  border-radius: 22px;
  padding: 28px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(25, 25, 20, 0.08);
}

.lock__mark {
  width: 46px;
  height: 58px;
  margin-bottom: 8px;
  border-radius: 8px 8px 3px 3px;
  background: var(--accent);
  box-shadow: inset 0 -12px 0 rgba(255, 255, 255, 0.32);
}

.lock__title {
  letter-spacing: -0.035em;
}

.lock__desc {
  margin-bottom: 10px;
  line-height: 1.65;
}

.lock__input {
  min-height: 48px;
  border-radius: 12px;
  background: var(--field);
}

.primary-btn {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

button,
input,
textarea {
  transition: border-color 160ms ease-out, background-color 160ms ease-out,
    opacity 160ms ease-out, transform 160ms ease-out;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, white);
  outline-offset: 2px;
}

@keyframes pulse {
  0%,
  100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@media (max-width: 480px) {
  .quiet-btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .quiet-btn {
    width: 44px;
    justify-content: center;
    padding: 0;
  }

  .entry {
    padding-inline: 15px;
  }

  .confirmation-card__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .confirm-btn {
    width: 100%;
  }

  .composer__footer p {
    max-width: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
