:root {
  --brand: #B23A5B;
  --brand-dark: #8e2c48;
  --bg: #f6f2f3;
  --text: #2b2326;
  --muted: #75696d;
  --border: #e2d8db;
  --topbar-height: 52px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg);
  overflow-wrap: anywhere; }
a { color: var(--brand); }

/* ---- Top bar ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  min-height: var(--topbar-height); padding: 8px 20px; padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right));
  background: var(--brand); color: #fff; }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .8; margin-left: 4px; }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar nav a, .topbar .link-button { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 6px; min-height: 40px; display: inline-flex; align-items: center; }
.topbar nav a.current, .topbar nav a:hover, .topbar .link-button:hover { background: rgba(255,255,255,.18); }
.topbar form { margin: 0; }
.link-button { background: none; border: 0; font: inherit; cursor: pointer; }

/* ---- Layout ---- */
main { max-width: 1000px; margin: 0 auto; padding: 20px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
h1 { font-size: 24px; margin: 0 0 16px; }
h1 small { font-size: 15px; color: var(--muted); font-weight: 400; }
h2 { font-size: 18px; margin: 0 0 12px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.title-row h1 { margin: 0; }
.breadcrumb { margin: 0 0 12px; }

/* Sign-in page: card centered in the screen */
body.auth main { display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--topbar-height)); min-height: calc(100dvh - var(--topbar-height)); }
body.auth main > .card { width: 100%; margin: 0; }
body.auth h1 { text-align: center; }
body.auth .primary { width: 100%; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin: 0 0 20px; }
.card.danger { border-color: #e6b3b3; }
.narrow { max-width: 420px; }
form.card.narrow { margin: 20px 0; }

/* ---- Forms (16px inputs: iOS does not zoom in on focus) ---- */
label { display: block; margin: 0 0 14px; font-weight: 600; }
.hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=search] {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text); }
input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.with-button { display: flex; gap: 6px; align-items: flex-end; }
.with-button input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; }

button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text); text-decoration: none; }
button:hover, .button:hover { border-color: var(--brand); }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-dark); }
button.danger { background: #b3261e; border-color: #b3261e; color: #fff; }
.small { min-height: 36px; padding: 5px 12px; font-size: 14px; }

.search { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search input { flex: 1 1 220px; max-width: 360px; margin: 0; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 16px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #faf6f7; font-size: 13px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td form { margin: 0; }
/* Button cells: less top padding so a 36 px button lines up with the row text */
td.cell-actions { padding-top: 4px; padding-bottom: 4px; text-align: right; white-space: nowrap; }
.actions { display: flex; gap: 8px; align-items: flex-start; justify-content: flex-end; }
/* The open form sits on its own line under the buttons, aligned right, without moving them or the other columns */
.actions:has(.password-change) { position: relative; min-width: 270px; }
.actions:has(.password-change[open]) { padding-bottom: 48px; }
.password-change .inline-form { position: absolute; right: 0; bottom: 0; }
.password-change { display: flex; flex-direction: column; align-items: flex-end; order: 1; }
.password-change summary { list-style: none; }
.password-change summary::-webkit-details-marker { display: none; }
.password-change summary::after { content: "▾"; margin-left: 6px; font-size: 12px; color: var(--muted); }
.password-change[open] summary { border-color: var(--brand); color: var(--brand); }
.password-change[open] summary::after { content: "▴"; }
.inline-form { display: flex; gap: 6px; margin-top: 6px; }
.inline-form input { width: 180px; margin: 0; padding-top: 6px; padding-bottom: 6px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.on, .badge.active { background: #e3f3e6; color: #22662f; }
.badge.off, .badge.inactive { background: #f6e1e1; color: #8a2121; }
.badge.pending { background: #fdf0d5; color: #7a5200; }

/* Status filters above the accounts list */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.filters a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 99px; background: #fff;
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; }
.filters a:hover { border-color: var(--brand); }
.filters a.current { background: var(--brand); border-color: var(--brand); color: #fff; }
.filters .count { font-weight: 400; opacity: .8; }

/* Pages below the accounts list */
.pagination { display: flex; gap: 8px 12px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 0 0 16px; }
.pagination span { color: var(--muted); font-size: 14px; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 16px; }
dt { color: var(--muted); }
dd { margin: 0; }

.notice { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; }
.notice.ok { background: #e3f3e6; color: #22662f; }
.notice.error { background: #f6e1e1; color: #8a2121; }
.notice.info { background: #fdf0d5; color: #7a5200; }
.empty { color: var(--muted); }

/* ---- Phones ---- */
@media (max-width: 700px) {
  :root { --topbar-height: 96px; }
  main { padding: 14px 12px; }
  .topbar { padding: 8px 12px; }
  .topbar nav { width: 100%; justify-content: space-between; }
  .topbar nav a, .topbar .link-button { padding: 8px 10px; }
  body.auth { --topbar-height: 52px; }
  h1 { font-size: 21px; }
  .card { padding: 16px; }
  .narrow { max-width: none; }
  .title-row .button { width: 100%; }
  .search input { max-width: none; }
  .search button { flex: 0 0 auto; }
  .card form button { width: 100%; }
  .with-button button[data-generate] { width: auto; flex: 0 0 auto; }

  /* Tables become one card per row, each value with its label */
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive { background: none; border: 0; border-radius: 0; overflow: visible; }
  table.responsive thead { display: none; }
  table.responsive tr { background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 0; }
  table.responsive td { border: 0; padding: 5px 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; }
  table.responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto; }
  table.responsive td.cell-title { font-weight: 600; font-size: 16px; text-align: left; padding-top: 8px; padding-bottom: 8px; }
  table.responsive td.cell-actions { display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 6px; padding-top: 8px; }
  table.responsive td.cell-actions button { width: 100%; }
  table.responsive td.cell-actions { white-space: normal; padding-bottom: 8px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions:has(.password-change) { min-width: 0; }
  .actions:has(.password-change[open]) { padding-bottom: 0; }
  .password-change .inline-form { position: static; }
  .password-change { align-items: stretch; }
  .inline-form input { width: auto; flex: 1; min-width: 0; }
  table.responsive td.cell-actions .inline-form button { width: auto; flex: 0 0 auto; }
}
