/* Brand: New Progress Group navy (#2E3192). Same in both themes. */
:root { --brand: #2E3192; --brand-deep: #1c1e66; --brand-night: #12143f;
  --brand-stripes: repeating-linear-gradient(180deg, rgba(255, 255, 255, .07) 0 2px, transparent 2px 16px); }

/* Theme: light by default, dark when the device prefers it, and either one
   forced by <html data-theme="light|dark"> (the switch in the top bar). */
:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #6b7280;
  --border: #e3e6eb; --accent: #2E3192; --accent-text: #fff; --accent-soft: #eceefa;
  --ok: #1d7a46; --ok-bg: #e6f4ec; --err: #b42318; --err-bg: #fdecea; --strong: #6941c6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14171c; --surface: #1d2128; --text: #e7e9ee; --muted: #9aa3b2;
    --border: #2c323c; --accent: #9aa1f2; --accent-text: #11132e; --accent-soft: #262a4f;
    --ok: #6fd39a; --ok-bg: #173325; --err: #ff8a80; --err-bg: #3a1d1b; --strong: #b9a3f5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14171c; --surface: #1d2128; --text: #e7e9ee; --muted: #9aa3b2;
  --border: #2c323c; --accent: #9aa1f2; --accent-text: #11132e; --accent-soft: #262a4f;
  --ok: #6fd39a; --ok-bg: #173325; --err: #ff8a80; --err-bg: #3a1d1b; --strong: #b9a3f5;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); transition: background-color .3s ease, color .3s ease; }
a { color: var(--accent); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .55rem 1rem; color: #fff; background: linear-gradient(90deg, var(--brand), var(--brand-deep)); }
.topbar .link, .topbar a { color: #fff; }
.topbar .muted { color: rgba(255, 255, 255, .75); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar form { margin: 0; }
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem;
  letter-spacing: .02em; text-decoration: none; }
.brand img { width: 34px; height: auto; display: block; }
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; margin: 1rem 0;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.muted { color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .6rem;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
  padding: .6rem 1.2rem; font: inherit; font-weight: 600; cursor: pointer; transition: filter .15s, transform .15s; }
.button:hover { filter: brightness(1.12); }
.button:active { transform: translateY(1px); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.tags { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.tags li { border: 1px solid var(--border); border-radius: 999px; padding: .15rem .7rem; }
.messages { list-style: none; padding: 0; }
.messages li { padding: .6rem .9rem; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }

/* --- Shared UI ------------------------------------------------------------- */
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
h4 { font-size: .9rem; margin: .5rem 0 .25rem; }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
input[type=search], input[type=text], select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; max-width: 100%;
}
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); }
code { font-size: .8rem; }
.danger { color: var(--err); }

.subnav { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0 0 1.5rem; border-bottom: 1px solid var(--border); }
.subnav a { padding: .5rem .8rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a[aria-current=page] { color: var(--text); border-color: var(--accent); font-weight: 600; }
.page-header { margin-bottom: 1rem; }
.page-header.row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.page-header p { margin: .25rem 0 0; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.filters input[type=search] { flex: 1 1 16rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.field-error { color: var(--err); width: 100%; margin: 0; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.card .table { background: transparent; }

.tag { display: inline-block; border: 1px solid var(--border); border-radius: 999px; padding: 0 .6rem; font-size: .85rem; text-decoration: none; color: var(--text); margin: 0 .15rem .15rem 0; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .5rem; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); vertical-align: middle; }
.badge-ok { color: var(--ok); }
.badge-off { color: var(--err); }
.badge-strong { color: var(--strong); }

.alert { padding: .6rem .9rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.alert-error { background: var(--err-bg); color: var(--err); border-color: transparent; }
.messages .success { background: var(--ok-bg); color: var(--ok); }
.messages .error { background: var(--err-bg); color: var(--err); }

.layout-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1rem; align-items: start; }
.layout-detail.layout-wide-first { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.layout-detail > .card, .stack > .card { margin: 0; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
@media (max-width: 760px) {
  .layout-detail, .layout-detail.layout-wide-first { grid-template-columns: 1fr; }
  .topbar .user-name { display: none; }
}
.brand { white-space: nowrap; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.checks { display: grid; gap: .6rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; }
.check input { margin-top: .2rem; }
.check label { display: grid; }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .4rem 1rem; margin-bottom: 1rem; }
.check-inline { display: flex; gap: .5rem; align-items: baseline; padding: .2rem 0; }
.check-inline input, .check input { flex-shrink: 0; }
.perm-app { border: 1px solid var(--border); border-radius: 6px; padding: .5rem 1rem 1rem; margin: 0 0 1rem; }
.perm-app legend { font-weight: 600; padding: 0 .3rem; }
.perm-list { margin: 0; padding-left: 1.1rem; }
.perm-list li { margin: .2rem 0; }

.rows { list-style: none; padding: 0; margin: .75rem 0 0; }
.rows li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.rows li form { margin: 0; }
.search-results { background: var(--bg); border-radius: 6px; padding: 0 .75rem; }
#member-search { width: 100%; }
.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: .35rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.log time { color: var(--muted); font-size: .85rem; margin-right: .3rem; }
.actions summary { cursor: pointer; }
.actions[open] { display: grid; gap: .5rem; justify-items: end; }
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* --- Sidebar layout -------------------------------------------------------- */
.shell { display: flex; align-items: flex-start; }
.shell > main { flex: 1; min-width: 0; }
.sidebar { position: sticky; top: 0; flex: 0 0 15rem; min-height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; }
.sidebar nav { display: flex; flex-direction: column; gap: .15rem; }
.sidebar a { display: flex; align-items: center; gap: .65rem; padding: .45rem .7rem; border-radius: 6px; text-decoration: none; color: var(--text); }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--muted); transition: color .2s ease, transform .2s ease; }
.sidebar a:hover .nav-icon, .sidebar a[aria-current=page] .nav-icon { color: var(--accent); }
.sidebar a:hover .nav-icon { transform: scale(1.08); }
.sidebar a:hover { background: var(--bg); }
.sidebar a[aria-current=page] { background: var(--accent-soft); color: var(--accent); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-heading { margin: 1rem .7rem .25rem; font-size: .75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.container-full { max-width: none; display: flex; flex-direction: column; min-height: calc(100vh - 3.3rem); }
.embed { flex: 1; display: block; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: static; min-height: 0; border-right: 0; border-bottom: 1px solid var(--border); padding: .5rem 1rem; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: .25rem; }
  .sidebar a { white-space: nowrap; }
  .sidebar-heading { display: none; }
}

.theme-toggle { white-space: nowrap; }

/* --- Branding ------------------------------------------------------------- */
.theme-dark-only { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-light-only { display: none; }
  :root:not([data-theme="light"]) .theme-dark-only { display: block; }
}
:root[data-theme="dark"] .theme-light-only { display: none; }
:root[data-theme="dark"] .theme-dark-only { display: block; }

/* Sign-in page: navy background with the logo's horizontal stripes. */
body.page-signin { min-height: 100vh; display: flex; flex-direction: column;
  background: var(--brand-stripes), linear-gradient(160deg, var(--brand) 0%, var(--brand-deep) 55%, var(--brand-night) 100%); }
body.page-signin .topbar { background: transparent; }
body.page-signin .shell { flex: 1; display: flex; align-items: center; justify-content: center; }
body.page-signin main { flex: 0 1 auto; width: 100%; max-width: 440px; }
.signin { text-align: center; padding: 2.25rem 2rem 2rem; border: 0; border-radius: 16px;
  box-shadow: 0 24px 60px rgba(8, 10, 40, .45); }
.signin-logo { position: relative; width: 100%; max-width: 280px; margin: 0 auto 1.5rem; }
.signin-logo img { width: 100%; height: auto; }
.signin h1 { font-size: 1.35rem; margin-bottom: 1.25rem; }
.signin .button { width: 100%; padding: .75rem 1rem; }
.signin-footer { text-align: center; color: rgba(255, 255, 255, .7); font-size: .85rem; margin: 1.25rem 0 0; }
.ms-mark { width: 18px; height: 18px; flex-shrink: 0; }

/* Home page banner. */
.hero { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
  color: #fff; border-radius: 14px; padding: 2rem 2rem; margin-bottom: 1rem;
  background: var(--brand-stripes), linear-gradient(120deg, var(--brand) 0%, var(--brand-deep) 70%, var(--brand-night) 100%); }
.hero h1 { font-size: 1.7rem; }
.hero p { margin: .35rem 0 0; color: rgba(255, 255, 255, .8); }
.hero-mark { width: 150px; height: auto; flex-shrink: 0; opacity: .95; }
@media (max-width: 760px) {
  .hero { padding: 1.5rem 1.25rem; }
  .hero-mark { width: 84px; }
}

/* --- Reports -------------------------------------------------------------- */
.company-switch { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; }
.company-switch a, .company-switch .soon { padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); text-decoration: none; color: var(--text); font-size: .9rem; white-space: nowrap; }
.company-switch a:hover { border-color: var(--accent); }
.company-switch a[aria-current=page] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.company-switch .soon { color: var(--muted); border-style: dashed; cursor: default; }
.embed-report { min-height: 560px; }
.center { text-align: center; }
.tag-strong { border-color: var(--accent); color: var(--accent); }
.grant-form { display: grid; gap: .5rem; margin-bottom: .5rem; }
.grant-form textarea, .field input[type=text] { width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; }
.field { display: grid; gap: .3rem; }
.grant-form .button { justify-self: start; }
input[type=number] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .45rem .6rem; width: 6rem; }
.rows li > span { min-width: 0; overflow-wrap: anywhere; }
.container-wide { max-width: 1240px; }
.report-matrix td:first-child { min-width: 12rem; }
.report-matrix th:not(:first-child) { min-width: 6.5rem; }

/* --- Motion --------------------------------------------------------------- */
@keyframes rise-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes stripes-drift { from { background-position: 0 0, 0 0; } to { background-position: 0 64px, 0 0; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
/* Login logo: rises out of a bottom-up wipe, settles, then a glint runs across it now and then. */
@keyframes logo-reveal {
  0% { opacity: 0; clip-path: inset(100% 0 0 0); transform: translateY(18px) scale(.92); filter: blur(6px); }
  60% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; clip-path: inset(0 0 0 0); transform: none; filter: none; }
}
@keyframes logo-glint { 0%, 55% { background-position: 150% 0; } 100% { background-position: -50% 0; } }

/* Theme switch fades rather than snaps. */
.card, .sidebar, .table, .badge, .tag, .tags li, .alert, .messages li,
input, select, textarea, .company-switch a {
  transition: background-color .3s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, transform .2s ease;
}

/* Page content eases in on every load; the first few blocks are staggered. */
body:not(.page-signin) main > * { animation: rise-in .45s cubic-bezier(.2, .7, .3, 1) both; }
body:not(.page-signin) main > *:nth-child(2) { animation-delay: .06s; }
body:not(.page-signin) main > *:nth-child(3) { animation-delay: .12s; }
body:not(.page-signin) main > *:nth-child(4) { animation-delay: .18s; }
body:not(.page-signin) main > *:nth-child(n+5) { animation-delay: .24s; }
.sidebar { animation: fade-in .35s ease both; }
.htmx-added { animation: fade-in .3s ease both; }
.htmx-request { opacity: .6; transition: opacity .2s ease; }

.brand img { transition: transform .4s cubic-bezier(.3, 1.5, .5, 1); }
.brand:hover img { transform: rotate(-8deg) scale(1.08); }
.topbar .link { transition: opacity .15s ease; }
.topbar .link:hover { opacity: .8; }
.sidebar a { transition: background-color .2s ease, color .2s ease, box-shadow .2s ease, padding-left .2s ease; }
.sidebar a:hover { padding-left: .95rem; }
.subnav a { transition: color .2s ease, border-color .2s ease; }
.subnav a:hover { color: var(--text); }
.company-switch a:hover { transform: translateY(-1px); }
.button:hover { box-shadow: 0 6px 18px rgba(46, 49, 146, .3); }
.button:focus-visible, .sidebar a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.table tbody tr { transition: background-color .15s ease; }
.table tbody tr:hover { background: var(--bg); }

.hero { background-size: 100% 64px, 100% 100%; animation: rise-in .5s cubic-bezier(.2, .7, .3, 1) both, stripes-drift 12s linear infinite; }
.hero-mark { animation: float 6s ease-in-out infinite; }

/* Sign-in page. */
body.page-signin { --shine: rgba(255, 255, 255, .85);
  background-size: 100% 64px, 100% 100%; animation: stripes-drift 14s linear infinite; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body.page-signin { --shine: rgba(154, 161, 242, .9); } }
:root[data-theme="dark"] body.page-signin { --shine: rgba(154, 161, 242, .9); }
.signin { animation: rise-in .6s cubic-bezier(.2, .7, .3, 1) both; }
.signin-logo { animation: logo-reveal 1.1s cubic-bezier(.2, .8, .2, 1) .15s both; }
.signin-logo::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, var(--shine) 50%, transparent 60%) 150% 0 / 250% 100% no-repeat;
  -webkit-mask: url("../img/logo.png") center / contain no-repeat; mask: url("../img/logo.png") center / contain no-repeat;
  animation: logo-glint 5s ease-in-out 1.2s infinite; }
.signin-logo:hover img { transform: scale(1.03); }
.signin-logo img { transition: transform .4s ease; }
.signin h1, .signin form { animation: rise-in .5s cubic-bezier(.2, .7, .3, 1) both; }
.signin h1 { animation-delay: .75s; }
.signin form { animation-delay: .85s; }
.signin-footer { animation: fade-in .6s ease 1.1s both; }

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