:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --nav: #1A1938;
  --accent: #4F65F1;
  --alert: #FF6B93;
  --text: #2B2D42;
  --text-2: #8D95A3;
  --divider: #EAEAEA;

  --glow: 0 8px 24px rgba(79, 101, 241, .25);
  --soft: 0 2px 10px rgba(0, 0, 0, .03);

  --r-card: 16px;
  --r-inner: 12px;
}

@media (prefers-color-scheme: dark) {
  /* Surfaces only. Accent and alert stay fixed so the identity holds in both themes. */
  :root {
    --bg: #14161F;
    --surface: #1C1F2B;
    --nav: #12111F;
    --text: #E9EBF2;
    --text-2: #8D95A3;
    --divider: #262A38;
    --soft: 0 2px 10px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  overflow: hidden;
}

.hidden { display: none !important; }

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

.app {
  display: grid;
  grid-template-columns: 90px 340px 1fr 300px;
  height: 100vh;
}

/* ---------------- column 1: navigation ---------------- */

.rail {
  background: var(--nav);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 8px;
}

.brand {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 18px;
  margin-bottom: 18px;
}

.rail-item {
  width: 54px; padding: 11px 0;
  border-radius: var(--r-inner);
  color: rgba(255, 255, 255, .55);
  text-decoration: none;
  display: grid; place-items: center; gap: 5px;
  font-size: 10px; font-weight: 500;
}
.rail-item:hover  { color: #fff; background: rgba(255, 255, 255, .07); }
.rail-item.active { color: #fff; background: rgba(255, 255, 255, .14); }
.rail-spacer { flex: 1; }

/* ---------------- column 2: inbox list ---------------- */

.list-panel {
  background: var(--surface);
  display: flex; flex-direction: column;
  min-height: 0;
  /* Active cards break this boundary, so they must not be clipped horizontally. */
  overflow: visible;
}

.search {
  margin: 20px 20px 10px;
  display: flex; align-items: center; gap: 9px;
  background: var(--bg);
  border-radius: var(--r-inner);
  padding: 0 14px;
  color: var(--text-2);
}
.search input {
  flex: 1; border: 0; background: none; outline: none;
  padding: 12px 0;
  font: inherit; color: var(--text);
}
.search input::placeholder { color: var(--text-2); }

.list-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px 10px;
}
.list-head h2 {
  font-size: 22px; font-weight: 600; margin: 0;
  letter-spacing: -.01em;
}

.badge {
  background: var(--alert); color: #fff;
  border-radius: 999px;
  font-size: 11px; font-weight: 500;
  padding: 3px 10px;
}

.convos { flex: 1; overflow-y: auto; overflow-x: visible; padding: 4px 20px 20px; }

.convo {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r-card);
  text-decoration: none; color: inherit;
  margin-bottom: 6px;
  background: transparent;
}
.convo:hover { background: var(--bg); }

/* Floating active state: flat accent, colored glow, and an offset that
   deliberately breaks the list grid so the card overlaps its boundaries. */
.convo.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--glow);
  margin-left: -10px;
  padding-left: 26px;
  margin-right: -10px;
  padding-right: 26px;
}
.convo.active .convo-time,
.convo.active .convo-preview { color: rgba(255, 255, 255, .8); }

.convo-main { flex: 1; min-width: 0; }
.convo-top  { display: flex; align-items: baseline; gap: 8px; }
.convo-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-time { margin-left: auto; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.convo-preview {
  display: block; font-size: 13px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
.convo .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--alert); flex: none; }
.convo.active .dot { background: #fff; }

/* ---------------- avatars ---------------- */

.avatar {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 14px;
}
.avatar.big { width: 96px; height: 96px; font-size: 32px; margin: 0 auto 16px; }

.avatar.c0 { background: #4F65F1; }
.avatar.c1 { background: #FF6B93; }
.avatar.c2 { background: #2BB673; }
.avatar.c3 { background: #F5A623; }
.avatar.c4 { background: #8A6DF1; }
.avatar.c5 { background: #35A7C8; }
.avatar.c6 { background: #EF7A54; }
.avatar.c7 { background: #7C879B; }

/* ---------------- column 3: chat ---------------- */

.thread-panel {
  background: var(--surface);
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  border-left: 1px solid var(--divider);
}

.thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--divider);
}
.thread-head .avatar { width: 40px; height: 40px; }
.thread-who { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.thread-who strong { font-size: 15px; font-weight: 600; }
.thread-who small  { color: var(--text-2); font-size: 12px; }
.thread-head .back { display: none; text-decoration: none; color: var(--text-2); font-size: 20px; }

.icon-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--text-2);
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 18px;
}
.icon-btn:hover { background: var(--bg); color: var(--accent); }
.thread-head .icon-btn { margin-left: auto; }

.thread { flex: 1; overflow-y: auto; padding: 24px; }

.day { text-align: center; margin: 18px 0 14px; }
.day span {
  background: var(--bg); color: var(--text-2);
  font-size: 12px; padding: 5px 14px; border-radius: 999px;
}

.msg { display: flex; flex-direction: column; max-width: 62%; margin-bottom: 14px; }
.msg.in  { align-items: flex-start; margin-right: auto; }
.msg.out { align-items: flex-end;   margin-left: auto; }

.bubble {
  padding: 12px 16px;
  font-weight: 400;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.in .bubble {
  background: var(--bg);
  color: var(--text);
  border-radius: 16px 16px 16px 4px;
}
.msg.out .bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.msg-meta { font-size: 11px; color: var(--text-2); margin: 5px 4px 0; }

.msg.pending { opacity: .55; }
.msg.failed .bubble { background: var(--alert); color: #fff; }
.msg.failed .msg-meta { color: var(--alert); }

/* media inside bubbles */

.bubble.media { padding: 6px; }
.bubble.media img.photo {
  display: block;
  max-width: 300px; max-height: 340px;
  width: 100%; height: auto;
  border-radius: var(--r-inner);
  cursor: zoom-in;
}
.bubble.media video { max-width: 300px; width: 100%; border-radius: var(--r-inner); display: block; }
.bubble .caption { padding: 8px 10px 4px; }

.doc-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  min-width: 220px;
  text-decoration: none; color: inherit;
}
.doc-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, .22);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.msg.in .doc-icon { background: var(--accent); color: #fff; }
.doc-meta { min-width: 0; }
.doc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-size { font-size: 12px; opacity: .75; }

/* audio visualiser */

.audio {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 4px;
  min-width: 240px;
}
.audio-play {
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  display: grid; place-items: center;
}
.msg.in .audio-play { background: var(--accent); color: #fff; }
.audio-body { flex: 1; min-width: 0; }
.wave {
  display: flex; align-items: center; gap: 2px;
  height: 30px; cursor: pointer;
}
.wave i {
  flex: 1;
  min-width: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .5);
  transition: background .1s linear;
}
.wave i.played { background: #fff; }
.msg.in .wave i { background: rgba(79, 101, 241, .35); }
.msg.in .wave i.played { background: var(--accent); }
.audio-time { font-size: 11px; opacity: .8; margin-top: 2px; }

/* lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(26, 25, 56, .88);
  display: grid; place-items: center;
  padding: 40px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--r-inner); }
.lightbox button {
  position: absolute; top: 20px; right: 24px;
  background: none; border: 0; color: #fff;
  font-size: 32px; cursor: pointer; line-height: 1;
}

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

.composer-wrap { border-top: 1px solid var(--divider); }

.attach-chip {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 24px 0;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--r-inner);
  font-size: 13px;
}
.attach-chip .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach-chip button { background: none; border: 0; cursor: pointer; color: var(--text-2); font-size: 18px; }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 16px 24px;
}
.composer textarea {
  flex: 1;
  border: 0;
  background: var(--bg);
  color: var(--text);
  border-radius: var(--r-inner);
  padding: 13px 16px;
  font: inherit;
  resize: none; outline: none;
  max-height: 140px;
}
.composer textarea::placeholder { color: var(--text-2); }
.composer.blocked textarea { opacity: .6; }

.attach-btn {
  width: 42px; height: 42px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--bg); color: var(--text-2);
  cursor: pointer; display: grid; place-items: center;
}
.attach-btn:hover { color: var(--accent); }

.send {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--glow);
}
.send:hover { filter: brightness(1.06); }

.composer-note {
  padding: 0 24px 14px;
  color: var(--alert);
  font-size: 13px;
}

/* ---------------- column 4: profile ---------------- */

.profile-panel {
  background: var(--surface);
  border-left: 1px solid var(--divider);
  display: flex; flex-direction: column;
  min-height: 0;
}
.profile-head {
  display: flex; align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--divider);
}
.profile-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.profile-head .icon-btn { margin-left: auto; }
.profile-body { padding: 26px 20px; overflow-y: auto; text-align: center; }

.name-input {
  width: 100%;
  border: 1px solid transparent;
  background: none; color: var(--text);
  font: inherit; font-size: 17px; font-weight: 600;
  text-align: center;
  padding: 7px 8px; border-radius: 10px;
  outline: none;
}
.name-input:hover { border-color: var(--divider); }
.name-input:focus { border-color: var(--accent); background: var(--bg); }

.number { color: var(--accent); font-size: 14px; font-weight: 500; margin: 3px 0 20px; }

.window-card {
  border-radius: var(--r-card);
  padding: 14px;
  margin-bottom: 20px;
  background: var(--bg);
  text-align: left;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: var(--soft);
}
.window-card .window-label {
  font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-2);
}
.window-card strong { font-size: 18px; font-weight: 600; }
.window-card small  { color: var(--text-2); font-size: 12px; }
.window-card.open   strong { color: #2BB673; }
.window-card.warn   strong { color: #F5A623; }
.window-card.closed strong { color: var(--alert); }

/* Spec's booking-card treatment, applied to real conversation stats. */
.stat-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: var(--r-inner);
  box-shadow: var(--soft);
  text-align: left;
}
.stat-thumb {
  width: 38px; height: 38px; flex: none;
  border-radius: 8px;
  background: var(--bg);
  display: grid; place-items: center;
  color: var(--accent);
  font-weight: 600; font-size: 13px;
}
.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-2); }
.stat-value { font-weight: 600; }

.notify-btn {
  width: 100%; margin-top: 12px;
  padding: 11px;
  border: 1px solid var(--divider);
  background: var(--surface); color: var(--text);
  border-radius: var(--r-inner);
  font: inherit; font-weight: 500; cursor: pointer;
}
.notify-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- empty states ---------------- */

.empty, .empty-state { color: var(--text-2); text-align: center; padding: 48px 24px; }
.empty-state { margin: auto; }
.empty-state h3 { color: var(--text); margin: 0 0 6px; font-weight: 600; }

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

body.login-page { overflow: auto; display: grid; place-items: center; }
.login {
  width: min(370px, 92vw);
  padding: 34px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--glow);
  text-align: center;
}
.login .brand { margin: 0 auto 18px; }
.login h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.login p  { margin: 0 0 22px; color: var(--text-2); }
.login input {
  width: 100%; margin-bottom: 12px;
  padding: 13px 16px;
  border: 1px solid var(--divider); border-radius: var(--r-inner);
  background: var(--bg); color: var(--text);
  font: inherit; outline: none;
}
.login input:focus { border-color: var(--accent); }
.login button {
  width: 100%; padding: 13px;
  border: 0; border-radius: var(--r-inner);
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 500; cursor: pointer;
  box-shadow: var(--glow);
}
.notice {
  padding: 11px 14px; border-radius: var(--r-inner);
  font-size: 13px; margin-bottom: 16px;
  background: var(--alert); color: #fff;
}

/* ---------------- responsive ---------------- */

@media (max-width: 1200px) {
  .app { grid-template-columns: 90px 320px 1fr; }
  .profile-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 300px; z-index: 40;
    box-shadow: var(--glow);
    transform: translateX(100%);
    transition: transform .18s ease;
  }
  body.profile-open .profile-panel { transform: none; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 72px 1fr; }
  .thread-panel { display: none; }
  body.has-selection .list-panel { display: none; }
  body.has-selection .thread-panel { display: flex; }
  .thread-head .back { display: block; }
  .msg { max-width: 84%; }
  .convo.active { margin-right: 0; padding-right: 16px; }
  .profile-panel { width: min(320px, 92vw); }
}
