/*
 * The same design language as the mobile app (mobile-app/src/theme/theme.ts):
 * white pages, white cards with a hairline border and 24px corners, the
 * burgundy brand colour, pill buttons, bold tight headings, system font.
 * Keep the values in step with that file.
 */
:root {
  /* palette.primary */
  --primary-50: #fbf4f5;
  --primary-100: #f8e9eb;
  --primary-200: #f2d6d9;
  --primary-300: #e7b5bc;
  --primary-400: #d88a96;
  --primary-500: #c46474;
  --primary-600: #a8475a;
  --primary-700: #8e3a4a;
  --primary-800: #77323f;

  --bg: #ffffff;
  --card: #ffffff;
  --input: #ffffff;
  --wash: #f8f9fa; /* neutral.100 */
  --text: #212529; /* neutral.900 */
  --text-2: #6c757d; /* neutral.600 */
  --text-3: #adb5bd; /* neutral.500 */
  --border: #e9ecef; /* neutral.200 */
  --focus: var(--primary-500);

  --accent: var(--primary-700);
  --on-accent: #ffffff;
  --accent-surface: var(--primary-50);
  --accent-surface-strong: var(--primary-100);
  --accent-border: var(--primary-200);
  --accent-text: var(--primary-700);

  --error: #b91c1c;
  --error-surface: #fee2e2;
  --success: #047857;
  --success-surface: #d1fae5;

  --shadow: 0 4px 6px rgba(33, 37, 41, 0.05);
  --radius-card: 24px;
  --radius-input: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --card: #1e1e1e;
    --input: #2c2c2c;
    --wash: #1e1e1e;
    --text: #ffffff;
    --text-2: #aaaaaa;
    --text-3: #888888;
    --border: #2c2c2c;
    --focus: var(--primary-400);

    --accent: var(--primary-600);
    --accent-surface: #261619;
    --accent-surface-strong: #341d22;
    --accent-border: #4a2a31;
    --accent-text: var(--primary-300);

    --error: #fca5a5;
    --error-surface: #3b1717;
    --success: #6ee7b7;
    --success-surface: #10332a;

    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/22px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 30px; line-height: 38px; font-weight: 700; letter-spacing: -0.75px; margin: 0 0 24px; }
h2 { font-size: 20px; line-height: 28px; font-weight: 600; letter-spacing: -0.25px; margin: 0 0 16px; }
a { color: var(--accent-text); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
p { margin: 0 0 12px; }
.muted { color: var(--text-2); }
.center { text-align: center; }
.small { font-size: 13px; line-height: 18px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.93em; letter-spacing: 0.02em; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Top bar */
header.top {
  display: flex;
  align-items: center;
  gap: 8px 24px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.25px; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand .tag {
  font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent-surface);
  border: 1px solid var(--accent-border); border-radius: 999px; padding: 0 8px;
}
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header.top nav a {
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--text-2);
  font-weight: 500;
}
header.top nav a:hover { background: var(--wash); text-decoration: none; color: var(--text); }
header.top nav a.on { background: var(--accent-surface); color: var(--accent-text); font-weight: 600; }
main { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.grid .card { margin-bottom: 0; }
.stat .n { font-size: 30px; line-height: 38px; font-weight: 800; letter-spacing: -0.75px; color: var(--accent-text); }
.stat .l {
  margin-top: 4px; color: var(--text-3);
  font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .grow { flex: 1; min-width: 200px; }
.page-head { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-head h1 { margin: 0; }

/* The person header: the app's profile avatar */
.person-head { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.person-head h1 { margin: 0; overflow-wrap: anywhere; }
.avatar {
  flex: none; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary-700); color: #fff;
  font-size: 20px; font-weight: 700; letter-spacing: 0.5px;
}

/* Forms */
label { display: block; font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
input, select, button {
  font: inherit;
  color: var(--text);
  min-height: 46px;
}
input, select {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  padding: 10px 16px;
}
select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236c757d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
input::placeholder { color: var(--text-3); }
input:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-surface-strong); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

button {
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  border-radius: 999px; /* pill, as in the app */
  padding: 10px 24px;
  background: transparent;
  border: 1px solid var(--accent-border);
  color: var(--accent-text);
}
button:hover:not(:disabled) { background: var(--accent-surface); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--primary-800); border-color: var(--primary-800); }
button.danger { color: var(--error); border-color: var(--error-surface); }
button.danger:hover:not(:disabled) { background: var(--error-surface); }
button.quiet { border-color: var(--border); color: var(--text-2); }
button.quiet:hover:not(:disabled) { background: var(--wash); color: var(--text); }
td button, header.top button { min-height: 36px; padding: 6px 16px; font-size: 14px; }
button:disabled { opacity: 0.5; cursor: default; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; margin-bottom: 16px; }

/* Tables */
.scroll { overflow-x: auto; margin: 0 -8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-3); white-space: nowrap; padding-top: 0;
}
th.right, td.right { text-align: right; }
tr:last-child td { border-bottom: 0; padding-bottom: 0; }
tr.off td { color: var(--text-3); }
tr.off td.strike { text-decoration: line-through; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; line-height: 18px; font-weight: 600;
  background: var(--accent-surface); color: var(--accent-text); border: 1px solid var(--accent-border);
}
.pill.grey { background: var(--wash); color: var(--text-2); border-color: var(--border); }
.pill.red { background: var(--error-surface); color: var(--error); border-color: transparent; }

.notice {
  padding: 12px 16px; border-radius: var(--radius-input); margin-bottom: 16px;
  background: var(--accent-surface); border: 1px solid var(--accent-border); color: var(--accent-text);
}
.notice.error { background: var(--error-surface); border-color: transparent; color: var(--error); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
dl.facts dt { color: var(--text-2); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; font-weight: 500; }

/* Sign-in */
.signin { max-width: 400px; margin: 10vh auto 0; padding: 0 24px; }
.signin .logo { display: block; width: 70px; height: 70px; border-radius: 16px; margin: 0 auto 24px; }
.signin h1 { text-align: center; margin-bottom: 4px; }
.signin .sub { text-align: center; color: var(--text-2); margin-bottom: 32px; }
.signin .field { margin-bottom: 16px; }
.signin button { width: 100%; margin-top: 8px; }

@media (max-width: 600px) {
  header.top { padding: 12px 16px; }
  main { padding: 24px 16px 48px; }
  .card { padding: 16px; border-radius: 20px; }
  h1 { font-size: 26px; line-height: 32px; }
}

/* People table: filters, sortable headers, pages */
.filters { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); align-items: end; margin-bottom: 24px; }
.filters .wide { grid-column: 1 / -1; }
.filters button { justify-self: start; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
th button.sort {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit;
  border-radius: 6px;
}
th button.sort:hover, th button.sort.on { color: var(--accent-text); }
th button.sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
th button.sort .arrow { font-size: 10px; opacity: 0.6; }
th button.sort.on .arrow { opacity: 1; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-surface); }
a.name { color: var(--text); font-weight: 600; }
tr.click:hover a.name { color: var(--accent-text); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.pager:empty { display: none; }
.pager button { min-height: 36px; padding: 6px 16px; font-size: 14px; }
