:root {
  --page-bg: #f3f3f1;
  --panel-bg: #ffffff;
  --sidebar-bg: #f4f4f2;
  --sidebar-hover: #ececea;
  --sidebar-active: #e8e8e5;
  --input-bg: #ffffff;
  --surface-muted: #f5f5f3;
  --text-primary: #151515;
  --text-secondary: #6f6f69;
  --text-muted: #a1a19a;
  --border-color: #deded9;
  --border-soft: #ededeb;
  --accent: #0a84ff;
  --accent-soft: #e7f2ff;
  --success: #138a54;
  --warning: #b36b00;
  --danger: #d4392f;
  --shadow-soft: 0 22px 60px rgba(20, 20, 18, 0.06);
  --shadow-input: 0 16px 36px rgba(20, 20, 18, 0.08);
  --sidebar-width: 300px;
  --right-width: 360px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

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

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

#app {
  display: flex;
  width: 100vw;
  height: 100vh;
}

#sidebar-left {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid #ddddda;
  color: #363631;
  user-select: none;
}

.window-menu {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px 0 8px;
  color: #777770;
  font-size: 14px;
  white-space: nowrap;
}

.window-menu button,
.primary-nav button,
.sidebar-footer button,
.header-actions button,
.composer-toolbar button,
#btn-toggle-law {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.window-menu button {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #898982;
}

.window-menu button:disabled {
  color: #c4c4bd;
  cursor: default;
}

.window-dot {
  width: 12px;
  height: 12px;
  border: 1px solid #8d8d86;
  border-radius: 4px;
  background: #fafafa;
}

.app-name {
  overflow: hidden;
  color: #33332f;
  font-weight: 500;
  text-overflow: ellipsis;
}

.primary-nav {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 26px 14px 24px;
}

.nav-action {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-radius: 6px;
  color: #2d2d29;
  text-align: left;
}

.nav-action:hover,
.sidebar-footer button:hover,
.chat-item:hover {
  background: var(--sidebar-hover);
}

.sidebar-section {
  padding: 0 16px 22px;
}

.sidebar-section h2 {
  margin-bottom: 14px;
  color: #92928b;
  font-size: 14px;
  font-weight: 500;
}

.chat-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
}

#chat-list {
  min-height: 0;
  overflow-y: auto;
}

.chat-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  padding: 10px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: #2d2d28;
}

.chat-item.active::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%);
}

.chat-item-title,
.chat-item-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-title {
  grid-column: 1 / -1;
  padding-right: 14px;
  font-size: 14px;
}

.chat-item-preview {
  display: none;
}

.sidebar-footer {
  padding: 10px 16px 12px;
}

.sidebar-footer button {
  width: 100%;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 6px;
  color: #252520;
  text-align: left;
}

#main-area {
  flex: 1;
  min-width: 0;
  height: calc(100vh - 34px);
  margin-top: 34px;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid #d9d9d5;
  border-bottom: 0;
  border-radius: 14px 0 0 0;
  box-shadow: var(--shadow-soft);
}

#chat-header {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px;
  color: var(--text-secondary);
}

#chat-title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.header-actions button {
  width: 30px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: #fff;
  color: #6d6d67;
}

.header-actions button:hover {
  border-color: var(--border-color);
  background: #f8f8f7;
  color: #171714;
}

#btn-clear-chat:hover {
  color: var(--danger);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 24px 74px;
}

.prompt-hero {
  width: min(760px, 100%);
  padding-bottom: 32px;
  text-align: center;
}

.prompt-hero h1 {
  font-size: 27px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
}

#chat-messages {
  width: min(780px, 100%);
  max-height: 34vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
  padding: 0 2px;
}

.message {
  width: 100%;
  display: flex;
  gap: 10px;
  animation: fadeIn 0.22s ease-out;
}

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

.message.user {
  justify-content: flex-end;
}

.msg-avatar {
  display: none;
}

.msg-content {
  max-width: min(660px, 92%);
}

.message.user .msg-content {
  margin-left: auto;
}

.msg-bubble {
  padding: 11px 13px;
  border-radius: 10px;
  line-height: 1.65;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bot-bubble {
  background: var(--surface-muted);
  color: #262622;
}

.user-bubble {
  background: #10100f;
  color: #fff;
}

.msg-bubble p {
  margin-bottom: 8px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble em {
  color: var(--text-secondary);
  font-size: 13px;
}

#chat-input-area {
  width: min(730px, 100%);
  min-height: 96px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  background: var(--input-bg);
  box-shadow: var(--shadow-input);
  overflow: hidden;
}

#chat-input {
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 13px 13px 5px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
}

#chat-input::placeholder {
  color: #8b8b84;
}

.composer-toolbar {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px 8px;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-toolbar button {
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #777770;
}

.composer-toolbar button:hover {
  background: #f0f0ee;
  color: #171714;
}

.mode-pill {
  width: auto;
  gap: 5px;
  padding: 0 8px;
  color: var(--accent) !important;
}

.mode-pill svg {
  width: 14px;
  height: 14px;
}

#btn-send {
  width: 30px;
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #070707;
  color: #fff;
}

#btn-send:hover {
  background: #222;
  color: #fff;
}

#btn-send:disabled {
  background: #cfcfca;
  color: #fff;
  cursor: not-allowed;
}

.workspace-label {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  background: #f4f4f2;
  color: #87877f;
  font-size: 13px;
}

.workspace-label svg {
  width: 16px;
  height: 16px;
}

.result-card {
  overflow: hidden;
  margin-top: 2px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
}

.result-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border-soft);
  background: #fbfbfa;
  font-size: 14px;
  font-weight: 600;
}

.result-card-body {
  padding: 14px;
}

.result-sentence {
  margin-bottom: 8px;
  color: #0f643e;
  font-size: 22px;
  font-weight: 650;
}

.result-bar {
  height: 7px;
  margin: 10px 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eeeeea;
}

.result-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #20a162, #0a84ff);
  transition: width 0.5s ease-out;
}

.result-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0ed;
  font-size: 13px;
}

.result-detail-row:last-child {
  border-bottom: 0;
}

.result-detail-label {
  color: var(--text-secondary);
}

.result-detail-value {
  font-weight: 600;
}

.steps-container {
  margin-top: 12px;
}

.step-item {
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: #fafafa;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.step-header:hover {
  background: #f1f1ee;
}

.toggle-icon {
  transition: transform 0.2s ease;
}

.step-header.open .toggle-icon {
  transform: rotate(90deg);
}

.step-body {
  display: none;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
}

.step-body.open {
  display: block;
}

.log-entry {
  padding: 4px 0;
  border-bottom: 1px solid #f0f0ed;
}

.log-entry:last-child {
  border-bottom: 0;
}

.ask-card {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid #ead08a;
  border-radius: 8px;
  background: #fff8e3;
}

.law-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
}

.law-link:hover {
  text-decoration: underline;
}

#sidebar-right {
  width: var(--right-width);
  min-width: var(--right-width);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-color);
  background: #fbfbfa;
  transition: margin-right 0.24s ease, opacity 0.2s ease;
}

#sidebar-right.collapsed {
  margin-right: calc(-1 * var(--right-width));
  opacity: 0;
}

.sidebar-right-header {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 600;
}

#btn-toggle-law {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: var(--text-secondary);
}

#btn-toggle-law:hover {
  background: #eeeeeb;
}

#law-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 13px;
  line-height: 1.7;
}

.law-placeholder {
  padding: 40px 12px;
  color: var(--text-secondary);
  text-align: center;
}

.law-section {
  margin-bottom: 16px;
}

.law-section-title {
  margin-bottom: 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 650;
}

.law-line {
  padding: 4px 0;
  color: #3d3d38;
}

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

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

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #d2d2cc;
}

::-webkit-scrollbar-thumb:hover {
  background: #aaa9a1;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9d9d96;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-5px);
  }
}

@media (max-width: 980px) {
  :root {
    --sidebar-width: 248px;
    --right-width: 320px;
  }

  .app-name {
    max-width: 150px;
  }

  .workspace {
    padding-inline: 18px;
  }
}

@media (max-width: 720px) {
  #sidebar-left,
  #sidebar-right {
    display: none;
  }

  #main-area {
    height: 100vh;
    margin-top: 0;
    border-radius: 0;
    border: 0;
  }

  .workspace {
    padding: 0 14px 44px;
  }

  .prompt-hero {
    padding-bottom: 22px;
  }

  .prompt-hero h1 {
    font-size: 23px;
  }
}
