/* Sign in, account and users. Same tokens, type and chrome as the visual
   editor (editor/src/styles.css) and the public website. */

:root {
  --paper: #fbf5ec;
  --sand: #f1e8dc;
  --card: #fffcf7;
  --butter: #f8e9c2;
  --ink: #2a1a12;
  --cocoa: #4d2b1f;
  --muted: #7a5a48;
  --orange: #da834d;
  --ember: #a9521d;
  --gold: #b89259;
  --chrome: #1f1712;
  --line: #e3d6c5;
  --focus: #2f7de1;
  --danger: #9b1c1c;
  --danger-bg: #fbeaea;
  --success: #2f6b3a;
  --success-bg: #e8f2e6;
  --radius: 18px;
  --sans: "Poppins", Arial, Helvetica, sans-serif;
  --serif: "Noto Serif", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--butter); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

a { color: var(--ember); text-underline-offset: 0.2em; }
h1, h2 { font-family: var(--serif); color: var(--ink); line-height: 1.15; text-wrap: balance; }
h1 { font-size: 1.9rem; font-weight: 800; margin: 0 0 0.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; font-weight: 700; margin: 0 0 0.75rem; }
p { margin: 0.5rem 0; }
.accent { color: var(--ember); }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; margin: 0; }
.hint.block { display: block; }
.small-text { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Chrome ──────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  min-height: 4rem;
  padding: 0.5rem 16px;
  background: var(--chrome);
  color: var(--paper);
}
.topbar .brand { display: flex; align-items: center; gap: 0.75rem; color: var(--paper); text-decoration: none; line-height: 1.2; }
.brand-logo { display: block; height: 40px; width: auto; }
.brand-sub {
  padding-left: 0.75rem; border-left: 1px solid rgb(255 255 255 / 0.2);
  font: 600 0.6875rem/1.25 var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: #cdbfb2;
  max-width: 9rem;
}
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.topbar nav a, .topbar .link {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 0.85rem;
  border-radius: 999px; color: #e9ddd0; text-decoration: none; font: 500 0.9rem var(--sans);
}
.topbar nav a:hover, .topbar .link:hover { background: rgb(255 255 255 / 0.1); color: #fff; }
.topbar form { margin: 0; }

.brand-mark {
  display: grid; place-items: center; width: 3.25rem; height: 3.25rem; border-radius: 16px;
  background: var(--orange); color: var(--ink); font: 800 1.6rem var(--serif);
}
.brand-mark.small { width: 2.25rem; height: 2.25rem; border-radius: 11px; font-size: 1.1rem; }

main { max-width: 880px; margin: 0 auto; padding: 2rem 16px 4rem; }
body.bare main { min-height: 100vh; display: grid; place-items: center; padding-block: 2rem; }

/* ── Sign in ─────────────────────────────────────────────────────────── */

.signin {
  width: min(100%, 26rem);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 2rem 1.75rem;
  box-shadow: 0 24px 60px -32px rgb(42 26 18 / 0.35);
}
.signin-brand { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin: 0.25rem 0 1.5rem; text-align: center; }
.signin-logo { display: block; width: min(13.5rem, 70%); height: auto; }
.system-name {
  display: flex; align-items: center; gap: 0.6rem; margin: 0;
  font: 600 0.6875rem/1 var(--sans); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ember);
}
.system-name::before, .system-name::after { content: ""; width: 1.25rem; height: 1px; background: var(--gold); }
.signin > .muted:first-of-type { text-align: center; margin-bottom: 1.25rem; }
.signin > .muted:last-child { margin-top: 1.25rem; }

/* ── Surfaces & messages ─────────────────────────────────────────────── */

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; margin: 1.25rem 0; }
.card.narrow { max-width: 30rem; }
.card.highlight { border-color: var(--orange); background: #fff8ef; }
.back { margin: 0 0 0.75rem; font-size: 0.9rem; }

.notice, .error { border-radius: 14px; padding: 0.8rem 1rem; margin: 0 0 1.25rem; }
.notice { background: var(--success-bg); color: var(--success); }
.error { background: var(--danger-bg); color: var(--danger); }

.secret { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 0.25rem 0 0.75rem; }
.secret code {
  font: 600 1.35rem/1.2 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.02em; color: var(--cocoa); background: var(--paper);
  border: 1px dashed var(--gold); border-radius: 12px; padding: 0.55rem 0.9rem;
  user-select: all;
}

/* ── Forms ───────────────────────────────────────────────────────────── */

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.stack > button:not(.wide) { align-self: flex-start; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > label, legend { font-weight: 600; font-size: 0.92rem; color: var(--ink); }
.field-error { margin: 0; min-height: 0; font-size: 0.85rem; font-weight: 500; color: var(--danger); }
.field-error:empty { display: none; }
.has-error input { border-color: var(--danger); }

input, select, textarea {
  font: inherit; width: 100%; min-height: 46px; padding: 0.6rem 0.85rem;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:hover, select:hover { border-color: #cdb9a3; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgb(47 125 225 / 0.2); }
input::placeholder { color: #9c8576; }
select:disabled { background: var(--sand); color: var(--muted); }

.password-field { position: relative; }
.password-field input { padding-right: 4.75rem; }
.password-field .reveal {
  position: absolute; top: 50%; right: 0.35rem; transform: translateY(-50%);
  min-height: 36px; padding: 0 0.75rem; border: 0; background: transparent;
  color: var(--ember); font: 600 0.85rem var(--sans);
}
.password-field .reveal:hover { background: var(--sand); }

fieldset.choice { border: 1px solid var(--line); border-radius: 14px; padding: 0.9rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
fieldset.choice legend { padding: 0 0.35rem; }
label.radio { display: flex; align-items: flex-start; gap: 0.6rem; font-weight: 500; cursor: pointer; }
label.radio input { width: 1.15rem; min-height: 0; height: 1.15rem; margin-top: 0.2rem; accent-color: var(--ember); }
.custom-password { padding-left: 1.75rem; }
.custom-password[hidden] { display: none; }

button, .button {
  font: 600 0.92rem var(--sans); display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 46px; padding: 0.5rem 1.15rem; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); text-decoration: none; cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
button:hover, .button:hover { border-color: var(--cocoa); }
button.primary, .button.primary { background: var(--ember); border-color: var(--ember); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--cocoa); border-color: var(--cocoa); }
button.danger { color: var(--danger); border-color: #e6bcbc; }
button.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
button.small, .button.small { min-height: 40px; padding: 0 0.95rem; font-size: 0.85rem; }
button.wide { width: 100%; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.link { border: 0; background: none; min-height: 40px; }
form.inline { display: inline; margin: 0; }

/* ── Users ───────────────────────────────────────────────────────────── */

.user-list { list-style: none; padding: 0; margin: 1.25rem 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.user { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 0.75rem 1.25rem; padding: 1rem 1.25rem; }
.user + .user { border-top: 1px solid var(--line); }
.user.is-disabled .user-who { opacity: 0.6; }
.user-who { display: flex; flex-direction: column; min-width: 0; }
.user-who .muted { font-size: 0.85rem; overflow-wrap: anywhere; }
.role-form { display: flex; align-items: center; gap: 0.5rem; margin: 0; }
.role-form select { width: auto; min-height: 40px; }
.role-badge {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 0.95rem;
  border-radius: 999px; background: var(--sand); color: var(--cocoa); font-weight: 600; font-size: 0.85rem;
}

/* ── Custom dropdown (static/admin.js enhances <select data-dropdown>) ── */

.dropdown { position: relative; min-width: 11rem; }
.field .dropdown { width: 100%; }
.dropdown-button {
  width: 100%; min-height: 46px; justify-content: space-between; gap: 0.75rem;
  border-radius: 12px; padding: 0.5rem 0.75rem 0.5rem 0.9rem; font-weight: 500; text-align: left;
}
.role-form .dropdown-button { min-height: 40px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.dropdown-button .chevron { flex: none; width: 1rem; height: 1rem; color: var(--muted); transition: transform 150ms ease-out; }
.dropdown-button[aria-expanded="true"] { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(47 125 225 / 0.2); }
.dropdown-button[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.dropdown-list {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 100%; width: max-content; max-width: min(20rem, 90vw);
  margin: 0; padding: 0.35rem; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 40px -18px rgb(42 26 18 / 0.4);
}
.dropdown-list[hidden] { display: none; }
.dropdown.up .dropdown-list { top: auto; bottom: calc(100% + 6px); }
.dropdown-option {
  display: grid; grid-template-columns: 1.25rem 1fr; align-items: start; gap: 0.15rem 0.5rem;
  padding: 0.55rem 0.75rem 0.55rem 0.5rem; border-radius: 10px; cursor: pointer;
}
.dropdown-option .check { grid-row: span 2; width: 1rem; height: 1rem; margin-top: 0.2rem; color: var(--ember); visibility: hidden; }
.dropdown-option[aria-selected="true"] .check { visibility: visible; }
.dropdown-option .label { font-weight: 600; color: var(--ink); }
.dropdown-option .hint { grid-column: 2; font-size: 0.8rem; }
.dropdown-option.active { background: var(--sand); }
.dropdown-option[aria-selected="true"] .label { color: var(--ember); }
.role-form [data-role-save][hidden] { display: none; }
.user-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
.badge { align-self: flex-start; margin-top: 0.3rem; font-size: 0.75rem; font-weight: 600; background: var(--sand); color: var(--cocoa); border-radius: 999px; padding: 0.1rem 0.6rem; }

@media (max-width: 640px) {
  main { padding-top: 1.5rem; }
  h1 { font-size: 1.6rem; }
  .user { grid-template-columns: 1fr; }
  .role-form select, .role-form .dropdown { flex: 1; }
  .user-actions { justify-content: flex-start; }
  .user-actions > * { flex: 1 1 8.5rem; }
  .user-actions button, .user-actions .button { width: 100%; min-height: 44px; white-space: nowrap; }
  .topbar { padding-block: 0.6rem 0.35rem; }
  .topbar nav { width: 100%; margin-inline: -0.6rem; gap: 0; }
  .topbar nav a, .topbar .link { padding: 0 0.6rem; font-size: 0.85rem; }
  .brand-logo { height: 34px; }
  .brand-sub { max-width: none; font-size: 0.625rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
