:root {
  --bg: #06101a;
  --surface: #0c1825;
  --surface-muted: #111f2e;
  --surface-light: #182a3c;
  --border: rgba(110, 150, 185, 0.13);
  --border-strong: rgba(110, 150, 185, 0.22);
  --text: #e2ecf5;
  --text-muted: #6a8aa5;
  --text-soft: #9ab2c8;
  --accent: #10a37f;
  --accent-strong: #0c8366;
  --accent-soft: rgba(16, 163, 127, 0.1);
  --danger: #e05555;
  --danger-soft: rgba(224, 85, 85, 0.09);
  --notice-soft: rgba(220, 180, 60, 0.1);
  --radius: 4px;
}

[data-theme="light"] {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-muted: #f5f8fb;
  --surface-light: #eaeff5;
  --border: rgba(55, 85, 115, 0.12);
  --border-strong: rgba(55, 85, 115, 0.2);
  --text: #0d1e2e;
  --text-muted: #546a80;
  --text-soft: #2c4860;
  --accent-soft: rgba(16, 163, 127, 0.08);
  --danger-soft: rgba(224, 85, 85, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  height: 100%;
}

body.workspace-body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

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

.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 {
  display: block;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

/* Brand */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-lockup strong,
.brand-lockup small {
  display: block;
  line-height: 1.3;
}

.brand-lockup strong {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.brand-lockup small {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.brand-lockup__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Buttons */
.button,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: opacity 0.12s ease, background 0.12s ease;
}

.button {
  min-height: 40px;
  padding: 0 1.1rem;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.button:hover:not(:disabled),
.theme-toggle:hover {
  opacity: 0.82;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.button--primary {
  background: var(--accent);
  color: #fff;
}

.button--ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}

.button--small {
  min-height: 32px;
  padding: 0 0.8rem;
  font-size: 0.82rem;
}

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

/* Theme toggle */
.theme-toggle {
  gap: 0.4rem;
  min-height: 32px;
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.theme-toggle__icon {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 0.7rem;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 500;
}

.status-pill--soft {
  background: var(--accent-soft);
  border-color: rgba(16, 163, 127, 0.2);
  color: var(--accent);
}

/* Flash messages */
.message {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.84rem;
}

.message--error {
  background: var(--danger-soft);
  border-color: rgba(224, 85, 85, 0.2);
  color: var(--danger);
}

.message--notice {
  background: var(--notice-soft);
  border-color: rgba(220, 180, 60, 0.18);
  color: #c29534;
}

/* ============ LOGIN PAGE ============ */

.login-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  text-align: center;
}

.login-card__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.login-card__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
}

.login-card__title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.login-card__sub {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.login-card__messages {
  width: 100%;
  display: grid;
  gap: 0.5rem;
  text-align: left;
}

.login-card__actions {
  width: 100%;
  display: grid;
  gap: 0.85rem;
}

.login-form {
  display: grid;
  gap: 0.75rem;
}

.login-form__field {
  display: grid;
  gap: 0.35rem;
  text-align: left;
}

.login-form__field span {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-form__field input {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s ease;
}

.login-form__field input:focus {
  border-color: var(--accent);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-footer {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
}

/* ============ WORKSPACE ============ */

.workspace-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.workspace-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 54px;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.workspace-topbar__left,
.workspace-topbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

/* User chip */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.25rem 0.7rem 0.25rem 0.25rem;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
}

.user-chip__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  object-fit: cover;
  font-size: 0.68rem;
  font-weight: 700;
}

.user-chip strong,
.user-chip small {
  display: block;
  line-height: 1.3;
}

.user-chip strong {
  font-size: 0.82rem;
  font-weight: 600;
}

.user-chip small {
  color: var(--text-muted);
  font-size: 0.72rem;
}

/* Account */
.account-page {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.account-card {
  width: min(520px, 100%);
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.account-card__header h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  line-height: 1.15;
}

.account-card__header p {
  margin-top: 0.55rem;
  color: var(--text-soft);
  max-width: 54ch;
}

.account-card__messages {
  display: grid;
  gap: 0.55rem;
}

.account-form {
  max-width: 420px;
}

.account-form__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

/* Sidebar controls */
.sidebar-toggle,
.sidebar-close,
.chat-overlay {
  display: none;
}

.sidebar-toggle,
.sidebar-close {
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Chat app layout */
.chat-app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.chat-sidebar__header,
.chat-sidebar__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
}

.chat-sidebar__header h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
}

.chat-sidebar__list {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 0.15rem;
  overflow-y: auto;
  align-content: start;
}

.empty-list {
  padding: 0.8rem;
  border-radius: var(--radius);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.empty-list strong {
  font-size: 0.86rem;
}

.empty-list p {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem;
  padding: 0.35rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background 0.1s ease, border-color 0.1s ease;
}

.conversation-row:hover,
.conversation-row.is-active {
  background: var(--surface-muted);
  border-color: var(--border);
}

.conversation-row__link {
  min-width: 0;
  display: block;
  padding: 0.15rem 0.15rem 0.15rem 0.3rem;
}

.conversation-row__link strong,
.conversation-row__link span,
.conversation-row__link small {
  display: block;
}

.conversation-row__link strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.conversation-row__link span {
  margin-top: 0.1rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row__link small {
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.conversation-row__delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 28px;
  min-width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
}

.conversation-row__delete:hover {
  background: var(--danger-soft);
  border-color: rgba(224, 85, 85, 0.18);
  color: var(--danger);
}

/* Chat workspace */
.chat-workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-workspace__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-workspace__header h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
}

.chat-workspace__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  flex-shrink: 0;
}

/* Thread */
.chat-thread {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 0.65rem;
  padding: 1.25rem;
  overflow-y: auto;
  align-content: start;
}

.empty-thread {
  display: grid;
  gap: 1rem;
  padding: 2rem 0;
}

.empty-thread__hero h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.5rem, 2.8vw, 2.2rem);
  line-height: 1.1;
}

.empty-thread__hero p {
  margin-top: 0.6rem;
  color: var(--text-soft);
  max-width: 56ch;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.prompt-card {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  text-align: left;
  transition: border-color 0.1s ease, background 0.1s ease;
}

.prompt-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.prompt-card strong,
.prompt-card span {
  display: block;
}

.prompt-card strong {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
}

.prompt-card span {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Message bubbles */
.message-bubble {
  max-width: min(820px, 100%);
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.92rem;
}

.message-bubble--user {
  justify-self: end;
  background: var(--accent-soft);
  border-color: rgba(16, 163, 127, 0.18);
}

.message-bubble--assistant {
  justify-self: start;
}

.message-bubble--pending {
  opacity: 0.6;
}

.message-bubble--pending .message-bubble__body {
  min-height: 1.2rem;
}

.message-bubble--pending .message-bubble__body:empty::before {
  content: "";
  display: inline-block;
  width: 2.8rem;
  height: 0.7rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--surface-muted) 0%, var(--surface-light) 50%, var(--surface-muted) 100%);
  background-size: 200% 100%;
  animation: pendingReplyPulse 1s linear infinite;
}

.message-bubble__label {
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.message-bubble__body {
  color: var(--text-soft);
  line-height: 1.65;
}

@keyframes pendingReplyPulse {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.message-bubble__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.message-attachment {
  display: block;
  width: min(240px, 100%);
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.message-attachment img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
}

/* Composer */
.chat-composer {
  display: grid;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 200px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color 0.12s ease;
}

.chat-composer textarea:focus {
  border-color: var(--accent);
}

.chat-composer__file-input {
  display: none;
}

.chat-composer__uploads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.upload-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 28px;
  padding: 0.2rem 0.35rem 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.upload-chip__name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.upload-chip__meta {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.upload-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--surface-light);
  color: var(--text-muted);
}

.chat-composer__left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.chat-composer__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.composer-hint {
  color: var(--text-muted);
  font-size: 0.76rem;
}

/* Responsive */
@media (max-width: 960px) {
  .workspace-topbar__right .user-chip {
    display: none;
  }

  .sidebar-toggle,
  .sidebar-close {
    display: inline-flex;
  }

  .chat-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 9;
    background: rgba(4, 10, 16, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
  }

  .chat-app {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 12;
    width: min(270px, calc(100% - 24px));
    transform: translateX(-108%);
    transition: transform 0.2s ease;
  }

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

  .workspace-shell.is-sidebar-open .chat-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 760px) {
  .workspace-topbar {
    padding: 0 1rem;
  }

  .workspace-topbar__right .status-pill {
    display: none;
  }

  .chat-workspace__header {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.7rem 1rem;
  }

  .chat-composer {
    padding: 0.75rem 1rem 0.9rem;
  }

  .chat-composer__actions,
  .chat-composer__left {
    flex-direction: column;
    align-items: stretch;
  }

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

  .message-bubble {
    max-width: 100%;
  }

  .account-page {
    padding: 1rem;
  }

  .account-card {
    padding: 1rem;
  }

  .account-form__actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .login-footer {
    position: static;
    margin-top: 2rem;
  }
}
