/* rayan-chat design. Change the colors in the first two blocks; everything else follows. */

:root {
  color-scheme: dark light;
  --bg: #0b0b0d;
  --surface: #131316;
  --surface-2: #1c1c21;
  --border: #2b2b33;
  --text: #ececf1;
  --muted: #9a9aa6;
  --accent: #e5383b;        /* main color (red) */
  --accent-deep: #b3262b;   /* my message bubbles and buttons */
  --on-accent: #ffffff;     /* text on top of --accent-deep */
  --good: #3ddc84;
  --warn: #f2c14e;
  --bad: #ff5a5f;
  --name-s: 75%;
  --name-l: 72%;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  --glow: 16%;
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f5;
    --surface: #ffffff;
    --surface-2: #ffffff;
    --border: #dcdce4;
    --text: #17171b;
    --muted: #5b5b69;
    --accent: #c62828;
    --accent-deep: #c62828;
    --on-accent: #ffffff;
    --good: #14803f;
    --warn: #a66b00;
    --bad: #c62828;
    --name-s: 65%;
    --name-l: 30%;
    --shadow: 0 8px 28px rgba(30, 30, 60, 0.12);
    --glow: 9%;
  }
}

/* Alternative accent colors (chosen with the small dots in the header) */
:root[data-accent="blue"] { --accent: #4c8dff; --accent-deep: #2b64d9; --on-accent: #ffffff; }
:root[data-accent="yellow"] { --accent: #f2c14e; --accent-deep: #f2c14e; --on-accent: #1a1400; }
@media (prefers-color-scheme: light) {
  :root[data-accent="blue"] { --accent: #1f5fd6; --accent-deep: #1f5fd6; --on-accent: #ffffff; }
  :root[data-accent="yellow"] { --accent: #c98a00; --accent-deep: #f2c14e; --on-accent: #1a1400; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(900px 340px at 50% -160px, color-mix(in srgb, var(--accent) var(--glow), transparent), transparent),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.6rem max(1rem, env(safe-area-inset-right)) 0.6rem max(1rem, env(safe-area-inset-left));
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; letter-spacing: 0.2px; }
.brand .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.who { color: var(--muted); font-size: 0.85rem; }
.spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.led { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--warn); }
.conn[data-state="ok"] .led { background: var(--good); }
.conn[data-state="bad"] .led { background: var(--bad); }
.conn[data-state="wait"] .led { animation: pulse 1.1s ease-in-out infinite; }
.swatches { display: flex; gap: 0.35rem; }
.sw { width: 1.05rem; height: 1.05rem; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.sw[data-accent="red"] { background: #e5383b; }
.sw[data-accent="blue"] { background: #4c8dff; }
.sw[data-accent="yellow"] { background: #f2c14e; }
.sw[aria-pressed="true"] { border-color: var(--text); }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.ghost:hover { color: var(--text); border-color: var(--accent); }

/* ---------- messages ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 1rem max(0.8rem, env(safe-area-inset-right)) 1rem max(0.8rem, env(safe-area-inset-left));
  scroll-behavior: smooth;
}
.empty { margin: auto; color: var(--muted); text-align: center; }
.day { align-self: center; margin: 0.9rem 0 0.5rem; }
.day span {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.15rem 0.75rem;
  border-radius: 999px;
}

.row { display: flex; align-items: flex-end; gap: 0.55rem; max-width: min(82%, 36rem); margin-top: 0.55rem; animation: rise 0.16s ease-out; }
.row.grouped { margin-top: 0; }
.row.other { align-self: flex-start; }
.row.mine { align-self: flex-end; }

.avatar {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #101012;
  background: hsl(var(--hue) 70% 66%);
  align-self: flex-start;
}
.row.grouped .avatar { visibility: hidden; height: 0; }

.bubble {
  min-width: 0;
  padding: 0.45rem 0.8rem 0.4rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.row.other .bubble { border-start-start-radius: 4px; }
.row.other.grouped .bubble { border-start-start-radius: var(--radius); }
.row.mine .bubble {
  background: var(--accent-deep);
  border-color: transparent;
  color: var(--on-accent);
  border-end-end-radius: 4px;
}
.meta { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.05rem; }
.name { font-weight: 700; font-size: 0.85rem; color: hsl(var(--hue) var(--name-s) var(--name-l)); }
.meta .time, .stamp { font-size: 0.7rem; color: var(--muted); }
.row.mine .stamp { color: color-mix(in srgb, var(--on-accent) 93%, transparent); }
.body { white-space: pre-wrap; }
.stamp { display: block; text-align: end; margin-top: 0.1rem; }

/* ---------- "new messages" pill ---------- */
#jump {
  position: absolute;
  inset-inline-start: 50%;
  translate: -50% 0;
  bottom: calc(4.6rem + env(safe-area-inset-bottom));
  background: var(--accent-deep);
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}
#jump[hidden] { display: none; }

/* ---------- composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.6rem max(0.8rem, env(safe-area-inset-right)) max(0.6rem, env(safe-area-inset-bottom)) max(0.8rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 9rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.send {
  flex: none;
  width: 2.7rem;
  height: 2.7rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent-deep);
  color: var(--on-accent);
  display: grid;
  place-items: center;
}
.send svg { width: 1.25rem; height: 1.25rem; fill: currentColor; transform: scaleX(-1); }
.send:hover { filter: brightness(1.12); }

/* ---------- login page ---------- */
.center { flex: 1; display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(94vw, 360px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 16px;
  padding: 1.6rem 1.4rem;
  box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 0.2rem; font-size: 1.35rem; display: flex; align-items: center; gap: 0.5rem; }
.card h1 .dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.card p { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; }
.card label { display: block; margin: 0.8rem 0 0.3rem; font-size: 0.85rem; color: var(--muted); }
.card input[type="text"], .card input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  direction: ltr;
  text-align: left;
}
.card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.showpw { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; font-size: 0.85rem; color: var(--muted); }
.card .primary {
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.75rem;
  border: 0;
  border-radius: 10px;
  background: var(--accent-deep);
  color: var(--on-accent);
  font-weight: 700;
}
.card .primary:hover:not(:disabled) { filter: brightness(1.12); }
.card .primary:disabled { opacity: 0.6; cursor: default; }
#error { min-height: 1.4rem; margin-top: 0.8rem; color: var(--bad); font-size: 0.88rem; text-align: center; }

@keyframes pulse { 50% { opacity: 0.25; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
@media (max-width: 480px) {
  .who { display: none; }
  .row { max-width: 90%; }
}
