/* Gradey Chat — web client.
   Layout mirrors the desktop app: dark rail on the left, content on the
   right. Tokens all come from styles.css. */

.app-body { height: 100dvh; overflow: hidden; }

/* ---------------------------------------------------------------- auth --- */

.auth-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--space-6);
  background:
    radial-gradient(900px 420px at 20% -10%, var(--primary-tint), transparent 62%),
    radial-gradient(700px 380px at 90% 10%, color-mix(in srgb, var(--indigo-300) 20%, transparent), transparent 60%);
  overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 412px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-xl);
  padding: var(--space-8); box-shadow: var(--shadow-lg);
}
.auth-brand {
  display: flex; align-items: center; gap: var(--space-3);
  justify-content: center; margin-bottom: var(--space-7);
}
.auth-brand .brand-mark { width: 30px; height: 30px; }
.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px; margin-bottom: var(--space-6);
}
.auth-tab {
  border: 0; background: transparent; color: var(--slate);
  padding: var(--space-3); border-radius: var(--radius-xs);
  font-size: .88rem; font-weight: 700; cursor: pointer;
}
/* A tab is a choice, not an action — tinted, never a block of solid indigo. */
.auth-tab.is-active { background: var(--primary-tint); color: var(--primary-text); }
.auth-submit { width: 100%; margin-top: var(--space-3); }
.auth-foot { text-align: center; margin-top: var(--space-6); }

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

.app { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100dvh; }

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--rail); border-right: 1px solid var(--n-800);
}
.sidebar-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-5); color: #fff; border-bottom: 1px solid var(--n-800);
}
.sidebar-head .brand-mark { width: 24px; height: 24px; }
.sidebar-search { padding: var(--space-4) var(--space-4) var(--space-3); }

.input-sm { height: 36px; font-size: .86rem; }
.sidebar .input {
  background: var(--n-800); border-color: var(--n-700); color: var(--n-100);
}
.sidebar .input::placeholder { color: var(--n-500); }
.sidebar .input:focus { border-color: var(--indigo-400); box-shadow: 0 0 0 3px rgba(79,70,229,.25); }

.conv-list { flex: 1; overflow-y: auto; padding: 0 var(--space-3) var(--space-4); }

.conv-group {
  color: var(--n-500); font-size: .66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  padding: var(--space-5) var(--space-3) var(--space-2);
}
.conv-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  padding: var(--space-3); border: 0; background: transparent; text-align: left;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--n-400);
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--rail-hover); color: var(--n-100); }
.conv-item.is-active {
  background: var(--rail-active); color: #fff;
  box-shadow: inset 3px 0 0 var(--indigo-400);
}
.conv-item strong { display: block; font-size: .88rem; font-weight: 600; }
.conv-item .preview { font-size: .74rem; color: var(--n-500); }
.conv-item.is-active .preview { color: var(--n-400); }

.unread {
  min-width: 20px; height: 20px; padding-inline: 6px; flex: none;
  background: var(--indigo-600); color: #fff; border-radius: var(--radius-full);
  font-size: .68rem; font-weight: 700; display: grid; place-items: center;
}

.sidebar-foot {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); border-top: 1px solid var(--n-800); color: var(--n-300);
}
.sidebar-foot strong { font-size: .85rem; color: #fff; }

.conn-banner {
  margin: var(--space-3) var(--space-4) 0; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs); font-size: .74rem; text-align: center;
  background: var(--warning-tint); color: var(--warning); border: 1px solid var(--warning-border);
}

.icon-btn {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: inherit; cursor: pointer; font-size: .95rem; opacity: .8;
}
.icon-btn:hover { background: rgba(255,255,255,.10); opacity: 1; }
.thread .icon-btn:hover, .popover .icon-btn:hover, .modal .icon-btn:hover {
  background: var(--surface-2);
}

.avatar {
  width: 34px; height: 34px; border-radius: var(--radius-full); flex: none;
  display: grid; place-items: center; color: #fff;
  font-size: .74rem; font-weight: 700; background: var(--indigo-600);
}
.avatar-sm { width: 26px; height: 26px; font-size: .62rem; }
.min-w-0 { min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* -------------------------------------------------------------- thread --- */

.thread { display: flex; flex-direction: column; min-width: 0; background: var(--canvas); }
.thread-empty { flex: 1; display: grid; place-items: center; padding: var(--space-8); }
.thread-empty-inner { text-align: center; max-width: 330px; }
.thread-empty-inner h3 { margin-block: var(--space-5) var(--space-3); }
.thread-empty-inner .btn { margin-top: var(--space-6); }

.thread-live { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.back-btn { display: none; }

.messages {
  flex: 1; overflow-y: auto; padding: var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-2);
}

.day-sep {
  align-self: center; margin-block: var(--space-4);
  font-size: .68rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-4);
}

.msg { display: flex; gap: var(--space-3); max-width: min(72%, 620px); }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-body { min-width: 0; }
.msg-sender {
  font-size: .7rem; font-weight: 700; color: var(--slate); margin-bottom: 3px;
}
.msg.mine .msg-sender { text-align: right; }

.msg-bubble {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border);
  font-size: .9rem; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
  border-bottom-left-radius: var(--radius-xs);
}
.msg.mine .msg-bubble {
  background: var(--primary); color: var(--on-primary); border-color: transparent;
  border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-xs);
}
.msg-bubble.deleted { font-style: italic; opacity: .6; }
/* Optimistic bubble, before the server has confirmed it. */
.msg.pending .msg-bubble { opacity: .55; }

.msg-meta {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: .66rem; color: var(--muted); margin-top: 3px;
}
.msg.mine .msg-meta { justify-content: flex-end; }
.msg-read { color: var(--indigo-400); font-weight: 700; }

.msg-media { border-radius: var(--radius-md); max-height: 300px; margin-top: var(--space-2); }
.msg-file {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); margin-top: var(--space-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--ink); font-size: .82rem;
}
.msg.mine .msg-file { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }
.msg-file:hover { text-decoration: none; border-color: var(--primary); }
.msg-del {
  border: 0; background: none; color: inherit; cursor: pointer;
  font-size: .66rem; opacity: .6; padding: 0;
}
.msg-del:hover { opacity: 1; text-decoration: underline; }

.typing-line {
  display: flex; align-items: center; gap: 4px;
  padding: 0 var(--space-6) var(--space-3); color: var(--muted); font-size: .76rem;
}
.typing-line span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--muted);
  animation: blink 1.3s infinite;
}
.typing-line span:nth-child(2) { animation-delay: .18s }
.typing-line span:nth-child(3) { animation-delay: .36s; margin-right: var(--space-2) }
@keyframes blink { 0%,60%,100% { opacity:.25 } 30% { opacity:1 } }

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

.composer {
  display: flex; align-items: flex-end; gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--surface); border-top: 1px solid var(--border);
}
.composer-input {
  flex: 1; min-height: 42px; max-height: 168px; resize: none;
  padding-block: var(--space-3); line-height: 1.45;
}
.send-btn { height: 42px; flex: none; }

.upload-bar {
  padding: var(--space-2) var(--space-5) var(--space-4);
  background: var(--surface); font-size: .78rem; color: var(--slate);
}

/* ------------------------------------------------------------- pickers --- */

.popover {
  position: absolute; bottom: 78px; left: 336px; z-index: 60;
  width: min(340px, calc(100vw - 32px));
  background: var(--surface-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.popover-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border);
}
.popover-body { padding: var(--space-4); }

.emoji-tabs {
  display: flex; gap: var(--space-1); padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.emoji-tab {
  border: 0; background: transparent; cursor: pointer; font-size: 1rem;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-xs);
}
.emoji-tab.is-active { background: var(--primary-tint); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 2px; padding: var(--space-3); max-height: 232px; overflow-y: auto;
}
.emoji-grid button {
  border: 0; background: transparent; font-size: 1.28rem; cursor: pointer;
  padding: var(--space-2); border-radius: var(--radius-xs); line-height: 1;
}
.emoji-grid button:hover { background: var(--surface-2); }

.gif-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2);
  max-height: 268px; overflow-y: auto; margin-top: var(--space-3);
}
.gif-grid img {
  width: 100%; height: 92px; object-fit: cover;
  border-radius: var(--radius-sm); cursor: pointer; background: var(--surface-2);
}
.gif-grid img:hover { outline: 2px solid var(--primary); }

/* --------------------------------------------------------------- modal --- */

.modal {
  position: fixed; inset: 0; z-index: 120; display: grid; place-items: center;
  background: rgba(11, 17, 32, .55); padding: var(--space-5);
}
.modal-card {
  width: 100%; max-width: 452px; max-height: 88dvh; overflow-y: auto;
  background: var(--surface-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
}

.dir-results { display: flex; flex-direction: column; gap: var(--space-2); }
.dir-item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  padding: var(--space-3); border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); cursor: pointer; text-align: left;
}
.dir-item:hover { border-color: var(--primary); background: var(--primary-tint); }

.empty-hint { color: var(--n-500); font-size: .82rem; padding: var(--space-6) var(--space-3); text-align: center; }

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

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  /* One pane at a time on a phone: the list, or the open thread. */
  .app.viewing-thread .sidebar { display: none; }
  .app:not(.viewing-thread) .thread { display: none; }
  .back-btn { display: grid; }
  .popover { left: var(--space-4); right: var(--space-4); width: auto; }
  .msg { max-width: 86%; }
  .messages { padding: var(--space-4); }
}
