:root {
  --ink: #1c1914;
  --paper: #f4efe4;
  --gold: #b08d3e;
  --panel: #fffdf8;
  --mute: #6b6458;
  --line: #e4d9c4;
  --yusuf: #1f3d2b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

/* ——— Public chat ——— */
body.public {
  font-family: "Source Sans 3", system-ui, sans-serif;
  background: #fff6e8;
  color: #1c1914;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
body.lang-ar.public,
body.lang-ar.public input,
body.lang-ar.public button,
body.lang-ar.public textarea {
  font-family: "Cairo", "Source Sans 3", sans-serif;
}

.app {
  height: 100%;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #fffaf1;
}

.app-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  color: #3b2a10;
  background: #fff;
  border-bottom: 1px solid #f0ddb0;
  z-index: 5;
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand-text { min-width: 0; }
.crest {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  background: linear-gradient(145deg, #ffd56a, #e2a21a);
  display: grid; place-items: center;
  font-family: "Cormorant Garamond", serif;
  font-weight: 700; color: #3b2a10; font-size: 20px;
}
.app-top h1 {
  font-family: "Cormorant Garamond", serif;
  font-size: 16px; margin: 0; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.lang-ar.public .app-top h1 { font-family: "Cairo", sans-serif; font-size: 14px; }
.sub { opacity: .7; font-size: 11px; margin-top: 2px; color: #7a5b1e; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.lang-switch {
  display: flex;
  flex: 0 0 auto;
  padding: 3px;
  gap: 3px;
  background: #fff6df;
  border: 1px solid #f0c45a;
  border-radius: 999px;
}
.lang-switch a {
  color: #8a6410;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 999px;
  line-height: 1;
}
.lang-switch a.on {
  background: linear-gradient(180deg, #ffd056, #f0b429);
  color: #3b2a10;
}
.admin-link {
  color: #8a6410; text-decoration: none; font-size: 13px;
  border: 1px solid #f0c45a; padding: 8px 12px; border-radius: 999px;
}

.thread {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff8ec;
}
.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 6px;
  color: #3b2a10;
}
.ava {
  width: 36px; height: 36px; border-radius: 50%;
  background: #0f9f62;
  color: #fff;
  display: grid; place-items: center; font-weight: 700;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px #ffcd4d;
}
.status { font-size: 12px; color: #7a6a4a; }
.online {
  width: 8px; height: 8px; background: #17c26a; border-radius: 50%;
  display: inline-block; margin-inline-end: 6px;
}

.log, #log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: min(92%, 560px);
  padding: 12px 16px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 15.5px;
  word-break: break-word;
}
.bot {
  align-self: flex-start;
  background: #fff;
  color: #1c1914;
  border: 1px solid #f3e2b6;
  border-end-start-radius: 6px;
}
.me {
  align-self: flex-end;
  background: linear-gradient(180deg, #1dbf73, #0e9a5a);
  color: #fff;
  border-end-end-radius: 6px;
}
.msg.typing { opacity: .65; font-style: italic; }

.composer-wrap {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 8;
  padding: 8px 14px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #fffaf1;
  border-top: 1px solid #f0ddb0;
}
.qs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 2px 10px;
}
.qs::-webkit-scrollbar { display: none; }
.qs button {
  flex: 0 0 auto;
  border: 1px solid #f0c45a;
  background: #fff4d4;
  color: #6b4d0c;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid #f0c45a;
  border-radius: 28px;
  padding: 6px 6px 6px 16px;
}
.composer input {
  flex: 1;
  border: 0;
  background: transparent;
  color: #1c1914;
  font: inherit;
  font-size: 16px;
  min-width: 0;
  padding: 10px 0;
}
.composer input::placeholder { color: #a38b52; }
.composer input:focus { outline: none; }
.send-btn {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: linear-gradient(180deg, #ffd056, #f0b429);
  color: #3b2a10;
}

@media (min-width: 800px) {
  body.public { padding: 16px 0; background: #ffe9b8; }
  .app {
    height: calc(100dvh - 32px);
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid #f0c45a;
    box-shadow: 0 20px 50px rgba(180,120,20,.18);
    background: #fffaf1;
  }
}

/* ——— Admin ——— */
body.admin { font-family: "Source Sans 3", system-ui, sans-serif; background: #f3eee4; color: var(--ink); height: auto; overflow: auto; }
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
nav.side { background: #16130e; color: #f4efe4; padding: 20px 14px; }
nav.side h1 { font-family: "Cormorant Garamond", serif; font-size: 22px; margin: 0 8px 18px; }
nav.side a { display: block; color: #e8d7a8; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
nav.side a.active, nav.side a:hover { background: #2a2418; }
nav.side .out { margin-top: 24px; color: #aaa; }
main.admin-main { padding: 24px 28px 48px; }
main.admin-main h2 { font-family: "Cormorant Garamond", serif; font-size: 30px; margin: 0 0 16px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.card b { font-size: 28px; display: block; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
table.grid th { background: #efe6d3; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.btn { border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer; font: inherit; font-weight: 600; }
.ok { background: #1f3d2b; color: #fff; }
.warn { background: #8a2a2a; color: #fff; }
.ghost { background: #efe6d3; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: block; font-size: 13px; margin: 8px 0 4px; color: var(--mute); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], textarea, select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
textarea { min-height: 90px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.pending { background: #f3e0b0; }
.approved { background: #cfe8d4; }
.rejected { background: #f0cfcf; }
.muted { color: var(--mute); font-size: 13px; }
pre.mail { white-space: pre-wrap; font-size: 13px; margin: 0; font-family: inherit; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { display: flex; gap: 8px; flex-wrap: wrap; }
  .cards, .grid2 { grid-template-columns: 1fr 1fr; }
}
body.login { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #12100c; font-family: "Source Sans 3", sans-serif; height: auto; overflow: auto; }
.login-box { background: #fffdf8; padding: 32px; border-radius: 16px; width: min(380px, 92vw); }
.login-box h1 { font-family: "Cormorant Garamond", serif; margin: 0 0 6px; }
.err { color: #8a2a2a; font-size: 13px; }