* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f5f5;
}

/* ── Header ─────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #1a1a2e;
  color: #fff;
  flex-shrink: 0;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: #e53935;
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 6px;
  letter-spacing: 0.05em;
}

#server-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #ccc;
}

#server-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9e9e9e;
  flex-shrink: 0;
  transition: background 0.3s;
}
#server-dot.connected  { background: #43a047; }
#server-dot.error      { background: #e53935; }
#server-dot.connecting { background: #fb8c00; }

/* ── Phase wrapper ──────────────────────────────────── */
.phase {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Phase A: Login ─────────────────────────────────── */
#phase-login {
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.login-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #777;
}

.select-row {
  display: flex;
  gap: 8px;
}

#connection-select {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  outline: none;
  cursor: pointer;
}
#connection-select:focus { border-color: #1a73e8; }

#btn-refresh {
  padding: 9px 13px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 15px;
  cursor: pointer;
  color: #555;
  line-height: 1;
}
#btn-refresh:hover { background: #f0f0f0; }

#secret-input {
  padding: 9px 11px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  width: 100%;
}
#secret-input:focus { border-color: #1a73e8; }

.login-error {
  padding: 8px 12px;
  background: #fff3f3;
  border: 1px solid #f5c6c6;
  border-radius: 4px;
  color: #c62828;
  font-size: 12px;
}

#btn-login {
  padding: 10px;
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
#btn-login:disabled { background: #999; cursor: default; }
#btn-login:not(:disabled):hover { background: #2d2d4e; }

/* ── Phase B: Chat ──────────────────────────────────── */
#phase-chat {
  overflow: hidden;
}

#session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

#session-detail {
  display: flex;
  align-items: center;
  gap: 8px;
}

#session-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #43a047;
  flex-shrink: 0;
  transition: background 0.3s;
}
#session-dot.lost { background: #e53935; }

#session-alias {
  font-weight: 600;
  font-size: 14px;
}

#session-id {
  font-size: 11px;
  color: #999;
}

#session-status-text {
  font-size: 11px;
  color: #e53935;
  font-weight: 600;
}

.mono { font-family: 'Courier New', monospace; }

#btn-back {
  padding: 6px 14px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: #444;
}
#btn-back:hover { background: #f0f0f0; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fafafa;
}

#messages .empty-hint {
  color: #bbb;
  font-size: 13px;
  text-align: center;
  margin-top: 40px;
}

.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.45;
  word-break: break-word;
  font-size: 13px;
}

.msg-in {
  align-self: flex-start;
  background: #f0f0f0;
  color: #1a1a1a;
}

.msg-out {
  align-self: flex-end;
  background: #1a1a2e;
  color: #fff;
}

.msg-meta {
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.6;
}

.msg-out .delivery-pending { color: #aab; }
.msg-out .delivery-sent    { color: #aab; }
.msg-out .delivery-failed  { color: #ffaaaa; font-weight: 600; }

/* ── Compose ────────────────────────────────────────── */
#compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 20px 14px;
  border-top: 1px solid #e0e0e0;
  background: #fff;
  flex-shrink: 0;
}

#compose-text {
  flex: 1;
  padding: 8px 11px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}
#compose-text:focus { border-color: #1a73e8; }

#btn-send {
  padding: 8px 18px;
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  align-self: flex-end;
}
#btn-send:disabled { background: #ccc; cursor: default; }

/* ── Command bar ────────────────────────────────────── */
#command-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px 12px;
  background: #fff;
  border-top: 1px dashed #d0d0d0;
  flex-shrink: 0;
}

#command-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #999;
}

.btn-commands {
  padding: 6px 16px;
  background: #37474f;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-commands:disabled { background: #ccc; cursor: default; }
.btn-commands:not(:disabled):hover { background: #546e7a; }

/* ── Global error bar ───────────────────────────────── */
#error-area {
  padding: 10px 20px;
  background: #fff3f3;
  border-top: 1px solid #f5c6c6;
  color: #c62828;
  font-size: 12px;
  word-break: break-word;
  flex-shrink: 0;
}

/* ── Utility ────────────────────────────────────────── */
.hidden { display: none !important; }
