:root {
  color-scheme: dark;
  --gold: #d4af37;
  --gold-deep: #8a6d21;
  --ink: #f5f1e6;
  --muted: #b7b1a3;
  --bg: #0b0b0d;
  --panel: #1a1a1f;
  --line: #3a3426;
  --danger: #ffb4b4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(#141414, #000);
  color: var(--ink);
  font-family: Montserrat, sans-serif;
}

a { color: var(--gold); }

h1, h2, .brand, .thread-title {
  font-family: "Playfair Display", serif;
  font-weight: 700;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #111;
}

.account-menu { position: relative; }
.account-menu summary {
  list-style: none;
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
}
.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  display: grid;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #161616;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.account-menu-panel a,
.account-menu-panel button {
  width: 100%;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  text-decoration: none;
}
.account-menu-panel a:hover,
.account-menu-panel button:hover { background: #241d0d; color: var(--gold); }

.brand {
  color: var(--gold);
  font-size: 1.4rem;
  text-decoration: none;
}

.topbar nav, .people li, .inline-form, .stack-form, .side-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.who { color: var(--muted); font-size: 0.85rem; }

button, .button-link, .primary {
  font: inherit;
}

button, .button-link {
  border: 1px solid var(--gold-deep);
  background: #241d0d;
  color: var(--gold);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.primary, button.primary {
  background: var(--gold);
  color: #1a1406;
  border-color: var(--gold);
  font-weight: 600;
}

.ghost { background: transparent; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.auth-card, .panel, .create-customer {
  width: min(460px, calc(100% - 32px));
  margin: 32px auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(20, 20, 24, 0.9);
}

.admin { width: min(860px, calc(100% - 32px)); margin: 24px auto 48px; }
.admin .panel { width: auto; margin: 16px 0; }
.admin-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid #2a2a2a;
  margin: 8px 0 16px;
}
.admin-tabs.sub { margin-top: 0; }
.admin-tab {
  flex: none;
  padding: 12px 16px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.admin-tab.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.admin-chat-link { margin: 0 0 8px; }

label, .stack-form, .create-customer form { display: grid; gap: 8px; }
label { margin-bottom: 12px; color: var(--muted); font-size: 0.85rem; }

input, select, textarea {
  width: 100%;
  border: 1px solid #444;
  background: #121216;
  color: white;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}

.lede { color: var(--muted); }
.validation, .chat-error { color: var(--danger); }
.banner {
  width: min(960px, calc(100% - 32px));
  margin: 16px auto 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: #241d0d;
  color: var(--gold);
}
.stack-top { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
.people { list-style: none; padding: 0; }
.people li { justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #2a2a2a; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.auth-card .banner { width: auto; margin: 0 0 16px; }
.people small { color: var(--muted); margin-left: 8px; }
h3 { color: var(--gold); font-size: 0.95rem; }

html:has(body.is-messenger) {
  height: auto;
  overflow: hidden;
}

.is-messenger {
  position: fixed;
  top: var(--vv-top, 0px);
  left: 0;
  width: 100%;
  height: var(--app-height, 100svh);
  min-height: 0;
  max-height: var(--app-height, 100svh);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  background: #000;
}
.is-messenger .topbar {
  flex: none;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
}
.is-messenger .topbar .who,
.is-messenger .topbar a[href="/Chat"] { display: none; }
.is-messenger main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.is-messenger .banner { margin: 0; border-radius: 0; }

.messenger { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #0b0b0d; }
.messenger-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.inbox, .thread { min-height: 0; display: flex; flex-direction: column; }
.messenger.show-thread .inbox,
.messenger.show-list .thread { display: none; }
.inbox, .messenger.show-thread .thread, .messenger.show-list .inbox { flex: 1; }

.inbox-head, .thread-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 12px;
  border-bottom: 1px solid #222;
  background: #111;
}
.inbox-head h1, .thread-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}
.thread-heading strong {
  margin: 0;
  font-family: Montserrat, sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
}
.thread-heading strong a { color: var(--gold); text-decoration: none; }
.profile { margin: 0 0 16px; }
.profile div { display: grid; gap: 2px; margin-bottom: 12px; }
.profile dt { color: var(--muted); font-size: 0.75rem; }
.profile dd { margin: 0; }
.inbox-head { justify-content: space-between; }
.thread-heading { display: flex; flex-direction: column; min-width: 0; }
.thread-heading small { color: var(--muted); font-size: 0.72rem; }
.back, .icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--gold);
  font-size: 2rem;
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-button { font-size: 1.6rem; border: 1px solid var(--line); }

.inbox-list { flex: 1; overflow: auto; }
.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid #1c1c1c;
}
.chat-row.active, .chat-row.unread { background: #16140e; }
.chat-row.unread .chat-row-name { color: var(--gold); }
.unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--gold);
  vertical-align: middle;
}
.avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #241d0d;
  color: var(--gold);
  font-weight: 600;
}
.chat-row-main { min-width: 0; flex: 1; }
.chat-row-top, .chat-row-name, .chat-row-preview { display: block; }
.chat-row-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-row-name { font-weight: 600; }
.chat-row-preview, .row-time { color: var(--muted); font-size: 0.82rem; }
.chat-row-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.add-panel { display: none; gap: 8px; padding: 12px; border-bottom: 1px solid #222; }
.add-panel.open { display: grid; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #0b0b0d;
}
.day-divider {
  align-self: center;
  flex: none;
  margin: 10px 0 2px;
}
.day-divider span {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  background: #1a1a1f;
  color: var(--muted);
  font-size: 0.75rem;
}
.msg {
  align-self: flex-start;
  width: fit-content;
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 18px 18px 18px 4px;
  background: #1c1c22;
}
.msg.mine { align-self: flex-end; border-radius: 18px 18px 4px 18px; background: #3a3114; }
.msg-name, .msg-body, .msg time { margin: 0; }
.msg-name { color: var(--gold); font-size: 0.75rem; margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { display: block; margin-top: 4px; color: #c8c0ae; font-size: 0.68rem; text-align: right; }
.msg-read { display: block; margin-top: 2px; color: var(--gold); font-size: 0.68rem; text-align: right; }
.composer {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #111;
}
.messenger:has(.club-tabs) .composer { padding-bottom: 8px; }
.composer input { flex: 1; min-width: 0; border-radius: 20px; padding: 12px 14px; }
.send {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  color: #1a1406;
  display: grid;
  place-items: center;
  padding: 0;
}
.send svg { width: 20px; height: 20px; fill: currentColor; }
.chat-error { flex: none; padding: 0 12px 8px; background: #111; }

.club-tabs {
  flex: none;
  display: flex;
  z-index: 2;
  background: #111;
  border-top: 1px solid #2a2a2a;
  padding-bottom: max(env(safe-area-inset-bottom), 0px);
}
.club-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 12px 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
}
.club-tab.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.club-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1406;
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
}

blockquote {
  margin: 0 0 16px;
  padding: 12px;
  border-left: 3px solid var(--gold);
  color: var(--ink);
}

@media (min-width: 840px) {
  .messenger-body { flex-direction: row; }
  .messenger.show-thread .inbox,
  .messenger.show-list .thread { display: flex; }
  .inbox { width: 340px; flex: none; border-right: 1px solid #222; }
  .thread { flex: 1; }
}
