:root {
  color-scheme: dark;
  --bg: #101112;
  --panel: #17191b;
  --panel-soft: #1d2023;
  --line: #2a2e32;
  --line-strong: #3a4147;
  --text: #e7e9eb;
  --muted: #8f989f;
  --accent: #61d394;
  --accent-ink: #06130b;
  --danger: #f36f6f;
  --warn: #e4b75d;
  --input: #0d0f10;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

body {
  min-width: 320px;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #23272a;
  color: var(--text);
  cursor: pointer;
  padding: 5px 9px;
  min-height: 28px;
  line-height: 1.1;
}

button:hover {
  border-color: #515b63;
  background: #2a2f33;
}

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

button.primary {
  border-color: #69d99a;
  background: var(--accent);
  color: var(--accent-ink);
}

button.primary:hover {
  background: #78e0a5;
}

button.ghost {
  background: transparent;
}

button.danger {
  border-color: #7f3f3f;
  background: #2b1818;
  color: #ffb4b4;
}

input,
select {
  width: 100%;
  min-height: 29px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--input);
  color: var(--text);
  padding: 5px 7px;
  outline: none;
}

input:focus,
select:focus {
  border-color: #6e7b84;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  font-weight: 620;
  letter-spacing: 0;
}

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

.login-panel {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 54px rgb(0 0 0 / 34%);
}

.login-panel p {
  margin-top: 4px;
  color: var(--muted);
}

.login-panel button {
  min-height: 34px;
}

.login-status {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}

.shell {
  width: min(1320px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

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

.topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.userbar {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 7px;
}

.userbar span {
  color: var(--muted);
  font-size: 12px;
}

.statusline {
  min-height: 28px;
  padding: 8px 0;
  color: var(--muted);
  font-size: 12px;
}

.statusline.error {
  color: var(--danger);
}

.statusline.ok {
  color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, .75fr);
  gap: 12px;
  align-items: start;
}

.config-panel {
  margin-bottom: 12px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  overflow: hidden;
}

.panel-head {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.tools {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 7px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: middle;
  font-size: 12px;
}

th {
  color: var(--muted);
  font-weight: 560;
  background: #141618;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #1d2124;
}

tbody tr.active {
  background: #202820;
}

.service-img {
  width: 32px;
  height: 24px;
  object-fit: contain;
  border-radius: 4px;
  background: #0b0d0e;
  border: 1px solid var(--line);
}

.name-cell strong {
  display: block;
  max-width: 190px;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-cell span,
.target-cell {
  display: block;
  max-width: 250px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-cell {
  max-width: 310px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  font-size: 11px;
}

.badge.on {
  border-color: #386b4d;
  color: #8be0af;
}

.badge.off {
  border-color: #6c4141;
  color: #f1a2a2;
}

.row-actions {
  display: flex;
  gap: 5px;
}

.row-actions button {
  padding: 4px 7px;
  min-height: 24px;
  font-size: 12px;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.detail-head span,
.config-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview {
  width: 58px;
  height: 44px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0d0e;
}

.service-form {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.grid {
  display: grid;
  gap: 8px;
}

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

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

.check {
  align-content: end;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 29px;
  color: var(--text);
}

.check input {
  width: 15px;
  height: 15px;
  min-height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.check.compact {
  width: max-content;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 2px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.chat-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 230px 360px;
  height: 100vh;
  max-width: calc(100vw - 14px);
  border-right: 1px solid var(--line);
  background: #111314;
  box-shadow: 18px 0 44px rgb(0 0 0 / 34%);
  transition: transform .22s ease;
}

.chat-sidebar.collapsed {
  transform: translateX(-100%);
}

.chat-toggle {
  position: absolute;
  top: 96px;
  left: calc(100% + 8px);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 92px;
  min-height: 34px;
  border-color: #315743;
  background: #18241d;
  color: #b9f0ce;
  box-shadow: 0 10px 24px rgb(0 0 0 / 28%);
}

.chat-toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

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

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 62px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #1b211e;
}

.chat-head span {
  display: block;
  margin-top: 3px;
  color: #9eb0a6;
  font-size: 12px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 14px 12px;
  overflow-y: auto;
  background:
    linear-gradient(rgb(16 17 18 / 84%), rgb(16 17 18 / 84%)),
    repeating-linear-gradient(45deg, #1d2420 0 2px, #151817 2px 10px);
}

.chat-empty {
  align-self: center;
  display: grid;
  gap: 3px;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgb(17 19 20 / 78%);
  color: var(--muted);
  text-align: center;
}

.chat-empty strong {
  color: var(--text);
}

.chat-bubble {
  display: grid;
  gap: 4px;
  width: fit-content;
  max-width: 82%;
  padding: 8px 10px 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.chat-message-content {
  display: grid;
  gap: 6px;
}

.chat-message-content p,
.chat-message-content ul,
.chat-message-content ol,
.chat-message-content blockquote,
.chat-message-content pre,
.chat-message-content h3,
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
  margin: 0;
}

.chat-message-content ul,
.chat-message-content ol {
  padding-left: 18px;
}

.chat-message-content li + li {
  margin-top: 3px;
}

.chat-message-content a {
  color: #a8d7ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-message-content code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgb(0 0 0 / 24%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.chat-message-content pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / 28%);
}

.chat-message-content pre code {
  display: block;
  padding: 0;
  background: transparent;
  white-space: pre;
}

.chat-message-content blockquote {
  padding-left: 9px;
  border-left: 3px solid rgb(255 255 255 / 24%);
  color: rgb(231 233 235 / 78%);
}

.chat-message-content h3,
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
  font-size: 13px;
  line-height: 1.25;
}

.thinking-wave {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  color: rgb(231 233 235 / 72%);
  font-weight: 560;
  white-space: nowrap;
}

.thinking-wave span {
  display: inline-block;
  animation: thinking-wave 1.05s ease-in-out infinite;
  animation-delay: calc(var(--i) * 55ms);
}

@keyframes thinking-wave {
  0%,
  70%,
  100% {
    transform: translateY(0);
  }

  35% {
    transform: translateY(-4px);
  }
}

.chat-bubble time {
  justify-self: end;
  color: rgb(231 233 235 / 58%);
  font-size: 10px;
}

.chat-bubble.mine {
  align-self: flex-end;
  border-color: #3e7254;
  background: #24593a;
}

.chat-bubble.hers {
  align-self: flex-start;
  border-color: #2c3439;
  background: #20262a;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #171a1b;
}

.chat-form textarea {
  width: 100%;
  min-height: 34px;
  max-height: 96px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input);
  color: var(--text);
  padding: 8px 9px;
  outline: none;
  font: inherit;
}

.chat-form textarea:focus {
  border-color: #6e7b84;
}

.conversation-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  background: #141718;
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 62px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #191c1d;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  padding: 10px;
  overflow-y: auto;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 8px;
  width: 100%;
  min-height: 62px;
  padding: 8px;
  border-color: var(--line);
  background: #1b1f21;
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active {
  border-color: #386b4d;
  background: #202820;
}

.conversation-item strong,
.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 620;
}

.conversation-item span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
}

.conversation-item time {
  color: #7e898f;
  font-size: 10px;
}

.conversation-menu {
  position: fixed;
  z-index: 60;
  display: grid;
  min-width: 150px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #171a1b;
  box-shadow: 0 16px 36px rgb(0 0 0 / 38%);
}

.conversation-menu[hidden] {
  display: none;
}

.conversation-menu button {
  justify-content: flex-start;
  width: 100%;
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(0 0 0 / 58%);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-modal {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 54px rgb(0 0 0 / 48%);
}

.confirm-modal p {
  color: var(--muted);
  line-height: 1.4;
}

.confirm-details {
  max-height: 160px;
  margin: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101213;
  color: var(--text);
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .shell {
    width: calc(100% - 18px);
    padding-top: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .userbar,
  .tools,
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    grid-template-columns: minmax(0, calc(100vw - 28px));
    grid-template-rows: 190px minmax(0, 1fr);
  }

  .chat-toggle {
    top: 74px;
  }

  .chat-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
