/* ============================================================
   Nakayama Coaching Bot - Chat UI Styles
   Mobile-first responsive design, vanilla CSS
   ============================================================ */

/* --- CSS Variables / Theme --- */
:root {
  --color-primary: #0097a7;
  --color-primary-dark: #00838f;
  --color-primary-light: #b2ebf2;
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-header: #1a1a2e;
  --color-header-text: #ffffff;
  --color-user-bubble: #0097a7;
  --color-user-text: #ffffff;
  --color-coach-bubble: #e8e8e8;
  --color-coach-text: #1a1a1a;
  --color-text: #333333;
  --color-text-secondary: #666666;
  --color-border: #dddddd;
  --color-error: #d32f2f;
  --color-error-bg: #fce4ec;
  --color-success: #2e7d32;
  --color-step-inactive: #cccccc;
  --color-step-active: #0097a7;
  --color-step-done: #4caf50;
  --font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Noto Sans JP',
                 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-bubble: 18px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
  --input-height: 60px;
  --header-height: 52px;
  --step-bar-height: 56px;
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--color-header);
  color: var(--color-header-text);
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-header {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-header-text);
  font-size: 13px;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.7);
}

/* --- Screens --- */
.screen {
  display: none;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* --- Member Selection Screen --- */
#screen-member {
  margin-top: var(--header-height);
  padding: 24px 16px;
  min-height: calc(100vh - var(--header-height));
  align-items: center;
  justify-content: flex-start;
}

.member-container {
  width: 100%;
  max-width: 420px;
}

.member-heading {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-card {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.member-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.member-card-name {
  font-weight: 600;
  font-size: 15px;
}

.member-card-info {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-left: auto;
}

.loading-text {
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 14px;
  padding: 16px 0;
}

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  gap: 12px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.divider span {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* --- New Member Form --- */
.new-member-form h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-family);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-primary:disabled {
  background: var(--color-step-inactive);
  cursor: not-allowed;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: var(--font-family);
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

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

/* --- Error Message --- */
.error-message {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--color-error-bg);
  color: var(--color-error);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* --- Chat Screen Layout --- */
#screen-chat {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
}

/* --- Step Indicator --- */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--step-bar-height);
  padding: 0 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.step-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  background: var(--color-step-inactive);
  transition: background 0.3s, transform 0.3s;
}

.step.active .step-circle {
  background: var(--color-step-active);
  transform: scale(1.15);
}

.step.done .step-circle {
  background: var(--color-step-done);
}

.step-label {
  font-size: 10px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  transition: color 0.3s;
}

.step.active .step-label {
  color: var(--color-step-active);
  font-weight: 600;
}

.step.done .step-label {
  color: var(--color-step-done);
}

.step-connector {
  width: 20px;
  height: 2px;
  background: var(--color-step-inactive);
  margin: 0 4px;
  margin-bottom: 14px;
  transition: background 0.3s;
}

.step-connector.done {
  background: var(--color-step-done);
}

/* --- Chat Messages Area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

/* --- Chat Bubbles --- */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: messageIn 0.25s ease-out;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-self: flex-end;
}

.message.coach {
  align-self: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  background: var(--color-user-bubble);
  color: var(--color-user-text);
  border-bottom-right-radius: var(--radius-sm);
}

.message.coach .message-bubble {
  background: var(--color-coach-bubble);
  color: var(--color-coach-text);
  border-bottom-left-radius: var(--radius-sm);
}

.message-meta {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 2px;
  padding: 0 4px;
}

.message.user .message-meta {
  text-align: right;
}

/* --- Typing Indicator --- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-coach-bubble);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: var(--radius-sm);
  width: fit-content;
  align-self: flex-start;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999999;
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* --- Feedback Buttons --- */
.feedback-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}

.btn-feedback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #aaaaaa;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.btn-feedback:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #666666;
}

.btn-feedback.selected {
  color: var(--color-primary);
}

.btn-feedback.selected.negative {
  color: var(--color-error);
}

/* Feedback comment area */
.feedback-comment-area {
  display: none;
  margin-top: 6px;
  padding: 0 4px;
}

.feedback-comment-area.visible {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  animation: messageIn 0.2s ease-out;
}

.feedback-comment-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-family);
  resize: none;
  min-height: 32px;
}

.feedback-comment-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-feedback-submit {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #ffffff;
  font-size: 13px;
  font-family: var(--font-family);
  cursor: pointer;
  white-space: nowrap;
}

.btn-feedback-submit:hover {
  background: var(--color-primary-dark);
}

.feedback-sent {
  font-size: 12px;
  color: var(--color-success);
  padding: 2px 4px;
}

/* --- Next Step Bar --- */
.next-step-bar {
  padding: 8px 16px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  text-align: center;
  flex-shrink: 0;
}

.btn-next-step {
  padding: 10px 24px;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-primary);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-next-step:hover {
  background: var(--color-primary);
  color: #ffffff;
}

/* --- Chat Input Area --- */
.chat-input-area {
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 15px;
  font-family: var(--font-family);
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color 0.2s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-send {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.btn-send:hover {
  background: var(--color-primary-dark);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Inline Error Toast --- */
.error-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--color-error);
  color: #ffffff;
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease-out;
  white-space: nowrap;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* --- No Members Message --- */
.no-members {
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 14px;
  padding: 12px 0;
}

/* --- Responsive (tablet/desktop) --- */
@media (min-width: 600px) {
  .app-title {
    font-size: 18px;
  }

  .chat-messages {
    padding: 24px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }

  .message {
    max-width: 70%;
  }

  .step-connector {
    width: 40px;
  }

  .step-label {
    font-size: 11px;
  }

  .step-circle {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }
}
