/* =====================================================================
   WPRP — Design tokens
   Official Nyarai palette: logo purple + black. Change the colours here
   (and in includes/branding.php for PDFs) to re-skin the whole app.
   ===================================================================== */

:root {
  --nyarai-pink: #B806D9;
  --nyarai-pink-dark: #7E0599;
  --nyarai-pink-light: #F5E3FA;
  --nyarai-brown: #100B16;
  --nyarai-brown-light: #4A3F58;
  --nyarai-tan: #C98BE3;
  --cream: #FAF6FC;
  --paper: #FFFFFF;
  --ink: #1D1625;
  --ink-soft: #6A6075;
  --border: #E6DBEC;
  --success: #3F7D5C;
  --success-bg: #E6F1EC;
  --warning: #C97A2B;
  --warning-bg: #FBEEE0;
  --danger: #B23A3A;
  --danger-bg: #FBEAEA;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(29, 22, 37, 0.06), 0 4px 16px rgba(29, 22, 37, 0.05);
}

html, body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}

h1, h2, h3, h4, .display-font {
  font-family: var(--font-display);
  color: var(--nyarai-brown);
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: var(--nyarai-pink-dark); text-decoration: none; }
a:hover { color: var(--nyarai-pink); text-decoration: underline; }

/* --- Signature element: the "roofline" top border -------------------
   A two-segment diagonal echoing the Nyarai logo's roof peak, used
   sparingly as a top accent on cards and the sidebar brand mark. */
.roofline-top {
  position: relative;
}
.roofline-top::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(120deg, var(--nyarai-pink) 0%, var(--nyarai-pink) 48%, var(--nyarai-tan) 52%, var(--nyarai-tan) 100%);
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
  opacity: 0.9;
}

/* --- App shell -------------------------------------------------------- */

.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--nyarai-brown);
  color: #EADFF0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}

.app-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.app-sidebar .brand-mark {
  width: 38px; height: 34px;
  display: grid; place-items: center;
}
.app-sidebar .brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.app-sidebar .brand-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: #fff;
  line-height: 1.1;
}
.app-sidebar .brand-text small {
  display: block;
  font-family: var(--font-body);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--nyarai-tan);
  font-weight: 500;
}

.app-nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.app-nav .nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(239,230,219,0.45);
  margin: 18px 10px 6px;
}
.app-nav .nav-link {
  color: #EADFF0;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}
.app-nav .nav-link i { font-size: 1rem; opacity: 0.85; width: 18px; text-align: center; }
.app-nav .nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.app-nav .nav-link.active {
  background: var(--nyarai-pink);
  color: #fff;
  font-weight: 600;
}

.app-sidebar .sidebar-footer {
  padding: 14px 20px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.8rem;
  color: rgba(239,230,219,0.6);
}

.app-main { margin-left: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.app-topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-topbar .search-box {
  position: relative;
  max-width: 380px;
  width: 100%;
}
.app-topbar .search-box input {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--cream);
  padding: 9px 16px 9px 38px;
  font-size: 0.9rem;
  width: 100%;
}
.app-topbar .search-box input:focus {
  outline: none;
  border-color: var(--nyarai-pink);
  box-shadow: 0 0 0 3px var(--nyarai-pink-light);
  background: #fff;
}
.app-topbar .search-box i {
  position: absolute;
  left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--ink-soft);
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 6px 5px 6px;
  border-radius: 999px;
  cursor: pointer;
}
.user-chip:hover { background: var(--cream); }
.user-chip .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--nyarai-pink-light);
  color: var(--nyarai-pink-dark);
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.85rem;
}

.app-content { padding: 28px; flex: 1; }

/* --- Stat cards --------------------------------------------------- */

.stat-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 600;
  color: var(--nyarai-brown);
  line-height: 1;
}
.stat-card .stat-meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 6px;
}
.stat-card .stat-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--nyarai-pink-light);
  color: var(--nyarai-pink-dark);
  font-size: 1.1rem;
}

/* --- Generic cards / panels ---------------------------------------- */

.panel {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h2 {
  font-size: 1.05rem;
  margin: 0;
}
.panel-body { padding: 20px; }

/* --- Quick action tiles --------------------------------------------- */

.quick-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  transition: border-color .15s ease, transform .15s ease;
}
.quick-action:hover {
  border-color: var(--nyarai-pink);
  transform: translateY(-1px);
  text-decoration: none;
}
.quick-action .qa-icon {
  width: 38px; height: 38px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--cream);
  color: var(--nyarai-pink-dark);
  font-size: 1.05rem;
  flex-shrink: 0;
}
.quick-action .qa-label { font-weight: 600; color: var(--ink); font-size: 0.92rem; }
.quick-action .qa-sub { font-size: 0.78rem; color: var(--ink-soft); }

/* --- Status badges ---------------------------------------------------- */

.badge-status {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: capitalize;
}
.badge-available { background: var(--success-bg); color: var(--success); }
.badge-placed { background: var(--warning-bg); color: var(--warning); }
.badge-inactive, .badge-blacklisted { background: var(--danger-bg); color: var(--danger); }
.badge-verified { background: var(--nyarai-pink-light); color: var(--nyarai-pink-dark); }

/* --- Buttons ------------------------------------------------------- */

.btn-nyarai {
  background: var(--nyarai-pink);
  border: 1px solid var(--nyarai-pink);
  color: #fff;
  font-weight: 600;
  border-radius: 8px;
  padding: 9px 18px;
}
.btn-nyarai:hover { background: var(--nyarai-pink-dark); border-color: var(--nyarai-pink-dark); color: #fff; }
.btn-nyarai-outline {
  background: transparent;
  border: 1px solid var(--nyarai-pink);
  color: var(--nyarai-pink-dark);
  font-weight: 600;
  border-radius: 8px;
  padding: 9px 18px;
}
.btn-nyarai-outline:hover { background: var(--nyarai-pink-light); color: var(--nyarai-pink-dark); }

/* --- Login page ------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}
.auth-side {
  flex: 1;
  background: var(--nyarai-brown);
  color: #EADFF0;
  display: none;
  flex-direction: column;
  justify-content: center;
  padding: 60px;
  position: relative;
  overflow: hidden;
}
.auth-side::after {
  content: "";
  position: absolute;
  right: -60px; bottom: -60px;
  width: 320px; height: 320px;
  background: var(--nyarai-pink);
  opacity: 0.15;
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
}
.auth-side h1 {
  color: #fff;
  font-size: 2.1rem;
  max-width: 380px;
}
.auth-side p { color: var(--nyarai-tan); max-width: 360px; }
@media (min-width: 900px) {
  .auth-side { display: flex; }
}
.auth-form-col {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 40px 28px;
}
.auth-card { width: 100%; }
.auth-card .form-control {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 10px 14px;
}
.auth-card .form-control:focus {
  border-color: var(--nyarai-pink);
  box-shadow: 0 0 0 3px var(--nyarai-pink-light);
}
.auth-card label { font-weight: 600; font-size: 0.86rem; color: var(--ink); margin-bottom: 4px; }

/* --- Responsive: sidebar collapses on small screens -------------------- */

@media (max-width: 900px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; z-index: 1050; }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex !important; }
}
.sidebar-toggle { display: none; }

/* --- Global loading overlay ------------------------------------------ */
#globalLoadingOverlay {
  position: fixed; inset: 0;
  background: rgba(16, 11, 22, 0.55);
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 2000;
  backdrop-filter: blur(1px);
}
#globalLoadingOverlay.show { display: flex; }
#globalLoadingOverlay .loading-spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: var(--nyarai-pink);
  border-radius: 50%;
  animation: wprp-spin 0.7s linear infinite;
}
#globalLoadingOverlay .loading-text {
  color: #fff; margin-top: 14px; font-size: 0.9rem; font-weight: 600;
}
@keyframes wprp-spin { to { transform: rotate(360deg); } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .quick-action, .app-sidebar { transition: none; }
  #globalLoadingOverlay .loading-spinner { animation: none; }
}

/* --- Flatpickr brand theming ------------------------------------------ */
.flatpickr-day.selected, .flatpickr-day.selected:hover {
  background: var(--nyarai-pink); border-color: var(--nyarai-pink);
}
.flatpickr-day.today { border-color: var(--nyarai-pink); }
.flatpickr-day:hover { background: var(--nyarai-pink-light); }
.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-weekdays { background: var(--nyarai-brown); }
.flatpickr-current-month input.cur-year { color: #fff; }
.flatpickr-current-month .flatpickr-monthDropdown-months { color: #fff; }
span.flatpickr-weekday { background: var(--nyarai-brown); color: #EADFF0; }
.flatpickr-months .flatpickr-prev-month, .flatpickr-months .flatpickr-next-month { color: #fff; fill: #fff; }
.flatpickr-months .flatpickr-prev-month:hover svg, .flatpickr-months .flatpickr-next-month:hover svg { fill: var(--nyarai-pink); }


/* =====================================================================
   UI consistency layer (shadcn-style rhythm)
   Layout, sizing and spacing only — NO colour tokens are changed here.
   Everything below can be deleted to return to the previous look.
   ===================================================================== */

:root {
  --control-h: 38px;
  --radius-sm: 8px;
}

/* --- Form controls: one height, one radius, one focus ring ------------- */
.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  line-height: 1.3;
}
.form-control, .form-select {
  min-height: var(--control-h);
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--ink);
  padding-top: 7px;
  padding-bottom: 7px;
}
textarea.form-control { min-height: 0; }
.form-control-sm, .form-select-sm { min-height: 32px; font-size: 0.85rem; padding-top: 4px; padding-bottom: 4px; }
.form-control::placeholder { color: var(--ink-soft); opacity: 0.7; }
.form-control:focus, .form-select:focus {
  border-color: var(--nyarai-pink);
  box-shadow: 0 0 0 3px var(--nyarai-pink-light);
}
.form-check-input { border-color: var(--border); }
.form-check-input:checked { background-color: var(--nyarai-pink); border-color: var(--nyarai-pink); }
.form-check-input:focus { border-color: var(--nyarai-pink); box-shadow: 0 0 0 3px var(--nyarai-pink-light); }
.form-text { font-size: 0.78rem; color: var(--ink-soft); }

/* Align controls on one baseline across a row even when a label wraps to
   two lines: the label grows, the control sits at the bottom. */
.row:not(:has(> [class*="col"] > :nth-child(3))) > [class*="col"]:has(> .form-label) {
  display: flex;
  flex-direction: column;
}
.row:not(:has(> [class*="col"] > :nth-child(3))) > [class*="col"]:has(> .form-label) > .form-label {
  flex: 1 0 auto;
  display: flex;
  align-items: flex-end;
}

/* --- Buttons: same height/weight everywhere ---------------------------- */
.btn:not(.btn-sm):not(.btn-lg):not(.btn-close) {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn-sm { font-size: 0.8rem; font-weight: 600; border-radius: 7px; padding: 0.3rem 0.65rem; display: inline-flex; align-items: center; gap: 0.35rem; }
.btn-nyarai, .btn-nyarai-outline { padding: 0.5rem 1rem; }
.btn-sm.btn-nyarai, .btn-sm.btn-nyarai-outline { padding: 0.3rem 0.65rem; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--nyarai-pink-light); }

/* --- Cards: equal heights in a row, consistent inner spacing ----------- */
.row > [class*="col"] > .stat-card:only-child { height: 100%; }
.stat-card { display: flex; flex-direction: column; min-height: 92px; }
.panel { overflow: hidden; }
.panel-header { min-height: 56px; padding: 12px 20px; gap: 12px; }
.panel-header h2 { font-size: 1rem; line-height: 1.3; }
.panel-body { padding: 20px; }
.panel-body > :last-child { margin-bottom: 0; }
.panel .panel-header + .panel-body { padding-top: 20px; }
.quick-action { height: 100%; }

/* Stacked panels in a column get the same gap as the grid */
.col-lg-4 > .panel + .panel, .col-lg-5 > .panel + .panel, .col-lg-8 > .panel + .panel, .col-lg-7 > .panel + .panel { margin-top: 16px; }

/* --- Tables inside panels: align with panel padding, quieter header ---- */
.panel .table { margin-bottom: 0; }
.panel .table > :not(caption) > * > * { padding: 0.7rem 0.75rem; }
.panel .table th:first-child, .panel .table td:first-child { padding-left: 20px; }
.panel .table th:last-child, .panel .table td:last-child { padding-right: 20px; }
.panel .table thead th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: transparent;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.panel .table tbody td { font-size: 0.9rem; }
.panel .table-responsive { border-radius: 0; }

/* keep the mobile menu button hidden on desktop (the .btn rule above would show it) */
.btn.sidebar-toggle { display: none; }
@media (max-width: 900px) { .btn.sidebar-toggle { display: inline-flex !important; } }

/* --- Badges: consistent pill ------------------------------------------ */
.badge-status { display: inline-flex; align-items: center; gap: 4px; line-height: 1.2; white-space: nowrap; }

/* --- Page header rhythm ----------------------------------------------- */
.app-content > h1, .app-content h1.h3, .app-content h1 { letter-spacing: -0.02em; }
.app-content > .row, .app-content > .panel { margin-bottom: 0; }
.app-content form > .panel { margin-bottom: 16px; }

/* --- Narrow screens: never let controls collapse oddly ----------------- */
@media (max-width: 767px) {
  .app-content { padding: 18px 14px; }
  .row > [class*="col"]:has(> .form-label) > .form-label { flex: 0 0 auto !important; }
}

/* --- Pagination ---------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); }
.pager-info { font-size: 0.84rem; color: var(--ink-soft); }
.pager-info strong { color: var(--ink); font-weight: 600; }
.pager-list { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.pager-btn, .pager-num { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 34px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--paper); color: var(--ink); font-size: 0.84rem; font-weight: 600; text-decoration: none; transition: background-color .15s ease, border-color .15s ease; }
a.pager-btn:hover, a.pager-num:hover { background: var(--nyarai-pink-light); border-color: var(--nyarai-pink); color: var(--nyarai-pink-dark); text-decoration: none; }
.pager-num.is-current { background: var(--nyarai-pink); border-color: var(--nyarai-pink); color: #fff; }
.pager-btn.is-disabled { opacity: 0.45; cursor: not-allowed; }
.pager-gap { padding: 0 4px; color: var(--ink-soft); }
@media (max-width: 575px) { .pager-btn span { display: none; } .pager { justify-content: center; } }

/* --- Motion: staged reveal + skeletons (all disabled for reduced motion) --- */
@keyframes ui-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.ui-reveal { animation: ui-rise 250ms cubic-bezier(.22,.61,.36,1) both; animation-delay: var(--reveal-delay, 0ms); }

@keyframes ui-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.chart-box.is-loading::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--cream) 25%, var(--nyarai-pink-light) 50%, var(--cream) 75%);
  background-size: 200% 100%; animation: ui-shimmer 1.4s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .ui-reveal { animation: none; }
  .chart-box.is-loading::after { animation: none; background: var(--cream); }
}

/* --- Compact stat cards (secondary row) ------------------------------ */
.stat-card-sm { padding: 14px 16px; min-height: 0; }
.stat-card-sm .stat-value { font-size: 1.6rem; }
.stat-card-sm .stat-label { font-size: 0.72rem; margin-bottom: 4px; }
.stat-card-sm .stat-icon { width: 32px; height: 32px; font-size: 0.95rem; border-radius: 8px; }

/* --- Data Entry home choices ---------------------------------------- */
.de-choice { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 20px; background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-card); color: var(--ink); text-decoration: none; transition: border-color .15s ease, transform .15s ease; }
.de-choice:hover { border-color: var(--nyarai-pink); transform: translateY(-2px); text-decoration: none; color: var(--ink); }
.de-choice-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; background: var(--nyarai-pink-light); color: var(--nyarai-pink-dark); font-size: 1.25rem; margin-bottom: 6px; }
.de-choice-title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; color: var(--nyarai-brown); }
.de-choice-sub { font-size: 0.86rem; color: var(--ink-soft); flex: 1; }
.de-choice-go { font-size: 0.86rem; font-weight: 600; color: var(--nyarai-pink-dark); margin-top: 6px; }

/* --- Data Entry forms --------------------------------------------------- */
.de-doc { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--cream); }
.de-emp { padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.de-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 0; background: linear-gradient(to top, var(--cream) 70%, transparent); }
.de-part { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; margin: 28px 0 12px; }
.de-part span { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--nyarai-pink); color: #fff; font-family: var(--font-body); font-size: 0.85rem; font-weight: 700; }
.review-card { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--paper); margin-bottom: 12px; }
.review-card:last-child { margin-bottom: 0; }
.review-tabs .nav-link { color: var(--ink); font-weight: 600; font-size: 0.88rem; border-radius: var(--radius-sm); }
.review-tabs .nav-link.active { background: var(--nyarai-pink); color: #fff; }

/* ======================================================================
   Responsive layer — written phone-first, widened with min-width queries.
   Root cause of the old sideways scroll: .app-main is a flex child, and a
   flex child will not shrink below its content (a wide table) unless
   min-width is 0.
   ====================================================================== */
.app-main, .app-content, .app-topbar > div { min-width: 0; }
.app-main { max-width: 100%; }

/* Phones */
.app-topbar { padding: 10px 14px; gap: 10px; }
.app-topbar > div:first-child { flex: 1 1 auto; gap: 8px !important; }
.app-topbar .search-box { max-width: none; flex: 1 1 auto; min-width: 0; }
.app-topbar .search-box input { padding-top: 8px; padding-bottom: 8px; text-overflow: ellipsis; }
.user-chip .bi-chevron-down { display: none; }
.user-chip { flex-shrink: 0; }
.app-content { padding: 16px 12px; }
.app-content > .d-flex.justify-content-between, .app-content > .d-flex.align-items-center { flex-wrap: wrap; gap: 10px; }
.app-content h1 { font-size: 1.55rem; }
.panel-header { flex-wrap: wrap; }
.pager { padding: 12px 14px; }
.review-card form .btn { white-space: nowrap; }

/* Tables become cards on phones (data-label is filled in by ui.js) */
@media (max-width: 767.98px) {
  .table-responsive:has(> table.t-stack) { overflow: visible; }
  table.t-stack, table.t-stack tbody, table.t-stack tfoot, table.t-stack tr, table.t-stack td { display: block; width: 100%; }
  table.t-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .panel table.t-stack tbody tr, .panel table.t-stack tfoot tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .panel table.t-stack tbody tr:last-child { border-bottom: 0; }
  .panel table.t-stack tbody td, .panel table.t-stack tfoot td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 5px 0; border: 0; text-align: right; font-size: 0.9rem; word-break: break-word;
    box-shadow: none; background: transparent;
  }
  table.t-stack td::before {
    content: attr(data-label); flex: 0 0 36%; max-width: 36%;
    color: var(--ink-soft); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; text-align: left;
  }
  table.t-stack td[data-label=""]::before { display: none; }
  .panel table.t-stack td.t-title { justify-content: flex-start; text-align: left; font-weight: 600; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px dashed var(--border); }
  table.t-stack td.t-title::before { display: none; }
  table.t-stack td:empty { display: none; }
  .panel table.t-stack td.t-wide { display: block; text-align: left; }
  .panel table.t-stack td.t-actions { justify-content: flex-end; padding-top: 10px; flex-wrap: wrap; }
  table.t-stack td > .badge, table.t-stack td > .badge-status { margin-left: auto; }
  .panel table.t-stack td:first-child, .panel table.t-stack td:last-child { padding-left: 0; padding-right: 0; }
}

/* Small tablets and up */
@media (min-width: 576px) {
  .user-chip .bi-chevron-down { display: inline-block; }
  .app-content { padding: 20px; }
}
@media (min-width: 768px) {
  .app-topbar { padding: 14px 24px; }
  .app-content { padding: 24px; }
  .app-content h1 { font-size: 1.8rem; }
}
@media (min-width: 901px) {
  .app-topbar .search-box { max-width: 380px; }
  .app-content { padding: 28px; }
}
@media (max-width: 575.98px) {
  .app-content .d-flex.gap-2:not(.flex-nowrap), .app-content .d-flex.gap-3:not(.flex-nowrap) { flex-wrap: wrap; }
}

@media (max-width: 767.98px) {
  .panel table.t-stack tr:has(> td.t-avatar) { position: relative; }
  .panel table.t-stack td.t-avatar { position: absolute; left: 14px; top: 12px; width: auto; padding: 0; display: block; }
  .panel table.t-stack td.t-avatar::before { display: none; }
  .panel table.t-stack td.t-avatar + td.t-title { padding-left: 48px; min-height: 38px; }
  .panel table.t-stack td.t-title { display: block; }
  table.t-stack td .t-val { min-width: 0; text-align: right; }
}

/* --- Footer credit ------------------------------------------------- */
.app-credit { margin-left: 0; background: var(--paper); border-top: 1px solid var(--border); padding: 14px 16px; font-size: 0.8rem; color: var(--ink-soft); }
.app-credit-inner { display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; }
.app-credit a { color: var(--nyarai-pink-dark); text-decoration: none; font-weight: 600; word-break: break-all; }
.app-credit a:hover { text-decoration: underline; }
.app-credit strong { color: var(--ink); font-weight: 600; }
body:has(.app-shell) .app-shell { min-height: calc(100vh - 78px); }
.auth-card .app-credit { margin-top: 28px; padding: 14px 0 0; background: transparent; }
@media (min-width: 768px) {
  .app-credit-inner { flex-direction: row; justify-content: space-between; text-align: left; gap: 16px; }
  body:has(.app-shell) .app-shell { min-height: calc(100vh - 50px); }
}
@media (min-width: 901px) {
  .app-credit { margin-left: 240px; padding: 14px 28px; }
  .auth-card .app-credit { margin-left: 0; }
}
.auth-card .app-credit-inner { flex-direction: column; text-align: left; align-items: flex-start; }
.license-page { max-width: 820px; margin: 0 auto; padding: 28px 16px 40px; }
.license-page h1 { font-size: 1.7rem; }
.license-page h2 { font-size: 1.05rem; margin-top: 1.6rem; }
.license-page p, .license-page li { color: var(--ink); line-height: 1.6; font-size: 0.95rem; }
.app-topbar .search-box input { min-width: 0; }
@media (max-width: 359.98px) { .app-topbar { padding: 8px 10px; } .app-topbar .search-box input { font-size: 0.85rem; padding-left: 34px; } }
@media (max-width: 575.98px) { .btn.user-chip:not(.btn-sm):not(.btn-lg):not(.btn-close) { padding: 3px; min-height: 0; height: auto; } }
/* Quick actions: icon beside text on phones (two narrow columns made the text wrap one word per line) */
@media (max-width: 575.98px) {
  .row > [class*="col-6"]:has(> .quick-action) { width: 100%; flex: 0 0 100%; }
  .quick-action { flex-direction: row; align-items: center; text-align: left; gap: 12px; padding: 12px 14px; }
}
.app-credit a { word-break: normal; white-space: nowrap; }
@media (max-width: 575.98px) {
  .review-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .review-tabs .nav-link { padding: 0.4rem 0.65rem; font-size: 0.82rem; white-space: nowrap; }
}

/* ======================================================================
   Workers data grid: Name + Role frozen on the left, everything else
   scrolls sideways. On wide screens the grid scrolls inside its own box so
   the sideways scrollbar is always on screen.
   ====================================================================== */
.filter-group { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--nyarai-pink-dark); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.grid-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.grid-arrows { display: none; gap: 6px; flex-shrink: 0; }
.data-grid-scroll { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; position: relative; }
.data-grid-scroll:focus-visible { outline: 2px solid var(--nyarai-pink); outline-offset: -2px; }
table.data-grid { --bs-table-bg: var(--paper); width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; margin-bottom: 0; }
table.data-grid th, table.data-grid td { white-space: nowrap; }
.panel table.data-grid thead th { background: var(--cream, #faf6fb); position: sticky; top: 0; z-index: 3; }
table.data-grid tbody td { background: var(--paper); border-bottom: 1px solid var(--border); }
table.data-grid tbody tr { cursor: pointer; }
table.data-grid tbody tr:hover > td { background: var(--nyarai-pink-light); }
table.data-grid td.col-mid  { white-space: normal; min-width: 170px; max-width: 220px; }
table.data-grid td.col-wide { white-space: normal; min-width: 220px; max-width: 300px; }
table.data-grid th.col-mid  { min-width: 170px; }
table.data-grid th.col-wide { min-width: 220px; }
table.data-grid td.col-view, table.data-grid th.col-view { width: 84px; min-width: 84px; text-align: center; }
.cell-clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.35; word-break: break-word; }
.min-w-0 { min-width: 0; }
.grid-name { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* Frozen columns (phones: only Name; wider screens: Name + Role) */
table.data-grid .sticky-1, table.data-grid .sticky-2 { position: sticky; background: var(--paper); }
table.data-grid .sticky-1 { left: 0; z-index: 2; width: 168px; min-width: 168px; max-width: 168px; }
table.data-grid .sticky-2 { left: auto; z-index: 1; min-width: 130px; max-width: 160px; white-space: normal; }
.panel table.data-grid thead th.sticky-1 { z-index: 5; }
.panel table.data-grid thead th.sticky-2 { z-index: 4; }
table.data-grid tbody tr:hover > td.sticky-1, table.data-grid tbody tr:hover > td.sticky-2 { background: var(--nyarai-pink-light); }
table.data-grid .sticky-1 { box-shadow: 1px 0 0 var(--border); }
@media (min-width: 576px) {
  table.data-grid .sticky-1 { width: 220px; min-width: 220px; max-width: 220px; }
  table.data-grid .sticky-2 { position: sticky; left: 220px; width: 160px; min-width: 160px; max-width: 160px; box-shadow: 6px 0 8px -6px rgba(16, 11, 22, 0.22); }
}
@media (min-width: 768px) {
  .data-grid-scroll { max-height: calc(100vh - 250px); min-height: 240px; }
  .grid-arrows { display: inline-flex; }
}

/* =====================================================================
   Workers on phones: cards with an expandable "More info" (iOS-style disclosure)
   Phones show the cards; 768px and up shows the frozen-column grid.
   ===================================================================== */
.worker-cards { display: grid; gap: 12px; padding: 12px; }
.grid-desktop { display: none; }
@media (min-width: 768px) {
  .worker-cards { display: none; }
  .grid-desktop { display: block; }
}
.wc {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(16, 11, 22, 0.04), 0 6px 18px -10px rgba(16, 11, 22, 0.18);
  transition: box-shadow .35s cubic-bezier(.32, .72, 0, 1), border-color .35s cubic-bezier(.32, .72, 0, 1);
}
.wc.is-open { border-color: rgba(184, 6, 217, 0.35); box-shadow: 0 2px 4px rgba(16, 11, 22, 0.05), 0 14px 30px -14px rgba(184, 6, 217, 0.35); }
.wc-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 8px;
  background: var(--paper); border-radius: 18px 18px 0 0;
}
/* While a card is open its header stays pinned, so you always know whose details you are reading */
.wc.is-open .wc-head { position: sticky; top: 0; z-index: 4; padding-bottom: 10px; border-bottom: 1px solid var(--border); box-shadow: 0 8px 14px -12px rgba(16, 11, 22, 0.25); }
.wc-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: 0 0 48px; }
.wc-avatar-ph { display: flex; align-items: center; justify-content: center; background: var(--nyarai-pink-light); color: var(--nyarai-pink-dark); font-weight: 700; font-size: .9rem; }
.wc-id { flex: 1 1 auto; min-width: 0; }
.wc-name { display: block; font-weight: 600; font-size: 1.02rem; line-height: 1.25; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.wc-sub { font-size: .82rem; color: var(--ink-soft, #6b6275); line-height: 1.3; margin-top: 2px; overflow-wrap: anywhere; }
.wc-head > .badge-status { flex: 0 0 auto; align-self: flex-start; }
.wc-quick { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 2px 14px 10px; font-size: .86rem; color: var(--ink-soft, #6b6275); }
.wc-quick i { color: var(--nyarai-pink); margin-right: 2px; }
.wc-quick > span { min-width: 0; overflow-wrap: anywhere; }
.wc-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 10px 10px; }
.wc-more, .wc-view {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  border: 0; border-radius: 999px; font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background .2s ease, transform .2s cubic-bezier(.32, .72, 0, 1);
}
.wc-more { background: var(--nyarai-pink-light); color: var(--nyarai-pink-dark); }
.wc-more:active, .wc-view:active { transform: scale(.96); }
.wc-more i { transition: transform .4s cubic-bezier(.32, .72, 0, 1); }
.wc.is-open .wc-more i { transform: rotate(180deg); }
.wc-view { color: var(--nyarai-pink-dark); background: transparent; }
/* height animation: 0fr -> 1fr (no JavaScript measuring) */
.wc-details { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .45s cubic-bezier(.32, .72, 0, 1); }
.wc.is-open .wc-details { grid-template-rows: 1fr; }
.wc-details-inner { overflow: hidden; min-height: 0; }
.wc-details:not(:has(*)) { display: none; }
.wc:not(.is-open) .wc-details-inner { visibility: hidden; transition: visibility 0s linear .45s; }
.wc-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; row-gap: 0; margin: 0; padding: 4px 14px 14px; border-top: 1px solid var(--border); }
.wc-item { padding: 10px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.wc-item-wide { grid-column: 1 / -1; }
.wc-item dt { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; color: var(--ink-soft, #6b6275); margin: 0 0 2px; }
.wc-item dd { margin: 0; font-size: .92rem; color: var(--ink); overflow-wrap: anywhere; }
.wc-item dd .cell-clip { display: inline; white-space: normal; max-width: none; overflow: visible; text-overflow: clip; }
@media (prefers-reduced-motion: reduce) {
  .wc, .wc-more, .wc-more i, .wc-details { transition: none !important; }
}
/* `overflow: hidden` on panels would stop the pinned card header from sticking; `clip` keeps the rounded corners without that side effect. */
.panel:has(.worker-cards) { overflow: visible; overflow: clip; }

/* Folded rows in stacked tables (phones only; on wider screens the toggle cell never shows) */
td.t-moretoggle { display: none; }
@media (max-width: 767.98px) {
  .panel table.t-stack td.t-moretoggle { display: flex; justify-content: flex-start; padding: 6px 0 2px; }
  .panel table.t-stack td.t-moretoggle::before { display: none; }
  .panel table.t-stack tr.t-foldable:not(.is-open) > td.t-more { display: none; }
  .panel table.t-stack tr.t-foldable.is-open > td.t-more { animation: t-fold-in .35s cubic-bezier(.32, .72, 0, 1); }
  .panel table.t-stack tr.t-foldable.is-open .wc-more i { transform: rotate(180deg); }
}
@keyframes t-fold-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .panel table.t-stack tr.t-foldable.is-open > td.t-more { animation: none; } }

/* Segmented control (iOS-style) and revenue summary */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--cream, #faf6fc); border: 1px solid var(--border); border-radius: 10px; }
.seg-btn { border: 0; background: transparent; padding: 6px 14px; min-height: 32px; border-radius: 8px; font-size: .85rem; font-weight: 600; color: var(--ink-soft, #6b6275); cursor: pointer; transition: background .25s cubic-bezier(.32,.72,0,1), color .25s, box-shadow .25s; }
.seg-btn.is-active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(16, 11, 22, .15), 0 0 0 .5px rgba(16, 11, 22, .06); }
.rev-total { font-family: 'Fraunces', serif; font-weight: 600; font-size: clamp(1.7rem, 6vw, 2.3rem); line-height: 1.15; color: var(--ink); }
.rev-chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.rev-chip { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--cream, #faf6fc); text-decoration: none; color: var(--ink); transition: transform .2s cubic-bezier(.32,.72,0,1), border-color .2s; }
a.rev-chip:hover { border-color: var(--nyarai-pink); }
a.rev-chip:active { transform: scale(.98); }
.rev-chip span { font-size: .75rem; color: var(--ink-soft, #6b6275); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.rev-chip strong { font-size: 1.02rem; }
[data-seg-pane][hidden] { display: none; }
@media (max-width: 575.98px) { .rev-chips { grid-template-columns: 1fr 1fr; } .rev-chip { padding: 9px 12px; } .rev-chip strong { font-size: .95rem; } }
