:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --panel-strong: #eef3ef;
  --text: #16201c;
  --muted: #66736d;
  --line: #dce4de;
  --accent: #087f5b;
  --accent-dark: #056647;
  --danger: #b42318;
  --warning: #ad6800;
  --blue: #175cd3;
  --shadow: 0 10px 30px rgba(18, 32, 26, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

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

button:hover {
  border-color: #b8c5be;
  background: #fafcfb;
}

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

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

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

button.icon-button {
  width: 36px;
  height: 36px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

button.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button.icon-button.danger {
  border-color: rgba(180, 35, 24, 0.22);
  background: #fff8f7;
}

button.icon-button.danger:hover {
  border-color: rgba(180, 35, 24, 0.42);
  background: #fff0ee;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.12);
}

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

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

.login-box h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-box p {
  margin: 0 0 20px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 650;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

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

.rail {
  background: #12201a;
  color: #e9f5ef;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  gap: 10px;
}

.brand {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  font-weight: 800;
  color: #ffffff;
}

.rail button {
  width: 54px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #cfe0d7;
  border-radius: 7px;
  font-size: 11px;
}

.rail button.active,
.rail button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  min-height: 0;
  overflow: hidden;
}

.chat-layout {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 360px minmax(360px, 1fr) 320px;
  min-width: 0;
}

.list-pane,
.detail-pane,
.profile-pane,
.page-pane {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

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

.profile-pane {
  border-left: 1px solid var(--line);
}

.pane-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.pane-head h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 8px;
}

.conversation-list {
  display: grid;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: var(--panel);
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--panel-strong);
}

.item-title {
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

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

.badge.ok {
  color: var(--accent-dark);
  border-color: rgba(8, 127, 91, 0.26);
  background: #eaf7f0;
}

.badge.warn {
  color: var(--warning);
  border-color: rgba(173, 104, 0, 0.25);
  background: #fff4dd;
}

.badge.danger {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.25);
  background: #fff0ee;
}

.badge.blue {
  color: var(--blue);
  border-color: rgba(23, 92, 211, 0.22);
  background: #eef4ff;
}

.unread {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.item-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  background: #edf2ee;
}

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

.chat-head h2 {
  margin: 0;
  font-size: 16px;
}

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

.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
}

.message {
  max-width: min(620px, 82%);
  border-radius: 8px;
  padding: 9px 11px;
  box-shadow: 0 1px 2px rgba(18, 32, 26, 0.08);
  background: var(--panel);
}

.message.out {
  align-self: flex-end;
  background: #d9fdd3;
}

.message.system {
  align-self: center;
  max-width: 86%;
  background: #fff7e6;
  color: #6f4a00;
  text-align: center;
}

.message .author {
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
}

.message .text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.35;
}

.message .time {
  margin-top: 5px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.message-status {
  width: 18px;
  height: 14px;
  display: inline-grid;
  place-items: center;
  color: #6f7c76;
}

.message-status svg {
  width: 18px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-status.sending svg,
.message-status.failed svg {
  width: 14px;
  height: 14px;
}

.message-status.read {
  color: #1a73e8;
}

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

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

.composer textarea {
  min-height: 46px;
  max-height: 130px;
}

.profile-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.profile-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

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

.info-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  font-size: 13px;
}

.info-row span:first-child {
  color: var(--muted);
}

.page {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-width: 0;
}

.page-wide {
  height: calc(100vh - 56px);
  overflow: auto;
  padding: 18px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

.table th,
.table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.table th {
  color: var(--muted);
  font-size: 12px;
  background: #f8faf8;
  position: sticky;
  top: 0;
}

.table th.action-col,
.table td.actions-cell {
  width: 56px;
  text-align: right;
  white-space: nowrap;
}

.side-form {
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
  overflow: auto;
}

.side-form h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.form-grid {
  display: grid;
  gap: 11px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

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

.metric strong {
  display: block;
  font-size: 26px;
  margin-bottom: 5px;
}

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

@media (max-width: 1180px) {
  .chat-layout {
    grid-template-columns: 320px minmax(360px, 1fr);
  }

  .profile-pane {
    display: none;
  }
}

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

  .rail {
    height: 58px;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .brand {
    flex: 0 0 auto;
  }

  .main {
    grid-template-rows: 54px minmax(0, 1fr);
  }

  .chat-layout,
  .page {
    height: calc(100vh - 112px);
    grid-template-columns: 1fr;
  }

  .list-pane {
    display: none;
  }

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

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
