/* ---------------------------------------------------------------
   Torenia - guest UI. Built for a phone first: guests arrive by
   scanning the QR code on their room door.
   --------------------------------------------------------------- */

:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f9;
  --border: #e4e7ec;
  --text: #16181d;
  --text-muted: #5c6472;
  --text-faint: #8b93a1;
  --accent: #5b4bd6;
  --accent-hover: #4c3dc4;
  --accent-soft: #eeecfd;
  --bubble-user: #5b4bd6;
  --ok: #17845a;
  --ok-soft: #e6f5ee;
  --danger: #d64545;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", Consolas, monospace;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --bg-soft: #171a20;
    --border: #272b34;
    --text: #e8eaef;
    --text-muted: #9aa1ae;
    --text-faint: #6b7280;
    --accent: #8878fb;
    --accent-hover: #9a8dfc;
    --accent-soft: #221f3b;
    --bubble-user: #6d5cf0;
    --ok: #4cc38a;
    --ok-soft: #14261f;
    --danger: #f26d6d;
  }
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none, but any class that sets a
   display wins over it. Everything here relies on `hidden`, so make it
   unambiguous - without this the composer stays visible on the home screen. */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }
textarea, input { font-family: inherit; }

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

.login-body {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 20px;
  background: radial-gradient(700px 380px at 50% -5%, var(--accent-soft), transparent 70%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: 0 16px 40px rgba(16, 18, 22, 0.10);
}

.brand { display: flex; align-items: center; gap: 12px; }

/* Torenia logo, centred above the sign-in form. */
.brand-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.brand-logo { width: 148px; height: auto; display: block; }
.brand-hero + .room-chip { display: table; margin: 14px auto 0; }

.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;
}
.brand-mark { font-size: 30px; line-height: 1; }
.brand h1 { font-size: 21px; margin: 0; letter-spacing: -0.02em; }
.brand-sub { font-size: 13px; color: var(--text-muted); }

.room-chip {
  display: inline-block;
  margin: 16px 0 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
}

.tagline { color: var(--text-muted); margin: 14px 0 22px; font-size: 14.5px; }

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.login-card input[type="tel"] {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 16px;          /* 16px stops iOS Safari zooming on focus */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input[type="tel"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 15px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 650;
}

.login-card button:hover:not(:disabled) { background: var(--accent-hover); }
.login-card button:disabled { opacity: 0.6; cursor: default; }

.error { color: var(--danger); font-size: 13.5px; margin: 12px 0 0; }
.hint { color: var(--text-faint); font-size: 12.5px; text-align: center; margin: 18px 0 0; }

@media (max-width: 420px) {
  .login-body { padding: 0; place-items: stretch; }
  .login-card {
    max-width: none;
    min-height: 100svh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 22px;
  }
}

/* --------------------------------------------------------- app --- */

.app {
  height: 100svh;                    /* small viewport: excludes the URL bar */
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.who strong { font-size: 15px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { font-size: 12.5px; color: var(--text-muted); }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex: 0 0 auto;
  font-size: 20px;
}

.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.signout {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 9px;
}

.signout:hover { border-color: var(--danger); color: var(--danger); }

.greeting-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}

.greeting-bar h1 { margin: 0; font-size: 24px; letter-spacing: -0.03em; }

.new-chat {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
}

.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.new-chat .plus { font-size: 16px; line-height: 1; color: var(--accent); }

/* ------------------------------------------------------- cards --- */

.cards {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  gap: 12px;
  padding: 6px 16px 20px;
  align-content: start;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 14px 13px 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.card:active { transform: scale(0.985); }
.card:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(91, 75, 214, 0.10); }

.card-icon {
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  margin-bottom: 7px;
}

.cat-room_service .card-icon { background: #e8eeff; }
.cat-food_ordering .card-icon { background: #fdeaf3; }
.cat-maintenance .card-icon { background: #fdf3d9; }
.cat-local_assistance .card-icon { background: #e2f6ec; }

@media (prefers-color-scheme: dark) {
  .cat-room_service .card-icon { background: #1b2440; }
  .cat-food_ordering .card-icon { background: #351c2b; }
  .cat-maintenance .card-icon { background: #322a15; }
  .cat-local_assistance .card-icon { background: #142c22; }
}

.card-title { font-size: 14.5px; font-weight: 650; letter-spacing: -0.01em; }
.card-blurb { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* -------------------------------------------------------- chat --- */

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.menu-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 16px 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}

.menu-icon { font-size: 19px; }
.menu-text { flex: 1; min-width: 0; }
.menu-text strong { display: block; font-size: 13.5px; }
.menu-text p { margin: 1px 0 0; font-size: 12px; color: var(--text-muted); }

.menu-banner button {
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
}

.menu-banner button:hover { background: var(--accent-hover); }

/* ------------------------------------------------- menu sheet --- */

.sheet {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.sheet-head {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 6px 0 16px;
  border-bottom: 1px solid var(--border);
}

.sheet-head strong { font-size: 15px; }
.sheet-actions { display: flex; align-items: center; gap: 6px; }

.sheet-actions a {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 calc(16px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.menu-frame {
  display: block;
  width: 100%;
  height: 62vh;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.menu-fallback-note {
  margin: 14px 16px 6px;
  font-size: 12px;
  color: var(--text-faint);
}

.menu-list { padding: 12px 16px 0; }
.menu-list section { margin-bottom: 18px; }

.menu-list h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.menu-list h3 span {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
  font-weight: 500;
}

.menu-list ul { list-style: none; margin: 0; padding: 0; }

.menu-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14.5px;
}

.menu-list li:last-child { border-bottom: 0; }
.menu-list li em { margin-left: auto; font-style: normal; color: var(--text-muted); font-size: 13.5px; }

.dot { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 9px; display: inline-block; }
.dot.veg { background: var(--ok); }
.dot.nonveg { background: var(--danger); }

.menu-none { padding: 24px 16px; margin: 0; color: var(--text-muted); font-size: 14px; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.msg { margin-bottom: 12px; display: flex; }
.msg.user { justify-content: flex-end; }

.msg .body {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  overflow-wrap: anywhere;
  font-size: 14.5px;
}

.msg.user .body {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}

.msg.assistant .body {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.msg.error .body { color: var(--danger); }

.body > *:first-child { margin-top: 0; }
.body > *:last-child { margin-bottom: 0; }
.body p { margin: 0 0 8px; }
.body ul, .body ol { margin: 0 0 8px; padding-left: 19px; }
.body li { margin: 3px 0; }
.body h2, .body h3 { margin: 11px 0 5px; font-size: 15px; }
.body a { color: var(--accent); }
.msg.user .body a { color: #fff; text-decoration: underline; }
.body strong { font-weight: 680; }
.body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
}
.body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 9px;
}
.body pre code { background: transparent; border: 0; padding: 0; }

.ticket-card {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 0 12px;
  padding: 11px 13px;
  border: 1px solid var(--ok);
  border-radius: 12px;
  background: var(--ok-soft);
}

.ticket-tick {
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
}

.ticket-card strong { display: block; font-size: 13.5px; }
.ticket-code { font-family: var(--mono); font-size: 12.5px; color: var(--ok); font-weight: 700; }

/* A real person from the hotel replying in the chat. */
.msg.staff { justify-content: flex-start; }
.staff-stack { display: flex; flex-direction: column; gap: 3px; max-width: 85%; }

.staff-from {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ok);
  padding-left: 4px;
}

.msg.staff .body {
  max-width: none;
  background: var(--ok-soft);
  border: 1px solid var(--ok);
  border-bottom-left-radius: 5px;
}

/* System messages: staff acknowledged / done / cancelled, and escalations. */
.notice {
  margin: 0 auto 12px;
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: center;
}

.notice p { margin: 0; }
.notice strong { color: var(--text); font-weight: 700; }
.notice.warn { border-color: var(--danger); color: var(--danger); background: transparent; }
.notice.escalation { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.escalate {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 11px 13px;
  border: 1px dashed var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
}

.escalate-text { flex: 1; font-size: 13.5px; color: var(--text); }
.escalate-text b { font-family: var(--mono); font-size: 12.5px; }

.escalate button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
}

.escalate button:hover:not(:disabled) { background: var(--accent-hover); }
.escalate button:disabled { opacity: 0.5; cursor: default; }

.cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  vertical-align: -2px;
  margin-left: 2px;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------- composer --- */

.composer {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 5px 5px 5px 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;          /* 16px stops iOS Safari zooming on focus */
  line-height: 1.45;
  max-height: 120px;
  padding: 7px 0;
}

.composer textarea::placeholder { color: var(--text-faint); }

.composer button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.composer button:hover:not(:disabled) { background: var(--accent-hover); }
.composer button:disabled { opacity: 0.4; cursor: default; }

/* ------------------------------------------------- sidebar --- */

.drawer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 82%;
  max-width: 320px;
  z-index: 30;
  background: var(--bg);
  border-right: 1px solid var(--border);
  transform: translateX(-101%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 28px rgba(0, 0, 0, 0.16);
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.drawer-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }

.drawer-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  text-align: left;
  color: var(--text);
}

.drawer-row:hover { background: var(--bg-soft); }
.drawer-row.on { background: var(--accent-soft); border-color: var(--accent); }

.row-icon { font-size: 17px; flex: 0 0 auto; }
.row-text { display: flex; flex-direction: column; min-width: 0; }
.row-title {
  font-size: 14px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-meta { font-size: 11.5px; color: var(--text-faint); }

.drawer-empty { padding: 16px; margin: 0; color: var(--text-faint); font-size: 13px; }

.drawer-brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 13px;
  font-weight: 650;
  color: var(--text-muted);
}

.drawer-brand img { display: block; }

.scrim {
  position: absolute;
  inset: 0;
  z-index: 29;
  background: rgba(0, 0, 0, 0.42);
}

@media (min-width: 700px) {
  .app { border-radius: 0; }
  .drawer { width: 300px; }
}
