:root {
  color-scheme: dark;
  --bg: #121314;
  --surface: #17191c;
  --panel: #181b1f;
  --panel-2: #202327;
  --panel-3: #25272b;
  --line: #30343a;
  --line-soft: #272b31;
  --text: #f0f1f2;
  --muted: #a1a7ae;
  --muted-2: #6f7780;
  --accent: #f3f4f5;
  --user: #2a2d31;
  --blue: #2787e8;
  --blue-hover: #3b96ef;
  --focus: #6aa8ff;
  --danger: #ffb6b6;
  --shadow: rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #3d434b transparent;
}

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

::-webkit-scrollbar-thumb {
  background: #3d434b;
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: #4b535d;
  border: 3px solid transparent;
  background-clip: content-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

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

button {
  color: inherit;
}

button,
select {
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.hidden-file-input {
  display: none;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 22px 60px var(--shadow);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.auth-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

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

.auth-actions button:not(.primary),
.account-box button,
.row-title button,
.balance-form button {
  border: 0;
  border-radius: 6px;
  background: #30343a;
  color: #f2f2f2;
  cursor: pointer;
  padding: 9px 12px;
}

.auth-actions button:not(.primary):hover,
.account-box button:hover,
.row-title button:hover,
.balance-form button:hover {
  background: #3a3f46;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 282px;
  background: #15181b;
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
}

.account-box {
  border-bottom: 1px solid var(--line-soft);
  padding: 0 6px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-box strong,
.account-box span {
  display: block;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-box span {
  color: var(--muted);
  font-size: 13px;
}

.account-box button {
  padding: 6px 9px;
  font-size: 13px;
}

.top-actions {
  display: grid;
  gap: 4px;
}

.nav-action,
.settings {
  height: 34px;
  border: 0;
  color: var(--text);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  min-width: 0;
}

.nav-action span:last-child,
.settings span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-action:hover,
.settings:hover,
.conversation-row:hover,
.conversation-row.active {
  background: rgba(255, 255, 255, 0.065);
}

.nav-action:active,
.settings:active,
.tool-button:active {
  transform: translateY(1px);
}

.nav-action.muted {
  color: #d4d8dd;
}

.icon,
.folder {
  width: 18px;
  display: inline-flex;
  justify-content: center;
  color: #c8cdd2;
}

.search-box {
  display: none;
  margin-top: 10px;
}

.search-box.open {
  display: block;
}

.search-box input,
.stack-form input,
.stack-form textarea,
.stack-form select {
  width: 100%;
  border: 1px solid var(--line);
  outline: 0;
  background: #22252a;
  color: var(--text);
  border-radius: 6px;
  padding: 10px 11px;
}

.search-box input:focus,
.stack-form input:focus,
.stack-form textarea:focus,
.stack-form select:focus {
  border-color: #4e5865;
  background: #262a30;
}

.search-box input {
  height: 36px;
}

.group {
  margin-top: 24px;
}

.group-title {
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 600;
  padding: 0 8px 8px;
  letter-spacing: 0;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-title button {
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.project-list {
  display: grid;
  gap: 4px;
}

.project-item {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  color: #d7dce1;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.project-item:hover,
.project-item.active {
  background: rgba(255, 255, 255, 0.07);
  color: #f4f5f6;
}

.project-item strong {
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversations {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.conversation-list {
  overflow: auto;
  padding-right: 4px;
  display: grid;
  gap: 2px;
}

.conversation-row {
  min-height: 36px;
  border-radius: 6px;
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
}

.conversation-item {
  min-width: 0;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: #dfe3e7;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}

.conversation-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation-time {
  color: var(--muted-2);
  font-size: 12px;
  align-self: center;
  white-space: nowrap;
}

.conversation-time.expired {
  color: var(--danger);
}

.conversation-delete {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
}

.conversation-delete:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.conversation-empty,
.panel-empty {
  color: var(--muted-2);
  font-size: 13px;
  padding: 8px;
}

.settings {
  margin-top: 12px;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
  height: 48px;
}

.main {
  margin-left: 282px;
  height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--bg);
}

.thread {
  overflow: auto;
  padding: 48px max(26px, 11vw) 190px;
  scroll-behavior: smooth;
}

.empty {
  min-height: calc(100vh - 280px);
  display: grid;
  place-items: center;
  text-align: center;
}

.empty h1 {
  font-size: 31px;
  line-height: 1.2;
  margin: 0;
  font-weight: 680;
  letter-spacing: 0;
  color: #e7e8ea;
}

.empty p {
  color: var(--muted);
  margin: 10px 0 0;
}

.message {
  max-width: 860px;
  margin: 0 auto 24px;
  display: grid;
  gap: 8px;
}

.message.user {
  justify-items: end;
}

.bubble {
  max-width: min(760px, 100%);
  border-radius: 8px;
  padding: 13px 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.62;
}

.user .bubble {
  background: #282b30;
  border: 1px solid #343940;
}

.assistant .bubble {
  background: transparent;
  padding-left: 0;
  color: #eceff1;
}

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

.message-attachments {
  max-width: min(760px, 100%);
  display: grid;
  gap: 7px;
}

.message.user .message-attachments {
  justify-items: end;
}

.message-attachment {
  max-width: min(360px, 100%);
  min-width: 220px;
  border: 1px solid #393f47;
  background: #23262b;
  color: inherit;
  text-decoration: none;
  border-radius: 7px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

.message-attachment:hover {
  border-color: #4d5662;
  background: #282c32;
}

.message-attachment div {
  min-width: 0;
}

.message-attachment strong,
.message-attachment small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-attachment strong {
  font-size: 13px;
  color: #f0f2f4;
}

.message-attachment small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.conversation-expiry {
  max-width: 860px;
  margin: -8px auto 22px;
  color: var(--muted-2);
  font-size: 13px;
  text-align: center;
}

.composer {
  position: fixed;
  left: calc(282px + ((100vw - 282px) / 2) - 48px);
  bottom: 32px;
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 342px - 48px));
  background: #26282c;
  border: 1px solid #383c42;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
}

.composer.drop-active {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(106, 168, 255, 0.22), 0 18px 48px rgba(0, 0, 0, 0.38);
}

.attachment-list {
  display: none;
  gap: 10px;
  padding: 12px 18px 4px;
  overflow-x: auto;
}

.composer.has-attachments .attachment-list {
  display: flex;
}

.attachment-item {
  position: relative;
  flex: 0 0 min(285px, calc(100vw - 150px));
  min-width: 0;
  min-height: 68px;
  border: 1px solid #44484f;
  background: #26272b;
  border-radius: 12px;
  padding: 12px 34px 12px 12px;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
}

.attachment-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #17191d;
  color: #f0f2f4;
  display: inline-grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.attachment-main {
  min-width: 0;
}

.attachment-main strong,
.attachment-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-main strong {
  color: #f1f3f5;
  font-size: 16px;
  font-weight: 700;
}

.attachment-main span {
  color: #a8adb4;
  font-size: 15px;
  margin-top: 4px;
  font-weight: 600;
}

.attachment-remove {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #f3f4f5;
  color: #2a2d31;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.attachment-remove:hover {
  background: #ffffff;
  color: #111317;
}

.composer textarea {
  width: 100%;
  min-height: 62px;
  max-height: 210px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  padding: 17px 18px 9px;
}

.composer.has-attachments textarea {
  min-height: 76px;
  padding-top: 10px;
}

.composer textarea::placeholder,
input::placeholder,
textarea::placeholder {
  color: #858585;
}

.composer-bar {
  min-height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 11px 11px 13px;
}

.left-tools,
.right-tools,
.row-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.right-tools {
  justify-content: flex-end;
}

.tool-button,
.send {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.tool-button {
  background: transparent;
  color: #c3c8ce;
  font-size: 18px;
}

.tool-button:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.send {
  background: #e3e5e7;
  color: #141617;
  font-weight: 700;
  font-size: 17px;
}

.send:hover {
  background: #fff;
}

.send:disabled {
  opacity: 0.45;
  cursor: wait;
}

select {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #e1e4e7;
  background: rgba(255, 255, 255, 0.04);
  outline: 0;
  padding: 0 28px 0 10px;
}

select:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: #3d444d;
}

.workdir {
  color: #a5a9ad;
  font-size: 13px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remaining-time {
  min-width: 78px;
  color: #b7d7ff;
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}

.remaining-time:empty {
  display: none;
}

.remaining-time.expired,
.conversation-expiry.expired {
  color: var(--danger);
}

.thinking {
  color: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0, 0, 0, 0.46);
  z-index: 15;
}

.drawer-backdrop.open {
  display: block;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, calc(100vw - 24px));
  height: 100vh;
  transform: translateX(100%);
  transition: transform 180ms ease;
  background: #1b1e22;
  border-left: 1px solid #333841;
  z-index: 20;
  padding: 24px;
  overflow: auto;
  box-shadow: -22px 0 60px rgba(0, 0, 0, 0.42);
}

.drawer.wide {
  width: min(520px, calc(100vw - 24px));
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.drawer h2,
.file-dialog h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 680;
  letter-spacing: 0;
}

.close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #b8bdc2;
  cursor: pointer;
  font-size: 23px;
}

.close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.template-list {
  display: grid;
  gap: 10px;
}

.template-list button,
.automation-item {
  border: 1px solid #333941;
  background: #24272c;
  color: var(--text);
  border-radius: 8px;
  padding: 12px;
}

.template-list button {
  cursor: pointer;
  text-align: left;
}

.template-list button:hover {
  border-color: #4a525c;
  background: #292d33;
}

.stack-form {
  display: grid;
  gap: 15px;
}

.stack-form label {
  display: grid;
  gap: 7px;
  color: #d9dde2;
  font-size: 13px;
}

.stack-form textarea {
  resize: vertical;
}

.primary,
.small,
.dialog-actions button {
  border: 0;
  border-radius: 6px;
  background: #343940;
  color: #f2f2f2;
  cursor: pointer;
  padding: 9px 12px;
}

.primary {
  background: var(--blue);
  justify-self: start;
}

.primary:hover {
  background: var(--blue-hover);
}

.small {
  padding: 6px 9px;
  font-size: 13px;
}

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

.automation-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.admin-users {
  display: grid;
  gap: 12px;
}

.admin-billing {
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.admin-user {
  border: 1px solid #333941;
  background: #24272c;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.admin-user strong,
.admin-user span {
  display: block;
}

.admin-user span {
  color: var(--muted);
  font-size: 13px;
}

.balance-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.balance-form input {
  min-width: 0;
  border: 1px solid var(--line);
  outline: 0;
  background: #20242a;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
}

.automation-item {
  display: grid;
  gap: 11px;
}

.automation-item strong,
.automation-item span {
  display: block;
}

.automation-item span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.setting-meta {
  color: var(--muted);
  font-size: 13px;
}

.setting-meta.ok {
  color: #8fdaa3;
}

.setting-meta.bad {
  color: var(--danger);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid #3d424a;
  border-radius: 8px;
  padding: 20px;
  background: #1f2328;
  color: var(--text);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.46);
}

.file-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dialog-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  background: #262b31;
  border: 1px solid #444c56;
  color: #fff;
  padding: 10px 13px;
  border-radius: 7px;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 30;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.34);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  place-items: center;
  pointer-events: none;
  background: rgba(8, 10, 12, 0.54);
}

.drop-overlay.show {
  display: grid;
}

.drop-overlay div {
  width: min(420px, calc(100vw - 40px));
  border: 1px solid #6f96dd;
  background: #20252d;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.44);
}

.drop-overlay strong,
.drop-overlay span {
  display: block;
}

.drop-overlay strong {
  font-size: 18px;
  margin-bottom: 6px;
}

.drop-overlay span {
  color: var(--muted);
  font-size: 13px;
}

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

@media (max-width: 820px) {
  .sidebar {
    width: 74px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .nav-action span:last-child,
  .settings span:last-child,
  .account-box strong,
  .account-box span,
  .group-title span,
  .project-item strong,
  .conversation-list,
  .search-box {
    display: none;
  }

  .main {
    margin-left: 74px;
  }

  .composer {
    left: calc(74px + ((100vw - 74px) / 2));
    width: calc(100vw - 98px);
    bottom: 18px;
  }

  .thread {
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 170px;
  }

  .drawer.wide,
  .drawer {
    width: calc(100vw - 18px);
  }
}
