:root {
  color-scheme: dark;
  --bg: #050712;
  --panel: #090b14;
  --panel-soft: #0d101c;
  --panel-raised: #111522;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f7f7ff;
  --muted: rgba(234, 234, 255, 0.64);
  --subtle: rgba(234, 234, 255, 0.42);
  --accent: #4ea1ff;
  --accent-strong: #1717c8;
  --success: #18d84f;
  --danger: #ff4d5a;
  --shadow: 0 22px 68px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: rgba(245, 247, 255, 0.72);
  text-decoration: none;
}

a:hover {
  color: #fff;
}

.app-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
  min-height: 0;
  background:
    radial-gradient(circle at 72% 20%, rgba(78, 161, 255, 0.04), transparent 32rem),
    var(--bg);
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(7, 8, 15, 0.98);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 40;
}

.sidebar-header {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.brand-mark {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.sidebar-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
}

.sidebar-nav-btn,
.sidebar-row {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.sidebar-nav-btn:hover,
.sidebar-row:hover,
.sidebar-nav-btn.is-active {
  background: rgba(78, 161, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(78, 161, 255, 0.18);
}

.nav-icon,
.row-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.78);
}

.sidebar-search {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border-radius: 10px;
  background: transparent;
}

.sidebar-search:focus-within {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.sidebar-search input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.sidebar-section {
  margin-top: 16px;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
  padding: 0 2px;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.mini-button {
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}

.thread-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.thread-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  text-align: left;
}

.thread-item:hover,
.thread-item.is-active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.thread-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 800;
}

.thread-subtitle {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: rgba(255, 255, 255, 0.48);
  font-size: 11px;
  font-weight: 700;
}

.thread-delete {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
}

.thread-delete:hover {
  background: rgba(255, 77, 90, 0.14);
  color: #fff;
}

.empty-history {
  padding: 10px 8px;
  color: rgba(255, 255, 255, 0.52);
  font-size: 12px;
}

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.account-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account-avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid rgba(78, 161, 255, 0.5);
  background: rgba(78, 161, 255, 0.22);
  font-weight: 900;
}

.account-text {
  min-width: 0;
}

.account-name,
.account-email {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.account-name {
  font-size: 13px;
  font-weight: 900;
}

.account-email {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  font-weight: 700;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 30;
}

.chat-stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 9, 16, 0.72);
  backdrop-filter: blur(16px);
  z-index: 10;
}

.topbar-minimal {
  justify-content: flex-end;
}

.topbar-minimal .topbar-left {
  display: none;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.eyebrow {
  color: rgba(255, 255, 255, 0.46);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--success);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.status-dot.bad {
  color: var(--danger);
}

.ghost-button,
.icon-button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.86);
  cursor: pointer;
  font-weight: 800;
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  width: 36px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 34px min(10vw, 170px) 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.messages.is-dragging {
  outline: 2px solid rgba(78, 161, 255, 0.36);
  outline-offset: -12px;
}

.chat-welcome {
  margin: auto;
  text-align: center;
  max-width: 720px;
  color: var(--muted);
}

.chat-welcome h2 {
  margin: 0 0 10px;
  color: rgba(245, 247, 255, 0.96);
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

.chat-welcome p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.message {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}

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

.message.agent,
.message.system {
  align-items: flex-start;
}

.message-meta {
  margin-bottom: 6px;
  color: rgba(214, 222, 255, 0.68);
  font-size: 12px;
  font-weight: 800;
}

.message.user .message-meta {
  padding-right: 10px;
}

.message-bubble {
  max-width: min(78%, 900px);
  min-width: 0;
  padding: 13px 16px;
  border-radius: 18px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: rgba(255, 255, 255, 0.02);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.28);
}

.message.agent .message-bubble,
.message.system .message-bubble {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(14, 17, 31, 0.78);
}

.message.system .message-bubble {
  color: rgba(255, 255, 255, 0.86);
  font-size: 13px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(24, 216, 79, 0.28);
  background: rgba(24, 216, 79, 0.1);
  color: rgba(190, 255, 210, 0.95);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.source-badge.local {
  border-color: rgba(78, 161, 255, 0.28);
  background: rgba(78, 161, 255, 0.11);
  color: rgba(188, 220, 255, 0.96);
}

.input-area {
  flex: 0 0 auto;
  padding: 10px 24px 14px;
  background: linear-gradient(180deg, rgba(5, 7, 18, 0), rgba(5, 7, 18, 0.96) 22%);
}

.activity-log {
  width: min(900px, 100%);
  max-height: 96px;
  overflow: auto;
  margin: 0 auto 8px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(8, 10, 18, 0.96);
  color: rgba(255, 255, 255, 0.72);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.composer-shell {
  position: relative;
  width: min(900px, 100%);
  margin: 0 auto;
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 66px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 30px;
  background: rgba(10, 10, 16, 0.94);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
}

.composer:focus-within {
  border-color: rgba(255, 255, 255, 0.22);
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  max-height: 140px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  padding: 8px 6px;
  line-height: 1.45;
  font-size: 14px;
  font-weight: 700;
}

.composer textarea::placeholder {
  color: rgba(255, 255, 255, 0.48);
}

.composer-plus,
.send-btn {
  height: 42px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  cursor: pointer;
}

.composer-plus {
  width: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.86);
  font-size: 24px;
}

.send-btn {
  width: 42px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.send-btn:not(:disabled):hover,
.composer-plus:not(:disabled):hover,
.ghost-button:not(:disabled):hover,
.icon-button:not(:disabled):hover,
.mini-button:not(:disabled):hover {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.09);
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.asset-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: min(340px, calc(100vw - 36px));
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(11, 14, 26, 0.98);
  box-shadow: var(--shadow);
  z-index: 20;
}

.asset-menu button {
  width: 100%;
  min-height: 40px;
  margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.asset-menu button:last-child {
  margin-bottom: 0;
}

.input-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 9px;
  color: rgba(243, 242, 255, 0.58);
  font-size: 12px;
  font-weight: 700;
}

.mobile-only {
  display: none;
}

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-102%);
    transition: transform 0.18s ease;
  }

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

  .mobile-only {
    display: inline-flex;
  }

  .topbar {
    padding: 12px 16px;
  }

  .topbar-minimal {
    justify-content: space-between;
  }

  .topbar-minimal .topbar-left {
    display: flex;
  }

  .messages {
    padding: 28px 18px 20px;
  }

  .message-bubble {
    max-width: min(92%, 900px);
  }

}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .topbar-left,
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .eyebrow {
    display: none;
  }

  .messages {
    gap: 18px;
  }

  .input-area {
    padding: 8px 10px 10px;
  }

  .composer {
    min-height: 58px;
    padding: 8px 10px;
  }

  .composer-plus,
  .send-btn {
    width: 38px;
    height: 38px;
  }

  .input-footer {
    font-size: 11px;
  }
}
