/* 基础布局：左侧会话，右侧聊天 */
:root {
  --bg: #0b1220;
  --panel: #0f1930;
  --panel-2: #111f3b;
  --border: rgba(255,255,255,0.10);
  --text: #e6edf3;
  --muted: rgba(230,237,243,0.70);
  --accent: #4cc9f0;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

#app {
  height: 100vh;
  display: flex;
  overflow: hidden;
  position: relative;
}


/* Mobile sidebar backdrop (for off-canvas sidebar) */
.sidebar-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1500;
}
#app:not(.sidebar-open) .sidebar-backdrop{ display:none; }
#app.sidebar-open .sidebar-backdrop{ display:block; }

/* Sidebar toggle buttons */
.sidebar-toggle{ display:none; }
.sidebar-close{ display:none; }

/* Sidebar */
#sidebar {
  width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-top {
  padding: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand-title {
  font-weight: 700;
  letter-spacing: .2px;
}
.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-section {
  padding: 12px 10px;
  flex: 1;
  overflow: auto;
}

.section-title {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 8px 8px;
}

.conv-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 6px 10px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  cursor: pointer;
}
.conv-item:hover { background: rgba(255,255,255,0.06); }
.conv-item.active {
  border-color: rgba(76,201,240,0.55);
  background: rgba(76,201,240,0.10);
}
.conv-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 12px 14px 14px;
}

.field { margin-top: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Main */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--panel-2), rgba(17,31,59,0.65));
}

#topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

#topbar .left {
  display: flex;
  gap: 8px;
  align-items: center;
}
#topbar select {
  min-width: 260px;
  max-width: 360px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.status { font-size: 12px; }
.muted { color: var(--muted); }

.messages {
  flex: 1;
  overflow: auto;
  padding: 16px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }
.msg-row.tool { justify-content: flex-start; }

.bubble {
  max-width: min(780px, 92%);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 14px;
}

.msg-row.user .bubble {
  background: rgba(76,201,240,0.14);
  border-color: rgba(76,201,240,0.28);
}
.msg-row.tool .bubble {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.03);
  border-style: dashed;
  opacity: 0.9;
}

.msg-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

/* Composer */
#composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(15,25,48,0.85);
}

.composer-left {
  display: flex;
  align-items: center;
}

.composer-left .btn {
  padding: 9px 10px;
}

/* message actions */
.bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.msg-row.assistant .bubble-wrap,
.msg-row.tool .bubble-wrap {
  align-items: flex-start;
}

.msg-actions {
  display: flex;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}

.msg-row:hover .msg-actions {
  opacity: 1;
  pointer-events: auto;
}

/* Touch devices: always show actions (no hover) */
@media (hover: none) {
  .msg-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

.icon-btn {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(15,25,48,0.9);
  color: var(--text);
  border-radius: 10px;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 12px;
}

/* sidebar file list */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 6px 8px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  cursor: pointer;
}
.file-item:hover { background: rgba(255,255,255,0.06); }

.file-item-left {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.file-item-left input[type="checkbox"] {
  margin-top: 2px;
}

.file-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.file-item-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.file-item-sub {
  font-size: 12px;
  color: var(--muted);
}

.icon-btn:hover {
  background: rgba(255,255,255,0.10);
}


/* file list actions */
.file-item-actions{
  display:flex;
  gap: 6px;
  align-items: center;
}

/* file bubbles */
.file-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-card a {
  color: var(--accent);
  text-decoration: none;
}
.file-card a:hover { text-decoration: underline; }

.file-meta {
  font-size: 12px;
  color: var(--muted);
}

.img-preview {
  max-width: 420px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.10);
}

/* inline editor */
.edit-area {
  width: min(780px, 92%);
  resize: vertical;
  min-height: 80px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
}

.edit-actions { margin-top: 8px; display:flex; gap: 8px; justify-content:flex-end; }

/* modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.hidden { display: none !important; }

.modal {
  width: min(560px, 92vw);
  background: #111a2e;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);
}

.modal-header {
  padding: 12px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.10);
}

.modal-title { font-weight: 700; }

.modal-body { padding: 12px 14px; }
.modal-footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.10); }

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

.file-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
}

.file-meta a {
  color: var(--text);
  text-decoration: none;
}

.file-meta a:hover {
  text-decoration: underline;
}

.file-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.img-preview {
  max-width: min(520px, 100%);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal {
  width: min(560px, 100%);
  background: #111a2e;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.03);
}

.modal-title {
  font-weight: 700;
}

.modal-body {
  padding: 12px 12px 4px;
}

.modal-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.10);
}

#input {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
}
#input:focus { border-color: rgba(76,201,240,0.55); }

.btn {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,0.10); }
.btn.primary {
  border-color: rgba(76,201,240,0.45);
  background: rgba(76,201,240,0.20);
}
.btn.primary:hover { background: rgba(76,201,240,0.28); }
.btn.danger {
  border-color: rgba(255,107,107,0.55);
  background: rgba(255,107,107,0.10);
}
.btn.danger:hover { background: rgba(255,107,107,0.18); }

input[type="password"], input[type="text"] {
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  outline: none;
}

/* Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255,255,255,0.15);
  border: 1px solid var(--border);
  transition: .2s;
  border-radius: 999px;
}
.slider:before {
  position: absolute; content: "";
  height: 18px; width: 18px;
  left: 3px; top: 2px;
  background-color: rgba(255,255,255,0.75);
  transition: .2s;
  border-radius: 999px;
}
.switch input:checked + .slider {
  background-color: rgba(76,201,240,0.25);
}
.switch input:checked + .slider:before {
  transform: translateX(20px);
}

@media (max-width: 860px) {
  #sidebar { width: 280px; }
  #topbar select { min-width: 200px; }
}



/* Responsive layout for narrow screens */
@media (max-width: 720px){
  /* Main takes full width; sidebar becomes off-canvas drawer */
  #sidebar{
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(320px, 86vw);
    max-width: 86vw;
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 2000;
    border-right: 1px solid var(--border);
  }
  #app.sidebar-open #sidebar{ transform: translateX(0); }

  /* Show toggle/close buttons on mobile */
  .sidebar-toggle{ display:inline-flex; align-items:center; justify-content:center; }
  .sidebar-close{ display:inline-flex; align-items:center; justify-content:center; margin-left:8px; }

  /* Topbar can wrap */
  #topbar{
    height: auto;
    gap: 8px;
    flex-wrap: wrap;
  }
  #topbar .left{
    width: 100%;
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  #topbar select{
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 100%;
  }
  #topbar .left .btn{
    flex: 1 1 auto;
  }

  /* Composer: tighter */
  #composer{ gap: 8px; padding: 10px; }
  #input{ min-height: 44px; }
}

/* Extra narrow screens */
@media (max-width: 420px){
  #composer{ flex-wrap: wrap; }
  #composer .composer-left{ width: 100%; }
  #input{ width: 100%; }
  #btnSend{ width: 100%; }
}
