:root {
  color-scheme: dark;
  --bg: #101014;
  --panel: #19191f;
  --panel-2: #22232b;
  --line: #333440;
  --text: #f1f1f3;
  --muted: #a9aab5;
  --accent: #2fbf71;
  --accent-2: #4f8cff;
  --danger: #ff5c7a;
  --font-scale: 1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(16px * var(--font-scale));
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #07130c;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0d12;
  color: var(--text);
  padding: 12px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent-2);
}

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

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-form {
  display: grid;
  gap: 12px;
  margin: 20px 0 10px;
}

.shell,
.chat-shell {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(16, 16, 20, 0.96);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
}

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

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
  font-size: 24px;
}

.top-title {
  flex: 1;
  min-width: 0;
}

.upload-band {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.jobs {
  display: grid;
  gap: 8px;
  padding: 12px 16px 0;
}

.job {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
}

.job summary {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  cursor: pointer;
}

.job pre,
.terminal {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.job pre {
  max-height: min(320px, 32vh);
  overflow: auto;
  padding: 10px;
  background: #0d0d12;
  border-radius: 8px;
}

progress {
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  padding: 16px;
}

.card {
  min-height: 148px;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.card:hover,
.session-row:hover {
  border-color: var(--accent-2);
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: var(--panel-2);
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 800;
}

.avatar.large {
  width: 108px;
  height: 108px;
  font-size: 40px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.card-title {
  font-size: 18px;
  font-weight: 800;
}

.card-desc {
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  color: #7af0a8;
  border-color: rgba(47, 191, 113, 0.55);
  background: rgba(47, 191, 113, 0.12);
}

.badge.work {
  color: #8fb8ff;
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.12);
}

.badge.warn {
  color: #ffd37a;
  border-color: rgba(255, 190, 80, 0.55);
  background: rgba(255, 190, 80, 0.12);
}

.badge.bad {
  color: #ff91a5;
  border-color: rgba(255, 92, 122, 0.55);
  background: rgba(255, 92, 122, 0.12);
}

.card-detail {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.chat-card-summary {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.settings-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.settings-panel.hidden {
  display: none;
}

.summary-copy {
  min-width: 0;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.detail-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.subtle-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 7px 10px;
}

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 92, 122, 0.5);
}

.hidden {
  display: none;
}

.session-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.session-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  border-radius: 8px;
  padding: 8px;
}

.session-row small {
  color: var(--muted);
}

.session-open {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: transparent;
  color: var(--text);
  padding: 8px;
  text-align: left;
}

.delete-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 92, 122, 0.4);
  padding: 8px 10px;
}

.terminal {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 14px 16px;
  background: #060609;
  color: #e7e7ea;
  overflow: auto;
}

.terminal-xterm {
  padding: 0;
  width: 100%;
  min-height: 0;
}

.terminal-xterm .xterm {
  width: 100%;
  height: 100%;
  padding: 12px 14px;
}

.terminal-xterm .xterm-viewport,
.terminal-xterm .xterm-screen {
  width: 100% !important;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  min-height: 46px;
  max-height: 160px;
  resize: vertical;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
}

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

@media (max-width: 640px) {
  .upload-form,
  .composer,
  .card-detail,
  .chat-card-summary {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    min-height: 58px;
  }

  .brand {
    font-size: 18px;
  }
}
