/* =====================================================================================================================
 * Real buttons and surfaces (RJL, 20 Nov 2026: "I want buttons to look and feel like real buttons and tablets look like
 * tablets and everything ... put in the most effort").
 * Loaded last, so it is the final word on look and feel. Based on the 20 Nov research report:
 *  - ONE light source for the whole portal: above and slightly left. Every highlight is on top, every shadow below.
 *  - Real shadows are layered (a tight dark contact shadow plus soft ambient ones) and tinted navy, not grey.
 *  - A real key goes DOWN fast (34 ms) and comes back UP with a small spring (260 ms, slight overshoot).
 *  - Nothing important happens on hover only; tablets have no hover, and a stuck hover would leave a key looking down.
 *  - Touch targets at least 48 px on touch screens (44 px small); emergency actions bigger.
 *  - Emergency screens (body.plain-mode: Evacuation, Roll call and drills, Fire and threat alerts) drop the decoration.
 *  - Reduced motion, increased contrast and Windows high-contrast all switch the decoration off.
 * Contrast (WCAG formula, worked 20 Nov 2026) is noted next to each colour pair that carries text.
 * ================================================================================================================== */

:root {
  /* The light: above, slightly left. Shadows fall down and a touch right. */
  --light-x: -1px;
  /* Three heights only. Tinted with the menu navy (hue 220) so they read as real shade, not grey haze. */
  --elev-1: 0 1px 1px rgba(10, 25, 55, .10), 0 2px 4px -1px rgba(10, 25, 55, .10);
  --elev-2: 0 1px 1px rgba(10, 25, 55, .10), 0 3px 6px -2px rgba(10, 25, 55, .14), 0 10px 20px -8px rgba(10, 25, 55, .22);
  --elev-3: 0 2px 2px rgba(10, 25, 55, .10), 0 8px 16px -6px rgba(10, 25, 55, .20), 0 24px 48px -16px rgba(10, 25, 55, .32);
  /* Key timing from the research: snap down, spring up. */
  --press-down: 34ms;
  --press-up: 260ms;
  --spring: cubic-bezier(.3, .7, .4, 1.5);
  --settle: cubic-bezier(.3, .7, .4, 1);
}

/* ---- Touch behaviour: no grey tap flash, no double-tap-zoom delay, no text selection while pressing --------------- */
html body:not(.signin-mode) :is(.button, .side-button, .dash-tab, .link-button, .stat-tile.is-link, .ts-pill, .ts-state) {
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}

/* ---- Keycap buttons: the existing caps, given real timing and a top light ------------------------------------------- */
/* Resting: cap sits on its 5 px edge; contact shadow under the edge, soft ambient shadow below that; highlight on top. */
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold)::before {
  transition: transform var(--press-up) var(--spring), box-shadow var(--press-up) var(--settle), filter .2s ease;
}
/* Hover is only for a real mouse, and only brightens the cap a little and lifts it 1 px: real keys do not sink when you
 * point at them. On tablets (no hover) this never applies, so a key can never look stuck down after a tap. */
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold):hover:not(:disabled)::before {
  transform: translateY(-1px);
  box-shadow: 0 6px 0 var(--key-edge, #bcc5d3), 0 11px 18px -3px rgba(10, 25, 55, .22), inset 0 1px rgba(255, 255, 255, .9);
  filter: brightness(1.03);
}
@media (hover: none), (pointer: coarse) {
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold):hover:not(:disabled)::before {
    transform: none; filter: none;
    box-shadow: 0 5px 0 var(--key-edge, #bcc5d3), 0 9px 15px -2px rgba(10, 25, 55, .2), inset 0 1px rgba(255, 255, 255, .9);
  }
}
/* Pressed (finger lands, mouse down, Space or Enter): cap travels the full 5 px onto its base in 34 ms. */
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold):is(:active, .is-down):not(:disabled)::before {
  transform: translateY(5px); filter: brightness(.97);
  box-shadow: 0 0 0 var(--key-edge, #bcc5d3), 0 1px 2px rgba(10, 25, 55, .25), inset 0 1px rgba(255, 255, 255, .6);
  transition: transform var(--press-down) linear, box-shadow var(--press-down) linear, filter var(--press-down) linear;
}
/* The words ride down with the cap, so the whole key moves as one piece. */
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold) { transition: color .15s ease; }
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold) { text-shadow: 0 1px 0 rgba(255, 255, 255, .35); }
html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold):is(:active, .is-down):not(:disabled) { padding-top: calc(.45rem + 5px); padding-bottom: calc(.45rem + 1px); }
html body:not(.signin-mode) .button.small:not(.link):not(.stat-tile):not(.hold):is(:active, .is-down):not(:disabled) { padding-top: calc(.35rem + 5px); padding-bottom: calc(.35rem + 1px); }
/* Edge colour per key, so the pressed and hover shadows above match each cap. */
html body:not(.signin-mode) .button:not(.secondary):not(.danger):not(.link):not(.stat-tile):not(.hold) { --key-edge: #1d6dc4; text-shadow: 0 -1px 0 rgba(4, 24, 47, .18); }
html body:not(.signin-mode) .button.danger:not(.link):not(.stat-tile):not(.hold) { text-shadow: 0 -1px 0 rgba(80, 10, 6, .35); }
html[data-theme="dark"] body:not(.signin-mode) .button.secondary:not(.link):not(.stat-tile):not(.hold) { --key-edge: #080b11; text-shadow: none; }

/* Danger key: the old red (#f0645a at the top) gave white writing only 3.15:1. This red keeps 4.8:1 or better across the
 * whole cap (top #d13a2f 4.8:1, bottom #a51d13 7.5:1), and still reads as danger next to the blue key. */
html body:not(.signin-mode) .button.danger:not(.link):not(.stat-tile):not(.hold) { --key-edge: #6e1209; }
html body:not(.signin-mode) .button.danger:not(.link):not(.stat-tile):not(.hold)::before {
  background: linear-gradient(180deg, #d13a2f, #a51d13);
  box-shadow: 0 5px 0 var(--key-edge), 0 9px 18px -2px rgba(110, 18, 9, .35), inset 0 1px rgba(255, 255, 255, .35);
}

/* ---- Hold-to-confirm (Help needed, Start evacuation): a heavy key that sinks while held ------------------------------ */
html body:not(.signin-mode) .button.hold {
  transition: transform var(--press-up) var(--spring), box-shadow var(--press-up) var(--settle);
  box-shadow: 0 6px 0 rgba(10, 25, 55, .35), var(--elev-2);
}
html body:not(.signin-mode) .button.hold.holding { transform: translateY(5px); box-shadow: 0 1px 0 rgba(10, 25, 55, .35), var(--elev-1); transition-duration: var(--press-down); }

/* ---- Side menu, tabs and small controls feel pressable too ----------------------------------------------------------- */
html body:not(.signin-mode) :is(.side-button, .dash-tab, .link-button) { transition: transform var(--press-up) var(--spring); }
html body:not(.signin-mode) :is(.side-button, .dash-tab, .link-button):is(:active, .is-down) { transform: translateY(1px) scale(.985); transition-duration: var(--press-down); }
html body:not(.signin-mode) :is(.ts-pill, .ts-state):is(:active, .is-down) { transform: translateY(1px) scale(.98); transition: transform var(--press-down) linear; }

/* ---- Touch screens: bigger targets (WCAG 2.5.5 level, Apple and Google guidance) -------------------------------------- */
@media (pointer: coarse) {
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile):not(.hold) { min-height: 52px; }
  html body:not(.signin-mode) .button.small:not(.link):not(.stat-tile):not(.hold) { min-height: 48px; }
  html body:not(.signin-mode) :is(.side-button, .dash-tab, .link-button, .ts-pill, .ts-state) { min-height: 44px; }
  html body:not(.signin-mode) .button.hold { min-height: 64px; }
}

/* ---- Plain mode: emergency screens. No 3D, no motion, solid high-contrast keys, big targets --------------------------
 * Contrast: white on #1452a8 7.5:1 / white on #b42318 6.6:1 / #0b1220 on #ffffff 18.7:1. */
body.plain-mode :is(.stat-tile, .stat-tile *, .button, .button::before, .side-button, .dash-tab) { transition: none !important; animation: none !important; }
body.plain-mode .stat-tile.is-link { transform: none !important; }
body.plain-mode .stat-tile.is-link::after { display: none !important; }
html body.plain-mode .button:not(.link):not(.stat-tile)::before { content: none !important; }
html body.plain-mode .button:not(.link):not(.stat-tile) {
  background: #ffffff !important; color: #0b1220 !important; border: 2px solid #0b1220 !important; border-radius: 10px;
  box-shadow: none !important; text-shadow: none !important; padding: .6rem 1.2rem !important; min-height: 56px; font-weight: 750;
  transform: none !important;
}
html body.plain-mode .button:not(.secondary):not(.danger):not(.link):not(.stat-tile) { background: #1452a8 !important; border-color: #1452a8 !important; color: #ffffff !important; }
html body.plain-mode .button.danger:not(.link):not(.stat-tile) { background: #b42318 !important; border-color: #b42318 !important; color: #ffffff !important; }
html body.plain-mode .button:not(.link):not(.stat-tile):is(:active, .is-down) { outline: 4px solid #0b1220; outline-offset: 2px; }
html body.plain-mode .button.hold { min-height: 72px; font-size: 1.1rem; }

/* ---- Increased contrast and Windows high contrast: flat, outlined, system colours win -------------------------------- */
@media (prefers-contrast: more) {
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile)::before { background: none !important; box-shadow: none !important; }
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile) { border: 2px solid currentColor !important; text-shadow: none !important; }
  html body:not(.signin-mode) .stat-tile.is-link::after { display: none; }
}
@media (forced-colors: active) {
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile)::before { content: none !important; }
  html body:not(.signin-mode) .button:not(.link):not(.stat-tile) { border: 2px solid ButtonText !important; background: ButtonFace !important; color: ButtonText !important; forced-color-adjust: auto; }
  html body:not(.signin-mode) .stat-tile.is-link { transform: none !important; }
}

/* ---- Reduced motion: keys still change state (colour, depth) but nothing slides or springs ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  html body:not(.signin-mode) .button::before,
  html body:not(.signin-mode) :is(.button, .side-button, .dash-tab, .link-button, .ts-pill, .ts-state) { transition: none !important; }
  html body:not(.signin-mode) :is(.side-button, .dash-tab, .link-button, .ts-pill, .ts-state):is(:active, .is-down) { transform: none; }
}

/* =====================================================================================================================
 * Real surfaces (RJL, 20 Nov 2026, part 3). Panels, their headers, text boxes and dialogs share the same light as the
 * keys: above and slightly left. Surfaces are a touch brighter at the top, carry a fine paper grain (surface-grain.png,
 * generated for this portal, ~1% visible), a 1 px bevel highlight on the top edge, and sit at one of three heights.
 * Text boxes are recessed, like a slot cut into the panel: darker at the top inside edge where the light cannot reach.
 * Text contrast is unchanged: grain and gradients stay within 2% of the old white and navy.
 * ================================================================================================================== */
html:not([data-theme="dark"]) body:not(.signin-mode) {
  background-color: #eef2f7;
  background-image: radial-gradient(1400px 800px at 12% -12%, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 62%);
  background-attachment: fixed;
}
html:not([data-theme="dark"]) body:not(.signin-mode) #workspace { background: transparent; }

/* Panels: raised card at height 2, lit from above. */
html:not([data-theme="dark"]) body:not(.signin-mode) #workspace .panel {
  background-color: #ffffff;
  background-image: url("/operations/assets/surface-grain.png"), linear-gradient(180deg, #ffffff 0%, #fafbfd 100%);
  border: 1px solid rgba(10, 25, 55, .09); border-top-color: rgba(10, 25, 55, .05);
  box-shadow: inset 0 1px 0 #ffffff, var(--elev-2);
}
/* Panel header: the navy bar, brighter at the top edge where the light hits, with a crisp bevel and a shadow line under it. */
html body:not(.signin-mode) #workspace .panel > .panel-head {
  background-image: linear-gradient(180deg, #17346a 0%, #0e2550 45%, #071530 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -1px 0 rgba(0, 0, 0, .35), 0 2px 3px -1px rgba(7, 21, 48, .35);
}

/* Text boxes and drop-downs: recessed wells. */
html:not([data-theme="dark"]) body:not(.signin-mode) :is(.field input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), .field select, .field textarea, .picker select) {
  background-color: #ffffff;
  background-image: linear-gradient(180deg, #f1f4f9 0%, #ffffff 38%);
  border: 1px solid #c3cddb; border-top-color: #aab6c7; border-bottom-color: #d9e0ea;
  box-shadow: inset 0 2px 3px rgba(10, 25, 55, .10), 0 1px 0 rgba(255, 255, 255, .9);
  transition: box-shadow .15s ease, border-color .15s ease;
}
html:not([data-theme="dark"]) body:not(.signin-mode) :is(.field input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), .field select, .field textarea, .picker select):focus-visible {
  border-color: #2447d6; outline: none;
  box-shadow: inset 0 2px 3px rgba(10, 25, 55, .10), 0 0 0 3px rgba(36, 71, 214, .28);
}

/* Dialogs float highest (height 3). */
html body:not(.signin-mode) dialog.form-dialog { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), var(--elev-3); }
html body:not(.signin-mode) dialog.form-dialog::backdrop { background: rgba(7, 21, 48, .38); backdrop-filter: blur(2px); }

/* Dark theme: the same light, quieter. A faint top bevel and deeper shadows; no grain. */
html[data-theme="dark"] body:not(.signin-mode) #workspace .panel {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 1px 1px rgba(0, 0, 0, .35), 0 10px 22px -10px rgba(0, 0, 0, .6);
}
html[data-theme="dark"] body:not(.signin-mode) :is(.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea) {
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .45), 0 1px 0 rgba(255, 255, 255, .05);
}

/* Plain mode, increased contrast and Windows high contrast: flat surfaces, no grain, no gradients. */
body.plain-mode #workspace .panel { background-image: none !important; }
@media (prefers-contrast: more) {
  html body:not(.signin-mode) #workspace .panel { background-image: none !important; border: 2px solid currentColor !important; }
  html body:not(.signin-mode) :is(.field input, .field select, .field textarea) { background-image: none !important; border: 2px solid currentColor !important; }
}
@media (forced-colors: active) {
  html body:not(.signin-mode) #workspace .panel, html body:not(.signin-mode) #workspace .panel > .panel-head { background-image: none !important; box-shadow: none !important; }
}
