body {
  padding: 0;
  margin: 0;
  overflow-y: scroll;
  font-family: monospace;
}
body,
input,
textarea {
  font-family: 'DejaVu Sans Mono', monospace;
  font-size: 12px;
  tab-size: 4;
  -moz-tab-size: 4;
  -o-tab-size: 4;
}
input[type="checkbox"] {
  margin: 0;
  margin-right: 1em;
}
label {
  vertical-align: 3px;
}
input,
textarea {
  background: none;
  border: none;
  outline: none;
  resize: none;
}
h4 {
  font-size: 12px;
  margin: 1em 0;
  font-weight: bold;
}
pre {
  tab-size: 2;
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 4;
  -moz-tab-size: 4;
  -o-tab-size: 4;
}
a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
a:hover {
  text-decoration: underline;
}
#sidebar-content ul {
  padding-inline-start: 20px;
}
#sidebar-content ul li {
  list-style: disc outside none;
}
ul, ol {
    margin-top: 0;
    margin-bottom: 10px;
    display: block;
    list-style-type: disc;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    padding-inline-start: 40px;
}
ul li {
  list-style: inside;
}
.hidden {
  display: none;
}
.expand {
    height: 100%;
}
.container {
  max-width: 600px;
  margin: 0 auto;
}
#messages {
  padding-top: 2em;
}
.message, .refmessage {
  padding-bottom: 1em;
}
.nick {
  float: left;
  width: 16em;
  margin-left: -17em;
  margin-right: 1em;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
}
.trip {
  font-size: 10px;
}
.text {
  margin: 0;
  margin-left: 1em;
}
.text p {
  margin: 0;
}
#footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  z-index: 1000;
  display: block !important; /* 强制显示 */
}
#chatform {
  border-top: 1px solid;
  margin: 0;
  display: block !important; /* 强制显示 */
}
.input-container {
  display: flex !important;
  align-items: flex-end !important;
  gap: 8px !important;
  padding: 1em !important;
  background: var(--color-bg, #2e2e2e);
  border-top: 1px solid var(--color-border, #4e4e4e);
}
#chatinput {
  flex: 1;
  padding: 12px;
  box-sizing: border-box;
  min-height: 20px;
  max-height: 120px;
  resize: none;
  border-radius: 8px;
  border: 1px solid #4e4e4e;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.4;
}
.send-btn {
  background: #28a745 !important;
  border: none !important;
  border-radius: 20px !important;
  width: auto !important;
  min-width: 60px !important;
  height: 40px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  color: white !important;
  transition: background-color 0.2s !important;
  flex-shrink: 0 !important;
  position: relative !important;
  z-index: 10 !important;
  padding: 0 12px !important;
  font-size: 14px !important;
  font-weight: bold !important;
}

.sidebar-toggle-btn {
  background: #6c757d !important;
  border: none !important;
  border-radius: 50% !important;
  width: 40px !important;
  height: 40px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  color: white !important;
  transition: background-color 0.2s !important;
  flex-shrink: 0 !important;
  font-size: 16px !important;
}
.send-btn:hover {
  background: #218838 !important;
}
.send-btn:active {
  background: #1e7e34 !important;
}
.send-btn:disabled {
  background: #6c757d;
  cursor: not-allowed;
}
#sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  padding: 1em;
  border-left: solid 1px;
  overflow-y: auto;
}
#sidebar-content {
  width: 180px;
  padding-bottom: 10%;
}
h1,h2,h3,h4,h5,h6 {
  margin: 3px;
  margin-top: 0px;
}
blockquote {
  padding: 3px 10px;
  margin: 3px;
  border-left: 5px solid #4e4e4e;
}
code {
  padding: 2px 4px;
  font-size: 90%;
  color: #000000;
  background-color: #4e4e4e;
  border-radius: 4px;
}
hr {
  margin-top: 20px;
  margin-bottom: 20px;
  border: 0;
  border-top: 1px solid #4e4e4e;
}
mark {
  background-color: #60ac39;
  color: black;
}
pre {
  display: block;
  padding: 9.5px;
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.42857143;
  color: #797979;
  word-break: break-all;
  word-wrap: break-word;
  background-color: #4e4e4e;
  border: 1px solid #000;
  border-radius: 4px;
}
table {
  background-color: transparent;
  width: 100%;
  max-width: 100%;
  margin-bottom: 20px;
  border-spacing: 0;
  border-collapse: collapse;
}
table > caption + thead > tr:first-child > th, table > colgroup + thead > tr:first-child > th, table > thead:first-child > tr:first-child > th, table > caption + thead > tr:first-child > td, table > colgroup + thead > tr:first-child > td, table > thead:first-child > tr:first-child > td {
    border-top: 0;
}
table > thead > tr > th {
    vertical-align: bottom;
    border-bottom: 2px solid #4e4e4e;
}
table > thead > tr > th, table > tbody > tr > th, table > tfoot > tr > th, table > thead > tr > td, table > tbody > tr > td, table > tfoot > tr > td {
    padding: 8px;
    line-height: 1.42857143;
    vertical-align: top;
    border-top: 1px solid #4e4e4e;
}
th {
    text-align: left;
}
td, th {
    padding: 0;
}
table > tbody > tr:nth-child(odd) > td, table > tbody > tr:nth-child(odd) > th {
    background-color: #4e4e4e;
}
table > thead > tr > th, table > tbody > tr > th, table > tfoot > tr > th, table > thead > tr > td, table > tbody > tr > td, table > tfoot > tr > td {
    padding: 8px;
    line-height: 1.42857143;
    vertical-align: top;
    border-top: 1px solid #4e4e4e;
}
td, th {
    padding: 0;
}
img {
  max-width: 50%;
  max-height: 800px;
}

@media only screen and (max-width: 600px) {
  /* 基础布局 */
  #messages {
    border: none !important;
    padding: 0.5em !important;
    padding-bottom: 80px !important; /* 为输入框留出空间 */
  }
  
  .message {
    padding-bottom: 0.5em !important;
    background: rgba(255,255,255,0.02) !important;
    border-radius: 8px !important;
    padding: 8px !important;
    margin-bottom: 4px !important;
  }
  
  .message.me {
    background: rgba(0,123,255,0.1) !important;
  }
  
  .nick {
    margin: 0 !important;
    float: none !important;
    text-align: left !important;
    display: inline !important;
    font-weight: bold !important;
    margin-right: 8px !important;
  }
  
  .text {
    display: inline !important;
    margin-left: 0 !important;
  }
  
  /* 移动端侧边栏优化 */
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.8) !important;
    z-index: 2000 !important;
    padding: 0 !important;
    border: none !important;
  }
  
  #sidebar-content {
    width: 280px !important;
    max-width: 80% !important;
    height: 100% !important;
    background: var(--color-bg, #2e2e2e) !important;
    margin-left: auto !important;
    padding: 1em !important;
    overflow-y: auto !important;
    border-left: 1px solid var(--color-border, #4e4e4e) !important;
  }
}
/* 移动端额外优化 */
@media only screen and (max-width: 600px) {
  /* 防止iOS Safari缩放 */
  input, textarea, select {
    font-size: 16px !important;
  }
  
  /* 确保输入框容器在移动端可见 */
  #footer {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 1000 !important;
  }
  
  .input-container {
    display: flex !important;
    align-items: flex-end !important;
    gap: 6px !important;
    padding: 8px !important;
    background: var(--color-bg, #2e2e2e) !important;
    border-top: 1px solid var(--color-border, #4e4e4e) !important;
  }
  
  #chatinput {
    flex: 1 !important;
    padding: 10px 12px !important;
    font-size: 16px !important;
    border-radius: 20px !important;
    min-height: 24px !important;
    max-height: 120px !important;
    border: 1px solid var(--color-border, #4e4e4e) !important;
    background: var(--color-input-bg, #1e1e1e) !important;
    color: var(--color-text, #ffffff) !important;
  }
  
  .send-btn {
    width: auto !important;
    min-width: 50px !important;
    height: 36px !important;
    font-size: 12px !important;
    background: #28a745 !important;
    color: white !important;
    border: none !important;
    border-radius: 18px !important;
    padding: 0 12px !important;
  }
  
  .sidebar-toggle-btn {
    display: flex !important;
    width: 36px !important;
    height: 36px !important;
    background: #6c757d !important;
    border: none !important;
    border-radius: 50% !important;
    color: white !important;
    font-size: 14px !important;
  }
  
  .sidebar-toggle-btn:hover {
    background: #5a6268 !important;
  }
  
  /* 优化触摸目标大小 */
  button, input[type="checkbox"], select {
    min-height: 36px;
    min-width: 36px;
  }
  
  /* 用户列表优化 */
  #users li {
    padding: 8px 4px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
  }
  
  #users li:hover, #users li:active {
    background-color: rgba(255,255,255,0.1);
  }
  
  /* 侧边栏关闭按钮样式 */
  #sidebar-close {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    background: #dc3545 !important;
    border: none !important;
    font-size: 20px !important;
    color: white !important;
    cursor: pointer !important;
    width: 30px !important;
    height: 30px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    z-index: 2001 !important;
  }
  
  /* 键盘弹出时的样式调整 */
  body.keyboard-open {
    height: 100vh;
    overflow: hidden;
  }
  
  body.keyboard-open #messages {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
  }
  
  /* 确保消息区域在键盘弹出时可滚动 */
  #messages {
    position: relative !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
  /* 确保侧边栏在移动端正确显示/隐藏 */
  #sidebar.hidden {
    display: none !important;
    visibility: hidden !important;
  }
  
  #sidebar-content.hidden {
    display: none !important;
    visibility: hidden !important;
  }
  
  #sidebar:not(.hidden) {
    display: block !important;
    visibility: visible !important;
  }
  
  #sidebar-content:not(.hidden) {
    display: block !important;
    visibility: visible !important;
  }
  
  /* 消息区域适配 */
  #messages {
    padding-bottom: 80px !important; /* 为输入框留出空间 */
  }
}

/* 发送按钮动画 */
.send-btn svg {
  transition: transform 0.2s;
}

.send-btn:active svg {
  transform: scale(0.9);
}

/* 输入框焦点状态 */
#chatinput:focus {
  outline: 2px solid #007bff;
  outline-offset: -2px;
}

/* 改善滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.5);
}

/* 消息气泡优化（移动端） */
@media only screen and (max-width: 600px) {
  .message {
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 4px;
  }
  
  .message.me {
    background: rgba(0,123,255,0.1);
  }
  
  .nick {
    font-weight: bold;
    margin-right: 8px;
  }
  
  .text {
    margin-left: 0;
  }
}
/* 桌面端隐藏侧边栏切换按钮 */
@media only screen and (min-width: 601px) {
  .sidebar-toggle-btn {
    display: none !important;
  }
  
  /* 确保桌面端正常显示 */
  #footer {
    display: block !important;
  }
  
  .input-container {
    display: flex !important;
  }
}
/* 移动端强制显示修复 */
@media only screen and (max-width: 600px) {
  /* 强制显示所有输入相关元素 */
  #footer,
  #chatform,
  .input-container,
  #chatinput,
  .send-btn,
  .sidebar-toggle-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  .input-container {
    display: flex !important;
  }
  
  .send-btn,
  .sidebar-toggle-btn {
    display: flex !important;
  }
  
  /* 确保没有被隐藏的类 */
  .hidden #footer,
  .hidden #chatform,
  .hidden .input-container {
    display: block !important;
  }
  
  .hidden .input-container {
    display: flex !important;
  }
  
  /* 确保侧边栏默认隐藏 */
  #sidebar {
    display: none !important;
  }
  
  #sidebar:not(.hidden) {
    display: block !important;
  }
}
/* 使用CSS环境变量处理移动端视口 */
@media only screen and (max-width: 600px) {
  /* 支持安全区域 */
  #footer {
    padding-bottom: env(safe-area-inset-bottom, 0) !important;
  }
  
  /* 动态视口高度处理 */
  body {
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
  }
  
  #messages {
    height: calc(100vh - 80px);
    height: calc(100dvh - 80px); /* 动态视口高度 */
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* 键盘弹出时的特殊处理 */
  body.keyboard-open #messages {
    height: auto !important;
    max-height: none !important;
  }
}

/* 防止页面滚动 */
@media only screen and (max-width: 600px) {
  html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }
  
  body.keyboard-open {
    position: static;
    overflow: visible;
  }
}