:root {
  color-scheme: dark;
  --bg: #0f0f10;
  --panel: #171717;
  --panel-2: #202123;
  --text: #ececf1;
  --muted: #a6a6a6;
  --border: #2f3032;
  --accent: #10a37f;
  --accent-2: #0d8f70;
  --danger: #ef4444;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-2);
}

button.ghost,
.logout {
  background: transparent;
  color: var(--text);
}

button.ghost:hover,
.logout:hover {
  background: var(--panel-2);
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #101011;
  color: var(--text);
  padding: 0 10px;
}

label span {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

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

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

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

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

.login-panel label {
  display: block;
  margin: 0 0 16px;
}

.login-panel button {
  width: 100%;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

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

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

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #0d0d0e;
  padding: 14px;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 4px 18px;
}

.sidebar-brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-2);
}

.logout {
  margin-top: auto;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar h2,
.panel h3 {
  margin: 0;
}

.topbar p,
.panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

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

.metric {
  padding: 16px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 106px);
}

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

.list-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111112;
  padding: 12px;
  cursor: pointer;
}

.list-item:hover,
.list-item.active {
  border-color: var(--accent);
}

.list-item strong {
  overflow-wrap: anywhere;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.settings label {
  min-width: 0;
}

.convo-list,
.messages {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.message {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #111112;
}

.message.user {
  background: #16231f;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.1fr) minmax(170px, 1fr) minmax(140px, 0.8fr) 120px 150px 150px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: #111112;
}

.muted {
  color: var(--muted);
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted);
}

.empty-state.compact {
  min-height: 120px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.62);
  cursor: default;
  padding: 0;
}

.modal-backdrop:hover {
  background: rgba(0, 0, 0, 0.62);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(960px, 100%);
  max-height: calc(100vh - 48px);
  min-height: min(680px, calc(100vh - 48px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 16px;
}

.modal-head {
  margin-bottom: 12px;
}

.modal-messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .metric-grid,
  .split,
  .settings,
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .table-row {
    grid-template-columns: 1fr;
  }
  .modal {
    padding: 12px;
  }
  .modal-panel {
    min-height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
  }
}
