:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #15803d;
  --green-bg: #dcfce7;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --info-bg: #dbeafe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: #0f172a;
  color: #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-nav {
  max-width: 1180px;
  margin: 0 auto;
  padding: .85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: #f8fafc;
  font-weight: 700;
  letter-spacing: -.01em;
  font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: #38bdf8; }

.nav-links { display: flex; gap: .35rem; }
.nav-links a {
  color: #cbd5e1;
  padding: .4rem .7rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .9rem;
}
.nav-links a:hover { background: #1e293b; color: #f8fafc; text-decoration: none; }

.app-main {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  flex: 1;
}

.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: .85rem;
}
.app-footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: .9rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  align-items: center;
  justify-content: space-between;
}
.version-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .15rem .6rem;
  font-weight: 600;
  color: var(--text);
}

.page-head { margin-bottom: 1.4rem; }
.page-title { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.02em; }
.page-subtitle { margin: 0; color: var(--muted); max-width: 70ch; }

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
}
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.1rem;
  align-items: start;
}
.span-2 { grid-column: 1 / -1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1.02rem; letter-spacing: -.01em; }
.card-body { padding: 1.1rem 1.15rem; }
.card-body > :first-child { margin-top: 0; }
.card-body > :last-child { margin-bottom: 0; }

.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 0 0 .6rem; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .86rem; }
.small { font-size: .82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; word-break: break-all; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Conversations */
.conversation-list { list-style: none; margin: 0; padding: 0; }
.conversation-item { border-bottom: 1px solid var(--border); }
.conversation-item:last-child { border-bottom: 0; }
.conversation-link {
  display: flex;
  gap: .85rem;
  align-items: center;
  padding: .85rem 1.15rem;
  color: inherit;
}
.conversation-link:hover { background: var(--surface-2); text-decoration: none; }
.avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}
.conversation-main { min-width: 0; flex: 1; }
.conversation-top { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.conversation-name { font-weight: 700; }
.conversation-time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.conversation-preview { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  min-width: 1.55rem;
  height: 1.55rem;
  padding: 0 .45rem;
  display: inline-grid;
  place-items: center;
  font-size: .76rem;
  font-weight: 700;
}
.empty-state { padding: 2rem 1.15rem; text-align: center; color: var(--muted); }

/* Forms and buttons */
label.field-label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .3rem; }
input[type="text"], input[type="url"], input[type="password"], select, textarea {
  width: 100%;
  padding: .55rem .65rem;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 74px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.form-row { margin-bottom: .8rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .5rem .85rem;
  font: inherit;
  font-weight: 650;
  font-size: .88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  transition: background .12s ease, border-color .12s ease, transform .02s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--primary); border-color: transparent; }
.btn-ghost:hover { background: var(--info-bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Status and badges */
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge-pill.ok { background: var(--green-bg); border-color: #bbf7d0; color: var(--green); }
.badge-pill.warn { background: var(--amber-bg); border-color: #fde68a; color: var(--amber); }
.badge-pill.err { background: var(--red-bg); border-color: #fecaca; color: var(--red); }
.badge-pill.info { background: var(--info-bg); border-color: #bfdbfe; color: var(--primary-dark); }

.status-list { display: flex; flex-direction: column; gap: .1rem; }
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .45rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: .9rem;
}
.status-row:last-child { border-bottom: 0; }
.status-label { color: var(--muted); }
.status-value { font-weight: 650; text-align: right; word-break: break-word; }

.dot { width: .55rem; height: .55rem; border-radius: 50%; display: inline-block; margin-right: .35rem; }
.dot.ok { background: #22c55e; }
.dot.warn { background: #f59e0b; }
.dot.err { background: #ef4444; }
.dot.info { background: #3b82f6; }
.dot.idle { background: #94a3b8; }

.note {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: .7rem .8rem;
  font-size: .86rem;
  color: var(--muted);
}
.note.warn { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.note.err { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.note.ok { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }

/* Messaging thread */
.message-thread {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding: 1.15rem;
  max-height: 58vh;
  overflow-y: auto;
  background: var(--surface-2);
}
.bubble {
  max-width: min(78%, 34rem);
  padding: .6rem .8rem;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 1px 1px rgba(15, 23, 42, .04);
}
.bubble.them { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { align-self: flex-end; background: var(--primary); border-color: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble .message-meta { font-size: .72rem; opacity: .7; margin-top: .2rem; }
.bubble.me .message-meta { color: #dbeafe; }
.composer { display: flex; gap: .6rem; padding: 1rem 1.15rem; border-top: 1px solid var(--border); background: #fff; }
.composer textarea { min-height: 48px; }

/* Notification preview */
.notification-preview {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: .8rem .9rem;
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  box-shadow: var(--shadow);
}
.notification-preview img { width: 38px; height: 38px; border-radius: 9px; }
.notification-preview .np-title { font-weight: 700; font-size: .9rem; }
.notification-preview .np-body { font-size: .85rem; color: #334155; }

.kv-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.kv-table th, .kv-table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv-table th { color: var(--muted); font-weight: 600; width: 38%; }
.kv-table tr:last-child th, .kv-table tr:last-child td { border-bottom: 0; }

code, .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #0f172a;
  color: #e2e8f0;
  padding: .12rem .35rem;
  border-radius: 5px;
  font-size: .82rem;
}
pre.code { display: block; padding: .7rem .8rem; overflow-x: auto; border-radius: 10px; }

ul.plain { margin: .3rem 0; padding-left: 1.1rem; }
ul.plain li { margin: .2rem 0; }
ol.steps { margin: .3rem 0; padding-left: 1.2rem; }
ol.steps li { margin: .25rem 0; }

.divider { height: 1px; background: var(--border); margin: 1rem 0; border: 0; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.inline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

@media (max-width: 900px) {
  .layout-grid, .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .app-main { padding: 1.25rem .8rem 2.5rem; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .page-title { font-size: 1.35rem; }
  .composer { flex-direction: column; }
  .composer .btn { width: 100%; justify-content: center; }
}
