:root {
  color-scheme: dark;
  --sidebar: #171717;
  --workspace: #212121;
  --surface: #2a2a2a;
  --surface-hover: #262626;
  --surface-active: #303030;
  --border: #343434;
  --border-soft: #292929;
  --text: #ececec;
  --text-soft: #c6c6c6;
  --muted: #8e8e8e;
  --faint: #656565;
  --accent: #b4e8c6;
  --danger: #ef8c81;
  --sidebar-width: 284px;
  font-family: Inter, "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  overflow: hidden;
  background: var(--workspace);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

kbd {
  margin-left: auto;
  color: #5f5f5f;
  font: 9px/1 "Segoe UI", sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.codex-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #454545;
  border-radius: 10px;
  background: #1d1d1d;
  color: var(--text);
  font-size: 18px;
  font-weight: 640;
}

.codex-mark.small {
  width: 29px;
  height: 29px;
  border-radius: 7px;
  font-size: 12px;
}

/* Login */
.login-shell {
  display: grid;
  min-height: 100svh;
  padding: 28px;
  place-items: center;
  background: var(--workspace);
}

.login-panel {
  width: min(500px, 100%);
}

.login-panel > .codex-mark {
  margin-bottom: 30px;
}

.login-panel h1 {
  margin: 0;
  font-size: clamp(46px, 8vw, 76px);
  font-weight: 520;
  letter-spacing: -0.055em;
  line-height: 1;
}

.login-copy {
  margin: 19px 0 45px;
  color: var(--muted);
  font-size: 14px;
}

.login-form label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
}

.login-row {
  display: flex;
  gap: 8px;
}

.login-row input,
.login-row button {
  min-height: 48px;
  border-radius: 10px;
}

.login-row input {
  min-width: 0;
  flex: 1;
  padding: 0 14px;
  border: 1px solid #444;
  outline: 0;
  background: #292929;
}

.login-row input:focus {
  border-color: #707070;
}

.login-row button {
  padding: 0 21px;
  border: 0;
  background: #ededed;
  color: #191919;
  font-weight: 650;
}

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

.secure-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 34px 0 0;
  color: var(--faint);
  font-size: 10px;
}

.secure-note span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* App shell */
.codex-shell {
  position: relative;
  display: grid;
  width: 100vw;
  height: 100svh;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns 180ms ease;
}

.codex-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  width: var(--sidebar-width);
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #1d1d1d;
  background: var(--sidebar);
  transition: transform 180ms ease, opacity 120ms ease;
}

.sidebar-collapsed .sidebar {
  pointer-events: none;
  opacity: 0;
  transform: translateX(-100%);
}

.sidebar-header {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px 13px;
}

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

.app-brand strong {
  font-size: 13px;
  font-weight: 600;
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}

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

.icon-button svg {
  width: 16px;
}

.primary-nav {
  padding: 3px 9px 8px;
}

.primary-nav button {
  display: flex;
  width: 100%;
  height: 36px;
  align-items: center;
  gap: 10px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  text-align: left;
}

.primary-nav button:hover,
.primary-nav button.active {
  background: var(--surface-hover);
  color: var(--text);
}

.primary-nav svg {
  width: 16px;
}

.search-field {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  margin: 1px 10px 8px;
  padding: 0 9px;
  border: 1px solid #383838;
  border-radius: 8px;
  background: #202020;
  color: var(--muted);
}

.search-field svg {
  width: 14px;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12px;
}

.search-field button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
}

.sidebar-content {
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px 7px;
  color: #747474;
  font-size: 11px;
  font-weight: 650;
}

.project-list {
  height: calc(100% - 31px);
  overflow-y: auto;
  padding: 0 7px 12px;
  scrollbar-width: thin;
  scrollbar-color: #383838 transparent;
}

.project-group {
  margin-bottom: 1px;
}

.project-row {
  display: grid;
  width: 100%;
  height: 37px;
  grid-template-columns: 13px 17px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
}

.project-row:hover,
.project-row.selected {
  background: var(--surface-hover);
}

.project-chevron {
  color: #666;
  font-size: 16px;
  transform: rotate(0deg);
  transition: transform 120ms ease;
}

.project-group.expanded .project-chevron {
  transform: rotate(90deg);
}

.folder-icon {
  position: relative;
  width: 15px;
  height: 11px;
  border: 1px solid #777;
  border-radius: 2px;
}

.folder-icon::before {
  position: absolute;
  top: -4px;
  left: 1px;
  width: 6px;
  height: 3px;
  border: 1px solid #777;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  content: "";
}

.project-copy {
  min-width: 0;
}

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

.project-copy strong {
  color: #d5d5d5;
  font-size: 12px;
  font-weight: 550;
}

.project-copy small {
  display: none;
}

.project-count {
  color: #616161;
  font-size: 10px;
}

.conversation-list {
  margin: 1px 0 5px;
}

.conversation-row {
  display: grid;
  width: 100%;
  min-height: 39px;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 4px 9px 4px 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
}

.conversation-row:hover,
.conversation-row.selected {
  background: var(--surface-hover);
}

.conversation-row.selected {
  background: var(--surface-active);
}

.conversation-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #5f5f5f;
}

.conversation-dot.live {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(180, 232, 198, 0.08);
}

.conversation-copy {
  min-width: 0;
}

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

.conversation-copy strong {
  color: #c8c8c8;
  font-size: 12px;
  font-weight: 480;
}

.conversation-copy small {
  margin-top: 2px;
  color: #666;
  font-size: 10px;
}

.navigation-empty,
.project-empty {
  margin: 9px 10px;
  color: #656565;
  font-size: 9px;
  line-height: 1.45;
}

.project-empty {
  margin-left: 38px;
}

.sidebar-footer {
  display: flex;
  min-height: 57px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #232323;
}

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

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #555;
}

.worker-indicator.online .status-dot {
  background: #86d7a2;
}

.worker-indicator.busy .status-dot {
  background: #e5bd68;
}

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

.worker-indicator strong {
  color: #bdbdbd;
  font-size: 11px;
  font-weight: 550;
}

.worker-indicator small {
  margin-top: 2px;
  color: #666;
  font-size: 9px;
}

/* Workspace */
.workspace {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 54px minmax(0, 1fr) auto auto;
  background: var(--workspace);
}

.workspace-header {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid #292929;
  background: rgba(33, 33, 33, 0.94);
  backdrop-filter: blur(12px);
}

.sidebar-open {
  flex: 0 0 auto;
}

.codex-shell:not(.sidebar-collapsed) .sidebar-open {
  display: none;
}

.workspace-heading {
  min-width: 0;
}

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

.workspace-heading strong {
  font-size: 14px;
  font-weight: 560;
}

.workspace-heading span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.sync-label {
  color: var(--muted);
  font-size: 11px;
}

.message-viewport {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #414141 transparent;
}

.message-stream {
  width: min(760px, calc(100% - 44px));
  margin: 0 auto;
  padding: 30px 0 88px;
}

.message {
  display: flex;
  width: 100%;
  padding: 15px 0;
}

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

.message.commentary {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 9px;
  padding: 7px 0;
}

.message-avatar {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid #484848;
  border-radius: 7px;
  background: #282828;
  color: #d8d8d8;
  font-size: 10px;
  font-weight: 650;
}

.message.assistant .message-avatar,
.message.commentary .message-avatar {
  border-color: #526158;
  color: var(--accent);
}

.message.user .message-avatar,
.message.assistant:not(.commentary) .message-avatar {
  display: none;
}

.message.commentary .message-avatar {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border: 0;
  background: #29322c;
  font-size: 8px;
}

.message-content {
  min-width: 0;
  width: 100%;
}

.message-content > strong {
  display: block;
  margin-bottom: 6px;
  color: #d8d8d8;
  font-size: 12px;
  font-weight: 590;
}

.message.user .message-content {
  width: auto;
  max-width: min(82%, 620px);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: #2d2d2d;
}

.message.user .message-content > strong,
.message.assistant:not(.commentary) .message-content > strong {
  display: none;
}

.message.commentary .message-content > strong,
.message.commentary .message-body {
  color: #969696;
}

.message.commentary + .message.commentary .message-avatar {
  visibility: hidden;
}

.message.commentary + .message.commentary .message-content > strong {
  display: none;
}

.message-body {
  color: #d2d2d2;
  font-size: 14px;
  line-height: 1.62;
}

.message.user .message-body {
  color: #ededed;
}

.message-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-body pre {
  overflow-x: auto;
  margin: 14px 0;
  padding: 14px 16px;
  border: 1px solid #353535;
  border-radius: 9px;
  background: #181818;
}

.message-body code {
  font: 12px/1.6 "Cascadia Code", Consolas, monospace;
  white-space: pre;
}

.message-error {
  margin: 16px 0;
  padding: 12px 14px;
  border: 1px solid rgba(239, 140, 129, 0.3);
  border-radius: 8px;
  color: var(--danger);
  font-size: 10px;
}

.empty-workspace {
  display: grid;
  min-height: 100%;
  padding: 50px 30px 170px;
  place-content: center;
}

.empty-workspace h1 {
  margin: 0;
  font-size: clamp(25px, 3.5vw, 36px);
  font-weight: 520;
  letter-spacing: -0.045em;
  text-align: center;
}

.empty-workspace > p {
  margin: 13px 0 30px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.suggestions {
  width: min(540px, 72vw);
}

.suggestions button {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 2px;
  border: 0;
  border-top: 1px solid #353535;
  background: transparent;
  color: #cecece;
  font-size: 11px;
  text-align: left;
}

.suggestions button:last-child {
  border-bottom: 1px solid #353535;
}

.suggestions button:hover {
  color: var(--text);
}

.suggestions span {
  color: #6d6d6d;
  font-size: 9px;
}

.activity-bar {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 9px;
  padding: 0 max(22px, calc((100% - 760px) / 2));
  color: var(--muted);
  font-size: 11px;
}

.activity-spinner {
  width: 10px;
  height: 10px;
  border: 1px solid #555;
  border-top-color: #ddd;
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.activity-bar button {
  margin-left: auto;
  padding: 4px 7px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 9px;
}

.composer-shell {
  padding: 7px max(22px, calc((100% - 760px) / 2)) 12px;
  background: linear-gradient(to top, var(--workspace) 80%, rgba(33, 33, 33, 0));
}

#message-form {
  padding: 13px 13px 9px 15px;
  border: 1px solid #464646;
  border-radius: 15px;
  background: #2b2b2b;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
}

#message-form:focus-within {
  border-color: #666;
}

#prompt {
  display: block;
  width: 100%;
  min-height: 28px;
  max-height: 190px;
  resize: none;
  overflow-y: auto;
  padding: 1px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

#prompt::placeholder {
  color: #858585;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.composer-context {
  display: flex;
  min-width: 0;
  gap: 5px;
}

.context-chip {
  max-width: 220px;
  overflow: hidden;
  padding: 4px 7px;
  border: 1px solid #444;
  border-radius: 6px;
  color: #b9b9b9;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-chip.muted {
  color: #797979;
}

#send-button {
  display: grid;
  width: 29px;
  height: 29px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #ececec;
  color: #202020;
}

#send-button svg {
  width: 15px;
  stroke-width: 1.8;
}

.composer-note {
  margin: 7px 0 0;
  color: #686868;
  font-size: 9px;
  text-align: center;
}

.sidebar-scrim {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .codex-shell,
  .codex-shell.sidebar-collapsed {
    display: block;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(88vw, var(--sidebar-width));
    transform: translateX(-102%);
    opacity: 1;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.42);
  }

  .codex-shell.sidebar-visible .sidebar {
    pointer-events: auto;
    transform: translateX(0);
  }

  .codex-shell.sidebar-visible .sidebar-scrim {
    display: block;
  }

  .sidebar-scrim {
    position: absolute;
    z-index: 10;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.52);
  }

  .desktop-collapse {
    display: none;
  }

  .workspace {
    width: 100%;
    height: 100svh;
  }

  .codex-shell:not(.sidebar-collapsed) .sidebar-open {
    display: grid;
  }

  .message-stream {
    width: calc(100% - 28px);
  }

  .composer-shell,
  .activity-bar {
    padding-right: 12px;
    padding-left: 12px;
  }

  .empty-workspace {
    padding-right: 18px;
    padding-left: 18px;
  }

  .suggestions {
    width: min(100%, 520px);
  }
}

@media (max-width: 520px) {
  .login-shell {
    padding: 21px;
  }

  .login-row {
    flex-direction: column;
  }

  .login-row button {
    width: 100%;
  }

  .message {
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 9px;
  }

  .message-avatar {
    width: 23px;
    height: 23px;
  }

  .message-body {
    font-size: 11px;
  }

  .suggestions button {
    display: block;
  }

  .suggestions span {
    display: block;
    margin-top: 4px;
  }

  .context-chip.muted {
    display: none;
  }

  .sync-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
