/* Cloud5060 UCC — brand red #A31E2D, charcoal #232323 */
:root {
  --brand: #A31E2D;
  --brand-hover: #8A1826;
  --charcoal: #232323;
  --bg: #F4F4F5;
  --surface: #FFFFFF;
  --border: #E2E2E5;
  --text: #232323;
  --muted: #6B6B70;
  --focus: #A31E2D;
  --ok-bg: #E8F5EC; --ok-text: #1E6B35;
  --err-bg: #FBEAEC; --err-text: #8A1826;
  --radius: 8px;
  --rail: 108px;
  --brand-text: #A31E2D;
  --topbar: 52px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181A; --surface: #232325; --border: #38383C; --text: #EDEDEF; --muted: #A1A1A8;
    --focus: #E0606E; --brand-text: #F07A86; --ok-bg: #16301F; --ok-text: #8FD6A4; --err-bg: #3A1A1F; --err-text: #F2A3AC;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); line-height: 1.45; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; margin-top: 24px; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.25); min-height: 32px; padding: 0 12px; }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input {
  width: 100%; min-height: 40px; padding: 8px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
form .btn { width: 100%; margin-top: 20px; }
.alert { padding: 10px 12px; border-radius: var(--radius); margin: 12px 0; font-size: 14px; background: var(--err-bg); color: var(--err-text); }
.alert[data-kind="ok"] { background: var(--ok-bg); color: var(--ok-text); }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 17px; letter-spacing: .2px; }
.brand-name strong { color: var(--brand-text); }

/* Login */
.login-page { display: grid; place-items: center; padding: 16px; min-height: 100%; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px 28px;
}
.login-card .brand { margin-bottom: 28px; }
.login-card.center { display: grid; justify-items: center; gap: 12px; text-align: center; }
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#ms-block .btn { width: 100%; }

/* App shell */
.app {
  display: grid; height: 100%;
  grid-template-columns: var(--rail) 1fr;
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas: "top top" "rail main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--charcoal); color: #fff;
}
.topbar .brand-name strong { color: #F07A86; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 14px; min-width: 0; }
.who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .muted { color: #B9B9BE; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #8A8A90; flex: none; }
.conn[data-state="on"] { background: #3FBF6A; }

.rail {
  grid-area: rail; display: flex; flex-direction: column; gap: 4px; padding: 8px 6px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.rail-btn {
  display: grid; justify-items: center; gap: 4px; padding: 10px 4px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted); font: inherit; font-size: 11.5px; cursor: pointer; min-width: 0;
  white-space: nowrap;
}
.rail-btn svg { width: 22px; height: 22px; fill: currentColor; }
.rail-btn:hover { background: var(--bg); color: var(--text); }
.rail-btn[aria-current="page"] { color: var(--brand-text); background: color-mix(in srgb, var(--brand) 10%, transparent); font-weight: 600; }

.main { grid-area: main; min-height: 0; overflow: auto; padding: 16px; }
.view { height: 100%; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-height: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.empty { color: var(--muted); font-size: 14px; }
.placeholder { display: grid; place-content: center; justify-items: center; text-align: center; height: 100%; min-height: 240px; }
.voice-panel { height: 100%; padding: 0; overflow: hidden; }
.voice-frame { display: block; width: 100%; height: 100%; border: 0; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-ghost-dark { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost-dark:hover { color: var(--text); background: var(--bg); }
.select-sm { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; }
.rail-btn { position: relative; }
.rail-dot { position: absolute; top: 8px; right: 26px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }

/* Conversations */
.conv-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr) 260px; grid-template-rows: minmax(0, 1fr); gap: 12px; height: 100%; min-height: 0; }
.conv-list, .conv-thread, .conv-contact { display: flex; flex-direction: column; min-height: 0; }
.conv-list { padding: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button {
  flex: 1 1 auto; min-height: 32px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; white-space: nowrap;
  background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs .count:not(:empty)::before { content: "· "; }
.conv-items { list-style: none; margin: 0 -6px; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.conv-item {
  display: flex; gap: 10px; width: 100%; padding: 10px 6px; border: 0; border-radius: var(--radius);
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.conv-item:hover { background: var(--bg); }
.conv-item.is-selected { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.avatar {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--charcoal); color: #fff; font-size: 13px; font-weight: 600;
}
.conv-item-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.conv-item-top, .conv-item-sub { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.conv-item-time { flex: none; color: var(--muted); font-size: 12px; }
.conv-item-preview { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.is-unread .conv-item-preview { color: var(--text); }
.chip { flex: none; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; }
#conv-more { margin-top: 8px; }

.conv-thread { padding: 0; overflow: hidden; }
.thread-empty { margin: auto; color: var(--muted); font-size: 14px; padding: 16px; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.thread-title { flex: 1; min-width: 0; }
.thread-title h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title span { font-size: 12.5px; }
.thread-actions { display: flex; gap: 8px; flex: none; }
.back { display: none; }
.thread-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.messages { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg--incoming { align-self: flex-start; }
.msg--outgoing, .msg--note { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 9px 12px; border-radius: 12px; font-size: 14px; overflow-wrap: anywhere; display: grid; gap: 6px; }
.msg--incoming .bubble { background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg--outgoing .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg--outgoing .bubble a { color: #fff; }
.msg--note .bubble { background: #FFF4D6; color: #4A3A10; border: 1px solid #F0D58A; border-bottom-right-radius: 4px; }
.note-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.msg-text { white-space: pre-wrap; }
.msg-image { display: block; max-width: 240px; max-height: 200px; border-radius: 6px; }
.msg-file { font-size: 13px; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.msg--activity { align-self: center; max-width: 90%; font-size: 12px; color: var(--muted); text-align: center; }

.composer { border-top: 1px solid var(--border); padding: 10px 16px 14px; display: grid; gap: 8px; }
.composer-modes { display: flex; gap: 4px; }
.composer-modes button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.composer-modes button[aria-checked="true"] { color: var(--text); background: var(--bg); font-weight: 600; }
.composer textarea {
  width: 100%; resize: vertical; min-height: 64px; max-height: 240px; padding: 10px 12px; font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.composer textarea:focus { outline: none; border-color: var(--focus); }
.composer--note textarea { background: #FFFBEF; border-color: #F0D58A; color: #232323; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-foot .btn { width: auto; margin: 0; }
.composer-error { color: var(--err-text); font-size: 13px; }

.conv-contact .facts { grid-template-columns: max-content minmax(0, 1fr); }
.conv-contact .facts dd { overflow-wrap: anywhere; }
.call-btn { margin-top: 16px; }

.account { max-width: 480px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Narrow screens: rail moves to the bottom, conversation columns stack */
@media (max-width: 1100px) {
  .conv-layout { grid-template-columns: 300px minmax(0, 1fr); }
  .conv-contact { display: none !important; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--topbar) 1fr 64px; grid-template-areas: "top" "main" "rail"; }
  .rail { flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--border); padding: 4px; }
  .rail-btn { flex: 1; }
  .who { display: none; }
  .conv-layout { grid-template-columns: 1fr; }
  .conv-layout[data-pane="list"] .conv-thread, .conv-layout[data-pane="list"] .conv-contact { display: none; }
  .conv-layout[data-pane="thread"] .conv-list, .conv-layout[data-pane="thread"] .conv-contact { display: none; }
  .back { display: inline-flex; }
  .thread-head { flex-wrap: wrap; row-gap: 8px; }
  .thread-title { flex: 1 1 calc(100% - 100px); }
  .thread-actions { flex: 1 1 100%; }
  .thread-actions .btn { flex: 1; }
  .msg { max-width: 88%; }
  .rail-dot { right: calc(50% - 22px); }
}
