/* Fafetai — warm Pacific design system */

:root {
  --teal-900: #0a3f43;
  --teal-700: #0f5e63;
  --teal-600: #14747a;
  --teal-500: #1b8b92;
  --teal-100: #e4f0ef;
  --teal-050: #f1f7f6;

  --coral: #ff6b57;
  --coral-600: #e8543f;
  --coral-100: #ffe6e1;

  --sand: #faf6ef;
  --sand-100: #f3ecdd;
  --card: #ffffff;

  --ink: #1c2b2d;
  --ink-soft: #4a5a5c;
  --ink-faint: #7c8b8c;

  --border: #e6ddc9;
  --border-soft: #ece5d4;

  --green: #1f9d55;
  --green-bg: #e5f7ec;
  --red: #d9483a;
  --red-bg: #fdeceb;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-sm: 0 1px 2px rgba(28, 43, 45, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 94, 99, 0.09);
  --shadow-lg: 0 16px 40px rgba(15, 94, 99, 0.14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--sand);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

a {
  color: var(--teal-700);
  text-decoration: none;
}

a:hover {
  color: var(--coral-600);
}

h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 1em;
}

::selection {
  background: var(--teal-100);
  color: var(--teal-900);
}

/* ---------- Layout shell ---------- */

.site-header {
  border-bottom: 1px solid var(--border-soft);
  background: rgba(250, 246, 239, 0.9);
  backdrop-filter: saturate(150%) blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 800;
  font-size: 1.35rem;
  color: var(--teal-900);
  letter-spacing: -0.02em;
}

.wordmark:hover {
  color: var(--teal-700);
}

.wordmark__mark {
  display: inline-block;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-900));
  box-shadow: var(--shadow-sm);
  position: relative;
  flex: none;
}

.wordmark__mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    circle at 30% 25%,
    rgba(255, 255, 255, 0.55),
    transparent 55%
  );
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 0.95rem;
  font-weight: 600;
}

.site-nav a {
  color: var(--ink-soft);
}

.site-nav a:hover {
  color: var(--coral-600);
}

.site-nav__admin.is-active {
  color: var(--teal-700);
  background: var(--teal-050);
  border: 1px solid var(--teal-100);
  padding: 6px 14px;
  border-radius: 999px;
}

.site-nav__admin.is-active:hover {
  color: var(--coral-600);
}

.site-main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.site-footer {
  border-top: 1px solid var(--border-soft);
  padding: 28px 24px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.88rem;
}

/* ---------- Flash messages ---------- */

.flashes {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flash {
  background: var(--teal-050);
  border: 1px solid var(--teal-100);
  color: var(--teal-900);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  font-weight: 500;
}

/* ---------- Buttons & form basics ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease,
    background-color 0.12s ease, opacity 0.12s ease;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--teal-700);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--teal-600);
  color: #fff;
}

.btn-danger {
  background: var(--coral);
  color: #fff;
}

.btn-danger:hover {
  background: var(--coral-600);
  color: #fff;
}

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

.btn-ghost:hover {
  background: var(--sand-100);
  color: var(--ink);
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.85rem;
}

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

label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field {
  margin-bottom: 18px;
}

.field .hint {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-weight: 400;
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 0.96rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(20, 116, 122, 0.15);
}

.radio-row {
  display: flex;
  gap: 20px;
  align-items: center;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 500;
  color: var(--ink);
  font-size: 0.94rem;
}

.radio-option label {
  margin: 0;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.checkbox-row label {
  margin: 0;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  width: 17px;
  height: 17px;
  accent-color: var(--teal-700);
}

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-pad {
  padding: 28px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--teal-900);
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---------- Home / portal grid ---------- */

.page-intro {
  margin-bottom: 36px;
}

.page-intro h1 {
  font-size: 2.1rem;
  color: var(--teal-900);
}

.page-intro p {
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 620px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.portal-card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease,
    border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--ink);
}

.portal-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--teal-100);
  color: var(--ink);
}

.portal-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.portal-card__name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--teal-900);
}

.lock-badge {
  flex: none;
  font-size: 0.95rem;
  line-height: 1;
  background: var(--sand-100);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.portal-card__desc {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0;
  flex: 1;
}

.portal-card__cta {
  font-size: 0.87rem;
  font-weight: 700;
  color: var(--teal-700);
}

.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--ink-faint);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  font-size: 1rem;
}

/* ---------- Admin login ---------- */

.auth-wrap {
  max-width: 400px;
  margin: 60px auto;
}

.auth-wrap h1 {
  text-align: center;
  color: var(--teal-900);
  font-size: 1.5rem;
}

.auth-wrap .card-pad {
  padding: 32px;
}

.auth-wrap .btn {
  width: 100%;
  margin-top: 6px;
}

/* ---------- Admin dashboard ---------- */

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.admin-topbar h1 {
  color: var(--teal-900);
  font-size: 1.7rem;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 640px;
}

thead th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 700;
}

tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--teal-050);
}

.portal-name-link {
  font-weight: 700;
  color: var(--teal-900);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.pill-public {
  background: var(--teal-100);
  color: var(--teal-900);
}

.pill-password {
  background: var(--coral-100);
  color: var(--coral-600);
}

.pill-on {
  background: var(--green-bg);
  color: var(--green);
}

.pill-off {
  background: var(--sand-100);
  color: var(--ink-faint);
}

/* ---------- Admin portal detail ---------- */

.portal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.portal-header h1 {
  color: var(--teal-900);
  font-size: 1.7rem;
  margin: 0 0 6px;
}

.public-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.92rem;
  background: var(--teal-050);
  border: 1px solid var(--teal-100);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  color: var(--teal-700);
}

.public-link:hover {
  background: var(--teal-100);
  color: var(--teal-900);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.doc-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}

.doc-row__name {
  font-weight: 600;
  color: var(--ink);
  flex: 1 1 200px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.doc-row__meta {
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-ready {
  background: var(--green-bg);
  color: var(--green);
}

.status-error {
  background: var(--red-bg);
  color: var(--red);
}

.doc-row__error {
  flex-basis: 100%;
  font-size: 0.82rem;
  color: var(--red);
}

.upload-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  background: var(--sand-100);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.upload-drop input[type="file"] {
  border: none;
  background: transparent;
  padding: 0;
  flex: 1;
  min-width: 220px;
}

.context-meter {
  margin: 18px 0 4px;
}

.context-meter__label {
  font-size: 0.86rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
  font-weight: 600;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--sand-100);
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.progress-bar__fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal-600), var(--teal-900));
  transition: width 0.3s ease;
}

.danger-zone {
  border: 1px solid var(--coral-100);
  background: var(--coral-100);
  border-radius: var(--radius-lg);
}

.danger-zone .section-title {
  color: var(--coral-600);
}

.danger-zone p {
  color: #7a3327;
  font-size: 0.9rem;
}

/* ---------- Public portal hero + chat ---------- */

.portal-hero {
  margin-bottom: 28px;
}

.portal-hero h1 {
  color: var(--teal-900);
  font-size: 2rem;
}

.portal-hero__desc {
  color: var(--ink-soft);
  font-size: 1.05rem;
  max-width: 680px;
}

.portal-hero__subtitle {
  color: var(--teal-700);
  font-weight: 600;
  font-size: 0.95rem;
}

.chat-shell {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-toolbar {
  display: flex;
  justify-content: flex-end;
}

.new-convo-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-faint);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0;
}

.new-convo-link:hover {
  color: var(--coral-600);
}

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble-row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 13px 17px;
  border-radius: 18px;
  font-size: 0.96rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0 0 0.65em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble pre {
  background: rgba(28, 43, 45, 0.06);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 0.85rem;
  margin: 0.5em 0;
}

.bubble code {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.bubble :not(pre) > code {
  background: rgba(28, 43, 45, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.bubble.user {
  background: var(--teal-100);
  color: var(--teal-900);
  border-bottom-right-radius: 5px;
}

.bubble.assistant {
  background: #fff;
  border: 1px solid var(--border-soft);
  color: var(--ink);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.bubble.system-note {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--ink-faint);
  font-size: 0.88rem;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal-500);
  opacity: 0.4;
  animation: typing-pulse 1.2s infinite ease-in-out;
}

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

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

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

.chat-form {
  position: sticky;
  bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-lg);
}

#chat-input {
  flex: 1;
  border: none;
  resize: none;
  padding: 10px 12px;
  font-size: 0.96rem;
  max-height: 160px;
  min-height: 24px;
  font-family: inherit;
  background: transparent;
}

#chat-input:focus {
  outline: none;
  box-shadow: none;
}

.chat-form .btn {
  flex: none;
  align-self: flex-end;
}

/* ---------- Locked page ---------- */

.locked-wrap {
  max-width: 440px;
  margin: 50px auto;
  text-align: center;
}

.locked-wrap .lock-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--teal-050);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 18px;
}

.locked-wrap h1 {
  color: var(--teal-900);
  font-size: 1.4rem;
}

.locked-wrap p {
  color: var(--ink-soft);
}

.locked-wrap form {
  text-align: left;
  margin-top: 20px;
}

.locked-wrap .btn {
  width: 100%;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .site-main {
    padding: 28px 16px 60px;
  }

  .page-intro h1 {
    font-size: 1.7rem;
  }

  .portal-header {
    flex-direction: column;
  }

  .admin-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .bubble {
    max-width: 88%;
  }

  .chat-form {
    bottom: 8px;
  }
}
