/* RiviuxReminder web client — light "QQ-like" theme.
   White surfaces, a soft grey canvas and a single blue accent, matching the
   Avalonia desktop and mobile heads. */

/* Source Han Sans SC, served from the API host so the browser needs no local
   font install. The file is an OpenType/CFF face (~16 MB) shipped as-is. */
@font-face {
  font-family: "Source Han Sans SC";
  src: url("fonts/SourceHanSansSC-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-app: "Source Han Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --canvas: #f2f3f5;
  --panel: #ffffff;
  --panel-alt: #f5f6f8;
  --rail: #f2f3f5;
  --border: #e7e7e7;
  --accent: #0099ff;
  --accent-hover: #0a8ce0;
  --accent-soft: #e5f4ff;
  --text: #1f1f1f;
  --muted: #9a9a9a;
  --mine: #0099ff;
  --other: #ffffff;
  --hover: #efefef;
  --danger: #e5484d;
  --badge: #f74c31;
  --radius: 6px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* A `hidden` element must never be shown, even when a class rule below sets a
   display mode such as `display: grid`. */
[hidden] {
  display: none !important;
}

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

body {
  background: var(--canvas);
  color: var(--text);
  font: 14px/1.5 var(--font-app);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.center {
  text-align: center;
}

.ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error {
  color: var(--danger);
  margin: 0;
  font-size: 13px;
}

/* ------------------------------------------------------------- controls */

button {
  font: inherit;
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.ghost {
  background: transparent;
  /* Dark enough to read as an action rather than a disabled control. */
  color: #5a6270;
}

button.ghost:hover {
  background: var(--hover);
  color: var(--text);
}

button.outline {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}

button.outline:hover {
  background: var(--hover);
}

/* QQ's send button: accent fill, white label, bottom-right of the composer. */
button.send {
  background: var(--accent);
  color: #fff;
  padding: 8px 26px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

button.send:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.send:disabled {
  background: #b7dcf5;
  color: #fff;
}

/* Square icon-only button used by the rail and the composer toolbar. */
button.tool {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: transparent;
  color: #5a5a5a;
  border-radius: 4px;
}

button.tool:hover {
  background: var(--hover);
  color: var(--text);
}

button.has-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-slot {
  display: inline-flex;
  align-items: center;
}

input,
textarea {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.field {
  display: block;
  margin: 10px 0;
}

.field > span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row.end {
  justify-content: flex-end;
  flex-wrap: wrap;
}

a.outline {
  display: inline-block;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  text-decoration: none;
}

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

.auth {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--panel);
}

.auth .card {
  width: min(400px, 100%);
}

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

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p {
  margin: 0;
  font-size: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}

.auth button {
  width: 100%;
  margin-top: 8px;
}

/* The fixed server line on the sign-in card: information, not an input. */
.server-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel-alt);
}

.server-hint svg {
  width: 15px;
  height: 15px;
  flex: none;
}

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

/* QQ window: icon rail | conversation list | thread | member panel. */
.chat {
  flex: 1;
  display: grid;
  grid-template-columns: 56px 232px 1fr 200px;
  min-height: 0;
  background: var(--canvas);
}

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

.rail-icons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rail-btn {
  background: transparent;
  padding: 0;
  border-radius: 6px;
  color: #5a5a5a;
}

.rail-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: #5a5a5a;
  border-radius: 6px;
}

.rail-icon:hover {
  background: var(--hover);
}

.rail-icon.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.rail-avatar,
.rail-avatar-fallback {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  object-fit: cover;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.rail-bottom {
  margin-top: auto;
}

.rail-bottom .rail-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
}

.sidebar {
  background: var(--panel);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.sidebar-search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  margin-bottom: 8px;
}

.sidebar-search input {
  border-radius: 14px;
  background: var(--panel-alt);
  padding: 6px 12px;
  font-size: 13px;
}

/* The account row under the search field opens the pull-out panel. */
.me-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.me-row:hover {
  background: var(--hover);
}

.me-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.me-text strong {
  font-size: 13px;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  object-fit: cover;
  flex: none;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
  border-radius: 8px;
}

.avatar img,
img.avatar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  display: block;
}

.conversation-list,
.contact-list,
.member-list,
.agent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.conversation,
.contact {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.conversation + .conversation,
.contact + .contact {
  margin-top: 2px;
}

.conversation:hover,
.contact:hover {
  background: var(--hover);
}

.conversation.active,
.contact.selected {
  background: var(--hover);
}

.conversation-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.conversation-text strong {
  font-size: 13px;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.badge {
  min-width: 18px;
  text-align: center;
  background: var(--badge);
  color: #fff;
  border-radius: 9px;
  padding: 1px 6px;
  font-size: 11px;
}

.empty {
  text-align: center;
  padding: 18px 10px;
}

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

.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--canvas);
}

.thread-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.thread-head strong {
  display: block;
  font-size: 14px;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto; /* newest message anchored to the bottom */
}

.bubble-row {
  display: grid;
  /* The middle track absorbs the slack, so each column must be pushed to the
     side its avatar sits on. Without that, a "mine" bubble stops at its
     max-width and leaves a huge hole between it and the right-hand avatar. */
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.bubble-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(560px, 82%);
  min-width: 0;
}

.bubble-col.other {
  align-items: flex-start;
  justify-self: start;
}

.bubble-col.mine {
  align-items: flex-end;
  justify-self: end;
  grid-column: 2;
}

.bubble-sender {
  font-size: 12px;
  color: #6b8ba6;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tag-agent {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 3px;
  padding: 1px 5px;
}

.bubble {
  border-radius: 6px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  min-width: 0;
}

.bubble-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-time {
  font-size: 11px;
  opacity: .72;
  align-self: flex-end;
}

.bubble.other {
  background: var(--other);
  border: 1px solid #e9e9e9;
  border-top-left-radius: 2px;
}

.bubble.mine {
  background: var(--mine);
  color: #fff;
  border-top-right-radius: 2px;
}

.bubble.mine .bubble-time {
  color: #eaf8ff;
}

/* attachments */

.attachment-image-wrap {
  margin: -2px -3px 2px;
}

.attachment-image {
  display: block;
  max-width: 280px;
  max-height: 220px;
  border-radius: 4px;
  cursor: zoom-in;
  background: var(--panel-alt);
}

.attachment-file {
  display: flex;
  gap: 9px;
  align-items: center;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
  cursor: pointer;
  min-width: 180px;
}

.bubble.mine .attachment-file {
  background: rgba(255, 255, 255, .16);
  border-color: rgba(255, 255, 255, .35);
  color: #fff;
}

.attachment-icon {
  display: grid;
  place-items: center;
  color: var(--accent);
}

.bubble.mine .attachment-icon {
  color: #fff;
}

.attachment-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 220px;
}

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

.composer {
  background: var(--panel);
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
}

.attach-wrap {
  position: relative;
}

.attach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 35, 41, .14);
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  z-index: 20;
}

.attach-menu button {
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 6px;
  padding: 9px 12px;
  white-space: nowrap;
}

.attach-menu button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-state {
  font-size: 12px;
  color: var(--accent);
  margin-left: 6px;
}

.composer form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Roomier input, matching QQ's multi-line composer. */
.composer textarea {
  resize: none;
  min-height: 96px;
  max-height: 200px;
  border-color: transparent;
  padding: 4px 2px;
}

.composer textarea:focus {
  outline: none;
  border-color: transparent;
}

.composer-send {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* --------------------------------------------------------- info column */

.info-pane {
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.member-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 4px;
}

.member-list .avatar {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  font-size: 12px;
}

/* ---------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 35, 41, .35);
}

/* Pull-out account panel anchored to the left edge. */
.drawer-body {
  position: absolute;
  inset: 0 auto 0 0;
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.drawer-head {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-identity {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.drawer-identity strong {
  font-size: 15px;
}

.drawer-identity p {
  margin: 2px 0 0;
}

.drawer-menu {
  list-style: none;
  margin: 8px 0 0;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.drawer-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
}

.drawer-item:hover {
  background: var(--hover);
}

.drawer-item.danger {
  color: var(--danger);
}

.drawer-foot {
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------- settings */

.settings-body {
  position: absolute;
  inset: 0;
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

.settings-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.settings-head strong {
  font-size: 16px;
}

.settings-scroll {
  overflow: auto;
  padding: 18px 24px 40px;
  width: min(900px, 100%);
  align-self: center;
}

.settings-scroll h3 {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  margin: 18px 0 8px;
}

.settings-scroll h3:first-child {
  margin-top: 0;
}

.settings-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-card .row {
  align-items: center;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.check input {
  width: auto;
}

.key-box {
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.key-box code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.key-box code.example {
  color: #5a6b7a;
}

.agent-list {
  flex: none;
}

.agent-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.agent-list .agent-icon {
  color: var(--accent);
  display: grid;
  place-items: center;
}

.agent-list .agent-actions {
  display: flex;
  gap: 4px;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(31, 35, 41, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal[hidden],
.attach-menu[hidden] {
  display: none !important;
}

.modal-card {
  width: min(460px, 100%);
  max-height: 84vh;
  overflow: auto;
}

.modal-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.modal-card .contact-list {
  max-height: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 10px 0;
  padding: 4px;
}

.attach-summary {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel-alt);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.attach-details {
  list-style: none;
  margin: 10px 0;
  padding: 12px;
  background: var(--panel-alt);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attach-details li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.will-upload {
  display: flex;
  justify-content: space-between;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 10px;
}

/* -------------------------------------------------------- image preview */

.modal.preview {
  background: rgba(16, 20, 24, .82);
}

.preview-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: min(1100px, 96vw);
  max-height: 92vh;
}

.preview-body img {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.preview-bar .muted {
  color: #d6dbe2;
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  box-shadow: 0 12px 30px rgba(31, 35, 41, .18);
  z-index: 80;
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

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

/* Narrow desktop: keep four columns but shrink the list and info pane. */
@media (max-width: 1200px) {
  .chat {
    grid-template-columns: 56px 200px 1fr;
  }

  .info-pane {
    display: none;
  }
}

/* Tablet: drop the rail, keep list plus thread. */
@media (max-width: 900px) {
  .chat {
    grid-template-columns: 200px 1fr;
  }

  .rail {
    display: none;
  }
}

/* Phone: conversations on top, thread below. */
@media (max-width: 780px) {
  .chat {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 38vh) 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .bubble-col {
    max-width: 88%;
  }

  .attachment-image {
    max-width: 220px;
  }

  .attachment-meta {
    max-width: 150px;
  }
}
