/* ============================================================
   TudorBot — Stylesheet
   Palette: wine, gold, parchment
   ============================================================ */

:root {
  --wine: #5a1020;
  --wine-deep: #2e0710;
  --wine-mid: #7a1c2e;
  --wine-soft: #8f3346;
  --gold: #c49a2c;
  --gold-soft: #e3c777;
  --gold-pale: #f0dfae;
  --parchment: #f6eddc;
  --paper: #fffaf0;
  --ink: #251a15;
  --ink-soft: #675448;
  --line: #e4d6bf;

  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius: 20px;
  --shadow-sm: 0 4px 16px rgba(46, 7, 16, 0.08);
  --shadow-md: 0 18px 50px rgba(46, 7, 16, 0.16);
  --shadow-lg: 0 30px 80px rgba(46, 7, 16, 0.24);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--parchment);
  background-image:
    radial-gradient(ellipse at 12% 0%, rgba(196, 154, 44, 0.16), transparent 45%),
    radial-gradient(ellipse at 90% 100%, rgba(90, 16, 32, 0.1), transparent 55%),
    linear-gradient(160deg, #fdf8ee 0%, #f3e7d2 55%, #ecdcc0 100%);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  color: var(--wine-deep);
  line-height: 1.1;
  font-weight: 600;
  margin: 0;
}

svg {
  display: block;
}

.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 shell ---------- */
.app {
  height: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 22px 22px 26px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--wine-deep);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  color: var(--wine);
  flex: none;
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--wine-deep);
  white-space: nowrap;
}

.brand-text span {
  color: var(--wine-mid);
}

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

.auth-btn {
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff8e8;
  background: var(--wine);
  border: 1px solid var(--wine);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.auth-btn:hover {
  background: var(--wine-deep);
  border-color: var(--wine-deep);
}

.auth-btn.ghost {
  color: var(--wine);
  background: transparent;
  border-color: rgba(90, 16, 32, 0.3);
}

.auth-btn.ghost:hover {
  color: var(--wine-deep);
  background: rgba(90, 16, 32, 0.08);
  border-color: rgba(90, 16, 32, 0.5);
}

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

.auth-badge {
  padding: 5px 10px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wine-deep);
  background: var(--gold-pale);
  border-radius: 999px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: rgba(255, 250, 240, 0.66);
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.back-link:hover {
  color: var(--wine);
  background: var(--paper);
  border-color: rgba(196, 154, 44, 0.6);
}

/* ---------- Chat card ---------- */
.chat-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.chat-head {
  flex: none;
  padding: 18px 22px;
  background:
    radial-gradient(ellipse at 85% 10%, rgba(196, 154, 44, 0.22), transparent 50%),
    linear-gradient(150deg, var(--wine-mid), var(--wine-deep));
  border-bottom: 1px solid rgba(227, 199, 119, 0.4);
}

.chat-id {
  display: flex;
  align-items: center;
  gap: 13px;
}

.chat-avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  color: var(--gold-soft);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(227, 199, 119, 0.45);
}

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

.chat-id-text h1 {
  margin: 0;
  font-size: 1.45rem;
  color: #fff8e8;
}

.chat-id-text p {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: rgba(245, 233, 210, 0.7);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  overflow-y: auto;
  scroll-behavior: smooth;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(196, 154, 44, 0.05), transparent 28%),
    radial-gradient(circle at 88% 82%, rgba(90, 16, 32, 0.04), transparent 30%);
}

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

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

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

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

.msg-user {
  align-self: flex-end;
  color: #fff8e8;
  background: var(--wine);
  border-bottom-right-radius: 5px;
  box-shadow: 0 8px 20px rgba(90, 16, 32, 0.18);
}

.msg-error {
  color: #8f1e1e;
  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(--wine-mid);
  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); }
}

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

.chat-suggestions button {
  padding: 7px 13px;
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--wine);
  background: rgba(90, 16, 32, 0.06);
  border: 1px solid rgba(90, 16, 32, 0.22);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.chat-suggestions button:hover {
  color: var(--wine-deep);
  background: rgba(196, 154, 44, 0.16);
  border-color: rgba(196, 154, 44, 0.65);
}

.chat-form {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  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.45;
  color: var(--ink);
  background: var(--parchment);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.chat-input:focus {
  background: var(--paper);
  border-color: var(--gold);
}

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

.chat-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  color: #fff8e8;
  background: var(--wine);
  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(--wine-deep);
  transform: translateY(-1px);
}

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

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

/* ---------- Modals ---------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(46, 7, 16, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 410;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 30px 30px 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-size: 1.75rem;
  margin: 0 0 6px;
}

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

.field {
  display: block;
  margin-bottom: 16px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field select {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 11px 13px;
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--parchment);
  border: 1.5px solid var(--line);
  border-radius: 11px;
  outline: none;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.field input:focus,
.field select:focus {
  background: #fff;
  border-color: var(--gold);
}

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

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

.btn-primary,
.btn-ghost {
  padding: 11px 20px;
  font-family: var(--font-body);
  font-size: 0.86rem;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.btn-primary {
  color: #fff8e8;
  background: var(--wine);
  border: 1.5px solid var(--wine);
}

.btn-primary:hover {
  background: var(--wine-deep);
  border-color: var(--wine-deep);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  color: var(--ink-soft);
  background: transparent;
  border: 1.5px solid var(--line);
}

.btn-ghost:hover {
  color: var(--wine);
  border-color: rgba(196, 154, 44, 0.65);
}

/* ---------- Responsive ---------- */
@media (max-width: 680px) {
  .app {
    padding: 12px 12px 16px;
  }

  .app-header {
    padding: 2px 2px 12px;
    gap: 10px;
  }

  .brand-text {
    font-size: 1.25rem;
  }

  .back-link span {
    display: none;
  }

  .auth-btn {
    padding: 7px 11px;
    font-size: 0.74rem;
  }

  .chat-head {
    padding: 15px 18px;
  }

  .chat-messages {
    padding: 18px 16px;
  }

  .chat-suggestions {
    padding: 0 14px 10px;
  }

  .chat-form {
    padding: 10px 12px;
  }

  .msg {
    max-width: 92%;
  }

  .modal {
    padding: 26px 22px 22px;
  }
}

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