:root {
  --bg: #0c0f0e;
  --panel: #141917;
  --panel-2: #1a201d;
  --sidebar: #0e1211;
  --line: #232a27;
  --text: #e7efeb;
  --muted: #8a978f;
  --accent: #25d366;
  --accent-dark: #1aa350;
  --danger: #f2555a;
  --warn: #f0b429;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body.centered {
  display: grid;
  place-items: center;
}

a {
  color: var(--accent);
  text-decoration: none;
}

h1,
h2,
h3 {
  margin: 0;
}

code {
  background: #0006;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12.5px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.side-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 18px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(150deg, #f0806a, #e05a7a);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.side-name {
  font-weight: 650;
}

.side-role {
  font-size: 12.5px;
  color: var(--muted);
}

.side-nav {
  display: grid;
  gap: 3px;
  margin-top: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: #ffffff0d;
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(90deg, #25d3661f, transparent);
  color: var(--accent);
  border-left-color: var(--accent);
}

.nav-ico {
  width: 20px;
  text-align: center;
  opacity: 0.9;
}

.side-foot {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 12px 10px 4px;
}

.socket-state {
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.socket-state::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.socket-state[data-state='online']::before {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.content {
  padding: 26px 32px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-head h1 {
  font-size: 22px;
}

/* ---------- primitives ---------- */
button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px 16px;
  background: #ffffff0f;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

button:hover:not(:disabled) {
  background: #ffffff1c;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06251a;
  font-weight: 620;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

button.danger {
  color: var(--danger);
  border-color: #f2555a4d;
}

button.small {
  padding: 6px 12px;
  font-size: 13px;
}

input,
select {
  font: inherit;
  width: 100%;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0a0f0d;
  color: var(--text);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #25d3661f;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.cols {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.row {
  display: flex;
  gap: 8px;
}

.row.wrap {
  flex-wrap: wrap;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.label {
  display: block;
  font-size: 11.5px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

/* ---------- stat cards ---------- */
.stat {
  padding: 18px;
}

.stat .value {
  font-size: 30px;
  font-weight: 700;
  margin-top: 4px;
}

.stat .value small {
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}

/* ---------- table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th,
.table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  font-size: 11.5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

.table td.actions {
  text-align: right;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 26px;
}

/* ---------- pills ---------- */
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.pill[data-status='open'],
.pill[data-tone='ok'] {
  color: var(--accent);
  border-color: #25d36659;
  background: #25d3661a;
}

.pill[data-status='qr'],
.pill[data-status='pairing'],
.pill[data-status='connecting'],
.pill[data-tone='warn'] {
  color: var(--warn);
  border-color: #f0b4294d;
  background: #f0b42914;
}

.pill[data-status='error'],
.pill[data-status='logged_out'],
.pill[data-tone='bad'] {
  color: var(--danger);
  border-color: #f2555a4d;
  background: #f2555a14;
}

/* ---------- accounts: list + detail ---------- */
.accounts-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 20px;
}

.account-list-card {
  padding: 8px;
  display: grid;
  gap: 2px;
}

.account-list {
  display: grid;
  gap: 2px;
  max-height: 70vh;
  overflow-y: auto;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
}

.account-row:hover:not(:disabled) {
  background: #ffffff0d;
}

.account-row.active {
  background: #25d3661a;
  border-color: #25d36659;
}

.account-row b {
  display: block;
  font-weight: 620;
}

.account-row .muted {
  font-size: 12.5px;
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

@media (max-width: 980px) {
  .accounts-layout {
    grid-template-columns: 1fr;
  }
  .account-list {
    max-height: 260px;
  }
}

/* ---------- account cards ---------- */
.session {
  display: grid;
  gap: 12px;
  align-content: start;
}

.session-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.detail {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.info-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding: 12px;
  border-radius: 11px;
  background: #ffffff08;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.proxy-line {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #ffffff08;
  overflow-wrap: anywhere;
}

.session[data-proxy='on'] .proxy-line {
  border-left: 3px solid var(--accent);
}

.session[data-proxy='off'] .proxy-line {
  border-left: 3px solid var(--warn);
}

.send-form {
  display: grid;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.session-actions button,
.row.wrap button {
  padding: 7px 12px;
  font-size: 13px;
}

input.narrow {
  width: 96px;
  flex: none;
  text-align: center;
}

/* ---------- log ---------- */
.log {
  display: grid;
  gap: 2px;
  max-height: 360px;
  overflow-y: auto;
  font-family: Consolas, monospace;
  font-size: 12.5px;
}

.log-line {
  display: flex;
  gap: 10px;
  padding: 4px 6px;
  border-radius: 6px;
}

.log-line:nth-child(odd) {
  background: #ffffff08;
}

.log-line time {
  color: var(--muted);
  flex: none;
}

.log-line .tag {
  color: var(--accent);
  flex: none;
}

.log-line[data-level='error'] .body {
  color: var(--danger);
}

.log-line[data-level='warn'] .body {
  color: var(--warn);
}

.log-line .body {
  overflow-wrap: anywhere;
}

/* ---------- login + toasts ---------- */
.login-card {
  width: min(380px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  padding: 28px;
}

.login-logo {
  font-size: 26px;
  font-weight: 680;
}

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 30;
}

.toast {
  padding: 11px 15px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #17211d;
  box-shadow: 0 12px 30px #0009;
  max-width: 340px;
  font-size: 13.5px;
  animation: rise 0.18s ease-out;
}

.toast[data-kind='error'] {
  border-color: #f2555a66;
  color: #ffd9da;
}

.toast[data-kind='success'] {
  border-color: #25d36666;
  color: #d7ffe8;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.warn-banner {
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid #f0b4294d;
  background: #f0b42914;
  color: #ffe6b0;
  font-size: 13.5px;
}

/* --- Chat view ----------------------------------------------------------- */
.chat-layout {
  align-items: stretch;
  height: calc(100vh - 150px);
}

.chat-layout .account-list-card {
  height: 100%;
  overflow: hidden;
  grid-template-rows: auto 1fr;
}

.chat-layout .account-list {
  max-height: none;
  overflow-y: auto;
  /* Rows must hug their content, otherwise a short grid list stretches each row to fill 1fr. */
  align-content: start;
  grid-auto-rows: min-content;
  gap: 1px;
}

.chat-row {
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  min-height: 0;
}

.chat-row-main {
  min-width: 0;
  flex: 1;
}

.chat-row-main b {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}

.chat-row-main .muted {
  margin-top: 1px;
}

.chat-row-main .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}

.chat-row-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.chat-time {
  font-size: 11px;
  color: var(--muted);
}

.chat-unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #06231a;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 4px;
  margin: 8px 0;
}

.chat-bubble {
  max-width: 72%;
  padding: 7px 11px 5px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-bubble.from-them {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}

.chat-bubble.from-me {
  align-self: flex-end;
  background: #1d5c3f;
  border: 1px solid #256b4a;
  border-bottom-right-radius: 3px;
}

.chat-bubble-time {
  align-self: flex-end;
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.chat-composer {
  margin-top: auto;
}

@media (max-width: 780px) {
  .chat-layout {
    height: auto;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .side-nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }
  .side-foot {
    margin: 0 0 0 auto;
  }
}
