/* snow — minimal */
:root {
  --bg: #070707;
  --surface: #101010;
  --surface2: #161616;
  --line: #222222;
  --text: #e8e8e8;
  --muted: #888888;
  --faint: #555555;
  --accent: #e8e8e8;
  --danger: #c44;
  --ok: #6a6;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --side: 210px;
  --radius: 6px;
  --space: 1rem;
  --main-max: 1100px;
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

#snow-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

.auth-screen,
.layout,
#toast-container,
#modal-root {
  position: relative;
  z-index: 1;
}

.hidden { display: none !important; }

/* auth */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.auth-layout {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
}

/* Login/register: layout used to share space with an announcements column; when only the
   auth card exists, center it horizontally inside the wide desktop strip. */
.auth-layout > .auth-box:only-child {
  margin-inline: auto;
}

@media (min-width: 960px) {
  .auth-layout {
    max-width: 920px;
    flex-direction: row;
    align-items: flex-start;
    gap: 1.5rem;
  }
  .auth-layout .auth-box {
    flex: 0 0 360px;
    max-width: 360px;
  }
  .auth-announce {
    flex: 1;
    min-width: 0;
    max-height: min(70vh, 520px);
    overflow-y: auto;
  }
}

.auth-announce {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-announce .panel {
  margin: 0;
}

.auth-announce .panel-title {
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.site-setup-body,
.feed-body {
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.site-feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-feed-list .feed-item {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}

.site-feed-list .feed-item:last-child {
  border-bottom: none;
}

.feed-ts {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.feed-item-admin .feed-item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.2rem;
}

.feed-item-admin .feed-item-head .feed-ts {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

.feed-delete {
  margin-top: 0 !important;
  padding: 0.25rem 0.55rem !important;
  font-size: 0.72rem !important;
  flex-shrink: 0;
}

.main-announce {
  margin-bottom: 1rem;
}

.main-announce .grid-announce {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 720px) {
  .main-announce .grid-announce {
    grid-template-columns: 1fr 1fr;
  }
}

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

.auth-box {
  width: 100%;
  max-width: 360px;
  background: rgba(16, 16, 16, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.wordmark {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin-bottom: 2rem;
}

.tabs {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: none;
  border: none;
  color: var(--faint);
  font: inherit;
  font-size: 0.9rem;
  padding: 0 0 0.65rem;
  margin-bottom: -1px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}

.auth-support {
  text-align: center;
  margin-top: 0.5rem;
}

.auth-support a {
  color: var(--accent);
  text-decoration: none;
}

.auth-support a:hover {
  text-decoration: underline;
}

.auth-forgot {
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--line);
}

.auth-forgot summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--muted);
  user-select: none;
  list-style: none;
}

.auth-forgot summary::-webkit-details-marker {
  display: none;
}

.auth-forgot label,
.auth-forgot input,
.auth-forgot button {
  margin-top: 0;
}

.hint.small {
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.live-ui-number-field {
  display: grid;
  grid-template-columns: minmax(5rem, min(28%, 10rem)) minmax(3.5rem, 4.75rem) minmax(0, 1fr);
  gap: 0.2rem 0.45rem;
  align-items: center;
}

.live-ui-number-field label {
  grid-column: 1;
  grid-row: 1;
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.25;
}

.live-ui-number-field .live-ui-num-input {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  max-width: none;
  padding: 0.18rem 0.35rem;
  font-size: 0.82rem;
}

.live-ui-number-field input.live-ui-range {
  grid-column: 3;
  grid-row: 1;
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

@media (max-width: 480px) {
  .live-ui-number-field {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
  }
  .live-ui-number-field label {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .live-ui-number-field .live-ui-num-input {
    grid-column: 2;
    grid-row: 2;
    width: 4.5rem;
    justify-self: end;
  }
  .live-ui-number-field input.live-ui-range {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}

.live-ui-rgba-field {
  --live-ui-rgb-ch: 128, 128, 128;
}

.live-ui-rgba-visual {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.35rem;
}

.live-ui-rgba-swatch {
  position: relative;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.live-ui-rgba-swatch-checker {
  position: absolute;
  inset: 0;
  background-color: #2a2a2e;
  background-image:
    linear-gradient(45deg, #3d3d42 25%, transparent 25%),
    linear-gradient(-45deg, #3d3d42 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3d3d42 75%),
    linear-gradient(-45deg, transparent 75%, #3d3d42 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

.live-ui-rgba-swatch-fill {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

input.live-ui-color-hex {
  width: 2.75rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

input.live-ui-color-hex::-webkit-color-swatch-wrapper {
  padding: 2px;
}

input.live-ui-color-hex::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.live-ui-rgba-channels {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.live-ui-rgba-ch {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  grid-template-rows: auto auto;
  gap: 0.15rem 0.5rem;
  align-items: center;
}

.live-ui-rgba-ch-alpha .live-ui-alpha-range-wrap {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 1.05rem;
}

.live-ui-alpha-range-bg {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 0.42rem;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: linear-gradient(
    to right,
    rgba(var(--live-ui-rgb-ch), 0),
    rgb(var(--live-ui-rgb-ch))
  );
}

.live-ui-alpha-range-wrap input.live-ui-range-alpha {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0;
  background: transparent;
}

.live-ui-rgba-ch-label {
  grid-row: 1 / span 2;
  font-size: 0.72rem;
  color: var(--muted);
}

.live-ui-rgba-ch .live-ui-num-input {
  grid-column: 2;
  width: 100%;
  max-width: 11rem;
}

.live-ui-rgba-ch input.live-ui-range {
  grid-column: 2;
  width: 100%;
  accent-color: var(--accent);
}

.live-ui-field.live-ui-rgba-field label:first-child {
  margin-bottom: 0.28rem;
}

.live-ui-rgba-channels-alpha-only {
  margin-top: 0.15rem;
}

.live-ui-keybind-field .live-ui-keybind-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
}

@media (max-width: 520px) {
  .live-ui-keybind-field .live-ui-keybind-mb-group {
    flex-wrap: wrap;
  }
}

.live-ui-keybind-field .live-ui-keybind-mb-group {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
}

.live-ui-keybind-mb {
  padding: 0.24rem 0.38rem !important;
  font-size: 0.72rem !important;
  min-width: 0;
  width: auto !important;
  flex: 0 0 auto;
  margin-top: 0 !important;
  text-align: center !important;
}

.live-ui-keybind-field .live-ui-keybind-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  width: auto;
  max-width: none;
  padding: 0.32rem 0.55rem;
  min-height: 0;
  margin-top: 0;
  text-align: left;
}

.live-ui-keybind-field .live-ui-keybind-name {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
}

.live-ui-keybind-field .live-ui-keybind-hint {
  font-size: 0.68rem;
  font-weight: 400;
  white-space: nowrap;
}

.live-ui-keybind-btn.live-ui-keybind-listen {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.live-ui-main-tabs.tabs {
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.live-ui-sub-tabs.tabs {
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin-bottom: 0.85rem;
  border-bottom-color: var(--line);
}

.live-ui-cloud-profiles-mount {
  margin-bottom: 0.65rem;
}

.live-ui-field.live-ui-number-field label:first-child {
  margin: 0;
}

.live-ui-menu-stack {
  min-height: 4rem;
}

.live-ui-main-panel[data-live-main-panel="colors"] .live-ui-sub-panel:not(.hidden) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 0.45rem 0.65rem;
  align-items: start;
}

.live-ui-main-panel[data-live-main-panel="colors"] .live-ui-control-panel + .live-ui-control-panel {
  margin-top: 0;
}

.live-ui-fields {
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.live-ui-split-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.85rem;
  align-items: start;
}

.live-ui-split-cards .live-ui-control-panel + .live-ui-control-panel {
  margin-top: 0;
}

.live-ui-split-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.live-ui-split-col .live-ui-control-panel + .live-ui-control-panel {
  margin-top: 0;
}

@media (max-width: 768px) {
  .live-ui-split-cards {
    grid-template-columns: 1fr;
  }
}

label.live-ui-native-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.12rem 0;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.live-ui-native-row .live-ui-native-cb {
  width: 1.25rem;
  height: 1.25rem;
  min-width: 1.25rem;
  min-height: 1.25rem;
  max-width: none;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.live-ui-field-select .live-ui-select,
select.live-ui-select {
  width: 100%;
  max-width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
}

.live-ui-field-select label:first-child {
  margin-top: 0;
  margin-bottom: 0.22rem;
}

.live-ui-native-label {
  color: var(--text);
  flex: 1;
  user-select: none;
}

.live-ui-card-head .panel-title {
  margin-top: 0;
}

.live-ui-card-sub {
  margin: 0.35rem 0 0;
}

.live-ui-control-panel + .live-ui-control-panel {
  margin-top: 0.75rem;
}

.live-ui-field label:first-child {
  display: block;
  margin-top: 0;
  margin-bottom: 0.22rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.live-ui-keybind-field > label:first-child {
  margin-bottom: 0.28rem;
}

.panel > label:not(.form-checkbox-row):not(.live-ui-native-row),
.modal label:not(.form-checkbox-row):not(.live-ui-native-row) {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 1rem 0 0.35rem;
}

.panel > label:not(.form-checkbox-row):first-child,
.modal label:not(.form-checkbox-row):first-child {
  margin-top: 0;
}

.auth-panel > label:first-child:not(.form-checkbox-row),
.panel form > label:first-child:not(.form-checkbox-row),
.panel form > .form-checkbox-row:first-child,
form.panel > .form-checkbox-row:first-child {
  margin-top: 0;
}

/* Panel forms: consistent vertical rhythm */
.panel form,
form.panel,
form.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.panel form > .panel-title,
form.panel > .panel-title {
  margin-bottom: 0;
}

.panel form > label:not(.form-checkbox-row),
form.panel > label:not(.form-checkbox-row),
form.auth-panel > label:not(.form-checkbox-row) {
  margin: 0;
  padding-top: 0.05rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.panel form > input:not([type="checkbox"]):not([type="radio"]),
.panel form > textarea,
.panel form > select,
form.panel > input:not([type="checkbox"]):not([type="radio"]),
form.panel > textarea,
form.panel > select,
form.auth-panel > input,
form.auth-panel > textarea,
form.auth-panel > select {
  margin-top: 0;
}

.panel form > button,
form.panel > button,
form.auth-panel > button {
  align-self: flex-start;
  margin-top: 0;
}

.panel form > button.btn.primary,
form.panel > button.btn.primary,
form.auth-panel > button.btn.primary {
  align-self: stretch;
}

/* Native checkboxes for toggles (outside live-control) */
label.form-checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0;
  cursor: pointer;
  user-select: none;
  color: var(--text);
  font-size: inherit;
}

input.form-checkbox {
  width: 1.2rem;
  height: 1.2rem;
  min-width: 1.2rem;
  min-height: 1.2rem;
  margin: 0.12rem 0 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
  border: none;
  background: transparent;
  box-shadow: none;
}

.form-checkbox-text {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 0;
  flex: 1;
}

.form-checkbox-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.form-checkbox-hint {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.tools .panel form {
  gap: 0.55rem;
}

input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  max-width: 100%;
}

input, select, textarea, .btn {
  touch-action: manipulation;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--faint);
}

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

.hint {
  font-size: 0.78rem;
  color: var(--faint);
  margin: 0.75rem 0 1rem;
}

.hint.dev-hint {
  margin-top: 0.5rem;
  padding: 0.5rem 0.65rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

/* mobile nav (hidden on desktop) */
.side-toggle,
.side-backdrop,
.side-close {
  display: none;
}

/* layout */
.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.side {
  width: var(--side);
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  background: rgba(12, 12, 12, 0.92);
  backdrop-filter: blur(8px);
}

.side-head {
  flex-shrink: 0;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.side-head .wordmark {
  margin-bottom: 0;
}

.role {
  font-size: 0.75rem;
  color: var(--faint);
}

.side-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
}

.nav-section {
  padding: 0.35rem 0 0.65rem;
}

.nav-section + .nav-section {
  border-top: 1px solid var(--line);
  margin-top: 0.35rem;
  padding-top: 0.75rem;
}

.nav-section .nav-label {
  font-size: 0.65rem;
  color: var(--faint);
  padding: 0.65rem 1.25rem 0.25rem;
  letter-spacing: 0.04em;
}

.nav-section .nav-label:first-child {
  padding-top: 0.15rem;
}

.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.35;
  padding: 0.4rem 1.25rem;
  cursor: pointer;
  margin: 0;
}

.nav-link:hover { color: var(--text); }

.nav-link.active {
  color: var(--text);
  background: var(--surface);
}

.side-foot {
  flex-shrink: 0;
  padding: 0.85rem 1.25rem 1.25rem;
  border-top: 1px solid var(--line);
}

.user {
  display: block;
  font-size: 0.78rem;
  color: var(--faint);
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem;
  overflow-y: auto;
  overflow-x: hidden;
  max-width: calc(100vw - var(--side));
}

.main-inner {
  max-width: var(--main-max);
}

/* page */
.ph { margin-bottom: 2rem; }
.ph h1 {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.ph p {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  background: rgba(16, 16, 16, 0.88);
  backdrop-filter: blur(6px);
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 1rem;
}

.panel.danger {
  border-color: var(--danger);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

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

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

.cell {
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.cell .k {
  display: block;
  font-size: 0.72rem;
  color: var(--faint);
  margin-bottom: 0.25rem;
}

.cell .v {
  font-size: 0.875rem;
}

.cell code {
  font-size: 0.8rem;
  color: var(--text);
}

.tools {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.stat {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.stat b {
  display: block;
  font-size: 1.25rem;
  font-weight: 500;
}

.stat span {
  font-size: 0.72rem;
  color: var(--faint);
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  margin-top: 0.75rem;
}

.btn:hover { border-color: var(--faint); }

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  width: 100%;
}

.btn.primary:hover { opacity: 0.9; }

.panel form .btn,
form.panel .btn,
form.auth-panel .btn {
  margin-top: 0;
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn.ok {
  border-color: var(--ok);
  color: var(--ok);
}

.btn.text {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  margin: 0;
  width: 100%;
  text-align: left;
}

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

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.row-actions .meta {
  margin-bottom: 0;
}

/* badges */
.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.tag.ok { border-color: var(--ok); color: var(--ok); }
.tag.bad { border-color: var(--danger); color: var(--danger); }

/* table */
.tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--faint);
  font-weight: 500;
  font-size: 0.75rem;
}

tr:last-child td { border-bottom: none; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface); }

td code { font-size: 0.78rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar input {
  flex: 1;
  min-width: 160px;
  margin: 0;
}

.toolbar .btn {
  margin-top: 0;
  flex-shrink: 0;
}

.meta {
  font-size: 0.78rem;
  color: var(--faint);
  margin-bottom: 1rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.back-link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.back-link:hover { color: var(--text); }

.panel form .btn:not(.primary) {
  width: auto;
}

.tools .panel .btn {
  margin-top: 0;
}

/* ticket chat */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 320px;
  max-height: 520px;
  padding: 0;
  overflow: hidden;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.chat-user {
  color: var(--faint);
  font-size: 0.78rem;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 200px;
}

.chat-msg {
  max-width: 85%;
  font-size: 0.85rem;
}

.chat-msg.mine {
  align-self: flex-end;
  text-align: right;
}

.chat-msg.theirs {
  align-self: flex-start;
}

.chat-meta {
  display: block;
  font-size: 0.68rem;
  color: var(--faint);
  margin-bottom: 0.2rem;
}

.chat-bubble {
  display: inline-block;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface2);
  text-align: left;
  word-break: break-word;
}

.chat-msg.mine .chat-bubble {
  background: var(--line);
}

.chat-img {
  max-width: 220px;
  max-height: 160px;
  border-radius: var(--radius);
  margin-top: 0.35rem;
  border: 1px solid var(--line);
}

.chat-file {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text);
}

.chat-compose {
  border-top: 1px solid var(--line);
  padding: 0.75rem 1rem;
}

.chat-compose textarea {
  margin: 0 0 0.5rem;
  min-height: 56px;
}

.chat-compose-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-compose .btn {
  margin-top: 0;
}

.file-btn {
  cursor: pointer;
}

.tickets-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0.75rem;
  align-items: start;
}

@media (max-width: 768px) {
  .tickets-layout {
    grid-template-columns: 1fr;
  }
}

.ticket-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 520px;
  overflow-y: auto;
  background: var(--surface);
}

.ticket-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.ticket-row:hover,
.ticket-row.active {
  background: var(--surface2);
}

.ticket-row small {
  display: block;
  color: var(--faint);
  margin-top: 0.2rem;
}

.ticket-row .tag {
  margin-top: 0.35rem;
}

/* misc */
.empty {
  color: var(--faint);
  font-size: 0.875rem;
  padding: 1.5rem 0;
}

.empty a { color: var(--text); }

.loading {
  padding: 4rem 0;
  text-align: center;
  color: var(--faint);
  font-size: 0.875rem;
}

.list-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}

.list-item:last-child { border-bottom: none; }

#toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toast {
  font-size: 0.85rem;
  padding: 0.65rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 420px;
  white-space: pre-line;
}

.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--ok); }

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
}

.modal h3 {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.keybox {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0.5rem 0;
  max-height: 180px;
  overflow: auto;
}

pre.json {
  font-size: 0.75rem;
  overflow: auto;
  max-height: 280px;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* database browser */
.db-layout {
  display: grid;
  grid-template-columns: 140px 160px 1fr;
  gap: 0.75rem;
  align-items: start;
}

@media (max-width: 900px) {
  .db-layout { grid-template-columns: 1fr; }
}

.db-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  max-height: 420px;
  overflow-y: auto;
}

.db-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
}

.db-list button:hover { color: var(--text); background: var(--surface2); }
.db-list button.active { color: var(--text); background: var(--surface2); }
.db-list button:last-child { border-bottom: none; }

.db-editor {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
  max-height: 520px;
  overflow-y: auto;
}

.db-editor label {
  margin-top: 0.65rem;
  font-size: 0.72rem;
}

.db-editor input,
.db-editor textarea {
  font-size: 0.8rem;
  padding: 0.45rem 0.55rem;
}

.db-cell-trunc {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal.wide {
  max-width: 640px;
}

/* ——— phones & tablets ——— */
@media (max-width: 768px) {
  html { font-size: 16px; }

  input, textarea, select {
    font-size: 16px;
  }

  .auth-screen {
    align-items: flex-start;
    padding-top: max(2rem, env(safe-area-inset-top));
  }

  .layout {
    flex-direction: row;
    height: 100dvh;
    overflow: hidden;
  }

  .side-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    position: fixed;
    top: max(0.65rem, env(safe-area-inset-top));
    left: max(0.65rem, env(safe-area-inset-left));
    z-index: 60;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .side-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    background: currentColor;
    border-radius: 1px;
  }

  .side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  .side-backdrop.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.nav-open {
    overflow: hidden;
  }

  .side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-width: 100%;
    height: 100dvh;
    z-index: 56;
    border-right: 1px solid var(--line);
    border-bottom: none;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.45);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .side.open {
    transform: translateX(0);
  }

  .side-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: max(0.75rem, env(safe-area-inset-top));
    right: 0.75rem;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface2);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .side-head {
    padding-right: 3rem;
  }

  .side-body {
    max-height: none;
    flex: 1;
    -webkit-overflow-scrolling: touch;
  }

  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }

  .main {
    flex: 1;
    width: 100%;
    max-width: 100%;
    padding: calc(3.25rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .ph h1 {
    font-size: 1.2rem;
  }

  .panel {
    padding: 1rem;
  }

  .tools {
    grid-template-columns: 1fr;
  }

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

  .grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar input {
    min-width: 0;
    width: 100%;
  }

  .toolbar .btn {
    width: 100%;
  }

  .row-actions .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }

  .btn.text {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .chat-panel {
    min-height: min(420px, 55dvh);
    max-height: min(520px, 65dvh);
  }

  .chat-msg {
    max-width: 92%;
  }

  .chat-img {
    max-width: min(220px, 100%);
    height: auto;
  }

  .chat-compose-actions .btn {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
  }

  .tickets-layout {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .tickets-layout:not(.ticket-chat-open) .ticket-chat {
    display: none;
  }

  .tickets-layout.ticket-chat-open .ticket-list {
    display: none;
  }

  .ticket-list {
    max-height: min(280px, 40dvh);
  }

  .ticket-chat-back {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    margin-right: 0.5rem;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    color: var(--muted);
    background: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
  }

  #toast-container {
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .toast {
    max-width: none;
    width: 100%;
  }

  .modal-bg {
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
    align-items: flex-end;
  }

  .modal {
    max-height: 90dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .modal.wide {
    max-width: 100%;
  }

  table {
    font-size: 0.78rem;
  }

  th, td {
    padding: 0.5rem 0.55rem;
    white-space: nowrap;
  }

  td code {
    word-break: break-all;
    white-space: normal;
  }
}

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

  .chat-compose-actions {
    flex-direction: column;
  }

  .chat-compose-actions .btn {
    width: 100%;
    flex: none;
  }
}

/* library cards */
.library-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.library-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  background: rgba(16, 16, 16, 0.88);
  backdrop-filter: blur(6px);
}

.library-card h3 {
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.library-card .meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.library-card .desc {
  font-size: 0.88rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.library-card code {
  font-size: 0.85rem;
}

/* user detail */
.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section h2 {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.75rem;
  text-transform: lowercase;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.65rem;
}

.detail-grid .cell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  background: rgba(7, 7, 7, 0.5);
}

.detail-grid .k {
  display: block;
  font-size: 0.72rem;
  color: var(--faint);
  margin-bottom: 0.25rem;
}

.detail-grid .v {
  font-size: 0.88rem;
  word-break: break-word;
}

.detail-grid .v code {
  font-size: 0.8rem;
}

.pw-cell code {
  color: var(--ok);
}

.sub-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sub-list .sub-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
  background: rgba(7, 7, 7, 0.45);
}

tr.db-row {
  cursor: pointer;
}

.db-cell-trunc {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr.db-row.active {
  background: rgba(255, 255, 255, 0.06);
}

.db-edit-panel {
  margin-top: 1rem;
  border-color: var(--muted);
}

.db-edit-panel textarea {
  min-height: 8rem;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

/* staff ticket back button — desktop hidden */
.ticket-chat-back {
  display: none;
}

@media (min-width: 769px) {
  .side-toggle,
  .side-backdrop,
  .side-close {
    display: none !important;
  }
}
