/* Staff layout shell and the screens inside it, following the UI style reference
   (reference/ui-export: assets/css/global.css, home_dashboard.css, buyer_portal_home.css).
   Uses the tokens in css/theme.css. Class names are the reference's. */

/* Page content stays hidden until the shell has confirmed the session. */
#page[hidden] {
  display: none;
}

/* ---- layout contract ------------------------------------------------------------- */

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

.app-shell > .page-main {
  flex: 1;
  min-width: 0; /* lets wide tables scroll inside the main column */
  display: flex;
  flex-direction: column;
}

.page-content {
  padding: var(--space-6);
  flex: 1;
  animation: fadeIn .2s ease;
}

/* ---- header ------------------------------------------------------------------------ */

.app-header {
  height: var(--header-h);
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.app-header .brand img {
  height: 40px;
  width: auto;
  display: block;
}

.app-header .header-title {
  font-size: 15px;
  font-weight: 600;
  color: #e5eaf2;
  white-space: nowrap;
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-header .header-actions a,
.app-header .header-actions button,
.app-header .header-user {
  color: #cfd8e6;
  background: transparent;
  border: none;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  white-space: nowrap;
}

.app-header .header-actions a,
.app-header .header-actions button {
  cursor: pointer;
}

/* The signed-in user: name over role, opening My Profile. */
.app-header .header-user { gap: 9px; padding: 4px 10px; }
.app-header .header-user > .fa { font-size: 20px; }
.app-header .header-user-text { display: flex; flex-direction: column; line-height: 1.25; text-align: left; }
.app-header .header-user-name { font-weight: 600; color: #fff; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.app-header .header-user-role { font-size: 11px; color: #9fb0c8; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.app-header .header-user:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.app-header .header-actions a:hover,
.app-header .header-actions button:hover {
  background: var(--navy-light);
  color: #fff;
  text-decoration: none;
}

.app-header .hamburger {
  display: none;
  background: transparent;
  border: none;
  color: #cfd8e6;
  font-size: 18px;
  cursor: pointer;
  margin-right: 4px;
}

.app-header .back-btn {
  background: var(--navy-light);
  border: 1px solid #26385c;
  color: #cfd8e6;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  transition: var(--transition);
}

.app-header .back-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---- side menu ----------------------------------------------------------------------- */

.main-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  color: #cbd5e6;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Stays in view while the page scrolls; its own list scrolls inside it. */
  position: sticky;
  top: 0;
  height: 100vh;
}

.main-sidebar .sb-scroll {
  overflow-y: auto;
  padding: 10px 0;
  flex: 1;
}

.main-sidebar .sb-scroll::-webkit-scrollbar {
  width: 6px;
}

.main-sidebar .sb-scroll::-webkit-scrollbar-thumb {
  background: #26385c;
  border-radius: 3px;
}

.main-sidebar .sb-group {
  padding: 14px 18px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6f83a8;
}

.main-sidebar .sb-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 18px;
  font-size: 13.5px;
  color: #c3cfe2;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: var(--transition);
}

.main-sidebar .sb-item i {
  width: 18px;
  text-align: center;
  font-size: 14px;
  color: #8ea3c6;
}

.main-sidebar .sb-item:hover {
  background: var(--navy-light);
  color: #fff;
  text-decoration: none;
}

.main-sidebar .sb-item:hover i {
  color: #fff;
}

.main-sidebar .sb-item.active {
  background: var(--navy-light);
  color: #fff;
  border-left-color: var(--accent);
}

.main-sidebar .sb-item.active i {
  color: var(--accent);
}

.main-sidebar .sb-home {
  color: #fff;
  font-weight: 600;
  margin-bottom: 4px;
}

/* A menu entry whose page is built (staff menu and buyer portal menu): light green label and
   icon. It stays green under the pointer and as the current page, which keeps its amber bar
   and amber icon. Entries that open "Coming soon" keep the menu's grey-blue. */
.main-sidebar .sb-item.is-built,
.main-sidebar .sb-item.is-built i {
  color: var(--menu-built);
}

.main-sidebar .sb-item.is-built:hover,
.main-sidebar .sb-item.is-built:hover i {
  color: var(--menu-built-hover);
}

.main-sidebar .sb-item.is-built.active i {
  color: var(--accent);
}

/* A menu entry whose screen is not available yet (buyer portal). */
.main-sidebar .sb-item.is-disabled {
  cursor: default;
  color: #7f91b0;
}

.main-sidebar .sb-item.is-disabled:hover {
  background: transparent;
  color: #7f91b0;
}

.main-sidebar .sb-item.is-disabled:hover i {
  color: #8ea3c6;
}

.sb-soon {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6f83a8;
  border: 1px solid #26385c;
  border-radius: 10px;
  padding: 1px 6px;
}

.sb-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .main-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }

  .main-sidebar.open {
    transform: translateX(0);
  }

  .main-sidebar.open + .sb-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(13, 27, 51, .5);
  }

  .app-header .hamburger {
    display: inline-flex;
  }

  .app-header .header-title,
  .app-header .header-user span,
  .app-header .header-actions .label {
    display: none;
  }

  .app-header {
    padding: 0 var(--space-3);
  }

  .app-header .header-actions {
    gap: var(--space-1);
  }

  .page-content {
    padding: var(--space-4);
  }
}

/* ---- dashboard (reference home_dashboard.css) ------------------------------------------- */

.dash-welcome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.dash-welcome .wtxt h1,
.dash-welcome .wtxt h2 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--navy);
  margin: 0;
}

.dash-welcome .wtxt p {
  font-size: 13px;
  color: #5a6779;
  margin: 4px 0 0;
}

.role-badge {
  background: var(--primary);
  color: #fff;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: #fff;
  border: 1px solid #e3e8ef;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow .18s;
}

.kpi-card:hover {
  box-shadow: 0 2px 10px rgba(13, 27, 51, .08);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* As rendered in the reference, where global.css's .kpi-card .kpi-label wins over the
   dashboard's own rule: 12px, grey-500, 4px top margin. */
.kpi-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-500);
  font-weight: 600;
  margin-top: 4px;
}

.kpi-ic {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.kpi-val {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}

.kpi-val.is-empty {
  color: var(--gray-400);
}

.kpi-delta {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  color: #8592a3;
}

.kpi-delta.up { color: #1a9e5f; }
.kpi-delta.down { color: #d13438; }

.ic-blue { background: #e7effa; color: #1e56a0; }
.ic-green { background: #e4f6ec; color: #1a9e5f; }
.ic-amber { background: #fdf3dd; color: #c07f00; }
.ic-red { background: #fbe7e8; color: #d13438; }
.ic-cyan { background: #e0f4f8; color: #0d8ba1; }

.dash-lower {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.dash-lower.single {
  grid-template-columns: 1fr;
}

/* Dashboard cards are slightly tighter than the global card. */
.dash-card {
  --bs-card-border-color: #e3e8ef;
  --bs-card-border-radius: 8px;
  --bs-card-inner-border-radius: 8px;
  --bs-card-cap-padding-x: 16px;
  --bs-card-cap-padding-y: 14px;
  --bs-card-spacer-x: 16px;
  --bs-card-spacer-y: 16px;
}

.chart-wrap {
  height: 260px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 12px;
  color: #5a6779;
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lg-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.dash-empty {
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  padding: 24px 12px;
}

.dash-empty i {
  font-size: 28px;
  display: block;
  margin-bottom: 10px;
}

.ql-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}

.ql-btn {
  position: relative;
  background: #fff;
  border: 1px solid #e3e8ef;
  border-radius: 8px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all .18s;
  color: var(--navy);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.ql-btn:hover {
  border-color: var(--primary);
  background: #f3f8ff;
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--navy);
}

.ql-btn i {
  font-size: 20px;
  color: var(--primary);
}

.ql-note {
  font-size: 10px;
  font-weight: 600;
  color: var(--gray-500);
}

/* ---- tiles (reference buyer_portal_home.css .quick-tile) ------------------------------------ */

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.quick-tile {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 22px 18px;
  text-align: left;
  cursor: pointer;
  transition: all .18s;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: inherit;
}

.quick-tile:hover {
  border-color: var(--primary);
  box-shadow: 0 3px 12px rgba(30, 86, 160, .12);
  transform: translateY(-2px);
  text-decoration: none;
  color: inherit;
}

.quick-tile .qt-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--navy);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
}

.quick-tile .qt-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
}

.quick-tile .qt-desc {
  font-size: 12px;
  color: #5a6b82;
  line-height: 1.4;
}

.quick-tile.is-disabled {
  cursor: default;
  background: var(--gray-50);
}

.quick-tile.is-disabled:hover {
  border-color: #e2e8f0;
  box-shadow: none;
  transform: none;
}

.quick-tile.is-disabled .qt-icon {
  background: var(--gray-200);
  color: var(--gray-500);
}

.quick-tile.is-disabled .qt-label {
  color: var(--gray-600);
}

/* ---- buyer portal home (reference buyer_portal_home.css) ------------------------------------- */

.welcome-bar {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.welcome-bar h1,
.welcome-bar h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  margin: 0 0 4px;
}

.welcome-bar p {
  margin: 0;
  color: #5a6b82;
  font-size: 13px;
}

.welcome-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.kpi-grid.three {
  grid-template-columns: repeat(3, 1fr);
}

/* ---- misc --------------------------------------------------------------------------------------- */

.state-card {
  max-width: 34rem;
  margin: 3rem auto 0;
}

.data-table td.cell-actions {
  white-space: nowrap;
  width: 1%;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  font-size: 12px;
  color: var(--gray-500);
}

textarea.font-monospace {
  font-size: 13px;
}

@media (max-width: 1024px) {
  .kpi-grid,
  .kpi-grid.three {
    grid-template-columns: repeat(2, 1fr);
  }

  .dash-lower {
    grid-template-columns: 1fr;
  }

  .ql-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .kpi-grid,
  .kpi-grid.three {
    grid-template-columns: 1fr;
  }

  .ql-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
