:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #65706a;
  --line: #dbe0dc;
  --accent: #147d64;
  --accent-strong: #0f624f;
  --danger: #b33c35;
  --shadow: 0 16px 32px rgba(23, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.primary,
.message-form button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

input,
textarea {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

textarea {
  min-height: 66px;
  max-height: 132px;
  padding: 9px 12px;
  line-height: 1.35;
  resize: vertical;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
}

.topbar h1,
.detail h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p,
.detail p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.operator-form {
  display: grid;
  grid-template-columns: minmax(180px, 320px);
  gap: 10px;
  align-items: center;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.session-list {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  display: flex;
  flex-direction: column;
}

.list-toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.sessions {
  overflow: auto;
  padding: 8px;
}

.session-item {
  width: 100%;
  min-height: 88px;
  display: grid;
  gap: 5px;
  text-align: left;
  border-color: transparent;
  border-radius: 6px;
  padding: 10px;
  background: transparent;
}

.session-item:hover,
.session-item.active {
  background: #ffffff;
  border-color: var(--line);
  box-shadow: 0 8px 20px rgba(23, 32, 29, 0.06);
}

.session-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-domain {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.badge {
  min-width: 64px;
  border-radius: 999px;
  padding: 3px 8px;
  text-align: center;
  font-size: 12px;
  color: #ffffff;
  background: var(--muted);
}

.badge.active {
  background: var(--accent);
}

.badge.stale {
  background: #946f1d;
}

.badge.offline,
.badge.closed {
  background: var(--danger);
}

.session-url,
.session-time {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.detail {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  color: var(--muted);
}

.session-detail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) minmax(180px, 260px);
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

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

.preview {
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 18px;
  background: #eef2ef;
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.preview img[src=""] {
  display: none;
}

#screenshotEmpty {
  color: var(--muted);
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.messages {
  overflow: auto;
  padding: 12px 16px;
}

.message {
  max-width: 72ch;
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f1f4f2;
}

.message.operator {
  margin-left: auto;
  background: #e1f3ee;
}

.message strong {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--muted);
}

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

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .operator-form,
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-rows: minmax(220px, 36vh) minmax(0, 1fr);
  }

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

  .detail-header {
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }
}
