/* ============================================
   KONNECT PAYROLL SCOPING — Sophie chat UI
   ============================================ */

:root {
  --navy: #1a3a5c;
  --navy-soft: #2a4a6c;
  --navy-deep: #0f2641;
  --gold: #c89b3c;
  --gold-soft: #d9b05a;
  --cream: #f5f1eb;
  --cream-soft: #faf7f2;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --ink-muted: #8a8a8a;
  --line: #e5e2dc;
  --line-soft: #f0ede7;
  --bg: #fbf9f5;
  --white: #ffffff;
  --err: #b84a3c;
  --success: #3d7a4a;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --shadow-sm: 0 1px 2px rgba(26, 58, 92, 0.06);
  --shadow-md: 0 4px 16px rgba(26, 58, 92, 0.08), 0 1px 3px rgba(26, 58, 92, 0.04);
  --shadow-lg: 0 12px 40px rgba(26, 58, 92, 0.12), 0 4px 12px rgba(26, 58, 92, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.view.active { display: flex; }

/* ============================================
   BRAND
   ============================================ */

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 40px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  background: var(--navy);
  color: var(--cream);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  letter-spacing: -0.01em;
}

.brand-mark.small {
  width: 32px;
  height: 32px;
  font-size: 16px;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  color: var(--navy);
  letter-spacing: -0.015em;
  line-height: 1;
}

.brand-text p {
  color: var(--ink-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

/* ============================================
   AUTH VIEW
   ============================================ */

#auth-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 15% 20%, rgba(200, 155, 60, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(26, 58, 92, 0.05) 0%, transparent 50%),
    var(--bg);
}

.auth-container {
  width: 100%;
  max-width: 440px;
  background: var(--white);
  padding: 48px 40px;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.auth-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--gold) 100%);
  border-radius: 4px 4px 0 0;
}

.auth-step { display: none; }
.auth-step.active { display: block; }

.auth-step h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 28px;
  color: var(--navy);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  line-height: 1.15;
}

.auth-subtitle {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--cream-soft);
  border: 1px solid var(--line);
  border-radius: 3px;
  transition: border-color 0.15s, background-color 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--navy);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(26, 58, 92, 0.1);
}

#otp-code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 20px;
  letter-spacing: 0.3em;
  text-align: center;
}

.btn-primary {
  width: 100%;
  padding: 13px 20px;
  background: var(--navy);
  color: var(--white);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  margin-top: 8px;
  position: relative;
  transition: background-color 0.15s, transform 0.05s;
}

.btn-primary:hover { background: var(--navy-deep); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.btn-primary .btn-loader {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
  vertical-align: -2px;
}

.btn-primary.loading .btn-label { opacity: 0.7; }
.btn-primary.loading .btn-loader { display: inline-block; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-text {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 13px;
  border: none;
  cursor: pointer;
  padding: 12px 0 0;
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, 0.15);
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.btn-text:hover { color: var(--ink); }

.security-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  padding: 12px 14px;
  background: var(--cream);
  border-radius: 3px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.security-note svg {
  flex-shrink: 0;
  color: var(--gold);
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: #faeae8;
  border: 1px solid #e8c4bf;
  border-radius: 3px;
  color: var(--err);
  font-size: 13px;
  display: none;
}

.auth-error.visible { display: block; }

/* ============================================
   CHAT VIEW
   ============================================ */

#chat-view {
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat-header {
  flex-shrink: 0;
  padding: 16px 28px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  color: var(--navy);
  letter-spacing: -0.01em;
  line-height: 1;
}

.chat-subtitle {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 3px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-soft);
  border-radius: 3px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn-ghost:hover {
  background: var(--cream-soft);
  border-color: var(--ink-muted);
}

.chat-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
}

.messages {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  gap: 14px;
  max-width: 100%;
  animation: msgFadeIn 0.25s ease-out;
}

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

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--cream);
  margin-top: 2px;
}

.msg.sophie .msg-avatar {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-soft) 100%);
}

.msg.user .msg-avatar {
  background: var(--cream);
  color: var(--navy);
  border: 1px solid var(--line);
}

.msg-bubble {
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  max-width: calc(100% - 50px);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.sophie .msg-bubble {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}

.msg.user .msg-bubble {
  background: var(--navy);
  color: var(--cream-soft);
  border-top-right-radius: 4px;
}

.msg-bubble p { margin: 0; }
.msg-bubble p + p { margin-top: 10px; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-bubble ul, .msg-bubble ol { margin: 8px 0 8px 20px; }
.msg-bubble li { margin: 4px 0; }

.msg.sophie .msg-bubble code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  background: var(--cream);
  padding: 1px 5px;
  border-radius: 2px;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-footer {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  background: var(--white);
  border-top: 1px solid var(--line);
}

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

#chat-input {
  flex: 1;
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--cream-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  line-height: 1.4;
  transition: border-color 0.15s, background-color 0.15s;
}

#chat-input:focus {
  outline: none;
  border-color: var(--navy);
  background: var(--white);
}

.btn-send {
  width: 44px;
  height: 44px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s, transform 0.05s;
}

.btn-send:hover { background: var(--navy-deep); }
.btn-send:active { transform: scale(0.95); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-disclaimer {
  max-width: 720px;
  margin: 10px auto 0;
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
  letter-spacing: 0.02em;
}

/* ============================================
   COMPLETE VIEW
   ============================================ */

#complete-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 30%, rgba(200, 155, 60, 0.08) 0%, transparent 50%),
    var(--bg);
}

.complete-container {
  max-width: 480px;
  text-align: center;
}

.complete-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  background: var(--cream);
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: checkIn 0.4s ease-out;
}

@keyframes checkIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.complete-container h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 32px;
  color: var(--navy);
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.complete-subtitle {
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: 12px;
}

.complete-sub2 {
  color: var(--ink-muted);
  font-size: 13px;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 640px) {
  .auth-container {
    padding: 36px 24px;
  }

  .auth-step h2 { font-size: 24px; }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-subtitle { display: none; }

  .btn-ghost {
    font-size: 12px;
    padding: 6px 10px;
  }

  .chat-scroll {
    padding: 20px 14px;
  }

  .msg-bubble {
    font-size: 14px;
    padding: 12px 14px;
  }

  .chat-footer {
    padding: 12px 14px 14px;
  }

  .complete-container h2 { font-size: 26px; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
