/* ─── Token overlay ────────────────────────────────────────────────────────── */
.token-overlay {
  position: fixed;
  inset: 0;
  background: #0d0d0d;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.token-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 2rem 1.75rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.token-dialog h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.token-dialog h2 span { color: var(--accent); }

.token-sub {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: -.25rem;
}

.token-dialog form {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-top: .25rem;
}

.token-dialog input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: .65rem .9rem;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}

.token-dialog input:focus { border-color: var(--accent); }

.token-error {
  font-size: .8rem;
  color: #f87171;
  margin-top: -.2rem;
}

.token-dialog .btn-primary { width: 100%; text-align: center; }

/* ─── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0d0d;
  --surface:    #161616;
  --surface-2:  #1f1f1f;
  --border:     #2a2a2a;
  --accent:     #6c63ff;
  --accent-dim: #4b44c4;
  --text:       #e8e8e8;
  --text-muted: #6b6b6b;
  --success-bg: #0d2b1e;
  --success-fg: #4ade80;
  --error-bg:   #2b0d0d;
  --error-fg:   #f87171;
  --radius:     10px;
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
  white-space: nowrap;
}

header h1 span {
  color: var(--accent);
}

/* ─── Status bar ───────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .85rem;
  font-size: .78rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: #4ade80;
  box-shadow: 0 0 6px #4ade8099;
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.disconnected {
  background: #f87171;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

.status-label {
  font-weight: 600;
  color: var(--text);
}

.status-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - 53px);
}

main {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 53px);
  padding: 1rem .75rem;
  position: sticky;
  top: 53px;
  overflow-y: auto;
}

.sidebar-title {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 .25rem .6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .65rem;
}

.sidebar-empty { padding: .25rem; font-size: .8rem; }

.app-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.app-item {
  padding: .6rem .65rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: default;
}

.app-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  margin-bottom: .25rem;
}

.app-name {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-state {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .05em;
  border-radius: 999px;
  padding: .1rem .45rem;
  flex-shrink: 0;
}

.app-state.online  { background: #0d2b1e; color: #4ade80; }
.app-state.offline { background: #2b0d0d; color: #f87171; }

.app-item-text {
  font-size: .72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .2rem;
}

.app-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-uid {
  font-size: .68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
  cursor: default;
}

.app-since {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* ─── Badge ────────────────────────────────────────────────────────────────── */
.badge {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: .15rem .55rem;
  animation: pulse 2s ease-in-out infinite;
}

/* ─── App message list ─────────────────────────────────────────────────────── */
.msg-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.msg-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .9rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  border-left: 3px solid var(--border);
}

.msg-row.online   { border-left-color: #4ade80; }
.msg-row.offline  { border-left-color: #7f1d1d; }
.msg-row.error    { border-left-color: #f87171; }
.msg-row.warning  { border-left-color: #facc15; }

.msg-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #6b6b6b;
}

.msg-row.online  .msg-status-dot { background: #4ade80; box-shadow: 0 0 5px #4ade8077; }
.msg-row.offline .msg-status-dot { background: #7f1d1d; }
.msg-row.error   .msg-status-dot { background: #f87171; box-shadow: 0 0 5px #f8717177; }
.msg-row.warning .msg-status-dot { background: #facc15; box-shadow: 0 0 5px #facc1577; }

.msg-body { flex: 1; min-width: 0; }

.msg-top {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .2rem;
}

.msg-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-status-tag {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: .1rem .5rem;
  flex-shrink: 0;
}

.msg-row.online   .msg-status-tag { background: #0d2b1e; color: #4ade80; }
.msg-row.offline  .msg-status-tag { background: #2b0000; color: #fca5a5; }
.msg-row.error    .msg-status-tag { background: #2b0d0d; color: #f87171; }
.msg-row.warning  .msg-status-tag { background: #2b2000; color: #facc15; }

.msg-text {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .2rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.msg-uid {
  font-size: .75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  cursor: default;
}

.msg-time {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

/* ─── Item list ────────────────────────────────────────────────────────────── */
.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.item-list li {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .75rem 1rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}

.item-list li strong {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}

/* ─── Form ─────────────────────────────────────────────────────────────────── */
form {
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.field label {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .95rem;
  padding: .65rem .9rem;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}

.field input::placeholder { color: var(--text-muted); }

.field input:focus {
  border-color: var(--accent);
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 600;
  padding: .6rem 1.2rem;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}

.btn:active  { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  align-self: flex-start;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .78rem;
  padding: .35rem .75rem;
}

.btn-secondary:hover { color: var(--text); border-color: var(--text-muted); }

/* ─── Utility ──────────────────────────────────────────────────────────────── */
.muted {
  color: var(--text-muted);
  font-size: .875rem;
}

.message {
  margin-top: .85rem;
  padding: .65rem .95rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
}

.message.success { background: var(--success-bg); color: var(--success-fg); }
.message.error   { background: var(--error-bg);   color: var(--error-fg);   }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    min-height: unset;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
  }

  .app-list { flex-direction: row; flex-wrap: wrap; }
  .app-item { flex: 1 1 150px; }

  main { padding: 1rem 1rem 3rem; }
}

@media (max-width: 480px) {
  header { padding: .65rem 1rem; flex-wrap: wrap; }
  header h1 { font-size: 1.05rem; }
  .status-time { display: none; }

  .card { padding: 1rem; }

  .btn-primary { width: 100%; text-align: center; }
}
