:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --panel: #ffffff;
  --panel-strong: #fdfcf8;
  --ink: #172326;
  --muted: #667275;
  --line: #d9ddd6;
  --accent: #166f68;
  --accent-dark: #0f524d;
  --blue: #315da8;
  --orange: #af5b21;
  --red: #ad3345;
  --shadow: 0 18px 50px rgba(22, 35, 38, 0.11);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.brand-lockup h1,
.brand-lockup p,
.brand-lockup strong,
.brand-lockup span {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 1.55rem;
  line-height: 1.2;
}

.brand-lockup p,
.brand-lockup span {
  color: var(--muted);
  font-size: 0.92rem;
}

.brand-lockup.compact {
  min-height: 40px;
}

.brand-lockup.compact div {
  display: grid;
  gap: 2px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 111, 104, 0.13);
}

.primary-button,
.ghost-button,
.nav-tab {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 9px 13px;
  font-weight: 650;
}

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

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

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

.ghost-button {
  background: var(--panel-strong);
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button:hover {
  border-color: #b9c2bc;
}

.ghost-button.danger {
  color: var(--red);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 0.9rem;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 22px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #fbfaf5;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  text-align: left;
  background: transparent;
  color: var(--muted);
}

.nav-tab.active {
  color: var(--ink);
  background: #e7f1ee;
  border-color: #c4ddd6;
}

.sidebar-actions {
  align-self: end;
  display: grid;
  gap: 8px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.topbar h2,
.topbar p,
.section-heading h3,
.chat-header h3,
.chat-header p {
  margin: 0;
}

.topbar h2 {
  font-size: 1.45rem;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #b7d9d3;
  color: var(--accent-dark);
  background: #e8f5f2;
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.muted {
  color: var(--muted);
  border-color: var(--line);
  background: var(--panel-strong);
}

.status-badge.warn {
  color: var(--orange);
  border-color: #e0b891;
  background: #fff3e8;
}

.app-notice {
  margin: 10px 24px 0;
  padding: 10px 12px;
  border: 1px solid #c4ddd6;
  border-radius: var(--radius);
  background: #e8f5f2;
  color: var(--accent-dark);
  font-size: 0.9rem;
}

.app-notice.error {
  border-color: #efc2ca;
  background: #fff0f2;
  color: var(--red);
}

.panel-grid {
  min-height: 0;
}

.chats-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.chat-rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.chat-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.chat-item {
  width: 100%;
  min-height: 82px;
  display: grid;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.chat-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.chat-item strong,
.chat-item span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
  white-space: normal;
}

.chat-item span {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.25;
  white-space: normal;
}

.chat-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.chat-header h3 {
  font-size: 1.1rem;
}

.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.messages {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 22px;
}

.history-more {
  align-self: center;
  min-height: 38px;
  border: 1px solid #c4ddd6;
  border-radius: var(--radius);
  background: #e8f5f2;
  color: var(--accent-dark);
  padding: 8px 12px;
  font-weight: 700;
}

.empty-state {
  margin: auto;
  max-width: 420px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.message {
  max-width: min(820px, 96%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px 13px;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  border-color: #c2d8ff;
  background: #f0f5ff;
}

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

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

.message-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.message-attachment {
  display: grid;
  gap: 6px;
  color: var(--ink);
  text-decoration: none;
}

.message-attachment img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.message-attachment span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-status {
  color: var(--orange);
}

.live-log {
  max-height: 136px;
  margin: 0 22px 14px;
  padding: 12px;
  overflow: auto;
  border: 1px solid #c8d4d1;
  border-radius: var(--radius);
  background: #101819;
  color: #d8f3ee;
  font: 0.86rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 10px;
  padding: 12px 22px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.composer-input {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.composer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: end;
  gap: 8px;
}

.composer .primary-button {
  min-height: 44px;
}

.composer button:disabled {
  filter: grayscale(0.35);
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-attachment {
  width: min(180px, 100%);
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.pending-attachment img {
  width: 44px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
}

.pending-attachment span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-attachment button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #fff0f2;
  color: var(--red);
  font-size: 1.1rem;
  line-height: 1;
}

.processes-view {
  min-height: 0;
  overflow: auto;
  padding: 18px 22px 24px;
}

.jobs-section,
.process-section {
  display: grid;
  gap: 12px;
}

.process-section {
  margin-top: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h3 {
  font-size: 1.05rem;
}

.process-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.process-tools input {
  width: min(280px, 44vw);
}

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

.job-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.job-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.job-main strong,
.job-main code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.job-main code {
  color: var(--muted);
  font-size: 0.84rem;
}

.job-output {
  margin-top: 6px;
  max-height: 132px;
  overflow: auto;
  padding: 9px;
  border-radius: var(--radius);
  background: #101819;
  color: #d8f3ee;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.8rem/1.42 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  background: var(--panel-strong);
}

td.command-cell {
  max-width: 620px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.tiny-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 5px 9px;
  font-weight: 700;
}

.tiny-button.danger {
  color: var(--red);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf1ef;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.chip.running {
  color: var(--blue);
  background: #edf3ff;
}

.chip.completed {
  color: var(--accent-dark);
  background: #e6f5ef;
}

.chip.failed,
.chip.killed {
  color: var(--red);
  background: #fff0f2;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto;
    align-items: center;
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-tabs {
    grid-auto-flow: column;
  }

  .sidebar-actions {
    align-self: auto;
    grid-auto-flow: column;
  }

  .workspace {
    height: 100%;
    min-height: 0;
  }

  .chats-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 170px minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
  }

  .chat-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(230px, 260px);
    overflow-x: auto;
    overflow-y: hidden;
  }
}

@media (max-width: 680px) {
  .sidebar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "tabs tabs";
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
    gap: 8px;
  }

  .sidebar .brand-lockup {
    grid-area: brand;
  }

  .sidebar .brand-lockup img {
    width: 32px;
    height: 32px;
  }

  .sidebar .brand-lockup strong {
    font-size: 0.94rem;
  }

  .sidebar .brand-lockup span {
    font-size: 0.8rem;
  }

  .nav-tabs {
    grid-area: tabs;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .nav-tab {
    min-height: 36px;
    padding: 7px 10px;
    text-align: center;
  }

  .sidebar-actions {
    grid-area: actions;
    display: flex;
    gap: 6px;
  }

  .sidebar-actions .ghost-button {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 0.84rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 0;
    gap: 8px;
    padding: 10px 14px;
  }

  .topbar h2 {
    font-size: 1.18rem;
  }

  .topbar p {
    max-width: 100%;
    font-size: 0.78rem;
    overflow-wrap: anywhere;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .status-badge {
    min-height: 26px;
    padding: 4px 8px;
    font-size: 0.76rem;
  }

  .app-notice {
    margin: 8px 12px 0;
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .chats-layout {
    grid-template-rows: 138px minmax(0, 1fr);
  }

  .chat-rail {
    gap: 8px;
    padding: 10px 12px;
  }

  .chat-rail .primary-button {
    min-height: 38px;
  }

  .chat-list {
    grid-auto-columns: minmax(210px, 78vw);
  }

  .chat-item {
    min-height: 72px;
    padding: 9px 10px;
  }

  .chat-item strong {
    font-size: 0.92rem;
  }

  .chat-item span {
    font-size: 0.78rem;
  }

  .chat-header {
    align-items: flex-start;
    padding: 10px 12px;
  }

  .chat-header h3 {
    font-size: 1rem;
  }

  .chat-header p {
    font-size: 0.78rem;
  }

  .chat-header .ghost-button {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 0.82rem;
  }

  .messages {
    gap: 10px;
    padding: 12px 12px;
  }

  .message {
    max-width: 100%;
    padding: 10px 11px;
    font-size: 0.92rem;
  }

  .message-meta {
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.7rem;
  }

  .history-more {
    width: 100%;
    min-height: 36px;
    font-size: 0.86rem;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  textarea {
    min-height: 64px;
    max-height: 108px;
  }

  .composer .primary-button {
    min-height: 44px;
  }

  .composer-actions {
    grid-template-columns: 1fr 1fr;
  }

  .attachment-preview {
    flex-direction: column;
  }

  .pending-attachment {
    width: 100%;
  }

  .process-tools,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .process-tools input {
    width: 100%;
  }

  .job-item {
    grid-template-columns: 1fr;
  }
}
