/* ==========================================================================
   Scout — Admin Theme (Tally Ho Tech Colors)
   FULL REWRITE of app.css
   Goals:
   - Match the new SCOUT military badge vibe (clean, crisp, “command console”)
   - Keep existing class names used by your PHP templates
   - Strong sidebar + disciplined spacing + consistent buttons/inputs
   - Accessible focus states + stable layouts (no jumpy hover)
   ========================================================================== */

/* =========================
   Theme Tokens
   ========================= */
:root {
  /* Brand (from your palette) */
  --tht-gold: #A77C29;
  --tht-blue: #004481;
  --tht-red: #CC101F;
  --tht-yellow: #FFD500;
  --tht-silver: #B7B7B1;
  --tht-ink: #0B1320;

  /* Surfaces */
  --bg: #f3f6fb;
  --paper: #ffffff;
  --paper-2: #f6f8fc;
  --border: #e4e9f2;

  /* Sidebar */
  --sidebar-950: #050a14;
  --sidebar-900: #081021;
  --sidebar-850: #0a1324;
  --sidebar-800: #0b1220;
  --sidebar-700: #121a2c;
  --sidebar-text: #dbe6f6;
  --sidebar-muted: rgba(219, 230, 246, .74);

  /* Text */
  --ink: #0B1320;
  --muted: #667085;

  /* Accents */
  --accent: var(--tht-blue);
  --accent-hover: #003968;
  --ring: var(--tht-yellow);
  --danger: var(--tht-red);

  /* Radius & shadow */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 28px rgba(0, 0, 0, .10);
  --shadow-2: 0 18px 50px rgba(0, 0, 0, .14);

  /* Layout */
  --container: 1200px;

  /* Rhythm */
  --pad: 1.25rem;
  --gap: 1rem;

  /* Controls */
  --control-h: 40px;

  /* Chat sizing */
  --chat-h-desktop: 65vh;
  --chat-h-mobile: 58vh;

  /* iOS safe area */
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Floating chat (legacy token used by your .gd-chat-* block) */
  --gd-navy: var(--sidebar-800);
}

/* =========================
   Resets / base
   ========================= */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
  height: auto;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* Utilities */
.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Links */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Focus */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Prevent long code from stretching layout */
code {
  white-space: nowrap;
}

/* =========================
   App layout
   ========================= */
.app {
  display: flex;
  min-height: 100vh;
}

/* =========================
   Sidebar
   ========================= */
.sidebar {
  width: 260px;
  flex: 0 0 260px;
  color: #fff;
  background:
    radial-gradient(1200px 600px at -200px -200px, rgba(255, 213, 0, .10), transparent 60%),
    radial-gradient(900px 500px at 120% 0%, rgba(204, 16, 31, .10), transparent 55%),
    linear-gradient(180deg, var(--sidebar-950), var(--sidebar-800) 60%, var(--sidebar-700));
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, .06);
}

/* Brand/logo block */
.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .55rem .75rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

/* Make the badge “feel” centered and not cramped */
.sidebar__brand .brand__logo {
  width: 100%;
  max-width: 240px;
  max-height: 110px;
  display: block;
  object-fit: contain;
}

/* Nav */
.sidebar__nav {
  padding: .75rem 0;
  overflow: auto;
}

/* Optional section label if you use it */
.nav__label {
  padding: .65rem 1rem .35rem;
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(219, 230, 246, .65);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: .78rem 1rem;
  border-left: 3px solid transparent;
  opacity: .94;
  position: relative;
}

.nav__item:hover {
  background: rgba(255, 255, 255, .06);
  color: #fff;
  opacity: 1;
}

.nav__item.is-active {
  background: linear-gradient(90deg, rgba(255, 213, 0, .16), rgba(255, 255, 255, .06));
  border-left-color: var(--ring);
  color: #fff;
  opacity: 1;
}

/* tiny “tactical” accent line */
.nav__item.is-active::after {
  content: "";
  position: absolute;
  right: 10px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--tht-red);
  box-shadow: 0 0 0 2px rgba(204, 16, 31, .18);
}

.sidebar__footer {
  margin-top: auto;
  padding: 1rem;
  color: var(--sidebar-muted);
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .88rem;
}

.sidebar__footer a {
  color: rgba(255, 255, 255, .85);
}

.sidebar__footer a:hover {
  color: #fff;
}

/* Sidebar brand responsive */
@media (max-width:900px) {
  .sidebar__brand {
    padding: .45rem .6rem;
  }

  .sidebar__brand .brand__logo {
    max-width: 200px;
    max-height: 72px;
  }
}

/* =========================
   Main
   ========================= */
.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* =========================
   Topbar
   ========================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.25rem;
  background: rgba(255, 255, 255, .86);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.only-mobile {
  display: none;
}

.topbar__title {
  min-width: 220px;
}

.topbar__title h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: .2px;
  font-weight: 900;
}

.topbar__title .subtitle {
  margin: .12rem 0 0;
  color: var(--muted);
  font-size: .88rem;
}

.topbar__actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user__name {
  font-size: .92rem;
  color: var(--accent);
  white-space: nowrap;
}

/* =========================
   Content container
   ========================= */
.content {
  padding: var(--pad);
  max-width: var(--container);
  margin: 0 auto;
  width: 100%;
}

/* Add a subtle “console” header spacing when pages have big H1s */
.content h1:first-child {
  margin-top: .25rem;
}

/* =========================
   Cards
   ========================= */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.card__head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(900px 250px at 10% -30%, rgba(0, 68, 129, .10), transparent 60%),
    linear-gradient(180deg, #fff, var(--paper-2));
}

.card__head h2 {
  margin: .15rem 0 .25rem;
  font-size: 1.05rem;
  font-weight: 900;
}

.card__head p {
  margin: 0;
  color: var(--muted);
}

.card__body {
  padding: 1.25rem;
}

.card.jump-highlight {
  box-shadow: 0 0 0 3px rgba(255, 213, 0, .25), var(--shadow);
  transition: box-shadow .6s ease;
}

/* =========================
   Flash messages
   ========================= */
.flash {
  margin: .5rem 0 1rem;
  padding: .75rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}

.flash--err {
  border-color: rgba(204, 16, 31, .25);
  background: rgba(204, 16, 31, .08);
  color: #7f1d1d;
}

.flash--ok {
  border-color: rgba(34, 197, 94, .30);
  background: rgba(34, 197, 94, .10);
  color: #065f46;
}

/* =========================
   Tables (common admin need)
   ========================= */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
}

.table th,
.table td {
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: .95rem;
}

.table th {
  background: linear-gradient(180deg, #fff, var(--paper-2));
  font-weight: 900;
  color: #0b1320;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: rgba(0, 68, 129, .03);
}

/* =========================
   Forms
   ========================= */
.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}

.form__label {
  grid-column: 1 / -1;
  font-weight: 900;
  letter-spacing: .2px;
}

.form__control {
  width: 100%;
  min-height: var(--control-h);
  padding: .68rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 1rem;
  outline: none;
  color: var(--ink);
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.form__control::placeholder {
  color: rgba(102, 112, 133, .72);
}

.form__control:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(255, 213, 0, .22);
}

.form__control:disabled {
  background: #f3f5f8;
  color: rgba(11, 19, 32, .55);
  cursor: not-allowed;
}

textarea.form__control {
  min-height: 180px;
  grid-column: 1 / -1;
  resize: vertical;
}

.form__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: .75rem;
  justify-content: flex-start;
  margin-top: .25rem;
  flex-wrap: wrap;
}

.form .full {
  grid-column: 1 / -1;
}

.form__checkbox {
  display: flex;
  align-items: center;
  gap: .55rem;
  margin: .25rem 0;
}

.note.small {
  font-size: .85rem;
  line-height: 1.35;
  color: #6b7280;
}

/* =========================
   Buttons
   ========================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: .62rem 1rem;
  font-weight: 900;
  cursor: pointer;
  background: #f8fafc;
  color: var(--ink);
  transition: background .12s ease, border-color .12s ease, filter .12s ease, transform .12s ease;
  white-space: nowrap;
  min-height: var(--control-h);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn--primary {
  background: var(--accent);
  border-color: rgba(0, 0, 0, .08);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 68, 129, .18);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  background: rgba(255, 255, 255, .65);
  border-color: var(--border);
  color: var(--ink);
}

.btn--ghost:hover {
  border-color: #cdd6e6;
  background: rgba(0, 0, 0, .02);
}

.btn--danger {
  background: var(--danger);
  border-color: rgba(0, 0, 0, .10);
  color: #fff;
  box-shadow: 0 8px 18px rgba(204, 16, 31, .14);
}

.btn--danger:hover {
  filter: brightness(.95);
}

/* Smaller button */
.btn--sm {
  min-height: 34px;
  padding: .45rem .75rem;
  border-radius: 10px;
  font-weight: 900;
}

/* Busy state */
.btn.is-busy {
  opacity: .78;
  pointer-events: none;
  position: relative;
}

.btn.is-busy::after {
  content: "";
  width: 14px;
  height: 14px;
  margin-left: .5rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================
   Pills / badges (if used)
   ========================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: .82rem;
  font-weight: 800;
  color: #111827;
}

.badge--blue {
  border-color: rgba(0, 68, 129, .22);
  background: rgba(0, 68, 129, .06);
  color: var(--accent);
}

.badge--red {
  border-color: rgba(204, 16, 31, .22);
  background: rgba(204, 16, 31, .06);
  color: var(--danger);
}

.badge--gold {
  border-color: rgba(255, 213, 0, .35);
  background: rgba(255, 213, 0, .12);
  color: #6b4d10;
}

/* =========================
   Layout helpers
   ========================= */
.cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem 2rem;
  align-items: start;
}

@media (min-width:900px) {
  .cols {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.cols>div {
  min-width: 0;
}

.kv {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: .5rem .75rem;
  align-items: center;
}

@media (max-width:700px) {
  .kv {
    grid-template-columns: 1fr;
  }

  .kv>div:first-child {
    font-weight: 900;
  }
}

.section-title {
  margin: 0 0 .35rem 0;
  font-size: 1rem;
  font-weight: 950;
  color: #111827;
}

/* Section tint */
.section--tint {
  background:
    radial-gradient(900px 260px at 10% -30%, rgba(255, 213, 0, .14), transparent 65%),
    linear-gradient(180deg, rgba(255, 255, 255, .80), #ffffff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Settings grid */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem 2rem;
  align-items: start;
}

@media (min-width:980px) {
  .settings-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.settings-grid .col {
  min-width: 0;
}

/* =========================
   Search bar (you still use .crm-search class)
   ========================= */
.crm-search {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, .75);
  min-width: min(520px, 52vw);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .06);
}

.crm-search input {
  border: 0;
  outline: none;
  width: 100%;
  font: inherit;
  padding: .35rem .35rem;
  background: transparent;
}

.crm-search .hint {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* =========================
   Quick Create menu
   ========================= */
.quick-create {
  position: relative;
  display: inline-flex;
}

.quick-create__menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 230px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
  z-index: 999999;
}

.quick-create__menu a {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.quick-create__menu a:hover {
  background: rgba(0, 68, 129, .04);
}

.quick-create.is-open .quick-create__menu {
  display: block;
}

/* =========================
   Mobile responsiveness
   ========================= */
@media (max-width:980px) {
  .form {
    grid-template-columns: 1fr;
  }

  .crm-search {
    min-width: min(420px, 70vw);
  }
}

@media (max-width:860px) {
  .only-mobile {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    bottom: 0;
    transition: left .25s ease;
    box-shadow: var(--shadow-2);
    z-index: 100000;
  }

  .sidebar.is-open {
    left: 0;
  }

  .main {
    margin-left: 0;
  }

  .topbar {
    padding: .8rem 1rem;
  }

  .topbar__title {
    min-width: auto;
  }

  .crm-search {
    min-width: min(360px, 74vw);
  }
}

@media (max-width:520px) {
  .topbar__actions {
    gap: .4rem;
  }

  .btn {
    padding: .55rem .85rem;
  }

  .crm-search {
    min-width: min(300px, 86vw);
  }
}

/* =========================
   Scout Floating Chat Widget
   (kept isolated to .gd-chat-*)
   ========================= */

/* Launcher */
.gd-chat-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2147483000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--gd-navy);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .10);
  padding: 12px 14px;
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
  cursor: pointer;
  font-weight: 950;
  letter-spacing: .02em;
}

.gd-chat-launcher:hover {
  filter: brightness(1.03);
}

/* Panel */
.gd-chat-panel {
  position: fixed;
  z-index: 2147483000;
  width: 380px;
  max-width: calc(100vw - 36px);
  height: min(520px, calc(100vh - 120px));
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .16);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
  overflow: hidden;
  display: none;
  grid-template-rows: auto 1fr auto;
}

/* Header */
.gd-chat-panel .gd-chat-header {
  background:
    radial-gradient(900px 220px at 20% -40%, rgba(255, 213, 0, .18), transparent 60%),
    linear-gradient(180deg, var(--gd-navy), #091427);
  color: #fff;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  cursor: grab;
  border-bottom: 1px solid rgba(255, 255, 255, .10);
}

.gd-chat-panel.is-dragging .gd-chat-header {
  cursor: grabbing;
}

.gd-chat-panel #gdChatDragHandle {
  touch-action: none;
}

.gd-chat-panel .gd-chat-header .title {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: center;
  align-items: center;
}

.gd-chat-panel .gd-chat-header .title strong {
  font-family: ui-serif, Georgia, "Times New Roman", Times, serif;
  font-size: 18px;
  letter-spacing: .06em;
}

.gd-chat-panel .gd-chat-header .title span {
  font-size: 12px;
  opacity: .92;
}

.gd-chat-panel .gd-chat-close {
  position: absolute;
  right: 10px;
  top: 6px;
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.gd-chat-panel .gd-chat-close:hover {
  filter: brightness(1.08);
}

/* Log */
#gdChatLog {
  overflow: auto;
  min-height: 0;
  padding: 12px;
  background:
    radial-gradient(900px 280px at 0% 0%, rgba(0, 68, 129, .06), transparent 55%),
    #f6f7f8;
}

/* Composer */
.gd-chat-composer {
  border-top: 1px solid rgba(0, 0, 0, .10);
  padding: 10px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: #fff;
}

.gd-chat-composer .gd-composer {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gd-chat-composer input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, .18);
  border-radius: 12px;
  padding: 10px;
  font: inherit;
}

.gd-chat-composer input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(255, 213, 0, .35);
}

.gd-chat-composer button {
  background: var(--gd-navy);
  color: #fff;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 950;
  cursor: pointer;
}

.gd-chat-composer button:hover {
  filter: brightness(1.03);
}

/* Footer row */
.gd-chat-footerrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  justify-content: space-between;
}

.gd-chat-iconbtn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, .18);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
  user-select: none;
}

.gd-chat-iconbtn:hover {
  filter: brightness(.98);
}

.gd-chat-hint {
  flex: 1;
  font-size: 12px;
  color: rgba(0, 0, 0, .55);
  text-align: center;
  padding: 0 6px;
}

/* Mobile tweaks */
@media (max-width:520px) {
  .gd-chat-panel {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }
}

/* =========================
   Global loader overlay (AppLoader)
   ========================= */
.app-loader {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(0, 0, 0, .35);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app-loader.is-open {
  display: flex;
}

.app-loader__card {
  width: min(520px, 92vw);
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--border);
}

.app-loader__title {
  font-weight: 950;
  font-size: 1.05rem;
  margin-bottom: .25rem;
}

.app-loader__msg {
  color: #334155;
  margin-bottom: .75rem;
}

.app-loader__bar {
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: .55rem;
}

.app-loader__barInner {
  height: 100%;
  background: var(--accent);
  width: 12%;
  transition: width .25s ease;
}

.app-loader__foot {
  color: #64748b;
  font-size: .85rem;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}