:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --teal: #0f766e;
  --teal-soft: #ccfbf1;
  --amber: #f59e0b;
  --danger: #b42318;
  --warn: #a16207;
  --code-bg: #0f172a;
  --code-text: #f8fafc;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.lock-screen {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(241, 245, 249, 0.96)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23dbe3ea' stroke-width='1'%3E%3Cpath d='M0 40h160M0 80h160M0 120h160M40 0v160M80 0v160M120 0v160'/%3E%3C/g%3E%3C/svg%3E");
}

.drive-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(12px);
}

.drive-brand,
.sidebar-head,
.message-role,
.message-tools,
.chat-actions,
.composer-actions,
.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
}

.drive-brand,
.sidebar-head {
  gap: 12px;
}

.drive-logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
}

.drive-logo svg,
.drive-nav-item svg,
.drive-action svg,
.file-card svg,
.icon-button svg,
.tool-button svg,
.send-button svg,
.primary-button svg,
.empty-state svg,
.message-role svg,
.search-box svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.drive-brand h1,
.sidebar-head h1 {
  font-size: 18px;
  line-height: 1.2;
}

.drive-brand p,
.sidebar-head p,
.drive-toolbar p,
.chat-header p,
.file-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.drive-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 13px;
}

.drive-status span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}

.drive-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) minmax(310px, 360px);
  gap: 22px;
  padding: 26px;
}

.drive-nav,
.drive-main,
.unlock-panel,
.sidebar,
.settings-modal {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.drive-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: min-content;
  padding: 12px;
}

.drive-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  text-align: left;
}

.drive-nav-item.active,
.drive-nav-item:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.drive-main {
  min-width: 0;
  padding: 18px;
}

.drive-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.drive-toolbar h2,
.unlock-panel h2,
.chat-header h2,
.modal-head h2 {
  font-size: 20px;
}

.icon-button,
.tool-button,
.drive-action,
.primary-button,
.send-button,
.message-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
}

.drive-action,
.tool-button {
  min-height: 40px;
  padding: 0 12px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  flex: 0 0 auto;
}

.icon-button:hover,
.tool-button:hover,
.message-action:hover {
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--accent-soft);
}

.primary-tool,
.primary-button,
.send-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-tool:hover,
.primary-button:hover,
.send-button:hover {
  background: var(--accent-strong);
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.file-card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.file-card svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.unlock-panel {
  align-self: start;
  display: grid;
  gap: 14px;
  padding: 22px;
}

.unlock-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  height: 100%;
  padding: 18px;
  border-width: 0 1px 0 0;
  border-radius: 0;
  box-shadow: none;
}

.sidebar-head {
  justify-content: space-between;
  min-width: 0;
}

.sidebar-head > div {
  min-width: 0;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.search-box {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
}

.search-box input {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  width: 100%;
  min-height: 56px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.conversation-item span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.conversation-item.active,
.conversation-item:hover {
  border-color: rgba(37, 99, 235, 0.2);
  background: var(--accent-soft);
}

.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chat-header,
.composer {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}

.title-block {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.title-block h2,
.title-block p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.strong {
  border-color: rgba(15, 118, 110, 0.24);
  background: var(--teal-soft);
  color: var(--teal);
}

.messages {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  min-height: 240px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.empty-state svg {
  width: 32px;
  height: 32px;
}

.mobile-menu-button {
  display: none;
}

.system-prompt-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  width: min(900px, 100%);
  margin: 0 auto 22px;
}

.system-icon,
.assistant-avatar,
.user-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: #ffffff;
  flex: 0 0 auto;
}

.system-icon {
  background: var(--amber);
}

.assistant-avatar {
  background: var(--teal);
}

.user-avatar {
  background: #7a7f86;
}

.system-icon svg,
.assistant-avatar svg,
.user-avatar svg {
  width: 18px;
  height: 18px;
}

.system-pill {
  width: fit-content;
  max-width: min(700px, 100%);
  padding: 12px 16px;
  border: 1px solid #bfdbfe;
  border-radius: 18px;
  background: #eff6ff;
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.system-caption {
  margin-bottom: 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.message-row {
  width: min(900px, 100%);
  margin: 0 auto 16px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(40px, 1fr) minmax(0, auto) 38px;
  align-items: start;
  gap: 10px;
}

.user-bubble {
  max-width: min(560px, 100%);
  padding: 13px 16px;
  border-radius: 18px;
  background: var(--accent);
  color: #ffffff;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.18);
}

.user-bubble .markdown,
.user-bubble .markdown * {
  color: inherit;
}

.user-message-tools {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  opacity: 0;
  transition: opacity 120ms ease;
}

.user-row:hover .user-message-tools,
.user-row:focus-within .user-message-tools {
  opacity: 1;
}

.assistant-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
}

.assistant-stack {
  min-width: 0;
}

.assistant-card {
  max-width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
  overflow: hidden;
}

.assistant-row.error .assistant-card {
  border-color: rgba(180, 35, 24, 0.36);
}

.assistant-meta {
  margin: 8px 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.message-role {
  gap: 8px;
  font-size: 13px;
  font-weight: 900;
}

.message-tools {
  gap: 6px;
}

.message-action {
  width: 32px;
  height: 32px;
  padding: 0;
}

.message-action svg {
  width: 16px;
  height: 16px;
}

.message-body {
  padding: 16px;
}

.edit-panel {
  display: grid;
  gap: 10px;
}

.edit-panel textarea {
  min-height: 150px;
  background: #ffffff;
}

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

.markdown {
  overflow-wrap: anywhere;
  line-height: 1.65;
  font-size: 15px;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  margin: 18px 0 10px;
  line-height: 1.25;
}

.markdown h1 {
  font-size: 24px;
}

.markdown h2 {
  font-size: 20px;
}

.markdown h3 {
  font-size: 17px;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown blockquote,
.markdown table {
  margin: 10px 0;
}

.markdown ul,
.markdown ol {
  padding-left: 24px;
}

.markdown a {
  color: var(--accent-strong);
  font-weight: 800;
}

.markdown blockquote {
  border-left: 4px solid var(--teal);
  padding: 4px 0 4px 12px;
  color: var(--muted);
  background: #f0fdfa;
}

.markdown code {
  border-radius: 6px;
  padding: 2px 5px;
  background: #e2e8f0;
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 0.92em;
}

.markdown pre,
.json-panel pre {
  overflow-x: auto;
  border-radius: 8px;
  padding: 14px;
  background: var(--code-bg);
  color: var(--code-text);
}

.markdown pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
}

.markdown th,
.markdown td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: var(--panel-soft);
}

.markdown details {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.markdown details summary {
  min-height: 42px;
  padding: 10px 12px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.markdown .details-markdown {
  padding: 12px 14px;
}

.markdown .details-markdown > :first-child {
  margin-top: 0;
}

.markdown .details-markdown > :last-child {
  margin-bottom: 0;
}

.markdown details table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.markdown .dialogue-text {
  color: #1e40af;
  font-weight: 700;
}

.markdown p.dialogue-text {
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: #eff6ff;
}

.reasoning {
  margin-bottom: 14px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  background: #fffbeb;
}

.reasoning summary {
  padding: 10px 12px;
  color: var(--warn);
  font-weight: 900;
  cursor: pointer;
}

.reasoning .markdown {
  padding: 0 12px 12px;
}

.json-panel {
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: 8px;
  background: #f0fdfa;
  overflow: hidden;
}

.json-panel-head {
  min-height: 42px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(15, 118, 110, 0.16);
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
}

.json-panel pre {
  margin: 0;
  border-radius: 0;
  font-family: Consolas, "SFMono-Regular", Menlo, monospace;
  font-size: 13px;
}

.warning-text {
  margin: 0 0 12px;
  color: var(--danger);
  font-weight: 900;
}

.composer {
  display: grid;
  gap: 12px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  min-height: 92px;
  max-height: 240px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.composer-actions {
  justify-content: space-between;
  gap: 14px;
}

.send-button,
.primary-button {
  min-height: 44px;
  padding: 0 16px;
}

.status-text {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-text.error {
  color: var(--danger);
  font-weight: 800;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.field > span,
.settings-section h3 {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 44px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.secret-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.checkline,
.switchline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 800;
}

.checkline input,
.switchline input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, 0.36);
}

.settings-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(860px, 100%);
  max-height: min(860px, 92vh);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.settings-content {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr 1fr;
  gap: 12px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

@media (max-width: 1040px) {
  .drive-layout {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .unlock-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(82vw, 320px);
    transform: translateX(-102%);
    transition: transform 180ms ease;
    border-right: 1px solid var(--line);
  }

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

  .mobile-menu-button {
    display: inline-flex;
  }

  .drive-layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .drive-nav {
    display: none;
  }
}

@media (max-width: 620px) {
  .drive-topbar,
  .chat-header,
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chat-header {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 66px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .title-block {
    text-align: center;
  }

  .title-block h2 {
    font-size: 18px;
  }

  .chat-actions {
    gap: 4px;
  }

  .chat-actions .badge {
    display: none;
  }

  .chat-actions .icon-button,
  .mobile-menu-button {
    width: 36px;
    height: 36px;
    border-color: transparent;
    background: transparent;
    color: #475569;
  }

  .messages {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .system-prompt-row,
  .message-row {
    width: 100%;
  }

  .system-prompt-row {
    grid-template-columns: 38px minmax(0, 1fr);
    margin-bottom: 18px;
  }

  .system-pill {
    max-width: 100%;
    border-radius: 18px;
  }

  .user-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, auto) 34px;
    gap: 8px;
  }

  .user-avatar,
  .assistant-avatar,
  .system-icon {
    width: 34px;
    height: 34px;
  }

  .user-bubble {
    max-width: 72vw;
    font-size: 16px;
  }

  .user-message-tools {
    display: none;
  }

  .assistant-row {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 8px;
  }

  .assistant-card {
    max-width: 100%;
    border-radius: 18px;
  }

  .message-head {
    min-height: 38px;
    padding: 10px 12px;
  }

  .message-body {
    padding: 12px 14px 14px;
  }

  .markdown {
    font-size: 16px;
  }

  .composer {
    padding-top: 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 78px;
    max-height: 170px;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.12);
  }

  .composer-actions {
    align-items: center;
    flex-direction: row;
  }

  .send-button {
    width: 50px;
    min-width: 50px;
    height: 50px;
    border-radius: 999px;
    padding: 0;
  }

  .send-button span {
    display: none;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }
}
