@font-face {
  font-family: "klaxon";
  src: url("/klaxon.otf");
}
@font-face {
  font-family: "Friend Bestie";
  src: url("/Friend_Bestie.otf");
}

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

html, body {
  overscroll-behavior: none;
}
body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: #111;
  color: #e0e0e0;
  min-height: 100vh;
}
header {
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-brand { min-width: 0; }
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.header-actions .server-label {
  font-size: 12px;
  color: #888;
}
header h1 { font-size: 16px; font-weight: 600; }
header .meta { font-size: 12px; color: #888; }
.nav-brand {
  display: flex;
  align-items: center;
  vertical-align: middle;
  color: #f0f0f0;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}
.nav-brand:hover { text-decoration: none; color: #fff; }
.brand-div, .brand-cord {
  background-clip: unset !important;
  -webkit-background-clip: unset !important;
  background: transparent !important;
  user-select: none;
}
.brand-div {
  font-family: klaxon;
  color: #FAA !important;
  margin: 0;
}
.brand-cord {
  font-family: Friend Bestie;
  color: #FFF !important;
  margin: 0;
}

button {
  background: #2563eb;
  color: white;
  border: none;
  padding: 7px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
button:hover { background: #1d4ed8; }
button.secondary { background: #333; }
button.secondary:hover { background: #444; }
button.danger { background: #b91c1c; }
button.danger:hover { background: #991b1b; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, textarea, select {
  background: #222;
  border: 1px solid #444;
  color: #eee;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
input:focus, textarea:focus { border-color: #555; }

select {
  appearance: none;
  -webkit-appearance: none;
  background-color: #222;
  background-image:
    linear-gradient(45deg, transparent 50%, #888 50%),
    linear-gradient(135deg, #888 50%, transparent 50%);
  background-position:
    calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
  cursor: pointer;
}
select:hover {
  border-color: #555;
  background-color: #262626;
}
select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}
select option {
  background: #1a1a1a;
  color: #eee;
}

#server-select {
  min-width: 160px;
  height: 32px;
  padding: 4px 28px 4px 10px;
  border-radius: 6px;
  font-weight: 500;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
}
.setting-row:hover {
  border-color: #3a3a3a;
  background: #1c1c1c;
}
.setting-row > span {
  flex: 1 1 auto;
  min-width: 0;
}
.setting-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 40px;
  width: 40px;
  height: 22px;
  min-width: 40px;
  min-height: 22px;
  margin: 0;
  padding: 0;
  align-self: center;
  position: relative;
  border: 1px solid #3f3f3f;
  border-radius: 11px;
  background: #2a2a2a;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.setting-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #c4c4c4;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: transform 0.16s ease, background 0.16s ease;
}
.setting-row input[type="checkbox"]:hover {
  border-color: #555;
}
.setting-row input[type="checkbox"]:checked {
  background: #2563eb;
  border-color: #1d4ed8;
}
.setting-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: #fff;
}
.setting-row input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #111, 0 0 0 4px #3b82f6;
}

/* Login */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#login.hidden { display: none; }
.login-wrap {
  width: min(400px, 100%);
}
.login-box {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { font-size: 18px; }
.login-box p.lead { font-size: 12px; color: #888; margin: 0; line-height: 1.4; }
.login-box input { width: 100%; }
.login-error { color: #f87171; font-size: 13px; min-height: 18px; }
.auth-switch {
  font-size: 12px;
  color: #888;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.auth-switch button.link {
  background: none;
  color: #7dd3fc;
  padding: 0;
  font-size: 12px;
}
.auth-switch button.link:hover {
  background: none;
  text-decoration: underline;
}

#app { display: none; }
#app.visible { display: block; }

.stats {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid #222;
}
.stat {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 100px;
}
.stat .n { font-size: 20px; font-weight: 600; color: #a5b4fc; }
.stat .l { font-size: 11px; color: #666; text-transform: uppercase; letter-spacing: 0.04em; }

.tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid #333;
  background: #161616;
}
.tabs button {
  background: transparent;
  color: #888;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
}
.tabs button:hover { color: #ccc; background: transparent; }
.tabs button.active {
  color: #e0e0e0;
  border-bottom-color: #2563eb;
}

.panel { display: none; padding: 16px; }
.panel.active { display: block; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a2a;
  vertical-align: top;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.04em;
  font-weight: 600;
}
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover,
th.sortable:focus-visible {
  color: #ccc;
  outline: none;
}
th.sortable[aria-sort="ascending"]::after,
th.sortable[aria-sort="descending"]::after {
  font-size: 10px;
  color: inherit;
  margin-left: 4px;
  font-family: "Font Awesome 6 Free";
}
th.sortable[aria-sort="ascending"]::after { content: "\f077"; }
th.sortable[aria-sort="descending"]::after { content: "\f078"; }
tr:hover td { background: #161616; }
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: #333;
  color: #aaa;
}
.actions {
  text-align: right;
  white-space: nowrap;
}
.badge.on { background: #14532d; color: #86efac; }
.badge.bot { background: rgba(99, 102, 241, 0.12); color: #a5b4fc; }
.badge.admin { background: rgba(251, 113, 133, 0.16); color: #fb7185; }
.badge.off { background: #333; color: #666; }
.actions button { padding: 4px 8px; font-size: 12px; }

.action-menu {
  position: fixed;
  z-index: 80;
  min-width: 168px;
  max-width: min(240px, calc(100vw - 16px));
  padding: 4px;
  background: #1c1c1c;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.action-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: #e0e0e0;
  border: none;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.action-menu-item:hover {
  background: #2a2a2a;
}
.action-menu-item.is-danger {
  color: #fca5a5;
}
.action-menu-item.is-danger:hover {
  background: #3f1d1d;
  color: #fecaca;
}
.action-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: #333;
}

.room-detail {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  margin-top: 12px;
}
@media (max-width: 700px) {
  .room-detail { grid-template-columns: 1fr; }
}
.side-card {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px;
}
.side-card h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.side-card ul { list-style: none; margin-bottom: 12px; }
.side-card li {
  padding: 3px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.side-add {
  display: flex;
  gap: 6px;
  margin: 6px 0 14px;
}
.side-add input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  font-size: 12px;
}
.side-add button {
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}
.side-note {
  font-size: 11px;
  color: #666;
  margin: -8px 0 10px;
}
.msg-list {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  max-height: 60vh;
  overflow-y: auto;
}
.msg-row {
  padding: 8px 12px;
  border-bottom: 1px solid #222;
}
.msg-row.deleted { opacity: 0.45; }
.msg-row .meta { font-size: 11px; color: #777; margin-bottom: 2px; }
.msg-row .content {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.empty { color: #666; padding: 20px; text-align: center; }
a.back {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 13px;
}
a.back:hover { text-decoration: underline; }
.invite-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  color: #cbd5e1;
}
.invite-new {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: none;
}
.invite-new.visible { display: block; }
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 420px;
  padding: 4px 0 16px;
}
.toolbar-end {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-left: auto;
}
.emoji-fields {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.emoji-fields .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.emoji-fields input { width: 100%; min-width: 0; }
.emoji-fields .field-alias { width: 120px; }
.emoji-fields .field-url { width: 260px; }
.widget-pick-help {
  font-size: 12px;
  color: #888;
  margin: 0 0 14px;
  line-height: 1.4;
  max-width: 720px;
}
.widget-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  padding-bottom: 16px;
}
.widget-pick-grid.is-off {
  opacity: 0.45;
  pointer-events: none;
}
button.widget-pick-card {
  text-align: left;
  background: #161616;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 132px;
  font-family: inherit;
  box-shadow: none;
  width: 100%;
}
button.widget-pick-card:hover {
  border-color: #555;
  background: #1a1a1a;
}
button.widget-pick-card.selected {
  border-color: #2563eb;
  background: #152033;
}
.widget-pick-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.widget-pick-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #222;
  border: 1px solid #333;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #93c5fd;
  font-size: 13px;
}
.widget-pick-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #444;
  background: #222;
  flex: 0 0 auto;
  position: relative;
}
button.widget-pick-card.selected .widget-pick-mark {
  background: #2563eb;
  border-color: #1d4ed8;
}
button.widget-pick-card.selected .widget-pick-mark::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.widget-pick-card strong {
  font-size: 13px;
  font-weight: 600;
}
.widget-pick-desc {
  font-size: 12px;
  color: #888;
  line-height: 1.35;
  flex: 1 1 auto;
}
.widget-pick-meta {
  font-size: 11px;
  color: #666;
}
.widget-pick-empty {
  grid-column: 1 / -1;
  color: #888;
  font-size: 13px;
  padding: 18px 4px;
}
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table { min-width: 640px; }
#panel-emojis .table-wrap table { min-width: 480px; }

@media (max-width: 800px) {
  header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .header-actions #server-select {
    flex: 1 1 160px;
    min-width: 0;
    max-width: 100%;
  }
  .header-actions button {
    flex: 0 0 auto;
  }
  .stats, .tabs, .panel {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .panel { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .stats { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .stat { flex: 1 1 120px; min-width: 0; }
  .tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: 0 0 auto;
    padding: 10px 12px;
  }
  .toolbar {
    align-items: stretch;
  }
  .toolbar-end {
    width: 100%;
    margin-left: 0;
  }
  .toolbar-end button,
  .header-actions button {
    min-height: 36px;
  }
  .settings-list { max-width: none; }
  .setting-row { align-items: flex-start; gap: 12px; }
  .emoji-fields,
  .emoji-fields .field {
    width: 100%;
  }
  .emoji-fields .field-alias,
  .emoji-fields .field-url {
    width: 100%;
  }
  input, textarea, select { font-size: 16px; }
  #login { padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .login-box { padding: 20px 16px; }
  .actions { white-space: normal; }
  .actions button {
    margin: 2px 2px 2px 0;
    min-height: 32px;
  }
  .room-detail .toolbar {
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  header h1, .nav-brand { font-size: 15px; }
  .header-actions .server-label { display: none; }
  .stat .n { font-size: 18px; }
  .table-wrap table { min-width: 560px; }
}
