/* ═══════════════════════════════════════════
   Mini-Code Pro — Web UI
   Refined dark chat interface
   ═══════════════════════════════════════════ */

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

:root {
  --bg:            #0d0f13;
  --bg-raised:     #15181e;
  --bg-surface:    #1a1d24;
  --bg-hover:      #1f222a;
  --fg:            #e2e4e9;
  --fg-secondary:  #9ca0ac;
  --fg-muted:      #636878;
  --border:        #242832;
  --border-light:  #2e3340;

  --accent:        #6c8cff;
  --accent-dim:    rgba(108,140,255,0.12);
  --accent-glow:   rgba(108,140,255,0.25);

  --user-bg:       #2e3a5c;
  --user-text:     #e8ecf4;
  --assistant-bg:  #14171d;
  --assistant-border: #22262f;
  --tool-bg:       #14161c;
  --tool-border:   #8b7e4a;

  --red:           #f25a5a;
  --amber:         #d4a843;
  --green:         #3fb980;

  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --radius-xl:     20px;

  --font-sans:     "Inter", -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-mono:     "JetBrains Mono", "Cascadia Code", "Fira Code", "SF Mono", ui-monospace, Menlo, monospace;
}

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ────────────────────────────── */

#sidebar {
  width: 244px;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-weight: 650;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

#new-session-btn {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-secondary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#new-session-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
  border-color: var(--border-light);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.session-item {
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--fg-secondary);
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  transition: background 0.12s;
  line-height: 1.35;
}

.session-item:hover { background: var(--bg-hover); color: var(--fg); }
.session-item.active {
  background: var(--accent-dim);
  color: var(--fg);
  border-left: 3px solid var(--accent);
  padding-left: 7px;
}

.session-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.session-item .del-btn {
  visibility: hidden;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.session-item:hover .del-btn { visibility: visible; }
.session-item .del-btn:hover { color: var(--red); }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-muted);
}

.work-dir {
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* ── Main Area ──────────────────────────── */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ─────────────────────────────── */

#topbar {
  height: 46px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
}

.topbar-left {
  font-size: 13px;
  font-weight: 550;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 4px;
}

#session-title { display: none; }

.topbar-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

#topbar select {
  background: var(--bg);
  color: var(--fg-secondary);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  max-width: 130px;
}

#topbar select:hover, #topbar select:focus {
  border-color: var(--accent);
  color: var(--fg);
}

#topbar button {
  background: var(--bg);
  color: var(--fg-secondary);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

#topbar button:hover {
  border-color: var(--accent);
  color: var(--fg);
}

#topbar button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  margin-left: 4px;
}

.status-dot.idle  { background: var(--green); }
.status-dot.busy  { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); animation: pulse 1.4s ease-in-out infinite; }
.status-dot.error { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ── Messages ───────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message {
  padding: 6px 20px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* User message — compact right-aligned bubble */
.message.user {
  align-self: flex-end;
  max-width: 68%;
  margin-right: 16px;
  padding: 7px 14px;
  border-radius: 14px;
  background: var(--user-bg);
  color: var(--user-text);
  font-size: 13px;
  line-height: 1.45;
}

/* Assistant message — left-aligned bubble */
.message.assistant {
  align-self: flex-start;
  max-width: 68%;
  margin-left: 16px;
  padding: 7px 14px;
  border-radius: 14px;
  background: var(--assistant-bg);
  border: 1px solid var(--assistant-border);
  font-size: 13px;
  color: var(--fg);
}

.message.assistant .text {
  line-height: 1.65;
}

.message.assistant .text p { margin: 0 0 0.5em; }
.message.assistant .text p:last-child { margin-bottom: 0; }

.message.assistant .text h1,
.message.assistant .text h2,
.message.assistant .text h3 {
  margin: 1em 0 0.4em;
  font-weight: 600;
  line-height: 1.3;
}

.message.assistant .text h1 { font-size: 1.15em; }
.message.assistant .text h2 { font-size: 1.05em; }
.message.assistant .text h3 { font-size: 0.95em; }

.message.assistant .text ul,
.message.assistant .text ol {
  padding-left: 1.4em;
  margin: 0.4em 0;
}

.message.assistant .text li { margin-bottom: 0.15em; }

.message.assistant .text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.message.assistant .text blockquote {
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 12px;
  margin: 0.5em 0;
  color: var(--fg-secondary);
}

.message.assistant .text a {
  color: var(--accent);
  text-decoration: none;
}

.message.assistant .text a:hover { text-decoration: underline; }

/* Inline & block code */
.message code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(255,255,255,0.06);
  padding: 1.5px 5px;
  border-radius: 4px;
  color: #d7dce6;
}

.message pre {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5em 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}

.message pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* Thinking block */
.thinking {
  color: var(--fg-muted);
  font-style: italic;
  font-size: 12px;
  border-left: 2px solid var(--border-light);
  padding: 2px 0 2px 10px;
  margin-bottom: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(255,255,255,0.02);
  border-radius: 0 4px 4px 0;
}

/* System message */
.message.system {
  background: transparent;
  color: var(--fg-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 6px 0;
  max-width: 100%;
}

/* Tool message */
.message.tool {
  background: var(--tool-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tool-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 12px;
  margin: 6px 0;
  color: var(--fg-secondary);

}

.message.tool .tool-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--fg);
  font-size: 12.5px;
  margin-bottom: 4px;
}

.message.tool .tool-head .tool-icon { color: var(--tool-border); }
.message.tool .tool-head .tool-id   { color: var(--fg-muted); font-weight: 400; font-size: 11px; }

.message.tool .tool-section {
  margin-top: 4px;
  color: var(--fg-muted);
  font-size: 11.5px;
}

.message.tool .tool-result {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--fg-secondary);
}

.message.tool.error { border-left-color: var(--red); }

.message pre {
  background: rgba(0,0,0,0.3);
  padding: 8px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

/* ── Permission Banner ──────────────────── */

.permission-banner {
  margin: 0 18px 10px;
  padding: 12px 16px;
  background: rgba(212,168,67,0.08);
  border: 1px solid rgba(212,168,67,0.25);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.permission-banner.hidden { display: none; }

.permission-banner .perm-tool {
  font-weight: 600;
  font-size: 13px;
  color: var(--amber);
}

.permission-banner .perm-prompt {
  font-size: 13px;
  color: var(--fg);
}

.permission-banner .perm-input {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px 10px;
  max-height: 100px;
  overflow: auto;
  white-space: pre-wrap;
}

.permission-banner .perm-actions {
  display: flex;
  gap: 8px;
}

.permission-banner button {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  transition: filter 0.15s;
}

.permission-banner button:hover { filter: brightness(1.1); }

.perm-allow        { background: var(--green); color: white; }
.perm-allow-always { background: var(--accent); color: white; }
.perm-deny         { background: var(--red); color: white; }

/* ── Composer ───────────────────────────── */

#composer {
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding: 12px 18px 14px;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  align-items: flex-end;
}

#input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#input::placeholder { color: var(--fg-muted); }

#send-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0 22px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 550;
  cursor: pointer;
  height: 42px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

#send-btn:hover  { background: #7a99ff; }
#send-btn:active { transform: scale(0.97); }

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Scrollbar ──────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }

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

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* ── Empty state ────────────────────────── */

.empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: auto;
  gap: 8px;
  opacity: 0.4;
  user-select: none;
  pointer-events: none;
}

.empty-icon {
  font-size: 36px;
  color: var(--accent);
  opacity: 0.5;
  margin-bottom: 4px;
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.empty-sub {
  font-size: 13px;
  color: var(--fg-secondary);
}

/* ── Login Overlay ──────────────────────── */

#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

#login-overlay.hidden { display: none; }

.login-card {
  text-align: center;
  width: 320px;
}

.login-logo {
  font-size: 40px;
  color: var(--accent);
  opacity: 0.6;
  margin-bottom: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 650;
  color: var(--fg);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13px;
  color: var(--fg-muted);
  margin-bottom: 20px;
}

#login-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  outline: none;
  letter-spacing: 4px;
  transition: border-color 0.2s;
}

#login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#login-input::placeholder {
  letter-spacing: 0;
  color: var(--fg-muted);
}

.login-error {
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

.login-error.hidden { display: none; }

#login-btn {
  width: 100%;
  margin-top: 14px;
  padding: 10px 0;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s;
}

#login-btn:hover { background: #7a99ff; }

/* ── Hamburger menu button ──────────────── */

#menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--fg-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  margin-right: 8px;
  border-radius: 4px;
  line-height: 1;
}

#menu-btn:hover { color: var(--fg); background: var(--bg-hover); }

/* ── Sidebar overlay (mobile) ──────────── */

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0.5);
}

/* ═══════════════════════════════════════════
   Mobile: max-width 768px
   ═══════════════════════════════════════════ */

@media (max-width: 768px) {

  #menu-btn {
    display: block;
    font-size: 24px;
    padding: 4px 8px;
  }

  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  #sidebar.open { transform: translateX(0); }

  #main { width: 100%; }

  #topbar {
    height: 50px;
    padding: 0 14px;
  }

  #topbar select {
    font-size: 12px;
    padding: 5px 8px;
    max-width: 90px;
  }

  #topbar button {
    font-size: 12px;
    padding: 5px 10px;
  }

  .status-dot { width: 10px; height: 10px; }

  .messages {
    padding: 8px 0;
    gap: 2px;
  }

  .message { padding: 6px 12px; }

  .message.user {
    max-width: 85%;
    margin-right: 8px;
    padding: 6px 12px;
    font-size: 13px;
  }

  .message.assistant {
    max-width: 100%;
    margin-left: 4px;
    padding: 6px 12px;
    font-size: 13px;
  }

  .message pre {
    font-size: 11px;
    padding: 8px 10px;
  }

  .message code { font-size: 0.85em; }

  #composer {
    padding: 8px 10px;
    gap: 6px;
  }

  #input {
    font-size: 16px; /* 16px 防止 iOS Safari 聚焦时自动缩放 */
    padding: 8px 10px;
    min-height: 40px;
    max-height: 120px;
  }

  #send-btn {
    font-size: 12px;
    padding: 0 14px;
    height: 36px;
  }

  .permission-banner {
    margin: 0 8px 6px;
    padding: 10px 12px;
  }

  .permission-banner button { font-size: 11px; padding: 4px 10px; }

  .empty-hint { padding: 20px; }
  .empty-icon { font-size: 28px; }
  .empty-title { font-size: 17px; }
  .empty-sub { font-size: 12px; }
}
