/* juristiq — minimal, typographic, light/dark via system preference or html[data-theme] (user menu). */

:root {
  --bg: hsl(0 0% 100%);
  --text: hsl(0 0% 5%);
  --muted: hsl(240 6% 46%);
  --border: hsl(240 6% 80%);
  --border-strong: hsl(0 0% 5%);
  --link: hsl(217 90% 55%);
  --error: hsl(0 65% 48%);
  --radius: 10px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: hsl(0 0% 7%);
    --text: hsl(0 0% 95%);
    --muted: hsl(240 6% 65%);
    --border: hsl(240 4% 30%);
    --border-strong: hsl(0 0% 95%);
    --link: hsl(217 90% 68%);
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: hsl(0 0% 7%);
  --text: hsl(0 0% 95%);
  --muted: hsl(240 6% 65%);
  --border: hsl(240 4% 30%);
  --border-strong: hsl(0 0% 95%);
  --link: hsl(217 90% 68%);
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
}
h1, h2, p { margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.125rem; font-weight: 500; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.beta { font-size: 0.6em; font-weight: 400; color: var(--error); margin-left: 0.2em; }
.beta-note { font-size: 0.8125rem; }

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}
.brand { font-family: var(--mono); font-weight: 600; font-size: 1.125rem; }

/* ---- Main ---- */
.main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 4rem 1rem;
}
.narrow {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.narrow h2 { margin-top: 1.5rem; }

/* ---- Form: floating labels (CSS only, input needs placeholder=" ") ---- */
.field { position: relative; }
.field input {
  width: 100%;
  padding: 0.9rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.field input:focus { border-color: var(--link); }
.field label {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  padding: 0 0.25rem;
  color: var(--muted);
  background: var(--bg);
  pointer-events: none;
  transition: top 0.12s, font-size 0.12s;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  top: 0;
  font-size: 0.75rem;
}
.field input:focus + label { color: var(--link); }
.field textarea {
  width: 100%;
  padding: 0.9rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  resize: vertical;
}
.field textarea:focus { border-color: var(--link); }
.field textarea + label { top: 1.5rem; }
.field textarea:focus + label,
.field textarea:not(:placeholder-shown) + label { top: 0; font-size: 0.75rem; }
.field textarea:focus + label { color: var(--link); }
.release { display: flex; flex-direction: column; gap: 0.5rem; }
.kinds { display: flex; gap: 1.5rem; }
.hp { position: absolute; left: -9999px; }

/* ---- Buttons ---- */
.button {
  display: block;
  width: 100%;
  padding: 0.9rem 1rem;
  font: inherit;
  font-weight: 500;
  text-align: center;
  color: var(--bg);
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.button:hover { opacity: 0.9; }
.button--outline { color: var(--text); background: transparent; border-color: var(--border); }
.button--outline:hover { opacity: 1; border-color: var(--border-strong); }

/* ---- Misc ---- */
.links { font-size: 0.875rem; }
.links a { color: var(--link); }
.links a:hover { text-decoration: underline; }
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.25rem 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.error { color: var(--error); font-size: 0.875rem; }
.info { font-size: 0.9375rem; }
.hint { font-size: 0.8125rem; margin-top: -0.25rem; }
.check {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.875rem;
  cursor: pointer;
}
.check input { margin: 0.2rem 0 0; accent-color: var(--text); }
.check a { text-decoration: underline; }
.legal {
  margin-top: 2rem;
  font-size: 0.8125rem;
  text-align: center;
  color: var(--muted);
}
.legal a { text-decoration: underline; }
.paycards { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.paycards img { height: 24px; width: auto; }

/* ---- Chat ---- */
.chat-page { height: 100vh; height: 100dvh; }
.chat-layout { flex: 1; min-height: 0; display: flex; }
.chat-side {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 1rem 1rem 1.25rem;
  border-right: 1px solid var(--border);
}
.new-chat {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius);
}
.new-chat:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.chat-list { display: flex; flex-direction: column; gap: 0.125rem; overflow-y: auto; flex: 1; min-height: 0; }
.chat-credits { display: flex; justify-content: space-between; margin: 0; padding: 0.5rem 0.75rem 0; font-size: 0.875rem; color: var(--muted); border-top: 1px solid var(--border); }
.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--radius);
}
.chat-item a {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item:hover, .chat-item.active, .chat-item:focus-within { background: color-mix(in srgb, var(--text) 8%, transparent); }
.chat-menu-btn {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  margin-right: 0.25rem;
  flex-shrink: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
}
.chat-item:hover .chat-menu-btn, .chat-item:focus-within .chat-menu-btn, .chat-menu-btn[aria-expanded="true"] { opacity: 1; }
.chat-menu-btn:hover { color: var(--text); background: color-mix(in srgb, var(--text) 10%, transparent); }
@media (hover: none) { .chat-menu-btn { opacity: 1; } }
.chat-menu {
  position: fixed;
  z-index: 30;
  min-width: 10rem;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
}
.chat-menu[hidden] { display: none; }
.chat-menu button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: calc(var(--radius) - 3px);
  cursor: pointer;
}
.chat-menu button:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.chat-menu .danger { color: var(--error); }
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 1.25rem max(1rem, env(safe-area-inset-bottom));
}
.chat-main > * { width: 100%; max-width: 760px; margin-inline: auto; }
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0 1rem;
}
.chat-empty { margin: auto 0; text-align: center; }
.msg { max-width: 85%; line-height: 1.55; overflow-wrap: anywhere; }
.msg p + p { margin-top: 0.75rem; }
.msg a { color: var(--link); text-decoration: underline; }
.msg--user {
  align-self: flex-end;
  padding: 0.6rem 1rem;
  white-space: pre-wrap;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: var(--radius);
}
.msg--assistant { align-self: flex-start; }
.msg--status { align-self: flex-start; color: var(--muted); font-size: 0.875rem; }
.msg--status::before { content: ''; display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.5em; vertical-align: -0.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: msg-spin 0.8s linear infinite; }
@keyframes msg-spin { to { transform: rotate(360deg); } }
.msg--error { color: var(--error); }
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chat-note { margin-bottom: 0.4rem; font-size: 0.8125rem; color: var(--muted); }
.chat-note a { text-decoration: underline; }
.chat-form:focus-within { border-color: var(--link); }
.chat-form textarea {
  flex: 1;
  padding: 0.4rem 0;
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  max-height: 200px;
}
.chat-form { position: relative; padding: 0.75rem 3.25rem 0.75rem 1rem; align-items: stretch; }
.chat-form textarea { min-height: calc(3 * 1.5em); }
.send {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  color: var(--bg);
  background: var(--text);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.send:disabled { opacity: 0.4; cursor: default; }
.chat-options { display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; padding-top: 0.5rem; font-size: 0.875rem; color: var(--muted); }
.pick summary {
  appearance: none;
  padding: 0.3rem 1.6rem 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='3'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.55rem center;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.pick { position: relative; }
.pick summary { box-sizing: border-box; min-width: 6rem; list-style: none; cursor: pointer; }
.pick summary::-webkit-details-marker { display: none; }
.pick-list {
  position: absolute;
  bottom: calc(100% + 0.4rem);
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem 0.8rem;
  white-space: nowrap;
  background: var(--bg, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pick-list label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.pick-list input { margin: 0; accent-color: var(--text); }
.pick--locked summary { opacity: 0.7; pointer-events: none; }
/* ---- User menu (bottom of the chat sidebar) ---- */
.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: color-mix(in srgb, var(--text) 8%, transparent); }
.avatar {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--text);
  border-radius: 50%;
}
.user-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-btn svg:last-child { flex-shrink: 0; color: var(--muted); }
.user-pop {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.25rem);
  z-index: 10;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
}
.user-pop[hidden] { display: none; }
.user-pop a, .user-pop-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: calc(var(--radius) - 3px);
}
.user-pop a:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.user-pop svg { flex-shrink: 0; }
.user-pop hr { margin: 0.25rem 0; border: 0; border-top: 1px solid var(--border); }
.user-pop-row { justify-content: space-between; }
.user-pop-row > span { display: flex; align-items: center; gap: 0.6rem; }
.theme-switch { display: flex; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius-pill); }
.theme-switch button {
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.theme-switch button[aria-pressed="true"] { color: var(--bg); background: var(--text); }

/* ---- Profile / billing pages ---- */
.settings { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 1.5rem; }
.settings > .links { margin-bottom: -0.5rem; }
.panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel .narrow { max-width: none; }
.panel--danger { border-color: var(--error); }
.panel--danger h2 { color: var(--error); }
.button--danger { color: #fff; background: var(--error); border-color: var(--error); }
.button:disabled { opacity: 0.4; cursor: default; }
.success { color: hsl(142 55% 38%); font-size: 0.875rem; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { padding: 0.5rem 0.25rem; text-align: right; border-bottom: 1px solid var(--border); }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { font-weight: 500; color: var(--muted); }
.table .icon-link { display: inline-flex; color: var(--muted); }
.table .icon-link:hover { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chat-page .legal { margin-top: 0.5rem; }
.icon-btn {
  display: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
@media (max-width: 720px) {
  .chat-page .header { padding: 0.25rem 0.5rem; }
  .icon-btn { display: grid; }
  .chat-side {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(300px, 85vw);
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: var(--bg);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s, visibility 0.2s;
  }
  .side-open .chat-side { transform: none; visibility: visible; }
  .side-open::after { content: ""; position: fixed; inset: 0; z-index: 15; background: rgb(0 0 0 / 0.4); }
  .chat-main { padding-inline: 1rem; }
  .msg { max-width: 95%; }
  .chat-form { padding: 0.5rem 3.25rem 0.5rem 1rem; }
  .chat-form textarea { min-height: 0; height: calc(1.5em + 0.8rem); }
  .chat-options { flex-wrap: wrap; justify-content: flex-start; }
  .chat-options > label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .pick-list { left: 0; right: auto; }
  .chat-page .legal { margin-top: 0.25rem; font-size: 0.75rem; }
}

.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: 0.4rem 0.75rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: inherit; border-bottom-color: currentColor; }

/* ---- Legal documents (/terms, /privacy) ---- */
.doc { width: 100%; max-width: 720px; display: flex; flex-direction: column; gap: 0.75rem; }
.doc h2 { margin-top: 1rem; }
.doc ul, .doc ol { margin: 0; padding-left: 1.25rem; }
.doc ol.alpha { list-style: lower-alpha; }
.doc li + li { margin-top: 0.25rem; }
.doc a { text-decoration: underline; }
.doc .table { display: block; overflow-x: auto; }
.doc .table th, .doc .table td { text-align: left; vertical-align: top; }
.faq { border-bottom: 1px solid var(--border); padding: 0.75rem 0; }
.faq summary { cursor: pointer; font-weight: 500; }
.faq p { margin-top: 0.5rem; }
.faq .button { display: inline-block; margin-top: 0.5rem; text-decoration: none; }

/* ---- Billing details (/user/profile): FO/PO switch, fields shown per kind via :has() ---- */
.seg { display: flex; padding: 0.2rem; border: 1px solid var(--border); border-radius: var(--radius-pill); }
.seg label { flex: 1; padding: 0.5rem; text-align: center; font-size: 0.875rem; border-radius: var(--radius-pill); cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { color: var(--bg); background: var(--text); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--link); }
.row { display: grid; grid-template-columns: 8rem 1fr; gap: 0.75rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.billing:has(input[value="FO"]:checked) .po-only,
.billing:has(input[value="PO"]:checked) .fo-only { display: none; }

/* ---- Credit packages (/user/credits) ---- */
.settings--wide { max-width: 760px; }
.packages { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.package {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 19rem;
  padding: 1.25rem;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}
.package:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--border-strong); }
.package:disabled { opacity: 0.5; cursor: default; }
.package-name { font-family: var(--mono); color: var(--muted); }
.package-price { font-size: 3rem; font-weight: 600; line-height: 1.2; }
.package-credits { font-weight: 500; }
.package-bonus { font-size: 0.8125rem; color: hsl(142 55% 38%); }
.package-buy { margin-top: auto; padding: 0.6rem; text-align: center; font-weight: 500; color: var(--bg); background: var(--text); border-radius: var(--radius-pill); }
