/* The look shared by the app and the admin: design tokens, buttons, and the top bar with the AGE logo and
   main menu (templates/_topbar.html). Loaded before app.css on app pages and before admin.css in the admin. */
:root {
  --primary: #3f51b5;
  --accent: #ff9800;
  --page: #f0f0f0;
  --paper: #ffffff;

  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --red-50: #fef2f2;
  --red-200: #fecaca;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-500: #22c55e;
  --green-800: #166534;
  --yellow-100: #fef9c3;
  --yellow-800: #854d0e;
  --orange-100: #ffedd5;
  --orange-800: #9a3412;

  /* the paper form keeps the shading of the controlled Word documents */
  --line: #808080;
  --bar: #dce6f1;
  --bar-ink: #1f3864;
  --edit: #fffbea;

  --ink: var(--gray-800);
  --muted: var(--gray-500);
  --line-soft: var(--gray-300);
  --link: var(--blue-700);

  --radius: 8px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);
  --ease: cubic-bezier(.4, 0, .2, 1);

  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
:root { --gutter: 12px; }
@media (min-width: 640px) {
  :root { --gutter: 16px; }
}
.icon { flex: none; vertical-align: -3px; }

/* top bar */
.topbar { display: flex; align-items: stretch; gap: 8px 24px; padding: 0 16px; background: var(--paper); box-shadow: var(--shadow-lg); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; padding: 10px 0; text-decoration: none; color: var(--primary); font-weight: 700; font-size: 1.15rem; }
.brand:hover { color: var(--primary); }
.brand img { height: 30px; }
.menu { display: flex; flex: 1; align-items: stretch; gap: 8px 24px; min-width: 0; }
.menu-toggle { display: none; }
.topbar nav { display: flex; flex: 1; gap: 4px; min-width: 0; overflow-x: auto; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 4px solid transparent; border-top: 4px solid transparent; color: var(--gray-600); text-decoration: none; font-weight: 500; white-space: nowrap; transition: all .15s var(--ease); }
.nav-link:hover { background: var(--gray-50); color: var(--gray-800); }
.nav-link[aria-current="page"] { background: var(--blue-50); border-bottom-color: var(--accent); color: var(--primary); }
.nav-icon { display: inline-flex; color: var(--gray-400); transition: all .15s var(--ease); }
.nav-link:hover .nav-icon { color: var(--gray-600); }
.nav-link[aria-current="page"] .nav-icon { color: var(--primary); }
.nav-group, .nav-desc, .nav-chevron { display: none; }
/* New NCMR: the main action, a button at the right of the bar */
.nav-new { order: 9; margin-left: auto; align-self: center; padding: 7px 14px; white-space: nowrap; }
.nav-new[aria-current="page"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent); }
.new-menu { flex: none; margin-left: auto; align-self: center; position: relative; }
.new-menu > summary { list-style: none; }
.new-menu > summary::-webkit-details-marker { display: none; }
.new-menu .nav-new { order: 0; margin: 0; }
.new-panel { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 300px; padding: 6px; background: var(--paper); border: 1px solid var(--gray-200); border-radius: var(--radius); box-shadow: var(--shadow-xl); }
.new-panel a { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: var(--radius); color: var(--gray-800); text-decoration: none; }
.new-panel a:hover { background: var(--blue-50); color: var(--primary); }
.new-panel .nav-icon { flex: none; width: 36px; height: 36px; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--blue-50); color: var(--primary); }
.new-panel strong { display: block; font-weight: 600; }
.new-panel small { display: block; color: var(--gray-500); font-size: .8rem; }
.topbar .nav-new-each { display: none; }
.scrim { display: none; }
.brand { order: 0; }
.menu { order: 1; }
.menu-toggle { order: 2; }

/* account: avatar button with a panel for the signed-in person */
.account { order: 3; position: relative; display: flex; align-items: center; }
.avatar-button { list-style: none; display: flex; align-items: center; padding: 4px; border-radius: 9999px; cursor: pointer; transition: all .15s var(--ease); }
.avatar-button::-webkit-details-marker { display: none; }
.avatar-button:hover, .account[open] .avatar-button { background: var(--gray-100); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 9999px; background: linear-gradient(to bottom right, #60a5fa, var(--blue-600)); color: #fff; font-weight: 600; font-size: .95rem; flex: none; }
.avatar.large { width: 44px; height: 44px; font-size: 1.1rem; }
.account-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; width: 288px; max-width: calc(100vw - 2 * var(--gutter)); padding: 16px; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow-xl); border: 1px solid var(--gray-200); }
.account-who { display: flex; align-items: center; gap: 12px; }
.account-who div { display: flex; flex-direction: column; min-width: 0; }
.account-who strong { color: var(--gray-800); font-weight: 600; }
.account-who div span { color: var(--gray-500); font-size: .85rem; overflow-wrap: anywhere; }
.account-roles { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--gray-200); }
.account-label { display: block; font-size: .75rem; font-weight: 500; color: var(--gray-500); margin-bottom: 4px; }
.account-roles ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.account-roles li { padding: 2px 10px; border-radius: var(--radius); background: var(--blue-50); color: var(--blue-800); font-size: .8rem; font-weight: 500; }
.account-panel form { margin: 16px 0 0; }
.account-panel .install-app { width: 100%; min-height: 40px; margin-top: 16px; font-size: .95rem; }
.account-panel .install-app + form { margin-top: 8px; }
[hidden] { display: none !important; }
.offline-icon { border-radius: 16px; margin-bottom: 12px; box-shadow: var(--shadow-md); }

/* menu badge: how many records wait on you */
.nav-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; margin-left: 4px; padding: 0 6px; border-radius: 9999px; background: var(--accent); color: var(--gray-800); font-size: .72rem; font-weight: 700; vertical-align: 1px; }

/* staging deployments only */
.staging-banner { padding: 6px var(--gutter); background: var(--yellow-100); color: var(--yellow-800); border-bottom: 1px solid #fde68a; font-size: .85rem; text-align: center; }

/* buttons */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border: 2px solid var(--gray-300); border-radius: var(--radius); background: var(--paper); color: var(--gray-700); text-decoration: none; font: inherit; font-weight: 500; line-height: 1.25; cursor: pointer; box-shadow: var(--shadow-sm); transition: all .15s var(--ease); }
.button:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--gray-800); box-shadow: var(--shadow); }
.button.primary { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.button.primary:hover { background: var(--blue-700); border-color: var(--blue-700); }
.button.danger { background: var(--red-500); border-color: var(--red-500); color: #fff; }
.button.danger:hover { background: var(--red-600); border-color: var(--red-600); }
.button.success { background: #16a34a; border-color: #16a34a; color: #fff; }
.button.success:hover { background: #15803d; border-color: #15803d; color: #fff; }
.button[disabled].success, .button[disabled].success:hover { background: #16a34a; border-color: #16a34a; }
.spinner { width: 16px; height: 16px; border: 2px solid rgb(255 255 255 / .45); border-top-color: #fff; border-radius: 9999px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.button.large { padding: 12px 24px; font-size: 1rem; }
.button[disabled], .button[disabled]:hover { opacity: .5; cursor: not-allowed; box-shadow: var(--shadow-sm); }
.button.primary[disabled]:hover { background: var(--blue-600); border-color: var(--blue-600); }
.account-panel .button.signout { width: 100%; min-height: 40px; font-size: .95rem; }
.button.signout { padding: 6px 12px; font-size: .875rem; }

/* smaller desktop screens: a slimmer menu so every link fits */
@media screen and (min-width: 1024px) and (max-width: 1599px) {
  .nav-link { padding: 0 10px; }
  .nav-link .nav-icon { display: none; }
}
@media screen and (min-width: 1024px) and (max-width: 1199px) {
  .brand > span { display: none; }
  .topbar { gap: 8px 12px; }
  .nav-link { padding: 0 8px; }
  .nav-new { padding: 7px 10px; }
}

/* phones and tablets: a menu button opens the menu over the page */
@media screen and (max-width: 1023px) {
  .topbar { padding: 0 var(--gutter); align-items: center; gap: 0 12px; }
  .brand img { height: 26px; }
  .menu-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 14px; border: 2px solid var(--gray-300); border-radius: var(--radius); background: var(--paper); color: var(--gray-700); font: inherit; font-weight: 500; cursor: pointer; transition: all .15s var(--ease); }
  .menu-toggle:hover { background: var(--gray-50); border-color: var(--gray-400); }
  .menu-toggle .when-open, .topbar.open .menu-toggle .when-closed { display: none; }
  .topbar.open .menu-toggle .when-open { display: inline-flex; }
  .menu-toggle span { display: inline-flex; }
  /* the menu drops down over the page, which dims behind it */
  .menu { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; gap: 0; padding: 12px var(--gutter) 16px; background: var(--paper); border-top: 1px solid var(--gray-200); box-shadow: var(--shadow-xl); max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px); overflow-y: auto; border-radius: 0 0 var(--radius-xl) var(--radius-xl); }
  .topbar:not(.js) .menu { position: static; flex-basis: 100%; margin: 0 calc(-1 * var(--gutter)); box-shadow: none; border-radius: 0; }
  .topbar.js:not(.open) .menu { display: none; }
  .topbar.open .menu { animation: menu-in .18s var(--ease); }
  .topbar.open + .scrim { display: block; position: fixed; inset: 0; z-index: 9; background: rgb(17 24 39 / .4); animation: scrim-in .18s var(--ease); }
  .topbar nav { display: grid; grid-template-columns: 1fr; gap: 2px; overflow: visible; }
  .new-menu { display: none; }
  .topbar .nav-new-each { display: inline-flex; }
  .nav-new { order: 0; margin: 0 0 8px; width: 100%; min-height: 48px; font-size: 1rem; }
  .nav-group { display: block; grid-column: 1 / -1; padding: 12px 12px 4px; font-size: .75rem; font-weight: 600; color: var(--gray-500); }
  .nav-link { display: grid; grid-template-columns: 40px 1fr 20px; align-items: center; gap: 12px; min-height: 60px; padding: 10px 12px; border: 0; border-radius: var(--radius); color: var(--gray-700); white-space: normal; }
  .nav-link:hover { background: var(--gray-50); }
  .nav-icon { width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: var(--radius); background: var(--blue-50); color: var(--primary); }
  .nav-link:hover .nav-icon { color: var(--primary); background: var(--blue-100); }
  .nav-text { display: flex; flex-direction: column; min-width: 0; }
  .nav-title { font-size: 1rem; font-weight: 600; color: var(--gray-800); }
  .nav-desc { display: block; font-size: .8rem; color: var(--gray-500); }
  .nav-chevron { display: flex; color: var(--gray-400); }
  .nav-link[aria-current="page"] { background: var(--blue-50); box-shadow: inset 4px 0 0 var(--accent); }
  .nav-link[aria-current="page"] .nav-icon { background: var(--primary); color: #fff; }
  .nav-link[aria-current="page"] .nav-title { color: var(--primary); }
  .nav-new[aria-current="page"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent); }
  .account { order: 1; margin-left: auto; }
  .menu-toggle { order: 2; }
  .menu { order: 3; }
  .account-panel .button.signout { min-height: 44px; }
}

@media screen and (max-width: 639px) {
  .brand { gap: 8px; font-size: 1rem; }
  .brand img { height: 22px; }
  /* phones: the menu button shows only its icon, still named "Menu" for screen readers */
  .topbar { gap: 0 8px; }
  .menu-toggle { padding: 8px 10px; }
  .menu-toggle .menu-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .avatar-button { padding: 2px; }
  .avatar-button .avatar { width: 32px; height: 32px; font-size: .85rem; }
}

@media screen and (max-width: 379px) {
  .brand { font-size: .95rem; gap: 6px; }
  .brand img { height: 20px; }
}

/* tablets: menu links two across */
@media screen and (min-width: 640px) and (max-width: 1023px) {
  .topbar nav { grid-template-columns: 1fr 1fr; column-gap: 8px; }
  .nav-new, .nav-home { grid-column: 1 / -1; }
}

@keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes scrim-in { from { opacity: 0; } }
/* the New and account menus drop in like the phone menu */
.new-menu[open] > .new-panel, .account[open] > .account-panel { animation: menu-in .18s var(--ease); }

/* Moving between pages, in the app and the admin: the browser crossfades the page body while the top bar holds
   still (a native cross-document view transition; browsers without it just load the page). A page that reloads
   itself, such as a sorted log, a posted comment or a form-editor move, swaps in place without the rise
   (site-head.js marks those "same-page"). */
@view-transition { navigation: auto; }
.topbar { view-transition-name: topbar; }
.staging-banner { view-transition-name: staging-banner; }
::view-transition-group(topbar), ::view-transition-group(staging-banner) { animation: none; }
::view-transition-old(root) { animation: page-out .12s cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: page-in .2s cubic-bezier(0, 0, .2, 1) .08s both; }
html:active-view-transition-type(same-page)::view-transition-old(root) { animation: page-out .08s linear both; }
html:active-view-transition-type(same-page)::view-transition-new(root) { animation: page-fade-in .12s linear both; }
@keyframes page-out { to { opacity: 0; } }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes page-fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .topbar .menu, .topbar + .scrim, .new-panel, .account-panel { animation: none !important; }
  ::view-transition-old(root) { animation: page-out .12s linear both !important; }
  ::view-transition-new(root) { animation: page-fade-in .12s linear both !important; }
}

@media print {
  .no-print, .topbar { display: none !important; }
}
