/* Superior Scientific Client Portal */
:root {
  --brand: #2c9167;          /* logo green, decorative */
  --brand-strong: #1c6648;   /* text, buttons, links on white */
  --brand-deep: #0f3d2b;
  --brand-tint: #e9f5ef;
  --ink: #17221d;
  --text: #2f3a35;
  --muted: #56625c;
  --line: #d7e0db;
  --line-strong: #8a9690;
  --bg: #f4f7f5;
  --card: #ffffff;
  --danger: #b42318;
  --danger-tint: #fdecea;
  --warn: #7a4f00;
  --warn-tint: #fff4dc;
  --info: #1d4f86;
  --info-tint: #e8f1fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 4px 16px rgba(16, 40, 30, .06);
  --focus: 0 0 0 3px #fff, 0 0 0 6px #1c6648;
  --t: 233ms;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 1rem; line-height: 1.55; color: var(--text); background: var(--bg); }
h1, h2, h3 { color: var(--ink); line-height: 1.25; margin: 0 0 .25em; }
h1 { font-size: clamp(1.5rem, 2.4vw, 1.9rem); letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--brand-strong); text-underline-offset: 2px; }
a:hover { color: var(--brand-deep); }
img { max-width: 100%; height: auto; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 1rem; top: -4rem; z-index: 100; background: var(--brand-strong); color: #fff; padding: .75rem 1rem; border-radius: 6px; font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 1rem; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.center { text-align: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: .78rem; font-weight: 700; color: var(--brand-strong); margin: 0 0 .25rem; }
.lead { font-size: 1.05rem; color: var(--muted); }

/* ---------- app shell ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem clamp(1rem, 3vw, 2rem); background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .9rem; text-decoration: none; color: var(--ink); }
.brand img { height: 44px; width: auto; }
.brand-sub { font-size: .85rem; font-weight: 600; color: var(--muted); padding-left: .9rem; border-left: 2px solid var(--line); }
.topbar-user { display: flex; align-items: center; gap: .75rem; }
.who { display: flex; align-items: center; gap: .5rem; font-size: .92rem; }
.role-chip { font-size: .75rem; font-weight: 700; color: var(--brand-strong); background: var(--brand-tint); border-radius: 999px; padding: .15rem .6rem; }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 62px - 56px); }
.sidebar { background: var(--card); border-right: 1px solid var(--line); padding: 1.25rem .75rem; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; position: sticky; top: 80px; }
.sidebar a { display: flex; align-items: center; min-height: 44px; padding: .5rem .9rem; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 600; transition: background var(--t), color var(--t); }
.sidebar a:hover { background: var(--bg); color: var(--ink); }
.sidebar a.active { background: var(--brand-tint); color: var(--brand-deep); box-shadow: inset 3px 0 0 var(--brand); }
main { padding: clamp(1rem, 3vw, 2rem); min-width: 0; animation: rise var(--t) ease-out both; }
main:focus { outline: none; }
.site-footer { padding: 1rem clamp(1rem, 3vw, 2rem); font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); background: var(--card); }
.site-footer p { margin: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- page parts ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .muted { margin: .25rem 0 0; }
.actions, .toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; padding: 0; margin: 0 0 .75rem; font-size: .9rem; }
.crumbs li + li::before { content: "/"; margin-right: .35rem; color: var(--line-strong); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(1rem, 2.4vw, 1.5rem); margin-bottom: 1.25rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.card-head.wrap { flex-wrap: wrap; }
.card-head .muted { margin: .15rem 0 0; }
.empty { color: var(--muted); padding: 1.5rem 0; text-align: center; margin: 0; }

.stats { list-style: none; padding: 0; margin: 0 0 1.25rem; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; display: flex; flex-direction: column; gap: .2rem; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: linear-gradient(90deg, var(--brand), #6cc49a); transform: scaleX(0); transform-origin: left; animation: grow 610ms 144ms ease-out forwards; }
.stat-num { font-size: 1.9rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { color: var(--muted); font-weight: 600; font-size: .92rem; }
@keyframes grow { to { transform: scaleX(1); } }

.db-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.db-tile { display: grid; gap: .2rem; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); background: #fbfdfc; transition: border-color var(--t), transform var(--t), box-shadow var(--t); min-height: 44px; }
.db-tile:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); color: var(--text); }
.db-name { font-weight: 700; color: var(--brand-deep); }
.db-meta { color: var(--muted); font-size: .9rem; }
.db-count { font-size: .88rem; font-weight: 600; }

.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .9rem 1.5rem; margin: 1rem 0 0; }
.dl-grid div.wide { grid-column: 1 / -1; }
.dl-grid dt { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dl-grid dd { margin: .15rem 0 0; white-space: pre-line; }
.details-card summary { cursor: pointer; font-weight: 700; color: var(--ink); min-height: 32px; display: flex; align-items: center; }

/* ---------- badges, flashes ---------- */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; vertical-align: middle; }
.badge-ok { background: var(--brand-tint); color: var(--brand-deep); }
.badge-muted { background: #eceff0; color: #4a5250; }
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.flash { margin: 0 0 1rem; padding: .8rem 1rem; border-radius: 8px; border: 1px solid; font-weight: 500; animation: rise var(--t) ease-out both; }
.flashes .flash { margin: 0; }
.flash ul { margin: .25rem 0 0; padding-left: 1.2rem; }
.flash p { margin: 0; }
.flash-success { background: var(--brand-tint); border-color: #b5dcc8; color: var(--brand-deep); }
.flash-error { background: var(--danger-tint); border-color: #f2b8b5; color: #8c1d14; }
.flash-warning { background: var(--warn-tint); border-color: #f0d49a; color: var(--warn); }
.flash-info { background: var(--info-tint); border-color: #b8d0ee; color: var(--info); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1.1rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background var(--t), border-color var(--t), transform 89ms, box-shadow var(--t); white-space: nowrap; }
.btn:hover { background: var(--bg); border-color: var(--ink); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.btn-danger { background: var(--card); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--brand-strong); }
.btn-ghost:hover { background: var(--brand-tint); border-color: transparent; color: var(--brand-deep); }
.btn-small { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.inline { display: inline; margin: 0; }

/* ---------- forms ---------- */
.form { display: grid; gap: 1rem; }
.form-grid { display: grid; gap: 1rem 1.25rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form.narrow { max-width: 30rem; }
.field { display: grid; gap: .35rem; align-content: start; min-width: 0; }
.field label, legend { font-weight: 600; color: var(--ink); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.small-link { font-size: .9rem; }
.req { font-size: .75rem; font-weight: 600; color: var(--muted); margin-left: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=tel], input[type=file], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .75rem; font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; transition: border-color var(--t), box-shadow var(--t);
}
input[type=file] { padding: .5rem; }
textarea { resize: vertical; min-height: 5rem; }
input:hover, select:hover, textarea:hover { border-color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-strong); box-shadow: 0 0 0 3px rgba(28, 102, 72, .25); }
[aria-invalid="true"] { border-color: var(--danger) !important; }
.hint { font-size: .88rem; color: var(--muted); margin: 0; }
.field-error { font-size: .9rem; color: var(--danger); font-weight: 600; margin: 0; }
.password-wrap { display: flex; gap: .4rem; }
.password-wrap input { flex: 1; }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem 1.25rem; margin: 0; }
fieldset.field { border: 0; padding: 0; margin: 0; }
.radio { display: inline-flex; align-items: center; gap: .4rem; margin-right: 1.25rem; min-height: 44px; font-weight: 500; }
.radio input, input[type=checkbox] { width: 1.5rem; height: 1.5rem; accent-color: var(--brand-strong); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .25rem; }
.inline-form { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form p { margin: 0; flex: 1 1 260px; }
.inline-form .field { flex: 1 1 260px; }
.danger-zone { border-color: #f2b8b5; }
.danger-zone h2 { color: var(--danger); }

.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; }
.filters .field { flex: 1 1 160px; }
.filters .field.grow { flex: 3 1 240px; }
.card .filters { margin-bottom: 1rem; }
.filter-actions { display: flex; gap: .4rem; }

/* ---------- menus (details/summary) ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; width: .45rem; height: .45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); margin-left: .35rem; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 16rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(16, 40, 30, .16); padding: .4rem; display: grid; animation: rise 144ms ease-out both; }
.menu-panel-wide { width: min(26rem, 90vw); padding: 1rem; }
.menu-panel a, .menu-btn { display: flex; align-items: center; min-height: 44px; padding: .5rem .8rem; border-radius: 6px; text-decoration: none; color: var(--ink); font: inherit; font-weight: 500; background: none; border: 0; text-align: left; cursor: pointer; }
.menu-panel a:hover, .menu-btn:hover:not([disabled]) { background: var(--brand-tint); }
.menu-btn[disabled] { color: var(--muted); cursor: not-allowed; }

/* ---------- tables ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; position: relative; }  /* contains absolutely positioned sr-only text */
.table-scroll:focus-visible { box-shadow: inset 0 0 0 3px var(--brand-strong); }
.card > form > .table-scroll, .card > .table-scroll { margin: 0 calc(-1 * clamp(1rem, 2.4vw, 1.5rem)); }
.table-card > .table-scroll { margin: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
.data-wide { min-width: 1100px; }
.data th, .data td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.data thead th { position: sticky; top: 0; background: #f0f4f2; color: var(--ink); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; z-index: 1; }
.data tbody tr { transition: background var(--t); }
.data tbody tr:nth-child(even) { background: #fafcfb; }
.data tbody tr:hover { background: var(--brand-tint); }
.data td.num, .data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data .check { width: 2.75rem; text-align: center; }
.data .check input { margin: .2rem 0 0; }
.data td.clip { max-width: 22ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: .3rem; min-height: 32px; }
.sort:hover { text-decoration: underline; color: var(--brand-deep); }
.sort-icon { font-size: .65rem; color: var(--brand-strong); }
.table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.5rem; padding: .9rem 0 0; }
.table-card .table-foot { padding: .9rem 1.25rem; }
.selection-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
#sel-count { font-weight: 600; color: var(--muted); margin-right: .25rem; }
.page-size { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.page-size select { width: auto; min-height: 36px; padding: .25rem .5rem; }
.pager ul { list-style: none; display: flex; flex-wrap: wrap; gap: .3rem; padding: 0; margin: 0; }
.pager a { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; padding: 0 .65rem; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; font-weight: 600; color: var(--ink); background: var(--card); }
.pager a:hover { border-color: var(--brand-strong); color: var(--brand-deep); }
.pager a.current { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.pager .gap { align-self: center; padding: 0 .2rem; color: var(--muted); }

/* ---------- sign-in pages ---------- */
body.auth { background: var(--card); }
.auth-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; }
.auth-brand { position: relative; overflow: hidden; color: #fff; background: radial-gradient(1200px 600px at -10% -10%, #1f7a55 0%, transparent 55%), radial-gradient(900px 700px at 110% 110%, #135a3e 0%, transparent 60%), linear-gradient(160deg, #134c35 0%, #0d3526 100%); display: flex; align-items: center; padding: clamp(2rem, 6vw, 5rem); }
.auth-brand::before { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 22px 22px; mask-image: linear-gradient(180deg, #000, transparent 85%); -webkit-mask-image: linear-gradient(180deg, #000, transparent 85%); }
.auth-brand::after { content: ""; position: absolute; width: 520px; height: 520px; right: -160px; top: -160px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); box-shadow: 0 0 0 60px rgba(255,255,255,.03), 0 0 0 140px rgba(255,255,255,.02); animation: breathe 6765ms ease-in-out infinite alternate; }
.auth-brand-inner { position: relative; max-width: 30rem; animation: rise 610ms 89ms ease-out both; }
.auth-brand .eyebrow { color: #bfe7d2; }
.auth-tagline { font-size: clamp(1.6rem, 3vw, 2.4rem); line-height: 1.2; font-weight: 700; letter-spacing: -.015em; margin: .5rem 0 1.5rem; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: .8rem; }
.auth-points li { position: relative; padding-left: 1.9rem; color: #e3f3ea; }
.auth-points li::before { content: ""; position: absolute; left: 0; top: .35em; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: rgba(255,255,255,.14) center / 60% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
@keyframes breathe { from { transform: scale(1); opacity: .8; } to { transform: scale(1.08); opacity: 1; } }
.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: clamp(1.5rem, 5vw, 4rem) 1.25rem; animation: none; }
.auth-card { width: 100%; max-width: 26rem; animation: rise 377ms ease-out both; }
.auth-logo { display: inline-block; margin-bottom: 1.75rem; }
.auth-logo img { height: 64px; width: auto; }
.auth-card h1 { font-size: 1.75rem; }
.auth-foot { margin-top: 2rem; font-size: .9rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: .5rem; position: sticky; top: 62px; z-index: 15; }
  .sidebar ul { display: flex; overflow-x: auto; position: static; gap: .25rem; }
  .sidebar a { white-space: nowrap; }
  .sidebar a.active { box-shadow: inset 0 -3px 0 var(--brand); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-brand { padding: 2rem 1.5rem; }
  .auth-tagline { font-size: 1.4rem; margin-bottom: 1rem; }
  .auth-points { display: none; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .brand-sub, .who-name { display: none; }
  .brand img { height: 36px; }
  .page-head { align-items: flex-start; }
  .toolbar { position: relative; width: 100%; }
  .menu { position: static; }
  .menu-panel, .menu-panel-wide { left: 0; right: 0; min-width: 0; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .stat::after { transform: scaleX(1); }
}
@media (prefers-contrast: more) {
  :root { --line: #6b7570; --muted: #2f3a35; --line-strong: #2f3a35; }
  .btn, input, select, textarea, .card, .stat, .db-tile { border-width: 2px; }
  a { text-decoration-thickness: 2px; }
}
@media print {
  .topbar-user, .sidebar, .toolbar, .filters, .table-foot, .danger-zone, .skip-link, .site-footer { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .data-wide { min-width: 0; font-size: .75rem; }
}

.forgot-link { margin-top: 1.25rem; }
