.detail-modal,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.modal-backdrop { background: rgba(18, 25, 22, 0.34); }

.detail-modal {
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100%;
  height: 88vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  background: var(--surface-plain);
  box-shadow: 0 -16px 44px rgba(20,35,29,0.16);
  transform: translateY(100%);
  transition: transform 220ms var(--ease-out);
}

.detail-modal.open { transform: translateY(0); }
.detail-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 12px;
}
.detail-modal-body {
  overflow: auto;
  padding: 0 20px 20px;
}
.section-block h3 { margin: 0 0 8px; color: var(--brand-strong); }
.analysis-preview { display: grid; gap: 8px; line-height: 1.45; }
.analysis-preview .analysis-section + .analysis-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.analysis-preview .analysis-section h4 { margin: 0; color: var(--brand-strong); font-size: 0.94rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  z-index: 11;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 18px;
  border-radius: 999px;
  color: var(--surface-plain);
  background: rgba(32,39,34,0.92);
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 180ms var(--ease-out), transform 220ms var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  background: rgba(18,25,22,0.28);
  backdrop-filter: blur(4px);
}
.confirm-overlay:not([hidden]) { display: flex; }
.confirm-card {
  width: min(380px, 90vw);
  padding: 26px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-plain);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.confirm-message { margin: 0 0 20px; color: var(--text-main); line-height: 1.6; }
.confirm-actions { display: flex; justify-content: center; gap: 10px; }
.folder-picker-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.folder-picker-item {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text-main);
  background: var(--surface);
  text-align: left;
}
.folder-picker-item:hover { border-color: rgba(36,114,95,0.3); background: var(--brand-soft); }

.notion-settings-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.notion-settings-form h3 { margin: 0; color: var(--brand-strong); font-size: 1rem; }
.notion-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.notion-settings-form input[type="text"],
.notion-settings-form input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text-main);
  background: var(--surface-plain);
}
.notion-toggle-row {
  display: flex !important;
  align-items: center;
  gap: 10px !important;
  color: var(--text-main) !important;
}
.notion-toggle-row input { width: 18px; height: 18px; accent-color: var(--brand); }
.notion-sync-records { display: grid; gap: 6px; }
.notion-sync-item {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.84rem;
}
.notion-sync-row,
.notion-sync-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.notion-sync-row strong { min-width: 0; overflow-wrap: anywhere; }
.notion-sync-meta { color: var(--text-muted); font-size: 0.78rem; }
.notion-sync-error { margin: 0; color: var(--danger); overflow-wrap: anywhere; line-height: 1.45; }
.notion-sync-item.is-failed { border-color: rgba(179,56,46,0.22); background: rgba(179,56,46,0.05); }

.ai-chat-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
}
.ai-chat-widget[hidden],
.ai-chat-panel[hidden] { display: none; }
.ai-chat-toggle {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  color: var(--surface-plain);
  background: var(--surface-ink);
  box-shadow: 0 16px 32px rgba(32,39,34,0.24);
  font-weight: 800;
}
.ai-chat-toggle:hover { transform: translateY(-2px); }
.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(640px, calc(100vw - 28px));
  height: min(620px, calc(100vh - 120px));
  min-width: 0;
  container-type: inline-size;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,254,250,0.98);
  box-shadow: var(--shadow-lg);
}
.ai-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.ai-chat-header h2 { margin: 0; color: var(--brand-strong); font-size: 1rem; }
.ai-chat-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.78rem; }
.ai-chat-layout {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
}
.ai-chat-sessions,
.ai-chat-main,
.ai-chat-messages,
.ai-chat-form { min-width: 0; }
.ai-chat-sessions {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px;
  border-right: 1px solid var(--line);
}
.ai-session-new,
.ai-session-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--brand-strong);
  background: var(--surface);
  text-align: left;
  font-size: 0.82rem;
}
.ai-session-item.active { border-color: rgba(36,114,95,0.28); background: var(--brand-soft); }
.ai-session-delete { color: var(--danger); font-weight: 800; padding: 0 4px; }
.ai-chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}
.ai-chat-messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 10px;
  padding: 14px;
}
.ai-message {
  flex: 0 0 auto;
  width: fit-content;
  min-width: 0;
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
  font-size: 0.88rem;
}
.ai-message-content {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ai-message.user {
  align-self: flex-end;
  color: var(--surface-plain);
  background: var(--brand-strong);
  border-bottom-right-radius: 6px;
}
.ai-message.assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: var(--surface);
  border-bottom-left-radius: 6px;
}
.ai-message.pending,
.ai-empty { color: var(--text-muted); }
.ai-empty {
  margin: auto;
  max-width: 260px;
  text-align: center;
  font-size: 0.86rem;
  line-height: 1.7;
}
.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(72px, 84px);
  align-items: end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.ai-chat-form textarea {
  width: 100%;
  min-height: 44px;
  min-width: 0;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text-main);
  background: var(--surface-plain);
}
.ai-chat-form .primary-button {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

@container (max-width: 560px) {
  .ai-chat-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .ai-chat-sessions {
    grid-auto-flow: column;
    grid-auto-columns: minmax(120px, 1fr);
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .ai-session-new,
  .ai-session-item { min-width: 120px; }
  .ai-chat-form { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .detail-modal { height: 92vh; border-radius: 20px 20px 0 0; }
  .detail-modal-header { padding: 14px 14px 8px; }
  .detail-modal-body { padding: 0 14px 14px; }
  .toast { bottom: calc(140px + env(safe-area-inset-bottom)); font-size: 0.8rem; }
  .ai-chat-widget { right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .ai-chat-toggle { width: 52px; height: 52px; }
  .ai-chat-panel {
    right: -4px;
    bottom: 64px;
    width: min(640px, calc(100vw - 20px));
    height: min(620px, calc(100dvh - 150px));
    border-radius: 18px;
  }
  .ai-chat-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .ai-chat-sessions {
    grid-auto-flow: column;
    grid-auto-columns: minmax(120px, 1fr);
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .ai-session-new,
  .ai-session-item { min-width: 120px; }
  .ai-chat-form {
    grid-template-columns: 1fr;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .ai-message { max-width: 96%; }
}
