:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172b40;
  background: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; }

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  background: #ffffff;
  transition: grid-template-columns .18s ease;
}
.app-shell.sidebar-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 12px;
  background: #f7f7f8;
  border-right: 1px solid #e5e7eb;
  overflow: hidden;
}
.sidebar-collapsed .sidebar {
  align-items: center;
  padding-inline: 8px;
}
.sidebar-collapsed .sidebar-nav,
.sidebar-collapsed .history-actions,
.sidebar-collapsed .thread-group,
.sidebar-collapsed .model-settings {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.sidebar-collapsed .brand {
  width: 100%;
  flex-direction: column;
  gap: 8px;
}
.brand img {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 14px;
  object-fit: cover;
  object-position: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .18);
}
.sidebar-collapsed .brand img {
  width: 48px;
  height: 48px;
  border-radius: 12px;
}
h1 {
  margin: 0;
  min-width: 0;
  flex: 1 1 auto;
  font-size: 1.85rem;
  line-height: 1.05;
  letter-spacing: -.04em;
  white-space: nowrap;
}
.sidebar-collapsed h1 { display: none; }
.sidebar-toggle {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 36px;
  text-align: center;
  font-size: 1.05rem;
}
.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
  width: 44px;
  min-width: 44px;
}
h2 { margin: 0; font-size: .78rem; color: #6b7280; font-weight: 600; }
p { line-height: 1.6; }

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

button {
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #1f2937;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

button:hover:enabled { background: #eceff3; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid #1877ce;
  outline-offset: 2px;
}
button.active, .thread-row.active .thread-select {
  background: #e8e8ea;
  color: #111827;
  font-weight: 600;
}

.history-actions {
  display: none;
}
.management .history-actions { display: block; }
#delete-selected {
  width: 100%;
  color: #9f1d1d;
  background: #fff;
  border: 1px solid #e5e7eb;
}

.thread-group {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
}
.thread-group.chats { flex: 1 1 auto; }
.model-settings {
  display: grid;
  gap: 6px;
  padding-top: 4px;
}
.model-settings label {
  margin: 6px 0 0;
  color: #6b7280;
  font-size: .78rem;
}
.model-settings .check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 2px;
  color: #1f2937;
}
.check-row input {
  width: 16px;
  height: 16px;
}
select {
  width: 100%;
  min-height: 32px;
  border: 1px solid #d7dce3;
  border-radius: 8px;
  background: white;
  color: #1f2937;
  font: inherit;
}

.search-settings {
  display: grid;
  grid-template-columns: 1fr repeat(3, auto);
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.search-settings > span {
  color: #6b7280;
  font-size: .78rem;
  font-weight: 600;
}
.search-settings .check-row {
  margin: 0;
  gap: 4px;
  font-size: .78rem;
  white-space: nowrap;
}
.model-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 132px;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.model-row > label {
  margin: 0;
  color: #6b7280;
  font-size: .78rem;
  font-weight: 600;
}
.model-row select {
  min-height: 30px;
  padding: 4px 8px;
  font-size: .74rem;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

li { margin: 2px 0; }

.thread-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 4px;
  align-items: center;
}
.management .thread-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.thread-row input {
  display: none;
  width: 18px;
  height: 18px;
}
.management .thread-row input { display: block; }
.thread-select {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-pin, .thread-rename {
  min-width: 36px;
  padding-inline: 8px;
  text-align: center;
  font-size: .85rem;
}

.empty-list {
  padding: 8px 10px;
  color: #6b7280;
  font-size: .92rem;
}

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

.chat-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 28px;
  border-bottom: 1px solid #f1f2f4;
}
.chat-header h2 {
  max-width: 72ch;
  color: #111827;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#thread-date {
  margin: 2px 0 0;
  color: #6b7280;
  font-size: .84rem;
}
#continue {
  flex: 0 0 auto;
  background: #111827;
  color: white;
  text-align: center;
}

#error {
  margin: 12px auto 0;
  width: min(760px, calc(100% - 48px));
  background: #fff0ef;
  color: #922819;
  padding: 10px 12px;
  border-radius: 8px;
}
#history-notice {
  margin: 12px auto 0;
  width: min(760px, calc(100% - 48px));
  color: #805017;
}

#messages {
  min-height: 0;
  overflow-y: auto;
  padding: 28px 28px 96px;
  scroll-behavior: smooth;
}
#empty {
  width: min(760px, 100%);
  margin: 0 auto;
  color: #6b7280;
}

.message {
  width: min(760px, 100%);
  margin: 0 auto 28px;
}
.message-codex, .message-claude {
  position: relative;
  padding-left: 52px;
}
.dragon-avatar {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-image: url('/static/hydra-logo.jpeg');
  background-repeat: no-repeat;
  background-size: 116px 116px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, .15);
}
.dragon-codex {
  background-position: 15% 27%;
  border: 2px solid #dbeafe;
}
.dragon-claude {
  background-position: 83% 27%;
  border: 2px solid #fed7aa;
}
.message-codex .message-head > strong { color: #334155; }
.message-claude .message-head > strong { color: #c2410c; }
.message-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.message strong {
  display: block;
  color: #111827;
}
.run-badge {
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #4b5563;
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-succeeded { background: #ecfdf3; color: #166534; }
.run-running { background: #eff6ff; color: #1d4ed8; }
.run-failed { background: #fef2f2; color: #991b1b; }
.run-cancelled, .run-timeout { background: #fff7ed; color: #9a3412; }
.run-agent-search { background: #fee2e2; color: #b91c1c; }
.message small {
  display: block;
  color: #6b7280;
  font-size: .82rem;
  margin-bottom: 10px;
}
.message-content { overflow-wrap: anywhere; }
.message-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.message-user .message-head, .message-user small {
  width: min(680px, 88%);
  justify-content: flex-end;
}
.message-user .message-content {
  max-width: min(680px, 88%);
  padding: 12px 16px;
  border-radius: 18px;
  background: #e9f3ff;
  white-space: pre-wrap;
}
.message:not(.message-user) .message-content {
  max-width: 100%;
}
.message-content p { margin: 10px 0; }
.message-content h3,
.message-content h4,
.message-content h5 { margin: 18px 0 8px; line-height: 1.35; color: #111827; }
.message-content ul { list-style: disc; padding-left: 1.4rem; margin: 10px 0; }
.message-content li { margin: 6px 0; }
.message-content blockquote {
  margin: 12px 0;
  padding: 8px 12px;
  border-left: 4px solid #c8d0da;
  background: #f7f8fa;
  color: #374151;
}
.message-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #eef1f5;
  border-radius: 4px;
  padding: 2px 5px;
}
.message-content pre {
  margin: 12px 0;
  padding: 14px;
  overflow-x: auto;
  border-radius: 8px;
  background: #101827;
  color: #eef4ff;
}
.message-content pre code { background: transparent; padding: 0; color: inherit; }

.composer {
  padding: 12px 28px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(255,255,255,0), #fff 20%);
}
.composer form, #phase-note {
  width: min(760px, 100%);
  margin: 0 auto;
}
label {
  display: block;
  margin-bottom: 6px;
  color: #6b7280;
  font-size: .86rem;
}
.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid #d7dce3;
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(0,0,0,.08);
}
textarea {
  width: 100%;
  max-height: 24dvh;
  padding: 8px 10px;
  border: 0;
  resize: vertical;
  font: inherit;
}
textarea:focus-visible { outline: none; }
#send {
  border-radius: 999px;
  background: #111827;
  color: white;
  text-align: center;
}
#phase-note {
  margin-top: 8px;
  color: #6b7280;
  font-size: .82rem;
  text-align: center;
}

a { color: #1565c0; text-decoration: underline; }
[hidden] { display: none !important; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .app-shell.sidebar-collapsed { grid-template-columns: 1fr; grid-template-rows: 64px minmax(0, 1fr); }
  .sidebar {
    height: 40dvh;
    border-right: 0;
    border-bottom: 1px solid #e5e7eb;
  }
  .sidebar-collapsed .sidebar {
    height: 64px;
    align-items: flex-start;
  }
  .sidebar-collapsed .brand {
    flex-direction: row;
    justify-content: space-between;
  }
  .sidebar-collapsed .brand img { display: none; }
  .chat-main { height: 60dvh; }
  .sidebar-collapsed .chat-main { height: auto; }
  .chat-header { padding: 10px 14px; }
  #messages { padding: 18px 14px 72px; }
  .composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
}

.login-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(10px);
}
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid #e5e7eb;
  border-radius: 22px;
  background: white;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .16);
}
.login-card img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, .18);
}
.login-card h2 {
  color: #111827;
  font-size: 1.45rem;
}
.login-card p {
  margin: 0;
  color: #6b7280;
}
.login-card input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #d7dce3;
  border-radius: 10px;
  font: inherit;
}
.login-card button {
  justify-content: center;
  text-align: center;
  background: #111827;
  color: white;
}
#login-error {
  color: #991b1b;
}
.auth-locked {
  filter: blur(1px);
  pointer-events: none;
}

.effort-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid #d7dce3;
  border-radius: 999px;
  background: #eef0f3;
}
.effort-control label {
  margin: 0;
  cursor: pointer;
}
.effort-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.effort-control span {
  display: block;
  padding: 5px 6px;
  border-radius: 999px;
  text-align: center;
  color: #4b5563;
  font-size: .82rem;
  font-weight: 600;
}
.effort-control input:checked + span {
  background: white;
  color: #111827;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
}
.effort-control input:focus-visible + span {
  outline: 3px solid #1877ce;
  outline-offset: 2px;
}

@media (max-width: 760px) {
  .search-settings {
    grid-template-columns: 1fr repeat(3, auto);
    gap: 6px;
  }
  .model-row {
    grid-template-columns: 52px minmax(0, 1fr) 118px;
    gap: 5px;
  }
  .model-row select {
    font-size: .8rem;
  }
  .effort-control span {
    padding: 5px 4px;
    font-size: .7rem;
  }
}

.login-panel[hidden] { display: none !important; }

.mobile-menu,
.sidebar-backdrop {
  display: none;
}

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-shell,
  .app-shell.sidebar-collapsed {
    position: relative;
    height: 100dvh;
    display: block;
  }
  .mobile-menu {
    position: fixed;
    z-index: 12;
    top: calc(10px + env(safe-area-inset-top));
    left: 10px;
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 4px 18px rgba(15, 23, 42, .14);
    text-align: center;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 13;
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, .28);
  }
  .sidebar-backdrop[hidden] { display: none !important; }
  .sidebar {
    position: fixed;
    z-index: 14;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(88vw, 360px);
    height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-102%);
    transition: transform .2s ease;
    border-right: 1px solid #e5e7eb;
    border-bottom: 0;
    box-shadow: 16px 0 40px rgba(15, 23, 42, .16);
  }
  .mobile-drawer-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-collapsed .sidebar,
  .sidebar-collapsed .brand,
  .sidebar-collapsed .brand img {
    display: flex;
  }
  .sidebar-collapsed .sidebar {
    align-items: stretch;
    height: 100dvh;
  }
  .sidebar-collapsed .sidebar-nav,
  .sidebar-collapsed .history-actions,
  .sidebar-collapsed .thread-group,
  .sidebar-collapsed .model-settings {
    display: flex;
  }
  .sidebar-collapsed .sidebar-nav,
  .sidebar-collapsed .model-settings {
    display: grid;
  }
  .sidebar-collapsed h1 { display: block; }
  .sidebar-collapsed .brand {
    width: auto;
    flex-direction: row;
    justify-content: flex-start;
  }
  .sidebar-collapsed .brand img {
    width: 64px;
    height: 64px;
  }
  .chat-main,
  .sidebar-collapsed .chat-main {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  }
  .chat-header {
    min-height: 62px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px 60px;
  }
  .chat-header h2 {
    max-width: calc(100vw - 92px);
  }
  #messages {
    padding: 18px 14px 92px;
  }
  .message-codex,
  .message-claude {
    padding-left: 48px;
  }
  .composer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  }
  .model-settings {
    padding-bottom: 12px;
  }
  .thread-group.chats {
    flex: 0 0 auto;
  }
  .thread-group ul {
    max-height: 34dvh;
  }
}
