/* ─────────────────────────────────────────────────────────────
   PHIL — VitaCare Living
   Brand: primary #00b4e4 (VitaCare blue), neutral #888a8b
   ───────────────────────────────────────────────────────────── */

:root {
  --vc-blue: #00b4e4;
  --vc-blue-dark: #0090b8;
  --vc-blue-soft: #e6f7fc;
  --vc-gray: #888a8b;
  --vc-ink: #1f2937;
  --vc-ink-soft: #4b5563;
  --vc-bg: #f4f7f9;
  --vc-surface: #ffffff;
  --vc-border: #e3e8ec;
  --vc-danger: #d9534f;
  --vc-success: #2e9e5b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(16, 42, 67, 0.08);
  --shadow-lg: 0 10px 40px rgba(16, 42, 67, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--vc-ink);
  background: var(--vc-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── App shell ─────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--vc-bg);
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--vc-blue) 0%, var(--vc-blue-dark) 100%);
  color: #fff;
  padding: 18px 20px 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
}

.header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1;
}

.header .subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.92;
}

.new-chat-btn {
  margin-left: auto;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}
.new-chat-btn:active {
  transform: scale(0.96);
}
.new-chat-btn svg {
  width: 15px;
  height: 15px;
}

.facility-pill {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}

.facility-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b6f2c5;
  box-shadow: 0 0 0 3px rgba(182, 242, 197, 0.3);
}

/* ── Access lock screen ────────────────────────────────────── */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: linear-gradient(135deg, var(--vc-blue) 0%, var(--vc-blue-dark) 100%);
  display: grid;
  place-items: center;
  padding: 24px;
}
/* `display: grid` above overrides the browser's [hidden]{display:none}, so the
   hidden attribute alone can't dismiss the overlay. This restores it. */
.lock-screen[hidden] {
  display: none;
}
.lock-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 30px 24px 26px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.lock-logo {
  display: block;
  width: 190px;
  max-width: 72%;
  height: auto;
  margin: 0 auto 18px;
}
.lock-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
}
.lock-sub {
  color: var(--vc-ink-soft);
  font-size: 14px;
  margin: 0 0 18px;
}
.lock-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--vc-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  text-align: center;
  margin-bottom: 12px;
  outline: none;
}
.lock-card input:focus {
  border-color: var(--vc-blue);
}
.lock-card .btn {
  width: 100%;
}
.lock-error {
  color: var(--vc-danger);
  font-size: 13px;
  margin: 12px 0 0;
}
.lock-hint {
  color: var(--vc-gray);
  font-size: 12px;
  margin: 16px 0 0;
}

/* ── Privacy disclaimer bar ────────────────────────────────── */
.disclaimer {
  background: #fff6e6;
  color: #8a6d3b;
  border-bottom: 1px solid #f0e0c0;
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 16px;
  text-align: center;
  position: relative;
  z-index: 2;
}
.disclaimer strong {
  color: #7a5c2e;
}

/* ── Watermark (faint logo behind the chat) ────────────────── */
.watermark {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 720px);
  background-image: url('/img/logo.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: min(60%, 300px);
  opacity: 0.08; /* faint watermark — lower toward 0.05 for subtler, raise for bolder */
  pointer-events: none;
  z-index: 0;
}

/* ── Chat area ─────────────────────────────────────────────── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1; /* sits above the watermark; bubbles cover it, empty space reveals it */
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 92%;
  animation: rise 0.25s ease;
}

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

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

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}

.msg.phil .avatar {
  background: linear-gradient(135deg, var(--vc-blue), var(--vc-blue-dark));
}

.msg.user .avatar {
  background: var(--vc-gray);
}

.bubble {
  padding: 12px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.55;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.phil .bubble {
  background: var(--vc-surface);
  border: 1px solid var(--vc-border);
  border-top-left-radius: 5px;
}

.msg.user .bubble {
  background: var(--vc-blue);
  color: #fff;
  border-top-right-radius: 5px;
}

/* Rendered markdown-ish content inside PHIL bubbles */
.bubble p {
  margin: 0 0 9px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 6px 0 9px;
  padding-left: 20px;
}
.bubble li {
  margin: 3px 0;
}
.bubble strong {
  font-weight: 700;
}
.bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.9em;
}

.sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--vc-border);
  font-size: 11.5px;
  color: var(--vc-gray);
}

/* Answer feedback (thumbs up/down) */
.feedback {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--vc-border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.fb-label {
  font-size: 11.5px;
  color: var(--vc-gray);
  margin-right: 2px;
}
.fb-btn {
  border: 1px solid var(--vc-border);
  background: #fff;
  border-radius: 8px;
  padding: 2px 9px;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.15s ease;
}
.fb-btn:hover {
  border-color: var(--vc-blue);
  background: var(--vc-blue-soft);
}
.sources b {
  color: var(--vc-ink-soft);
}

/* Typing indicator */
.typing .bubble {
  display: inline-flex;
  gap: 5px;
  padding: 15px;
}
.typing .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--vc-gray);
  animation: blink 1.2s infinite ease-in-out;
}
.typing .dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing .dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Idle "still there?" check-in prompt */
.idle-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 4px;
}
.idle-btn {
  border: 1.5px solid var(--vc-border);
  background: #fff;
  color: var(--vc-ink-soft);
  border-radius: 999px;
  padding: 9px 14px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.idle-btn:hover {
  border-color: var(--vc-blue);
  color: var(--vc-blue);
  background: var(--vc-blue-soft);
}
.idle-btn.primary {
  background: var(--vc-blue);
  border-color: var(--vc-blue);
  color: #fff;
}
.idle-btn.primary:hover {
  background: var(--vc-blue-dark);
  color: #fff;
}
.idle-note {
  font-size: 11.5px;
  color: var(--vc-gray);
  margin: 4px 0 0;
}

/* Suggestion chips */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 6px;
}
.chip {
  background: var(--vc-surface);
  border: 1px solid var(--vc-border);
  color: var(--vc-ink-soft);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover {
  border-color: var(--vc-blue);
  color: var(--vc-blue);
  background: var(--vc-blue-soft);
}

/* ── Composer ──────────────────────────────────────────────── */
.composer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--vc-surface);
  border-top: 1px solid var(--vc-border);
  position: relative;
  z-index: 2;
}
.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--vc-border);
  border-radius: 22px;
  padding: 11px 16px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s ease;
}
.composer textarea:focus {
  border-color: var(--vc-blue);
}
.send-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--vc-blue);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.send-btn:hover {
  background: var(--vc-blue-dark);
}
.send-btn:active {
  transform: scale(0.94);
}
.send-btn:disabled {
  background: #c7d0d6;
  cursor: not-allowed;
}
.send-btn svg {
  width: 20px;
  height: 20px;
}

/* ── Footer ────────────────────────────────────────────────── */
.footer {
  text-align: center;
  font-size: 11.5px;
  color: var(--vc-gray);
  padding: 8px 16px 10px;
  background: var(--vc-surface);
  position: relative;
  z-index: 2;
}
.footer strong {
  color: var(--vc-ink-soft);
}

/* ── Admin ─────────────────────────────────────────────────── */
.admin-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px 60px;
}
.card {
  background: var(--vc-surface);
  border: 1px solid var(--vc-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-top: 18px;
}
.card h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
.card .hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--vc-gray);
}

/* ── Collapsible admin cards ───────────────────────────────── */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 38px; /* reserve room for the pinned collapse toggle */
}
.card-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* Pinned to the header's top-right and lifted above siblings so nothing
   (long status pills, action buttons, hints) can ever cover its hit area. */
.card-toggle {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--vc-ink-soft);
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}
.card-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}
.card-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}
.card.collapsed .card-toggle svg {
  transform: rotate(-90deg);
}
.card-body {
  margin-top: 14px;
}
.card.collapsed .card-body {
  display: none;
}
label.field {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--vc-ink-soft);
}
label.field span {
  display: block;
  margin-bottom: 6px;
}
input[type='text'],
input[type='password'],
input[type='file'],
select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--vc-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  background: #fff;
}
input:focus,
select:focus {
  border-color: var(--vc-blue);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--vc-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn:hover {
  background: var(--vc-blue-dark);
}
.btn:disabled {
  background: #c7d0d6;
  cursor: not-allowed;
}
.btn.secondary {
  background: #fff;
  color: var(--vc-ink-soft);
  border: 1.5px solid var(--vc-border);
}
.btn.secondary:hover {
  border-color: var(--vc-blue);
  color: var(--vc-blue);
}
.btn.danger {
  background: transparent;
  color: var(--vc-danger);
  border: 1.5px solid #f0c9c8;
  padding: 7px 12px;
  font-size: 13px;
}
.btn.danger:hover {
  background: #fbecec;
}

.radio-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.radio-row label {
  flex: 1;
  min-width: 90px;
  border: 1.5px solid var(--vc-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--vc-ink-soft);
}
.radio-row input {
  display: none;
}
.radio-row input:checked + span {
  color: var(--vc-blue);
}
.radio-row label:has(input:checked) {
  border-color: var(--vc-blue);
  background: var(--vc-blue-soft);
}

.doc-filter-btn {
  border: 1px solid var(--vc-border);
  background: #fff;
  color: var(--vc-ink-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.doc-filter-btn:hover {
  border-color: var(--vc-blue);
  color: var(--vc-blue);
}
.doc-filter-btn.active {
  background: var(--vc-blue);
  border-color: var(--vc-blue);
  color: #fff;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.doc-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--vc-gray);
  padding: 6px 8px;
  border-bottom: 2px solid var(--vc-border);
}
.doc-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--vc-border);
  vertical-align: middle;
}
.doc-table tr:last-child td {
  border-bottom: none;
}
.doc-name {
  font-weight: 600;
  word-break: break-all;
}
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.badge.MN {
  background: #e6f0ff;
  color: #2e5cb8;
}
.badge.WI {
  background: #fdeede;
  color: #b8722e;
}
.badge.Both {
  background: #e9f7ef;
  color: #2e9e5b;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
}

/* ── Usage dashboard (admin) ───────────────────────────────── */
.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.stat-tile {
  background: var(--vc-bg);
  border: 1px solid var(--vc-border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.stat-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--vc-blue-dark);
}
.stat-label {
  font-size: 11.5px;
  color: var(--vc-gray);
  margin-top: 3px;
}
.fac-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 2px;
  border-bottom: 1px solid var(--vc-border);
  font-size: 14px;
}
.fac-row:last-child {
  border-bottom: none;
}

/* ── Knowledge gaps (admin) ────────────────────────────────── */
.gap-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--vc-border);
}
.gap-item:last-child {
  border-bottom: none;
}
.gap-q {
  font-size: 14px;
  color: var(--vc-ink);
}
.gap-meta {
  font-size: 12px;
  color: var(--vc-gray);
  margin-top: 3px;
}
.punchlist {
  margin-top: 14px;
  padding: 16px;
  background: var(--vc-blue-soft);
  border: 1px solid #bfe9f5;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--vc-ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.status.ok .dot {
  background: var(--vc-success);
}
.status.off .dot {
  background: var(--vc-danger);
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--vc-ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.error {
  background: var(--vc-danger);
}
.toast.success {
  background: var(--vc-success);
}

.muted {
  color: var(--vc-gray);
  font-size: 14px;
}
.empty {
  text-align: center;
  padding: 30px 10px;
  color: var(--vc-gray);
}

.admin-header {
  background: linear-gradient(135deg, var(--vc-blue) 0%, var(--vc-blue-dark) 100%);
  color: #fff;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-header .left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}
.admin-header .sub {
  font-size: 12px;
  opacity: 0.9;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 721px) {
  .app {
    box-shadow: var(--shadow-lg);
  }
}
