:root {
  color-scheme: light dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e7ecf3;
  --muted: #9aa8bc;
  --accent: #5b9fd4;
  --accent-2: #3d7eab;
  --border: #2c3a4f;
  --error: #e07070;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --text: #1a2332;
    --muted: #5a6b80;
    --accent: #2a6fad;
    --accent-2: #1e5a8f;
    --border: #d0d8e4;
    --error: #b33;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* Avoid iOS/safe-area clipping the fixed bar */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

a {
  color: var(--accent);
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}
.skip:focus {
  left: 0.5rem;
  top: 0.5rem;
  background: var(--surface);
  padding: 0.5rem 1rem;
  z-index: 10;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.muted {
  color: var(--muted);
}
.tiny {
  font-size: 0.8rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

/* Room for fixed bottom status bar when visible */
body.has-status-bar main,
body.is-authed main {
  padding-bottom: 3.25rem;
}

.shell-dashboard .dash-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.shell-dashboard h1,
.shell-login h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.dash-empty {
  margin-top: 1.5rem;
}

/* ---- Fixed bottom status bar ---- */
.status-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.75rem 0.35rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.25);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.status-bar[hidden] {
  display: none;
}

.status-bar-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  min-width: 0;
  color: var(--muted);
}

.status-bar-metrics .status-item {
  white-space: nowrap;
}

.status-bar-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}

.notification-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.notification-toggle:hover,
.notification-toggle[aria-expanded="true"] {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.notification-toggle.has-unread {
  color: #e0a800;
}

.notification-toggle-icon {
  display: flex;
  line-height: 0;
}

.notification-badge {
  position: absolute;
  top: -0.2rem;
  right: -0.25rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #c45c26;
  color: #fff;
  font-size: 0.65rem;
  font-family: var(--font);
  font-weight: 600;
  line-height: 1.05rem;
  text-align: center;
}

.notification-badge[hidden] {
  display: none;
}

/* ---- Inbox panel (above bar, right) ---- */
.notification-panel {
  position: fixed;
  right: 0.5rem;
  bottom: 2.6rem;
  z-index: 45;
  width: min(22rem, calc(100vw - 1rem));
  max-height: min(20rem, 50vh);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.notification-panel[hidden] {
  display: none;
}

.notification-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.9rem;
}

.notification-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.notification-empty {
  padding: 0.85rem 0.9rem;
  font-size: 0.88rem;
}

.notification-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 0.86rem;
}

.notification-row:hover,
.notification-row:focus {
  background: var(--surface-2);
  outline: none;
}

.notification-row.level-info {
  border-left-color: var(--accent);
}
.notification-row.level-success {
  border-left-color: #3cba7a;
}
.notification-row.level-warning {
  border-left-color: #d4a017;
}
.notification-row.level-error {
  border-left-color: var(--error, #e85d5d);
}

.notification-row-icon {
  flex-shrink: 0;
  width: 1rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.notification-row-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

/* ---- Detail popup ---- */
.notification-detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
}

.notification-detail[hidden] {
  display: none;
}

.notification-detail-card {
  width: min(28rem, 100%);
  max-height: min(80vh, 32rem);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.notification-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.notification-detail-head strong {
  font-size: 1rem;
  line-height: 1.3;
}

.notification-detail-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  word-break: break-word;
  font-size: 0.95rem;
}

.notification-detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.btn-danger {
  border-color: rgba(232, 93, 93, 0.45);
  color: #f0a0a0;
}

.btn-danger:hover {
  background: rgba(232, 93, 93, 0.15);
  border-color: var(--error, #e85d5d);
}

.linkish {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.15rem 0.25rem;
}

.linkish:hover {
  text-decoration: underline;
}

.status-line {
  margin: 0;
  font-size: 0.95rem;
}

#ws-status[data-state="on"] {
  color: #3cba7a;
}
#ws-status[data-state="off"] {
  color: var(--error);
}
#ws-status[data-state="local"] {
  color: #d4a017;
}

.messages {
  flex: 1;
  min-height: 16rem;
  max-height: min(60vh, 36rem);
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.msg {
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid transparent;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}

.msg-author {
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.82rem;
}

.msg-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

textarea,
input[type="text"],
input[type="password"],
input:not([type]) {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 2.8rem;
}

button {
  font: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
}
button:hover {
  background: var(--accent-2);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.linkish,
.auth .linkish {
  background: transparent;
  color: var(--accent);
  padding: 0.2rem 0.4rem;
  font-weight: 500;
  text-decoration: underline;
}

.auth {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  justify-content: flex-end;
}

.login-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.login-inline input {
  width: auto;
  min-width: 7rem;
}

.inline {
  display: inline;
  margin: 0;
}

.error {
  color: var(--error);
  margin: 0;
}

.narrow {
  max-width: 24rem;
}

.empty {
  margin: auto;
  text-align: center;
}
