/* ============================================================
   CoastBot - standalone AI chat
   Palette: deep ocean blues, warm sand, cream
   ============================================================ */

:root {
  --deep: #0a2f4d;
  --ocean: #0f4c75;
  --ocean-2: #1b6ea8;
  --sea-light: #3f9fd4;
  --sand: #e6cfa4;
  --cream: #fbf7ef;
  --paper: #ffffff;
  --ink: #10222f;
  --ink-soft: #40566a;
  --line: #e3ddd1;

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

  --radius: 18px;
  --shadow-sm: 0 4px 16px rgba(10, 47, 77, 0.06);
  --shadow-md: 0 18px 50px rgba(10, 47, 77, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.6;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(63, 159, 212, 0.16), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(230, 207, 164, 0.28), transparent 55%),
    var(--cream);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2vw, 20px);
  width: 100%;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--deep);
}

.brand-mark {
  color: var(--ocean-2);
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--deep);
}

.brand-text span {
  color: var(--ocean-2);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ocean);
  background: rgba(27, 110, 168, 0.08);
  border: 1px solid rgba(27, 110, 168, 0.22);
  border-radius: 999px;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.back-link:hover {
  background: rgba(27, 110, 168, 0.16);
  border-color: var(--ocean-2);
}

.chat-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 16px 18px;
  color: #fff;
  background: linear-gradient(160deg, var(--deep), var(--ocean));
}

.chat-id {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--sea-light);
  background: rgba(255, 255, 255, 0.14);
}

.chat-id-text {
  min-width: 0;
}

.chat-id-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.28rem;
  line-height: 1.1;
  font-weight: 600;
  color: #fff;
}

.chat-id-text p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
}

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 18px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.msg {
  max-width: 86%;
  padding: 12px 15px;
  font-size: 0.94rem;
  line-height: 1.55;
  border-radius: 14px;
  animation: fadeUp 0.3s var(--ease);
}

.msg p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-bot {
  align-self: flex-start;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.msg-user {
  align-self: flex-end;
  color: #fff;
  background: var(--ocean-2);
  border-bottom-right-radius: 5px;
}

.msg-error {
  color: #9b2e2e;
  background: rgba(214, 84, 84, 0.1);
  border: 1px solid rgba(214, 84, 84, 0.4);
}

.msg-typing-wrap {
  display: inline-flex;
  align-self: flex-start;
  padding: 14px 16px;
}

.msg-typing {
  display: inline-flex;
  gap: 5px;
}

.msg-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ocean-2);
  opacity: 0.3;
  animation: typingDot 1.2s infinite var(--ease);
}

.msg-typing span:nth-child(2) { animation-delay: 0.18s; }
.msg-typing span:nth-child(3) { animation-delay: 0.36s; }

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

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

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: none;
  padding: 0 18px 12px;
}

.chat-suggestions button {
  padding: 7px 13px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ocean);
  background: rgba(27, 110, 168, 0.08);
  border: 1px solid rgba(27, 110, 168, 0.25);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.chat-suggestions button:hover {
  background: rgba(27, 110, 168, 0.16);
  border-color: var(--ocean-2);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex: none;
  padding: 12px 14px;
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.chat-input {
  flex: 1;
  max-height: 120px;
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--cream);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s var(--ease);
}

.chat-input:focus {
  border-color: var(--ocean-2);
}

.chat-input:disabled {
  opacity: 0.6;
}

.chat-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  color: #fff;
  background: var(--ocean-2);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease), opacity 0.2s var(--ease);
}

.chat-send:hover:not(:disabled) {
  background: var(--ocean);
  transform: translateY(-1px);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-disclaimer {
  margin: 0;
  padding: 0 16px 12px;
  flex: none;
  font-size: 0.72rem;
  text-align: center;
  color: var(--ink-soft);
  background: var(--paper);
}

@media (max-width: 560px) {
  .app-header .brand-text {
    font-size: 1.02rem;
  }

  .back-link span {
    display: none;
  }

  .back-link {
    padding: 9px;
    border-radius: 10px;
  }

  .msg {
    max-width: 90%;
  }
}

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

/* ---------- Auth & admin ---------- */

[hidden] {
  display: none !important;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  background: var(--ocean-2);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.auth-btn:hover {
  background: var(--ocean);
  transform: translateY(-1px);
}

.auth-btn.ghost {
  color: var(--ocean);
  background: rgba(27, 110, 168, 0.08);
  border-color: rgba(27, 110, 168, 0.22);
}

.auth-btn.ghost:hover {
  background: rgba(27, 110, 168, 0.16);
  border-color: var(--ocean-2);
}

.admin-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--deep);
  background: rgba(242, 181, 68, 0.22);
  border: 1px solid rgba(242, 181, 68, 0.55);
  border-radius: 999px;
}

.auth-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2f9e6f;
}

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(7, 31, 51, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal {
  position: fixed;
  z-index: 70;
  top: 50%;
  left: 50%;
  width: min(380px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: fadeUp 0.25s var(--ease);
}

.modal h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--deep);
}

.modal-sub {
  margin: 0 0 16px;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input,
.field select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--cream);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s var(--ease);
}

.field input:focus,
.field select:focus {
  border-color: var(--ocean-2);
}

.form-error {
  margin: 0 0 12px;
  padding: 9px 12px;
  font-size: 0.82rem;
  color: #9b2e2e;
  background: rgba(214, 84, 84, 0.1);
  border: 1px solid rgba(214, 84, 84, 0.4);
  border-radius: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.btn-primary,
.btn-ghost {
  padding: 9px 18px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), opacity 0.2s var(--ease);
}

.btn-primary {
  color: #fff;
  background: var(--ocean-2);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--ocean);
  background: rgba(27, 110, 168, 0.08);
  border-color: rgba(27, 110, 168, 0.22);
}

.btn-ghost:hover {
  background: rgba(27, 110, 168, 0.16);
}

@media (max-width: 560px) {
  .header-tools {
    gap: 6px;
  }

  .auth-btn {
    padding: 8px 12px;
  }
}
