:root {
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-subtle: #f5f5f7;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --line: rgba(0, 0, 0, 0.075);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --success: #30b95c;
  --danger: #e5484d;
  --radius: 24px;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.075);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -18%, rgba(255, 255, 255, 0.95), transparent 55%),
    var(--bg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

h1,
h2,
h3 {
  letter-spacing: -0.035em;
}

h1 {
  margin-bottom: 34px;
  font-size: 42px;
  font-weight: 650;
}

h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 620;
}

h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(420px, 100%);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--surface-solid);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  margin-bottom: 28px;
  place-items: center;
  border-radius: 15px;
  color: #fff;
  background: #1d1d1f;
  font-size: 23px;
  font-weight: 620;
}

.brand-mark.small {
  width: 32px;
  height: 32px;
  margin: 0;
  border-radius: 9px;
  font-size: 16px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid transparent;
  outline: none;
  color: var(--text);
  background: var(--surface-subtle);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input {
  height: 52px;
  padding: 0 16px;
  border-radius: 14px;
}

textarea {
  min-height: 58px;
  max-height: 180px;
  padding: 14px 16px;
  resize: none;
  border-radius: 16px;
}

input:focus,
textarea:focus {
  border-color: rgba(0, 113, 227, 0.28);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

.button,
.icon-button,
.send-button {
  border: 0;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease, opacity 120ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 15px;
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-subtle);
  font-weight: 520;
  white-space: nowrap;
}

.button:hover,
.icon-button:hover {
  background: #ececf0;
}

.button:active,
.icon-button:active,
.send-button:active {
  transform: scale(0.97);
}

.button:disabled,
.icon-button:disabled,
.send-button:disabled {
  cursor: default;
  opacity: 0.38;
  transform: none;
}

.button.primary {
  min-height: 52px;
  color: #fff;
  background: #1d1d1f;
  border-radius: 14px;
  font-weight: 560;
}

.button.primary:hover {
  background: #000;
}

.button.quiet {
  color: var(--text-secondary);
  background: transparent;
}

.button.quiet:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.danger-text {
  color: var(--danger);
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  font-size: 18px;
  line-height: 1;
}

.icon-button.accent {
  color: #fff;
  background: #1d1d1f;
}

.icon-button.accent:hover {
  background: #000;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  padding: 0 16px 16px;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1440px, 100%);
  height: 64px;
  margin: 0 auto 12px;
  background: rgba(245, 245, 247, 0.76);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
}

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

.brand-name {
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.025em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.workspace-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.workspace-chip {
  max-width: 235px;
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  gap: 7px;
  color: var(--text);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.status-pill.running .status-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

.status-pill.error .status-dot {
  background: var(--danger);
}

@keyframes pulse {
  50% { opacity: 0.35; transform: scale(0.8); }
}

.layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 14px;
  width: min(1440px, 100%);
  min-height: 0;
  margin: 0 auto;
}

.files-panel,
.chat-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.015);
  backdrop-filter: saturate(160%) blur(24px);
  -webkit-backdrop-filter: saturate(160%) blur(24px);
}

.files-panel.drag-active {
  border-color: rgba(0, 113, 227, 0.38);
  background: rgba(242, 247, 255, 0.94);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 14px;
}

.heading-actions,
.composer-actions,
.composer-buttons {
  display: flex;
  align-items: center;
  gap: 7px;
}

.breadcrumb {
  display: flex;
  min-height: 34px;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 0 16px 12px;
  font-size: 12px;
}

.crumb {
  max-width: 150px;
  overflow: hidden;
  padding: 4px 7px;
  border: 0;
  border-radius: 7px;
  color: var(--text-secondary);
  background: transparent;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.crumb.current {
  color: var(--text);
  font-weight: 520;
}

.crumb-separator {
  color: #c7c7cc;
}

.file-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
}

.file-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto 62px auto;
  gap: 9px;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 7px 10px;
  border-radius: 11px;
  color: var(--text);
  outline: none;
}

.file-row:hover,
.file-row:focus-visible {
  background: var(--surface-subtle);
}

.file-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 7px;
  color: var(--text-tertiary);
  background: #ececf0;
  font-size: 9px;
  font-weight: 650;
}

.file-icon.directory {
  color: var(--accent);
  background: rgba(0, 113, 227, 0.09);
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size,
.file-date {
  color: var(--text-tertiary);
  font-size: 11px;
}

.file-date {
  text-align: right;
}

.file-download {
  display: none;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-size: 12px;
}

.file-row:hover .file-download {
  display: block;
}

.list-message {
  padding: 42px 16px;
  color: var(--text-tertiary);
  text-align: center;
  font-size: 13px;
}

.messages {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 20px 22px;
}

.empty-state {
  display: grid;
  margin: auto;
  place-items: center;
  color: var(--text-secondary);
  text-align: center;
}

.empty-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: #1d1d1f;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.14);
  font-size: 28px;
  font-weight: 620;
}

.message {
  display: flex;
  max-width: 78%;
  flex-direction: column;
  gap: 5px;
  animation: rise 180ms ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-body {
  padding: 12px 15px;
  border-radius: 18px;
  color: var(--text);
  background: #ececf0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .message-body {
  color: #fff;
  background: var(--accent);
}

.message.error .message-body {
  color: #9f1f25;
  background: #fff0f0;
}

.activity-list {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 5px;
  margin-top: 2px;
}

.activity {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--text-tertiary);
  font-size: 11px;
}

.activity::before {
  flex: 0 0 auto;
  color: var(--accent);
  content: "•";
}

.activity code {
  min-width: 0;
  overflow: hidden;
  color: var(--text-tertiary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 3px 0;
}

.thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: blink 1.1s ease-in-out infinite;
}

.thinking span:nth-child(2) { animation-delay: 120ms; }
.thinking span:nth-child(3) { animation-delay: 240ms; }

@keyframes blink {
  50% { opacity: 0.2; transform: translateY(-2px); }
}

.composer {
  margin: 0 16px 16px;
  padding: 10px 12px 10px 15px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-solid);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.045);
}

.composer textarea {
  padding: 4px 2px 8px;
  background: transparent;
}

.composer textarea:focus {
  border-color: transparent;
  box-shadow: none;
}

.composer-actions {
  justify-content: flex-end;
  min-height: 36px;
}

.send-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--accent);
  font-size: 19px;
  line-height: 1;
}

.send-button:hover {
  background: var(--accent-hover);
}

.toast {
  position: fixed;
  z-index: 20;
  right: 22px;
  bottom: 22px;
  max-width: min(400px, calc(100vw - 44px));
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(18px);
  font-size: 13px;
}

.toast.error {
  color: #9f1f25;
}

.mobile-tabs {
  display: none;
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    overscroll-behavior: none;
  }

  .login-shell {
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }

  .login-card {
    width: 100%;
    max-width: 430px;
    padding: 34px 26px;
    border-radius: 28px;
  }

  input,
  textarea {
    font-size: 16px;
  }

  .app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: env(safe-area-inset-top) 8px calc(8px + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .topbar {
    height: 52px;
    min-height: 52px;
    margin: 0 4px 6px;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .workspace-chip {
    display: none;
  }

  .brand-mark.small {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: 15px;
  }

  .brand-name {
    font-size: 16px;
  }

  .status-pill {
    min-height: 30px;
    padding: 0 10px;
    font-size: 11px;
  }

  .topbar-meta {
    gap: 4px;
  }

  .layout {
    display: block;
    flex: 1;
    width: 100%;
    min-height: 0;
    margin: 0;
    overflow: hidden;
  }

  .files-panel,
  .chat-panel {
    display: none;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    box-shadow: none;
  }

  .app-shell[data-mobile-view="chat"] .chat-panel,
  .app-shell[data-mobile-view="files"] .files-panel {
    display: flex;
  }

  .panel-heading {
    padding: 16px 16px 10px;
  }

  .panel-heading h2 {
    font-size: 19px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .breadcrumb {
    padding: 0 12px 10px;
  }

  .file-list {
    padding: 0 8px 10px;
    -webkit-overflow-scrolling: touch;
  }

  .file-row {
    min-height: 50px;
    padding: 9px 10px;
    grid-template-columns: 28px minmax(0, 1fr) auto 54px auto;
  }

  .file-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  .messages {
    gap: 14px;
    padding: 16px 14px;
    -webkit-overflow-scrolling: touch;
  }

  .message {
    max-width: 90%;
  }

  .message-body {
    padding: 11px 14px;
    font-size: 15px;
    line-height: 1.45;
  }

  .empty-mark {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    font-size: 25px;
  }

  .empty-state h3 {
    font-size: 22px;
  }

  .composer {
    margin: 0 10px 10px;
    padding: 8px 9px 8px 12px;
    border-radius: 20px;
  }

  .composer textarea {
    min-height: 50px;
    max-height: 130px;
    padding: 5px 2px 6px;
  }

  .composer-actions {
    min-height: 40px;
  }

  .send-button {
    width: 40px;
    height: 40px;
    font-size: 21px;
  }

  .toast {
    right: 14px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    left: 14px;
    max-width: none;
    text-align: center;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    width: 100%;
    height: 62px;
    min-height: 62px;
    margin-top: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 21px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    backdrop-filter: saturate(180%) blur(22px);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
  }

  .mobile-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 0;
    border-radius: 16px;
    color: var(--text-secondary);
    background: transparent;
    font-size: 13px;
    font-weight: 540;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tab svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
  }

  .mobile-tab.active {
    color: #fff;
    background: #1d1d1f;
  }
}

@media (max-width: 390px) {
  .status-pill {
    display: none;
  }

  .file-row {
    grid-template-columns: 28px minmax(0, 1fr) 50px;
  }

  .file-size,
  .file-download {
    display: none !important;
  }

  .message {
    max-width: 94%;
  }
}
