/* ==========================================================================
   HITT Ops — Design tokens & base styles
   Colours extracted from "HITT corporate colours.jpg"
   ========================================================================== */

:root {
  /* Corporate palette */
  --hitt-ink:        #171717;   /* near-black, primary text / wordmark */
  --hitt-charcoal:   #211916;   /* darkest swatch, deep backgrounds */
  --hitt-teal:       #5C757C;   /* primary brand accent */
  --hitt-sage:       #ABAF96;   /* secondary accent / muted UI */
  --hitt-cream:      #DAD4B2;   /* light surface tint */
  --hitt-olive:      #B3B07D;   /* secondary surface */
  --hitt-amber:      #BC9A1C;   /* call-to-action / highlight */

  /* Semantic tokens (light theme, default) */
  --bg-app:          #F7F6F1;
  --bg-surface:      #FFFFFF;
  --bg-surface-alt:  var(--hitt-cream);
  --bg-header:       var(--hitt-ink);
  --text-primary:    var(--hitt-charcoal);
  --text-secondary:  #5A5650;
  --text-inverse:    #FFFFFF;
  --border-subtle:   #E4E0D4;
  --accent:          var(--hitt-amber);
  --accent-hover:    #A5870F;
  --accent-contrast: #1A1300;
  --brand:           var(--hitt-teal);
  --brand-hover:     #4A6167;
  --success:         #6E8F5A;
  --warning:         var(--hitt-amber);
  --danger:          #B24A3A;
  --focus-ring:      #7FA0A8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(23,23,23,0.06), 0 1px 1px rgba(23,23,23,0.04);
  --shadow-md: 0 4px 12px rgba(23,23,23,0.08), 0 2px 4px rgba(23,23,23,0.06);
  --shadow-lg: 0 12px 32px rgba(23,23,23,0.14);

  --font-sans: "Calibri", "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  --header-height: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app:          #15140F;
    --bg-surface:      #201E19;
    --bg-surface-alt:  #2A2820;
    --bg-header:       var(--hitt-charcoal);
    --text-primary:    #F1EFE6;
    --text-secondary:  #B9B4A5;
    --text-inverse:    #FFFFFF;
    --border-subtle:   #38352C;
    --accent:          var(--hitt-amber);
    --accent-hover:    #D4AE24;
    --accent-contrast: #1A1300;
    --brand:           #7C99A0;
    --brand-hover:     #93AEB4;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.55);
  }
}

/* ==========================================================================
   Admin-selected colour theme (Settings -> Customizations -> "Look and
   feel"). "teal" is the block above — the shipped HITT palette, no override
   needed, so an instance that never touches this looks exactly as before.
   Each other preset restates the two brand hues (--hitt-teal / --hitt-amber
   — most of the app's CSS reads these directly, and so does the override
   block in css/projects.css for the one page still on compiled Tailwind)
   plus the handful of hover/focus tokens the base :root sets as fixed
   values rather than deriving from those hues. Dark mode needs its own
   --brand/--brand-hover per preset too — the base dark block already hard-
   codes those independent of --hitt-teal (for contrast against a dark
   background), so overriding --hitt-teal alone wouldn't reach them.
   See public/js/branding.js for how <html data-theme="…"> gets set.
   ========================================================================== */
:root[data-theme="ocean"] {
  --hitt-teal:    #2C6E8E;
  --hitt-amber:   #D96A4C;
  --brand-hover:  #20536B;
  --accent-hover: #B8543A;
  --focus-ring:   #8FBFD4;
}
:root[data-theme="forest"] {
  --hitt-teal:    #3F6B4A;
  --hitt-amber:   #B8912A;
  --brand-hover:  #2E4F37;
  --accent-hover: #93731E;
  --focus-ring:   #9BC2A7;
}
:root[data-theme="slate"] {
  --hitt-teal:    #495468;
  --hitt-amber:   #7C5CBF;
  --brand-hover:  #37404F;
  --accent-hover: #644999;
  --focus-ring:   #A9B3C4;
}
:root[data-theme="burgundy"] {
  --hitt-teal:    #7A3B42;
  --hitt-amber:   #B98A4A;
  --brand-hover:  #5E2E33;
  --accent-hover: #93703A;
  --focus-ring:   #C79FA3;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="ocean"]    { --brand: #5FA0BE; --brand-hover: #7BB4CF; --accent-hover: #E68763; --focus-ring: #8FBFD4; }
  :root[data-theme="forest"]   { --brand: #6FA37D; --brand-hover: #87B896; --accent-hover: #D4AE3C; --focus-ring: #9BC2A7; }
  :root[data-theme="slate"]    { --brand: #8B96AC; --brand-hover: #A3ACBE; --accent-hover: #9B7ED9; --focus-ring: #A9B3C4; }
  :root[data-theme="burgundy"] { --brand: #B87D82; --brand-hover: #C89599; --accent-hover: #D9AD73; --focus-ring: #C79FA3; }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand); }
img { max-width: 100%; display: block; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* Some browsers' UA stylesheet gives placeholder text its own (often
   italic/serif) default instead of inheriting the field's own font — pin it
   to match the rest of the UI everywhere, not just where a page happens to
   style a particular input. */
input::placeholder, textarea::placeholder {
  font-family: inherit;
  font-style: normal;
  color: var(--text-secondary);
  opacity: 1;
}
input::-ms-input-placeholder, textarea::-ms-input-placeholder {
  font-family: inherit;
  font-style: normal;
  color: var(--text-secondary);
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .05s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-primary);
}
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Square icon-only button — the "Refresh from database" control, matching the
   Kanban page's #btnRefresh. */
.btn-icon {
  padding: 0;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.btn-icon:hover { background: var(--bg-surface-alt); color: var(--brand); }
.btn-icon svg { width: 1rem; height: 1rem; }

/* ---------- Top App Header (shared across pages) ---------- */
.app-header {
  height: var(--header-height);
  background: var(--bg-header);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text-inverse);
}
.app-header__brand .dot { color: var(--accent); }
.app-header__logo {
  height: 34px;
  width: auto;
  background: #fff;
  border-radius: 4px;
  padding: 3px 7px;
}
.app-header__nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}
.app-header__nav a {
  position: relative;
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.4rem 0.2rem;
  border-bottom: 2px solid transparent;
}
/* Balloons on a nav item (e.g. Tasks: red = past due, orange = near due). */
.nav-badges {
  position: absolute;
  top: -0.3rem;
  right: -0.7rem;
  display: flex;
  gap: 2px;
}
.nav-badge {
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg-header);
}
.nav-badge--over { background: var(--danger); }
.nav-badge--near { background: #C2681C; }
.app-header__nav a:hover,
.app-header__nav a.active {
  color: #fff;
  border-bottom-color: var(--accent);
}
.app-header__user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
}
/* A header with links (js/usermenu.js marks it --folds) never shrinks or
   wraps: if it doesn't fit on one line, the script sees the overflow and
   folds it, a step at a time —
   --compact: the links go behind a menu button named after this page,
   and your name goes (the avatar stays);
   --tight:   no "Ops", tighter spacing;
   --icons:   no page name on the button, no "Live data" pill;
   --bare:    no logo either (Home is in the menu). */
.app-header--folds .app-header__brand, .app-header--folds .app-header__nav, .app-header--folds .app-header__user { flex-shrink: 0; }
.app-header--folds .app-header__nav a { white-space: nowrap; }
.app-header__menu {
  display: none;
  align-items: center;
  gap: 0.45rem;
  height: 34px;
  padding: 0 0.75rem 0 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.app-header__menu:hover,
.app-header__menu[aria-expanded="true"] { border-color: var(--accent); }
.app-header__menu svg { width: 18px; height: 18px; flex: none; }
.app-header__menu-label { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; }
.app-header--compact .app-header__menu { display: inline-flex; position: relative; margin: 0 auto 0 0.75rem; }
/* a nav balloon (Tasks past due…) shows as a dot on the closed menu */
.app-header--compact:has(.app-header__nav .nav-badge) .app-header__menu::after {
  content: ""; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 0 2px var(--bg-header);
}
.app-header--compact .app-header__nav {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0.35rem 0 0.6rem;
  background: var(--bg-header);
  box-shadow: var(--shadow-md);
  max-height: calc(100dvh - var(--header-height));
  overflow-y: auto;
}
.app-header--compact.is-nav-open .app-header__nav { display: flex; }
.app-header--compact .app-header__nav a {
  padding: 0.75rem 1.25rem;
  border-bottom: none;
  border-left: 3px solid transparent;
  white-space: normal;
}
.app-header--compact .app-header__nav a.active { border-left-color: var(--accent); background: rgba(255,255,255,0.06); }
.app-header--compact .nav-badges { position: static; display: inline-flex; margin-left: 0.6rem; vertical-align: 1px; }
.app-header--compact #userName { display: none; }
.app-header--tight { padding: 0 0.75rem; }
.app-header--tight .app-header__brand .app-header__name { display: none; }
.app-header--tight .app-header__menu { margin-left: 0.5rem; }
.app-header--tight .app-header__user { gap: 0.4rem; }
.app-header--icons .app-header__menu-label, .app-header--icons .app-header__user .data-pill { display: none; }
.app-header--icons .app-header__menu { padding: 0 0.5rem; }
.app-header--bare .app-header__brand { display: none; }
.app-header--bare .app-header__menu { margin-left: 0; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  overflow: hidden;
}
/* Photo avatar — the image is set as a cover background so it stays a
   perfect circle regardless of aspect ratio (see js/avatar.js paint()). */
.avatar--photo {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
}

/* .btn-secondary defaults to --text-primary, which is near-black — right
   for light surfaces, invisible against the dark header background (only
   the hover color showed). Override just within the header. */
.app-header .btn-secondary {
  color: var(--text-inverse);
  border-color: rgba(255,255,255,0.35);
}
.app-header .btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Layout helpers ---------- */
.page-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0 0 0.25rem;
}
.page-subtitle {
  color: var(--text-secondary);
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}
/* A page title with buttons beside it: the guided tour (js/tour.js) and
   "How this process works" (css/workflow-help.css). */
.page-title-row { display: flex; align-items: center; gap: 0.55rem; }
.page-title-row > .page-title { margin-bottom: 0.25rem; }
/* The tour's button: a compass, so it doesn't read as the process "?". */
.tour-btn {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; padding: 0;
  border: 1.5px solid var(--hitt-teal); background: transparent; color: var(--hitt-teal);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.page-title-row > .tour-btn { margin-bottom: 0.2rem; }
.tour-btn:hover, .tour-btn:focus-visible { background: var(--hitt-teal); color: #fff; outline: none; }
.tour-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }

/* ---------- Responsive grid for cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

/* ---------- Notification badge (red count balloon) ---------- */
.notif-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
}
.notif-badge.hidden { display: none; }

/* ---- search-clear.js: a ✕ inside any search field ---- */
.search-clear-wrap { position: relative; display: flex; align-items: center; }
.search-clear-wrap > input { min-width: 0; }
.search-clear-wrap.has-value > input { padding-right: 2rem !important; }
.search-clear-wrap > input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear-btn {
  position: absolute; right: 0.4rem; top: 50%; transform: translateY(-50%);
  display: none; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; padding: 0;
  border: none; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--text-secondary);
  font-size: 1.1rem; line-height: 1;
}
.search-clear-wrap.has-value > .search-clear-btn { display: flex; }
.search-clear-btn:hover { background: rgba(0, 0, 0, 0.08); color: var(--text-primary); }
.search-clear-btn:active { transform: translateY(-50%) scale(0.92); }

/* Custom field type "link" (public/js/cf-link.js): the URL stays editable,
   the ↗ beside it opens it in a new tab. */
.cf-link { display: flex; align-items: stretch; gap: 0.35rem; }
.cf-link > input { flex: 1; min-width: 0; }
.cf-link__open {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 2.25rem; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--brand); font-weight: 700; text-decoration: none;
}
.cf-link__open:hover { background: var(--bg-surface-alt); }
.cf-link__open.is-hidden { visibility: hidden; }

/* Quick create (js/quick-embed.js): the page runs in the "+" launcher's
   full-screen iframe with ?quick=<kind>, showing its create modal over the
   page underneath — so everything but its modals (and the toasts that say
   what a save refused) goes, background included. */
html.qc-embed, html.qc-embed body { background: transparent !important; }
html.qc-embed .app-header,
html.qc-embed main,
html.qc-embed .qc-embed-hide,
html.qc-embed #opsc-banner,
html.qc-embed .opsc-fab,
html.qc-embed .opsc-panel,
html.qc-embed .ops-dock { display: none !important; }

/* A project over the page you're on (js/project-frame.js): the frame is that
   same embed, with its modal over the page underneath. */
.project-frame { position: fixed; inset: 0; z-index: 1100; }
.project-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  opacity: 0;
}
.project-frame.is-ready iframe { opacity: 1; }
.project-frame__wait {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: rgba(23, 23, 23, 0.45);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
}
.project-frame.is-ready .project-frame__wait { display: none; }
.project-frame__spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: project-frame-spin 0.8s linear infinite;
}
@keyframes project-frame-spin { to { transform: rotate(360deg); } }
body.project-frame-open { overflow: hidden; }
