/* ==========================================================================
   e-Division — Application shell & components
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

/**
 * The `hidden` attribute must always win.
 *
 * A UA stylesheet gives [hidden] display:none, but any author rule that sets
 * `display` — and this file sets it on .login-screen, .pager, .dot, .btn and
 * others — overrides it, leaving "hidden" elements painted on screen. Declaring
 * it here once removes that whole class of bug.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.011em;
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--sand-500); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ==========================================================================
   LOGIN
   ========================================================================== */

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  background: var(--bg);
  z-index: 100;
}

.login-art {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 12% 10%, #F5A04A 0%, transparent 55%),
    radial-gradient(100% 80% at 88% 88%, #B45412 0%, transparent 60%),
    linear-gradient(150deg, #8F4316 0%, #5A2A0E 48%, #33170A 100%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 46px 52px;
  color: #FBEFE2;
}

/* Soft chakra-inspired motif — subtle, never a flag reproduction. */
.login-art::before {
  content: "";
  position: absolute;
  width: 720px;
  height: 720px;
  right: -240px;
  bottom: -260px;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg,
      rgba(255, 240, 220, 0.055) 0deg 3deg,
      transparent 3deg 15deg);
  mask-image: radial-gradient(circle, #000 32%, transparent 71%);
  -webkit-mask-image: radial-gradient(circle, #000 32%, transparent 71%);
  animation: slow-spin 140s linear infinite;
}
.login-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(transparent 0%, rgba(30, 14, 5, 0.42) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
}

@keyframes slow-spin { to { transform: rotate(360deg); } }

.login-art > * { position: relative; z-index: 1; }

.login-emblem {
  display: flex;
  align-items: center;
  gap: 14px;
}
.login-emblem .mark {
  width: 46px;
  height: 46px;
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  background: rgba(255, 247, 237, 0.14);
  border: 1px solid rgba(255, 233, 208, 0.28);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.login-emblem .mark svg { width: 26px; height: 26px; }
.login-emblem .wordmark {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.login-emblem .wordmark span { color: var(--saffron-300); }
.login-emblem small {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(251, 239, 226, 0.62);
  font-weight: 500;
  margin-top: 1px;
}

.login-art-body { max-width: 460px; }
.login-art-body h1 {
  font-size: 40px;
  line-height: 1.12;
  color: #FFF7ED;
  letter-spacing: -0.028em;
  margin-bottom: 16px;
  font-weight: 600;
}
.login-art-body p {
  font-size: var(--fs-md);
  line-height: 1.65;
  color: rgba(251, 239, 226, 0.76);
  margin: 0;
}
.login-art-body .rule {
  width: 54px;
  height: 3px;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--saffron-300), rgba(250, 191, 123, 0.15));
  margin-bottom: 26px;
}

.login-art-foot {
  display: flex;
  gap: 30px;
  font-size: var(--fs-sm);
  color: rgba(251, 239, 226, 0.55);
}
.login-art-foot div strong {
  display: block;
  color: rgba(255, 247, 237, 0.92);
  font-size: var(--fs-lg);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 40px;
  overflow-y: auto;
  background: var(--surface);
}

.login-form {
  width: 100%;
  max-width: 366px;
  animation: rise 460ms var(--ease) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.login-form h2 {
  font-size: var(--fs-2xl);
  letter-spacing: -0.024em;
  margin-bottom: 6px;
}
.login-form .sub {
  color: var(--text-muted);
  font-size: var(--fs-md);
  margin: 0 0 30px;
}

.login-form .field { margin-bottom: 16px; }

.login-alert {
  display: none;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: var(--red-50);
  border: 1px solid color-mix(in srgb, var(--red-600) 26%, transparent);
  color: var(--red-600);
  font-size: var(--fs-sm);
  margin-bottom: 18px;
  line-height: 1.5;
}
.login-alert.show { display: flex; animation: shake 380ms var(--ease); }
.login-alert svg { flex-shrink: 0; margin-top: 1px; }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  30%, 70% { transform: translateX(2px); }
  50% { transform: translateX(-2px); }
}

.login-meta {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: 1.7;
}
.login-meta strong { color: var(--text-secondary); font-weight: 600; }

/* Developer credit — shown over the artwork on wide screens, under the form on
   narrow ones, and in the sidebar throughout the portal.

   The credit sits on three very different backgrounds: the dark saffron
   artwork, the white sign-in panel and the dark sidebar. Each therefore gets
   its own colour rather than the muted grey they once shared, which fell well
   below a readable contrast on all three. */
.login-art-credit {
  /* Inside the artwork, so it never runs onto the white sign-in panel. */
  position: relative;
  z-index: 2;
  margin: 28px 0 0;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 217, 168, 0.22);
  text-align: center;
  font-size: var(--fs-sm);
  letter-spacing: 0.03em;
  color: rgba(255, 241, 224, 0.88);            /* 6.5:1 over the brightest part of the artwork */
  text-shadow: 0 1px 3px rgba(40, 18, 6, 0.55);
}
.login-art-credit strong {
  color: #FFD9A8;                               /* 5.5:1 over the brightest part of the artwork */
  font-weight: 700;
  letter-spacing: 0.01em;
}

.login-credit {
  display: none;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-secondary);                 /* 8.2:1 on the sign-in panel */
}
.login-credit strong { color: var(--saffron-800); font-weight: 700; }
:root[data-theme="dark"] .login-credit { color: var(--sand-200); }
:root[data-theme="dark"] .login-credit strong { color: var(--saffron-300); }

/* The same credit, carried through the whole portal under the user chip. */
.sidebar-credit {
  margin: 10px 2px 0;
  text-align: center;
  font-size: var(--fs-xs);
  line-height: 1.55;
  letter-spacing: 0.02em;
  color: rgba(244, 231, 216, 0.72);             /* 6.9:1 on the sidebar */
}
.sidebar-credit strong {
  display: block;
  color: #FFCE93;                               /* 9.6:1 on the sidebar */
  font-weight: 700;
  letter-spacing: 0.01em;
}

@media (max-width: 940px) {
  .login-screen { grid-template-columns: minmax(0, 1fr); }
  .login-art { display: none; }
  .login-art-credit { display: none; }
  .login-credit { display: block; }
}

/* A work name is clickable wherever it appears in the portal. */
.work-link {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary-border);
}
.work-link:hover { color: var(--primary); border-bottom-color: var(--primary); text-decoration: none; }

/* ==========================================================================
   APP SHELL
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
.app[hidden] { display: none; }

/* ---- Sidebar ------------------------------------------------------------- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-brand .mark {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--saffron-400), var(--saffron-600));
  box-shadow: 0 2px 8px rgba(238, 132, 34, 0.34);
  flex-shrink: 0;
}
.sidebar-brand .mark svg { width: 19px; height: 19px; }
.sidebar-brand .name {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #FFF7ED;
  line-height: 1.15;
}
.sidebar-brand .name span { color: var(--saffron-400); }
.sidebar-brand .name small {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 18px;
  scrollbar-width: thin;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(238, 132, 34, 0.2);
  border: none;
}

.nav-group { margin-bottom: 3px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 11px;
  border: none;
  background: none;
  color: var(--sidebar-text);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  position: relative;
}
.nav-item:hover { background: rgba(255, 247, 237, 0.06); color: #FFF7ED; }
.nav-item.active { background: var(--sidebar-active-bg); color: #FFF7ED; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 var(--r-full) var(--r-full) 0;
  background: var(--saffron-400);
}
.nav-item .icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.88; }
.nav-item.active .icon { opacity: 1; color: var(--saffron-300); }
.nav-item .label { flex: 1; min-width: 0; }
.nav-item .chev {
  width: 13px; height: 13px;
  opacity: 0.5;
  transition: transform var(--dur) var(--ease);
}
.nav-group.open .nav-item .chev { transform: rotate(90deg); }
.nav-item .pill {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--saffron-500);
  color: #2A1408;
  line-height: 1.5;
}

.nav-sub {
  overflow: hidden;
  max-height: 0;
  transition: max-height 240ms var(--ease);
}
.nav-group.open .nav-sub { max-height: 340px; }

.nav-sub a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 11px 6px 40px;
  font-size: var(--fs-sm);
  color: var(--sidebar-muted);
  border-radius: var(--r-sm);
  text-decoration: none;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
  position: relative;
}
.nav-sub a::before {
  content: "";
  position: absolute;
  left: 20px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
}
.nav-sub a:hover { color: #F5E9DC; background: rgba(255, 247, 237, 0.05); text-decoration: none; }
.nav-sub a.active { color: var(--saffron-300); background: rgba(238, 132, 34, 0.1); font-weight: 600; }
.nav-sub a.active::before { opacity: 1; }

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: var(--r-md);
  background: rgba(255, 247, 237, 0.05);
  cursor: pointer;
  border: 1px solid transparent;
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: border-color var(--dur) var(--ease);
}
.sidebar-user:hover { border-color: var(--sidebar-border); }
.sidebar-user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--saffron-400), var(--saffron-700));
  display: grid; place-items: center;
  font-weight: 600; font-size: var(--fs-sm);
  color: #FFF7ED;
  flex-shrink: 0;
  object-fit: cover;
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .who b {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #FFF7ED;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .who span {
  display: block;
  font-size: var(--fs-xs);
  color: var(--sidebar-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Main ---------------------------------------------------------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 10;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  min-width: 0;
}
.crumbs .sep { opacity: 0.4; }
.crumbs .here {
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-md);
  font-family: var(--font-display);
  letter-spacing: -0.012em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 33px; height: 33px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  background: none;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  position: relative;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-subtle); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn .dot {
  position: absolute;
  top: 5px; right: 5px;
  min-width: 15px; height: 15px;
  padding: 0 3px;
  border-radius: var(--r-full);
  background: var(--red-600);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
  line-height: 1;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 44px;
  scroll-behavior: smooth;
}

.view-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.view-head .titles { min-width: 0; flex: 1; }
.view-head h1 {
  font-size: var(--fs-2xl);
  letter-spacing: -0.026em;
  line-height: 1.2;
}
.view-head p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: var(--fs-base);
  max-width: 70ch;
}
.view-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ==========================================================================
   PRIMITIVES
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur) var(--ease);
  box-shadow: var(--shadow-xs);
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(180deg, var(--saffron-500), var(--saffron-600));
  border-color: var(--saffron-700);
  color: #fff;
  box-shadow: 0 1px 2px rgba(180, 84, 18, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--saffron-600), var(--saffron-700));
  border-color: var(--saffron-800);
}
.btn-ghost { background: none; border-color: transparent; box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-subtle); }
.btn-danger { color: var(--red-600); border-color: color-mix(in srgb, var(--red-600) 30%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--red-50); border-color: var(--red-600); }
.btn-sm { padding: 4px 9px; font-size: var(--fs-sm); }
.btn-sm svg { width: 13px; height: 13px; }
.btn-lg { padding: 10px 20px; font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* ---- Cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 17px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-alt);
}
.card-head h3 {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.012em;
  flex: 1;
  min-width: 0;
}
.card-head .sub { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 400; }
.card-head .actions { display: flex; gap: 6px; align-items: center; }
.card-body { padding: 17px; }
.card-body.flush { padding: 0; }

/* ---- Stat tiles ---------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(196px, 100%), 1fr));
  gap: 13px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent, var(--saffron-500));
}
.stat .k {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 7px;
}
.stat .k svg { width: 14px; height: 14px; color: var(--accent, var(--saffron-600)); }
.stat .v {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: var(--fs-md); font-weight: 500; color: var(--text-muted); letter-spacing: 0; }
.stat .d { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 5px; }
.stat .d b { color: var(--text-secondary); font-weight: 600; }

/**
 * A tighter tile for the strip above a register.
 *
 * The full-size tile is right on a dashboard, where it is the content. Above a
 * register it is context, and every pixel it takes comes off the rows below —
 * so trim the padding and the headline size there.
 */
.stat-grid.compact { gap: 10px; margin-bottom: 14px; }
.stat-grid.compact .stat { padding: 9px 13px; }
.stat-grid.compact .stat .k { margin-bottom: 3px; font-size: var(--fs-xs); }
.stat-grid.compact .stat .v { font-size: var(--fs-xl); }
.stat-grid.compact .stat .d { margin-top: 2px; font-size: var(--fs-xs); }

/* ---- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

/**
 * A register table scrolls within itself rather than with the page.
 *
 * `overflow-x: auto` already makes .table-wrap a scroll container, which is why
 * a sticky <th> anchored to top:0 was pinning to a box that scrolled away with
 * the page. Giving the wrapper its own height makes the header behave, and lets
 * the first column stay put while the other columns scroll sideways — with
 * sixteen columns on screen the Work ID is what tells you which row you are on.
 */
.table-wrap.register {
  overflow: auto;
  /* A fallback ceiling; register.js measures the real space and overrides it. */
  max-height: calc(100vh - 300px);
}

/**
 * Keep register rows to two lines: the value, and its subtitle underneath.
 *
 * Many cells render a name with a smaller identifier below it. Left to wrap,
 * each of those becomes two or three lines and every row grows past 100px, so
 * only five or six rows fit on screen. Holding each line to one line with an
 * ellipsis — the full text stays available via the cell's title attribute —
 * halves the row height and makes the register scannable.
 */
.table-wrap.register table.data tbody td > a,
.table-wrap.register table.data tbody td > div,
.table-wrap.register table.data tbody td > span.muted,
.table-wrap.register table.data tbody td > b {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Badges and progress bars must keep their own layout. */
.table-wrap.register table.data tbody td > .badge,
.table-wrap.register table.data tbody td > .progress-cell,
.table-wrap.register table.data tbody td > .row-actions,
.table-wrap.register table.data tbody td > .row { display: flex; }
.table-wrap.register table.data tbody td > .badge {
  display: inline-flex;
  white-space: nowrap;
}

/* Amounts, counts and dates are atomic — never break them across lines. */
.table-wrap.register table.data td.num,
.table-wrap.register table.data th.num,
.table-wrap.register table.data td.date,
.table-wrap.register table.data th.date { white-space: nowrap; }
.table-wrap.register table.data td.date { text-align: center; }

/* Keep the identity column visible while scrolling sideways. */
.table-wrap.register table.data tbody td:first-child,
.table-wrap.register table.data tfoot td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border-subtle);
}
.table-wrap.register table.data tbody tr:hover td:first-child { background: var(--bg-hover); }
.table-wrap.register table.data tfoot td:first-child { background: var(--surface-alt); }

/* The header cell above it must outrank both the row cells and the header row. */
.table-wrap.register table.data thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  box-shadow: 1px 0 0 var(--border);
}

@media (max-width: 700px) {
  /* Too little width to spare a frozen column on a phone. */
  .table-wrap.register table.data tbody td:first-child,
  .table-wrap.register table.data thead th:first-child,
  .table-wrap.register table.data tfoot td:first-child {
    position: static;
    box-shadow: none;
  }
  .table-wrap.register { max-height: none; }
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}
table.data th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--text-muted);
  padding: 9px 13px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { opacity: 0.4; margin-left: 3px; }
table.data th.sorted .arrow { opacity: 1; color: var(--primary); }

table.data td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
table.data tbody tr { transition: background var(--dur) var(--ease); }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr.clickable { cursor: pointer; }

table.data td.num, table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
table.data td.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
table.data td.strong { font-weight: 600; }
table.data td .muted { color: var(--text-muted); font-size: var(--fs-sm); display: block; }
table.data tfoot td {
  font-weight: 600;
  background: var(--surface-alt);
  border-top: 2px solid var(--border);
  padding: 10px 13px;
}
table.data .row-actions { display: flex; gap: 3px; justify-content: flex-end; opacity: 0; transition: opacity var(--dur); }
table.data tr:hover .row-actions { opacity: 1; }
table.data .row-actions .icon-btn { width: 26px; height: 26px; }
table.data .row-actions .icon-btn svg { width: 14px; height: 14px; }

/* ---- Badges -------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.65;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge.plain::before { display: none; }
.badge-green  { background: var(--green-50);  color: var(--green-600);  border-color: color-mix(in srgb, var(--green-600) 22%, transparent); }
.badge-amber  { background: var(--amber-50);  color: var(--amber-600);  border-color: color-mix(in srgb, var(--amber-600) 22%, transparent); }
.badge-red    { background: var(--red-50);    color: var(--red-600);    border-color: color-mix(in srgb, var(--red-600) 22%, transparent); }
.badge-teal   { background: var(--teal-50);   color: var(--teal-500);   border-color: color-mix(in srgb, var(--teal-500) 22%, transparent); }
.badge-indigo { background: var(--indigo-50); color: var(--indigo-600); border-color: color-mix(in srgb, var(--indigo-600) 22%, transparent); }
.badge-saffron{ background: var(--primary-soft); color: var(--saffron-700); border-color: var(--primary-border); }
.badge-grey   { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--border-subtle); }

:root[data-theme="dark"] .badge-saffron { color: var(--saffron-300); }

/* ---- Progress ------------------------------------------------------------ */
.progress {
  height: 6px;
  background: var(--bg-sunken);
  border-radius: var(--r-full);
  overflow: hidden;
  min-width: 70px;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--saffron-400), var(--saffron-600));
  transition: width 600ms var(--ease);
}
.progress.good > i { background: linear-gradient(90deg, #4FAE79, var(--green-600)); }
.progress.warn > i { background: linear-gradient(90deg, var(--saffron-400), var(--amber-600)); }
.progress.bad  > i { background: linear-gradient(90deg, #E4705A, var(--red-600)); }

.progress-cell { display: flex; align-items: center; gap: 9px; }
.progress-cell span { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; color: var(--text-secondary); }

/* ---- Forms --------------------------------------------------------------- */
.field { display: block; margin-bottom: 14px; }
.field > label,
.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field .req { color: var(--red-600); margin-left: 2px; }
.field .hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  padding: 7px 11px;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  box-shadow: var(--shadow-xs);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--bg-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.textarea { resize: vertical; min-height: 74px; line-height: 1.6; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239C8A76' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.input-group .addon {
  display: grid; place-items: center;
  padding: 0 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.search {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 340px;
}
.search svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.search .input { padding-left: 32px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 0 15px;
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
}

.fieldset {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: 15px;
  margin-bottom: 16px;
  background: var(--surface-alt);
}
.fieldset > legend {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--primary);
  padding: 0 7px;
  margin-left: -4px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-base);
  cursor: pointer;
  padding: 5px 0;
  user-select: none;
}
.checkline input[type="checkbox"], .checkline input[type="radio"] {
  width: 15px; height: 15px;
  accent-color: var(--saffron-600);
  cursor: pointer;
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border-subtle);
}
.toolbar .spacer { flex: 1; }

/**
 * Compact controls, so a register's filter bar fits two rows rather than three.
 *
 * A search box, six filters, a date range and four buttons cannot share 1000px
 * at full size; every extra wrapped row is 34px stolen from the table below it.
 */
.toolbar .select {
  width: auto;
  min-width: 0;
  max-width: 150px;
  padding: 4px 24px 4px 8px;
  font-size: var(--fs-sm);
  background-position: right 7px center;
}
.toolbar .input { width: auto; min-width: 0; padding: 4px 8px; font-size: var(--fs-sm); }
.toolbar .search { min-width: 150px; max-width: 260px; }
.toolbar .search .input { padding-left: 28px; width: 100%; }
.toolbar .search svg { left: 8px; width: 14px; height: 14px; }
.toolbar input[type="date"] { max-width: 130px; width: auto; }
.toolbar .btn { padding: 4px 9px; font-size: var(--fs-sm); }
.toolbar .btn svg { width: 13px; height: 13px; }

/* The filter row sits directly under the action row. */
.toolbar.filters {
  padding-top: 6px;
  padding-bottom: 6px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
}
.toolbar.filters .filter-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-right: 2px;
}
.toolbar.filters .filter-label svg { width: 12px; height: 12px; }

/* ---- Modal --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(38, 25, 14, 0.42);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 200;
  animation: fade 160ms var(--ease);
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } }

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-subtle);
  animation: pop 220ms var(--ease);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}
.modal.wide { max-width: 940px; }
.modal.narrow { max-width: 430px; }

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 17px 20px 15px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.modal-head h3 { font-size: var(--fs-lg); letter-spacing: -0.018em; }
.modal-head p { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-muted); }
.modal-head .titles { flex: 1; min-width: 0; }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-alt);
  flex-shrink: 0;
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.modal-foot .spacer { flex: 1; }

/* ---- Toast --------------------------------------------------------------- */
.toasts {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 9px;
  z-index: 300;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 15px;
  background: var(--sand-900);
  color: var(--sand-50);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base);
  max-width: 400px;
  pointer-events: auto;
  animation: toast-in 260ms var(--ease);
  border-left: 3px solid var(--saffron-500);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
}
.toast.leaving { animation: toast-out 200ms var(--ease) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
.toast.ok  { border-left-color: #4FAE79; }
.toast.err { border-left-color: #E4705A; }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.toast b { display: block; font-weight: 600; }

/* ---- Empty / loading ----------------------------------------------------- */
.empty {
  text-align: center;
  padding: 52px 24px;
  color: var(--text-muted);
}
.empty .art {
  width: 52px; height: 52px;
  margin: 0 auto 14px;
  border-radius: var(--r-lg);
  display: grid; place-items: center;
  background: var(--primary-soft);
  color: var(--saffron-600);
  border: 1px solid var(--primary-border);
}
.empty .art svg { width: 24px; height: 24px; }
.empty h4 { font-size: var(--fs-md); color: var(--text-secondary); margin-bottom: 4px; }
.empty p { margin: 0 auto 16px; max-width: 46ch; font-size: var(--fs-base); line-height: 1.6; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border-subtle) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
  height: 13px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 17px; height: 17px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Pagination ---------------------------------------------------------- */
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: var(--surface-alt);
  flex-wrap: wrap;
}
.pager .spacer { flex: 1; }
.pager .pages { display: flex; gap: 3px; }
.pager .pages button {
  min-width: 28px; height: 28px;
  padding: 0 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  cursor: pointer;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  transition: all var(--dur) var(--ease);
}
.pager .pages button:hover:not(:disabled) { background: var(--bg-hover); }
.pager .pages button.on {
  background: var(--primary);
  border-color: var(--saffron-700);
  color: #fff;
  font-weight: 600;
}
.pager .pages button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Alerts panel -------------------------------------------------------- */
.alert-row {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--dur) var(--ease);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.alert-row:hover { background: var(--bg-hover); text-decoration: none; }
.alert-row:last-child { border-bottom: none; }
.alert-row .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.alert-row.critical .dot { background: var(--red-600); box-shadow: 0 0 0 3px var(--red-50); }
.alert-row.warning  .dot { background: var(--amber-600); box-shadow: 0 0 0 3px var(--amber-50); }
.alert-row.info     .dot { background: var(--teal-500); box-shadow: 0 0 0 3px var(--teal-50); }
.alert-row .body { min-width: 0; flex: 1; }
.alert-row .body b { display: block; font-size: var(--fs-base); font-weight: 600; margin-bottom: 1px; }
.alert-row .body p { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.5; }
.alert-row .cat {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--bg-sunken);
  padding: 1px 7px;
  border-radius: var(--r-full);
  height: fit-content;
  flex-shrink: 0;
  font-weight: 500;
}

/* ---- Charts -------------------------------------------------------------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font-sans); fill: var(--text-muted); font-size: 10.5px; }
.chart .axis-line { stroke: var(--border-subtle); stroke-width: 1; }
.chart .grid-line { stroke: var(--border-subtle); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .bar { transition: opacity var(--dur) var(--ease); }
.chart .bar:hover { opacity: 0.82; }
.chart .val { fill: var(--text-secondary); font-weight: 600; font-size: 10px; }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 17px 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.legend i {
  width: 9px; height: 9px;
  border-radius: 2px;
  display: inline-block;
  margin-right: 5px;
  vertical-align: -1px;
}

.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 6px; }
.donut-legend .row {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm);
}
.donut-legend .row i { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.donut-legend .row .name { flex: 1; color: var(--text-secondary); }
.donut-legend .row .n { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- Layout helpers ------------------------------------------------------
   Every track is written minmax(0, …) or minmax(min(N, 100%), …).

   A bare `1fr` is really minmax(auto, 1fr), and `auto` floors the track at its
   content's min-content width. One long word, a wide chart or a table then
   pushes the track past its share and the whole page scrolls sideways. Flooring
   at 0 lets the track shrink as intended; anything that genuinely needs width
   scrolls inside its own .table-wrap.
   -------------------------------------------------------------------------- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr));
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 16px;
}
.split-2-1 {
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr);
  gap: 16px;
}
@media (max-width: 1100px) { .split-2-1 { grid-template-columns: minmax(0, 1fr); } }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 16px; } .mb-2 { margin-bottom: 16px; }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 16px; font-size: var(--fs-base); }
.kv dt { color: var(--text-muted); white-space: nowrap; }
.kv dd { margin: 0; font-weight: 500; }

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tabs button {
  padding: 8px 14px;
  border: none;
  background: none;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: all var(--dur) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.note {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  line-height: 1.55;
  border: 1px solid;
  margin-bottom: 14px;
}
.note svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.note-info  { background: var(--teal-50);  border-color: color-mix(in srgb, var(--teal-500) 25%, transparent); color: var(--teal-500); }
.note-warn  { background: var(--amber-50); border-color: color-mix(in srgb, var(--amber-600) 25%, transparent); color: var(--amber-600); }
.note-error { background: var(--red-50);   border-color: color-mix(in srgb, var(--red-600) 25%, transparent); color: var(--red-600); }
.note-ok    { background: var(--green-50); border-color: color-mix(in srgb, var(--green-600) 25%, transparent); color: var(--green-600); }
.note b { font-weight: 600; }
.note p { margin: 2px 0 0; color: var(--text-secondary); }
.note ul { margin: 4px 0 0; padding-left: 18px; color: var(--text-secondary); }

/* ---- Responsive ---------------------------------------------------------- */

/**
 * The scrim that dims the page behind the slide-out navigation.
 *
 * It must be display:none at every width by default. It sits inside .app, which
 * is a two-column grid — left visible it would take the first grid cell and
 * shunt the sidebar into column two and the main area onto a second row.
 */
.nav-scrim { display: none; }

@media (max-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 240ms var(--ease);
    box-shadow: var(--shadow-xl);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(38, 25, 14, 0.4);
    z-index: 15;
  }
  .menu-toggle { display: grid !important; }
  .view { padding: 16px 15px 40px; }
}
.menu-toggle { display: none; }

/* ==========================================================================
   PRINT — office reports must come out clean on A4
   ========================================================================== */
@media print {
  .sidebar, .topbar, .toolbar, .pager, .toasts, .no-print,
  .row-actions, .btn, .modal-foot { display: none !important; }
  .app { display: block; height: auto; }
  .view { overflow: visible; padding: 0; height: auto; }
  .card, .stat { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { max-width: none; max-height: none; box-shadow: none; border: none; }
  body { background: #fff; font-size: 10.5pt; }
  table.data th { background: #f4f4f4 !important; -webkit-print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
  .print-only { display: block !important; }
  @page { margin: 14mm; size: A4; }
}
.print-only { display: none; }

.print-head {
  text-align: center;
  border-bottom: 2px solid var(--sand-800);
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.print-head h2 { font-size: 15pt; margin-bottom: 2px; }
.print-head p { margin: 0; font-size: 9.5pt; color: var(--text-secondary); }
.print-head .doc-title {
  margin-top: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11pt;
}

/* ==========================================================================
   ACCESS RIGHTS  —  the matrix the Executive Engineer assigns against
   ========================================================================== */

.rights-scope {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-alt);
}
.rights-scope legend {
  padding: 0 7px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.scope-opt {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--text-secondary);
  cursor: pointer;
}
.scope-opt + .scope-opt { border-top: 1px dashed var(--border-subtle); }
.scope-opt input { margin-top: 4px; flex: none; }
.scope-opt b { color: var(--text); }

.rights-matrix { display: grid; gap: 16px; }

.rights-group {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.rights-group > header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border-subtle);
}
.rights-group > header h4 { margin: 0; font-size: var(--fs-sm); }
.rights-group > header .bulk { margin-left: auto; display: flex; gap: 5px; }

.rights-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 14px;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.rights-row + .rights-row { border-top: 1px solid var(--border-subtle); }
.rights-row:hover { background: var(--bg-hover); }
.rights-row .what { flex: 1; min-width: 230px; color: var(--text); }
.rights-row .what em {
  display: block;
  font-style: normal;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.rights-row .levels { display: flex; gap: 14px; flex-wrap: wrap; }
.rights-row .lvl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
}
.rights-row.blocked { opacity: 0.5; cursor: default; }
.rights-row.blocked .lvl { cursor: default; }

.chip-list { display: flex; flex-wrap: wrap; gap: 7px; }

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}
label.inline .input { width: auto; }

/* ==========================================================================
   AN EMBEDDED MODULE  —  eEstimate keeps its own document and stylesheet
   ========================================================================== */

.module-frame {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  /* Fill the view: the shell's own header and breadcrumb are all that sit above. */
  height: calc(100vh - 168px);
  min-height: 520px;
}
.module-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}
.module-frame-note {
  margin: 10px 2px 0;
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--text-secondary);
}
@media (max-width: 760px) {
  .module-frame { height: calc(100vh - 150px); min-height: 440px; }
}

/* ==========================================================================
   COLLAPSING THE SHELL
   The menu folds to a rail of icons so a wide register gets the whole window.
   ========================================================================== */

.sidebar-brand .nav-collapse {
  margin-left: auto;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  color: var(--sidebar-muted);
  background: transparent;
  border: 1px solid transparent;
}
.sidebar-brand .nav-collapse:hover {
  color: #FFF7ED;
  background: rgba(255, 247, 237, 0.08);
  border-color: var(--sidebar-border);
}
.sidebar-brand .nav-collapse svg { width: 15px; height: 15px; }

.app.nav-collapsed { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr); }

.app.nav-collapsed .sidebar-brand { padding: 0; justify-content: center; }
.app.nav-collapsed .sidebar-brand .name { display: none; }
.app.nav-collapsed .sidebar-brand .nav-collapse {
  position: absolute;
  top: calc(var(--topbar-h) + 8px);
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
  z-index: 2;
}
.app.nav-collapsed .sidebar-nav { padding-top: 44px; }

.app.nav-collapsed .nav-item { justify-content: center; padding: 9px 0; }
.app.nav-collapsed .nav-item .label,
.app.nav-collapsed .nav-item .chev,
.app.nav-collapsed .nav-item .pill,
.app.nav-collapsed .nav-sub,
.app.nav-collapsed .sidebar-user .who,
.app.nav-collapsed .sidebar-user > svg,
.app.nav-collapsed .sidebar-credit { display: none; }

.app.nav-collapsed .sidebar-foot { padding: 10px 8px; }
.app.nav-collapsed .sidebar-user { justify-content: center; padding: 7px 0; }

/* The rail must still say which screen you are on. */
.app.nav-collapsed .nav-item.active {
  background: var(--sidebar-active-bg);
  box-shadow: inset 2px 0 0 var(--saffron-400);
}

/* Below 1000px the menu is already an overlay, so the rail does not apply. */
@media (max-width: 1000px) {
  .app.nav-collapsed { grid-template-columns: minmax(0, 1fr); }
  .app.nav-collapsed .sidebar { width: var(--sidebar-w); }
  .app.nav-collapsed .sidebar-brand { padding: 0 18px; justify-content: flex-start; }
  .app.nav-collapsed .sidebar-brand .name,
  .app.nav-collapsed .nav-item .label,
  .app.nav-collapsed .nav-item .chev,
  .app.nav-collapsed .sidebar-user .who,
  .app.nav-collapsed .sidebar-credit { display: revert; }
  .app.nav-collapsed .nav-group.open .nav-sub { display: block; }
  .app.nav-collapsed .nav-item { justify-content: flex-start; padding: 8px 11px; }
  .app.nav-collapsed .sidebar-brand .nav-collapse { position: static; transform: none; }
  .app.nav-collapsed .sidebar-nav { padding-top: 12px; }
}

/* ==========================================================================
   A MODULE AT FULL SCREEN
   eEstimate is a complete application in its own right. It is given the whole
   window while it is open, and the portal returns the moment it is closed.
   ========================================================================== */

body.module-fullscreen .sidebar,
body.module-fullscreen .topbar,
body.module-fullscreen .nav-scrim { display: none; }

body.module-fullscreen .app { grid-template-columns: minmax(0, 1fr); }
body.module-fullscreen .view { padding: 0; overflow: hidden; }

body.module-fullscreen .module-frame {
  height: 100vh;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
body.module-fullscreen .module-frame-note { display: none; }
