/*
 * PSBLA desk theme. Loaded by every desk page through views/partials/shared-styles.ejs.
 *
 * The desk pages are written with stock Tailwind 2 classes (bg-white, text-gray-700, bg-brand-primary).
 * This file points those classes at the storefront's colors, so one file restyles every page and
 * gives every page dark mode. Selectors start with `html` so they win over the Tailwind CDN file
 * no matter which one loads first.
 *
 * Colors are "R G B" so an alpha can be added: rgb(var(--ink) / 0.6).
 * Keep the values in step with frontend/src/index.css and frontend/tailwind.config.js.
 */

:root {
  --ink: 9 38 24; /* text, solid buttons */
  --ink-hover: 20 99 58;
  --paper: 247 240 222; /* page background */
  --surface: 253 249 238; /* cards, inputs */
  --fill: 250 244 229; /* table heads, soft fills on a card */
  --fill-strong: 232 219 190;
  /* Pouch colors. These never flip. */
  --pine: 10 61 36; /* text on gold */
  --pine-deep: 5 36 20; /* nav bar */
  --gold: 212 164 55; /* loud buttons, icon chips, highlights on the nav */
  --ok: 31 122 72; /* success notes */
  --alert: 255 90 54; /* warnings and errors */
  --accent-text: var(--ink); /* links and highlights. Gold on the dark green nav. */
  /* How strong the light grey text steps are. They flip on the dark nav, where light text is the main text. */
  --a300: 0.3;
  --a400: 0.45;
  --a500: 0.6;
  color-scheme: light;
}

/* The `dark` class is set by the script in views/partials/shared-styles.ejs. */
html.dark {
  --ink: 247 240 222;
  --ink-hover: 232 219 190;
  --paper: 4 26 15;
  --surface: 8 46 27;
  --fill: 12 56 33;
  --fill-strong: 20 76 46;
  --ok: 134 199 152;
  color-scheme: dark;
}

/* The nav bars stay dark green in both modes, like the storefront footer. */
html .bg-black {
  --ink: 247 240 222;
  --accent-text: var(--gold);
  --a300: 0.8;
  --a400: 0.6;
  --a500: 0.5;
  background-color: rgb(var(--pine-deep));
  color-scheme: dark;
}

html nav.bg-black {
  --tw-shadow: 0 0 #0000;
  box-shadow: 0 1px 0 rgb(var(--gold) / 0.35);
}

/* ---------- Page ---------- */

html *,
html ::before,
html ::after {
  border-color: rgb(var(--ink) / 0.12);
}

html body {
  background-color: rgb(var(--paper));
  color: rgb(var(--ink));
  font-family: Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html body.bg-gray-50,
html body.bg-gray-100 {
  background-color: rgb(var(--paper));
}

/* ---------- Backgrounds ---------- */

html .bg-white,
html .hover\:bg-white:hover {
  background-color: rgb(var(--surface));
}

html .bg-gray-50,
html .bg-gray-100,
html .hover\:bg-gray-50:hover {
  background-color: rgb(var(--fill));
}

html .bg-gray-200 {
  background-color: rgb(var(--fill-strong));
}

html .bg-black .bg-gray-900,
html .bg-black .hover\:bg-gray-900:hover {
  background-color: rgb(255 255 255 / 0.1);
}

html .bg-black .hover\:bg-gray-700:hover {
  background-color: rgb(255 255 255 / 0.2);
}

html .bg-black .bg-gray-700 {
  background-color: rgb(255 255 255 / 0.2);
}

html .bg-black .border-gray-700,
html .bg-black .border-gray-800,
html .bg-black.border-gray-700,
html .bg-black.border-gray-800 {
  border-color: rgb(255 255 255 / 0.12);
}

/* ---------- Text ---------- */

html .text-gray-900,
html .text-gray-800,
html .hover\:text-gray-800:hover,
html .hover\:text-gray-600:hover {
  color: rgb(var(--ink));
}

html .text-gray-700 {
  color: rgb(var(--ink) / 0.82);
}

html .text-gray-600 {
  color: rgb(var(--ink) / 0.7);
}

html .text-gray-500 {
  color: rgb(var(--ink) / var(--a500));
}

html .text-gray-400 {
  color: rgb(var(--ink) / var(--a400));
}

html .text-gray-300 {
  color: rgb(var(--ink) / var(--a300));
}

html ::placeholder {
  color: rgb(var(--ink) / 0.45);
  opacity: 1;
}

/* ---------- Borders and rings ---------- */

html .border-gray-100 {
  border-color: rgb(var(--ink) / 0.08);
}

html .border-gray-200,
html .divide-gray-200 > :not([hidden]) ~ :not([hidden]) {
  border-color: rgb(var(--ink) / 0.12);
}

html .border-gray-300,
html .hover\:border-gray-300:hover {
  border-color: rgb(var(--ink) / 0.18);
}

html .ring-gray-300 {
  --tw-ring-color: rgb(var(--ink) / 0.18);
}

/* ---------- Brand classes (were the old green) ---------- */

html .bg-brand-primary,
html .bg-brand-secondary,
html .bg-brand-dark {
  background-color: rgb(var(--ink));
  color: rgb(var(--paper));
}

html :is(.bg-brand-primary, .bg-brand-secondary, .bg-brand-dark).text-white,
html :is(.bg-brand-primary, .bg-brand-secondary, .bg-brand-dark) .text-white {
  color: rgb(var(--paper));
}

html :is(.bg-brand-primary, .bg-brand-secondary, .bg-brand-dark):hover,
html .hover\:bg-brand-primary:hover,
html .hover\:bg-brand-secondary:hover,
html .hover\:bg-brand-dark:hover {
  background-color: rgb(var(--ink-hover));
  color: rgb(var(--paper));
}

html .text-brand-primary,
html .text-brand-secondary,
html .text-brand-dark,
html .hover\:text-brand-primary:hover,
html .hover\:text-brand-secondary:hover,
html .group:hover .group-hover\:text-brand-primary {
  color: rgb(var(--accent-text));
}

/* Text links on a page (not in the nav) get the storefront's underline. */
html a:is(.text-brand-primary, .text-brand-secondary):not(nav a) {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

/* Icon chips: a loud fill with dark content, like the storefront's trust marks. */
html .bg-brand-light {
  background-color: rgb(var(--gold));
  color: rgb(var(--pine));
}

html .bg-brand-light * {
  color: rgb(var(--pine));
}

html .border-brand-primary,
html .focus\:border-brand-primary:focus {
  border-color: rgb(var(--ink));
}

html .ring-brand-primary,
html .focus\:ring-brand-primary:focus,
html .focus-within\:ring-brand-primary:focus-within,
html .focus\:ring-indigo-500:focus {
  --tw-ring-color: rgb(var(--ink));
}

/* ---------- Shape and weight ---------- */

/* Buttons are pills. */
html :is(button, a, input[type='submit'], label.cursor-pointer):is(.rounded, .rounded-md, .rounded-lg) {
  border-radius: 9999px;
}

html :is(button, a.inline-flex, input[type='submit']) {
  font-weight: 700;
}

/* Cards are round and flat, with a hairline in place of the drop shadow. */
html :is(div, section, form, ul, li, article, table).bg-white:is(.rounded-md, .rounded-lg, .rounded-xl, .sm\:rounded-md, .sm\:rounded-xl),
html .card {
  border-radius: 1.5rem;
}

/* Form pages wrap a white panel in a shadowed box. The box carries the card shape. */
html .shadow.sm\:rounded-md.sm\:overflow-hidden {
  border-radius: 1.5rem;
  overflow: hidden;
  border: 1px solid rgb(var(--ink) / 0.08);
}

html :is(.shadow-sm, .shadow, .shadow-md, .shadow-lg, .shadow-xl, .hover\:shadow-md:hover) {
  --tw-shadow: 0 0 #0000;
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

html .bg-white:is(.shadow-sm, .shadow, .shadow-md, .shadow-lg, .shadow-xl):not(button, a, input, select, textarea) {
  --tw-shadow: 0 0 0 1px rgb(var(--ink) / 0.08);
}

html :is(h1, h2, .page-title) {
  font-weight: 900 !important;
  letter-spacing: -0.02em;
}

html h3 {
  font-weight: 800 !important;
  letter-spacing: -0.01em;
}

html th {
  font-weight: 700;
}

/* ---------- Form fields ---------- */

html :is(input:not([type='checkbox'], [type='radio'], [type='file'], [type='hidden'], [type='range'], [type='submit'], [type='button'], [type='color']), select, textarea) {
  background-color: rgb(var(--surface));
  color: rgb(var(--ink));
  border-color: rgb(var(--ink) / 0.18);
}

html :is(input:not([type='checkbox'], [type='radio'], [type='file'], [type='hidden'], [type='range'], [type='submit'], [type='button'], [type='color']), select, textarea):not(.rounded-l-md, .rounded-r-md, .rounded-none, .rounded-full) {
  border-radius: 1rem;
}

html :is(input[type='checkbox'], input[type='radio']) {
  accent-color: rgb(var(--ink));
}

html :is(input, select, textarea):focus-visible {
  outline: 2px solid rgb(var(--ink));
  outline-offset: 1px;
}

/* Bare inputs that sit inside a styled box (the tags field) keep no fill and no ring of their own. */
html :is(input, select, textarea).bg-transparent {
  background-color: transparent;
}

html :is(input, select, textarea).border-none:focus-visible {
  outline: none;
}

html :is(a, button, summary):focus-visible {
  outline: 2px solid rgb(var(--ink));
  outline-offset: 2px;
}

html ::-webkit-scrollbar-thumb,
html ::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--ink) / 0.3);
}

/* ---------- Status colors in dark mode ---------- */

html.dark :is(.bg-red-50, .bg-red-100, .hover\:bg-red-50:hover, .hover\:bg-red-100:hover) {
  background-color: rgb(var(--alert) / 0.16);
}

html.dark :is(.text-red-500, .text-red-700, .text-red-800, .hover\:text-red-500:hover, .hover\:text-red-600:hover, .hover\:text-red-700:hover) {
  color: #ff9d87;
}

html.dark :is(.border-red-200, .border-red-400, .border-red-500) {
  border-color: rgb(var(--alert) / 0.45);
}

html.dark :is(.bg-green-50, .bg-green-100) {
  background-color: rgb(var(--ok) / 0.14);
}

html.dark :is(.text-green-700, .text-green-800) {
  color: rgb(var(--ok));
}

html.dark .border-green-200 {
  border-color: rgb(var(--ok) / 0.35);
}

html.dark .bg-blue-100 {
  background-color: rgb(96 165 250 / 0.18);
}

html.dark .text-blue-800 {
  color: #93c5fd;
}

html.dark .bg-purple-100 {
  background-color: rgb(192 132 252 / 0.18);
}

html.dark .text-purple-800 {
  color: #d8b4fe;
}

/* ---------- Shared classes the older pages use ---------- */

html .card {
  border-radius: 1.5rem;
  overflow: hidden;
}

/* Alerts are cards with their own color (bg-red-50, bg-green-50), so only plain cards get the surface. */
html .card:not([class*='bg-']) {
  background-color: rgb(var(--surface));
  border: 1px solid rgb(var(--ink) / 0.1);
}

html .card:hover {
  box-shadow: none;
}

.card-body {
  padding: 1.5rem;
}

.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: rgb(var(--ink) / 0.82);
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid rgb(var(--ink) / 0.18);
}

html :is(.btn, .btn-primary, .btn-secondary, .btn-danger) {
  border-radius: 9999px;
  font-weight: 700;
}

html.dark .btn-danger {
  background-color: rgb(var(--alert) / 0.16);
  border-color: rgb(var(--alert) / 0.45);
  color: #ff9d87;
}

html :is(.tag-container, .category-section) {
  border-radius: 1rem;
}

@media (max-width: 640px) {
  .mobile-full-width {
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: 4px;
}

/* Colors flip in one step when the mode changes, with no half-faded buttons. */
.theme-switching * {
  transition: none !important;
}

/* ---------- Desk parts (for pages written against this theme) ---------- */

.desk-title {
  font-size: 1.875rem;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.desk-card {
  background-color: rgb(var(--surface));
  border-radius: 1.5rem;
  padding: 1.25rem;
  box-shadow: 0 0 0 1px rgb(var(--ink) / 0.06);
}

.desk-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 600;
}

html .desk-input {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  border-width: 1px;
  border-style: solid;
  font-size: 1rem;
}

.desk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.625rem 1.25rem;
  border: 1px solid transparent;
  border-radius: 9999px;
  background-color: rgb(var(--ink));
  color: rgb(var(--paper));
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: background-color 180ms, border-color 180ms, transform 180ms;
}

.desk-btn:hover {
  background-color: rgb(var(--ink-hover));
}

.desk-btn:active {
  transform: scale(0.98);
}

.desk-btn--block {
  display: flex;
  width: 100%;
}

.desk-btn--quiet {
  background-color: rgb(var(--surface));
  color: rgb(var(--ink));
  border-color: rgb(var(--ink) / 0.18);
}

.desk-btn--quiet:hover {
  background-color: rgb(var(--surface));
  border-color: rgb(var(--ink) / 0.45);
}

.desk-btn--loud {
  background-color: rgb(var(--gold));
  color: rgb(var(--pine));
}

.desk-btn--loud:hover {
  background-color: #ecc25c;
}

.desk-btn--warn {
  background-color: rgb(var(--alert));
  color: rgb(var(--pine));
}

.desk-btn--warn:hover {
  background-color: #ff7355;
}

/* Filter pills, like the storefront's category chips. */
.desk-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border: 1px solid rgb(var(--ink) / 0.12);
  border-radius: 9999px;
  background-color: rgb(var(--surface));
  font-weight: 600;
}

.desk-chip:hover {
  border-color: rgb(var(--ink) / 0.35);
}

.desk-chip[aria-current='true'] {
  background-color: rgb(var(--ink));
  border-color: rgb(var(--ink));
  color: rgb(var(--paper));
}

.desk-chip__count {
  font-weight: 400;
  opacity: 0.65;
}

.desk-link {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.desk-muted {
  color: rgb(var(--ink) / 0.6);
}

.desk-note {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  font-weight: 600;
}

.desk-note--ok {
  background-color: rgb(var(--ok) / 0.16);
  color: rgb(var(--pine));
}

html.dark .desk-note--ok {
  background-color: rgb(var(--ok) / 0.14);
  color: rgb(var(--ok));
}

.desk-note--error {
  background-color: rgb(var(--alert) / 0.18);
  color: #a32410;
}

html.dark .desk-note--error {
  color: #ff9d87;
}

/* Round light/dark button. */
.desk-theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  border-radius: 9999px;
  background-color: rgb(var(--ink) / 0.08);
  color: rgb(var(--ink));
  transition: background-color 180ms;
}

.desk-theme-toggle:hover {
  background-color: rgb(var(--ink) / 0.14);
}

.desk-theme-toggle__sun,
html.dark .desk-theme-toggle__moon {
  display: none;
}

html.dark .desk-theme-toggle__sun {
  display: block;
}

/* ---------- Store desk shell ---------- */

.desk-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: none;
  width: 16rem;
  flex-direction: column;
  background-color: rgb(var(--surface));
  border-right: 1px solid rgb(var(--ink) / 0.1);
}

.desk-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 3.5rem;
  padding: 0 0.75rem;
  background-color: rgb(var(--surface));
  border-bottom: 1px solid rgb(var(--ink) / 0.1);
}

.desk-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  background-color: rgb(var(--paper));
  overflow: auto;
}

.desk-drawer.is-open {
  display: block;
}

.desk-nav-label {
  margin: 1.25rem 0.75rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(var(--ink) / 0.45);
}

.desk-nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin: 0.125rem 0.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: 9999px;
  font-weight: 600;
  color: rgb(var(--ink) / 0.78);
}

.desk-nav-link:hover {
  background-color: rgb(var(--ink) / 0.06);
  color: rgb(var(--ink));
}

.desk-nav-link[aria-current='page'] {
  background-color: rgb(var(--ink));
  color: rgb(var(--paper));
}

.desk-nav-link svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}

/* The old pages pad for a top bar. The sidebar replaces that bar on a wide screen. */
body:has(.desk-sidebar) .pt-24,
body:has(.desk-sidebar) .pt-28 {
  padding-top: 4.75rem;
  padding-bottom: 1.5rem;
}

@media (min-width: 768px) {
  .desk-sidebar {
    display: flex;
  }

  .desk-topbar,
  .desk-drawer {
    display: none;
  }

  body:has(.desk-sidebar) {
    padding-left: 16rem;
  }

  body:has(.desk-sidebar) .pt-24,
  body:has(.desk-sidebar) .pt-28 {
    padding-top: 2rem;
  }
}

body.desk-nav-open {
  overflow: hidden;
}

@media print {
  .desk-sidebar,
  .desk-topbar,
  .desk-drawer {
    display: none !important;
  }

  body:has(.desk-sidebar) {
    padding-left: 0 !important;
  }
}

/* Paper is white, so print in light colors even from dark mode. */
@media print {
  html,
  html.dark {
    --ink: 17 17 17;
    --ink-hover: 42 42 42;
    --paper: 255 255 255;
    --surface: 255 255 255;
    --fill: 255 255 255;
    --fill-strong: 232 232 234;
    color-scheme: light;
  }
}
