/* =====================================================================
   Staff Management System - application styles
   Mobile first. Layered on top of Bootstrap 5.3.
   ===================================================================== */

:root {
  --app-sidebar-w: 260px;
  --app-topbar-h: 60px;

  --app-bg: #f4f6fb;
  --app-surface: #ffffff;
  --app-border: #e5e9f2;
  --app-ink: #1b2333;
  --app-muted: #6b7688;

  --app-primary: #2f5bea;
  --app-primary-soft: #eaf0ff;
  --app-accent: #0aa07a;

  --app-radius: 14px;
  --app-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --app-shadow: 0 6px 24px -12px rgba(16, 24, 40, .22);
}

/* ---------------------------------------------------------------- base */
body {
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: .95rem;
  padding-top: var(--app-topbar-h);
  overflow-x: hidden;
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

.min-w-0 { min-width: 0; }

/* Visible focus ring for keyboard users */
:focus-visible {
  outline: 3px solid rgba(47, 91, 234, .35);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- topbar */
.app-topbar {
  height: var(--app-topbar-h);
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  box-shadow: var(--app-shadow-sm);
  z-index: 1035;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  color: var(--app-ink);
  max-width: 55vw;
}
.app-brand:hover { text-decoration: none; color: var(--app-ink); }

.app-brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--app-primary), #6d8bff);
  color: #fff;
  font-size: 1rem;
  flex: 0 0 auto;
}

.app-brand-text { font-size: 1rem; }

.btn-icon {
  border: 0;
  background: transparent;
  color: var(--app-ink);
  border-radius: 10px;
  padding: .4rem .55rem;
  line-height: 1;
}
.btn-icon:hover { background: var(--app-primary-soft); color: var(--app-primary); }

.app-badge-dot {
  position: absolute;
  top: 2px; right: 0;
  font-size: .6rem;
  padding: .18em .4em;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--app-primary-soft);
  color: var(--app-primary);
  font-weight: 700;
  font-size: .78rem;
  overflow: hidden;
  flex: 0 0 auto;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: .7rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.15rem; }

/* ------------------------------------------------------------ sidebar */
.app-sidebar {
  background: var(--app-surface);
  border-right: 1px solid var(--app-border);
  width: var(--app-sidebar-w);
}

.app-sidebar-body {
  display: flex;
  flex-direction: column;
  padding: 1rem .75rem;
}

.app-nav-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  font-weight: 700;
  color: var(--app-muted);
  padding: .35rem .6rem;
}

.app-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: #3c4557;
  border-radius: 10px;
  padding: .6rem .65rem;
  font-weight: 500;
  min-height: 44px; /* touch target */
}
.app-nav .nav-link:hover { background: #f2f5fc; color: var(--app-primary); text-decoration: none; }
.app-nav .nav-link.active { background: var(--app-primary-soft); color: var(--app-primary); font-weight: 600; }
.app-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }

.app-sidebar-foot {
  margin-top: auto;
  padding: .85rem .65rem 0;
  border-top: 1px solid var(--app-border);
}

@media (min-width: 992px) {
  .app-sidebar.offcanvas-lg {
    position: fixed;
    top: var(--app-topbar-h);
    bottom: 0;
    left: 0;
    z-index: 1030;
    overflow-y: auto;
  }
  .app-main { margin-left: var(--app-sidebar-w); }
}

/* --------------------------------------------------------------- main */
.app-main { min-height: calc(100vh - var(--app-topbar-h)); display: flex; flex-direction: column; }
.app-container { padding: 1rem; flex: 1 1 auto; max-width: 1500px; }

@media (min-width: 768px) { .app-container { padding: 1.5rem; } }

.app-footer {
  border-top: 1px solid var(--app-border);
  background: var(--app-surface);
  padding: .85rem 1rem;
  font-size: .82rem;
  color: var(--app-muted);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--app-muted); margin: .2rem 0 0; font-size: .88rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (max-width: 575.98px) {
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
}

.breadcrumb { margin-bottom: .6rem; }

/* -------------------------------------------------------------- cards */
.card {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow-sm);
}
.card-header {
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  font-weight: 600;
  border-radius: var(--app-radius) var(--app-radius) 0 0 !important;
  padding: .85rem 1rem;
}

/* Summary stat cards */
.stat-card {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .95rem 1rem;
  height: 100%;
}
.stat-icon {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  font-size: 1.15rem;
  background: var(--app-primary-soft);
  color: var(--app-primary);
  flex: 0 0 auto;
}
.stat-icon.green  { background: #e6f7f1; color: #0aa07a; }
.stat-icon.amber  { background: #fef3e2; color: #d98218; }
.stat-icon.red    { background: #fdeaea; color: #d9534f; }
.stat-icon.purple { background: #f1ebfd; color: #7a4fd1; }
.stat-icon.slate  { background: #eef1f6; color: #55637a; }

.stat-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--app-muted); font-weight: 600; }
.stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; word-break: break-word; }
.stat-hint  { font-size: .74rem; color: var(--app-muted); }

/* ------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .7rem .75rem; }
.table thead th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--app-muted);
  border-bottom-width: 1px;
  white-space: nowrap;
  background: #fafbfe;
}
.table tbody tr:hover { background: #f8faff; }
.table td { vertical-align: middle; }

.row-link { cursor: pointer; }

/* Card view replacement for tables on very small screens */
.stack-table thead { display: none; }
@media (max-width: 767.98px) {
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr {
    border: 1px solid var(--app-border);
    border-radius: 12px;
    margin-bottom: .65rem;
    padding: .25rem .15rem;
    background: #fff;
  }
  .stack-table td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border: 0;
    padding: .4rem .75rem;
    text-align: right;
  }
  .stack-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--app-muted);
    font-size: .78rem;
    text-align: left;
    flex: 0 0 42%;
  }
  .stack-table td[data-label=""]::before { content: ""; }
}
@media (min-width: 768px) {
  .stack-table thead { display: table-header-group; }
}

/* ------------------------------------------------------------- forms */
.form-label { font-weight: 600; font-size: .82rem; margin-bottom: .3rem; }
.form-control, .form-select {
  border-radius: 10px;
  border-color: #d8deea;
  min-height: 42px;
  font-size: .92rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 .2rem rgba(47, 91, 234, .15);
}
textarea.form-control { min-height: 90px; }
.form-text { font-size: .78rem; }

.btn { border-radius: 10px; font-weight: 500; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-sm { min-height: 34px; font-size: .82rem; border-radius: 8px; }
.btn-primary { background: var(--app-primary); border-color: var(--app-primary); }
.btn-primary:hover { background: #2549c4; border-color: #2549c4; }

.required-mark { color: #d9534f; }

/* Filter panel */
.filter-card .card-body { padding: 1rem; }
.filter-grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 576px) { .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 992px) { .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Tick-list filter: a closed button that opens a panel of checkboxes.
   Replaces <select multiple>, which phones render as a plain dropdown. */
.check-list { position: relative; }

/* The button takes its width, border and arrow from Bootstrap's
   .form-select; only the bits Bootstrap cannot know about live here. */
.check-toggle { min-height: 42px; }
.check-toggle:hover:not(:disabled) { border-color: #b9c4da; }
.check-toggle:disabled { background: #f4f6fb; color: #8a97ad; }
.check-toggle .check-summary {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.check-list.is-open .check-toggle { border-color: var(--app-primary); }

.check-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 14rem;
  padding: .5rem;
  border: 1px solid #d8deea;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(22, 35, 63, .16);
}
/* Closed state is the `hidden` attribute, which the browser honours with or
   without this stylesheet. Nothing here re-hides it. */
.check-panel[hidden] { display: none; }
.check-panel .check-search { margin-bottom: .35rem; border-radius: 8px; }

.check-list-items { max-height: 13rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.check-list .form-check {
  margin: 0;
  padding: .45rem .5rem .45rem 2rem;
  border-radius: 8px;
}
.check-list .form-check + .form-check { border-top: 1px solid #eef1f7; }
.check-list .form-check-input { margin-left: -1.5rem; width: 1.1rem; height: 1.1rem; }
.check-list .form-check-label { cursor: pointer; width: 100%; }
.check-list .form-check:has(.form-check-input:checked) { background: #eef3ff; }
.check-item.is-hidden { display: none; }

.check-panel-foot {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .4rem;
  padding-top: .4rem;
  border-top: 1px solid #eef1f7;
}

/* Fingers need more room than a mouse pointer. */
@media (max-width: 991.98px) {
  .check-list-items { max-height: 15rem; }
  .check-list .form-check { padding-top: .6rem; padding-bottom: .6rem; }
  .check-list .form-check-input { width: 1.25rem; height: 1.25rem; }
  .check-panel-foot .btn { flex: 1; min-height: 40px; }
}

.filter-toggle { width: 100%; justify-content: space-between; }
@media (min-width: 992px) { .filter-toggle { display: none; } .filter-body { display: block !important; } }

/* Searchable dropdown */
.searchable-wrap { position: relative; }
.searchable-input { padding-right: 2rem; }
.searchable-clear {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--app-muted); line-height: 1;
}

/* Rating inputs */
.rating-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: .5rem;
  padding: .85rem 0;
  border-bottom: 1px dashed var(--app-border);
}
@media (min-width: 768px) {
  .rating-row { grid-template-columns: 1.4fr 1fr .9fr; align-items: center; gap: 1rem; }
}
.rating-row:last-child { border-bottom: 0; }
.rating-value {
  display: inline-grid; place-items: center;
  min-width: 46px; height: 34px;
  border-radius: 9px;
  background: var(--app-primary-soft);
  color: var(--app-primary);
  font-weight: 700;
}
.score-pill {
  display: inline-block;
  min-width: 42px;
  text-align: center;
  border-radius: 999px;
  padding: .15rem .5rem;
  font-weight: 700;
  font-size: .8rem;
  background: #eef1f6;
  color: #55637a;
}
.score-pill.good { background: #e6f7f1; color: #08795e; }
.score-pill.mid  { background: #fef3e2; color: #a9640d; }
.score-pill.low  { background: #fdeaea; color: #b33b37; }

/* --------------------------------------------------- picked item table */
/* Keeps the quantity and unit controls from being squeezed to nothing
   while the product name takes the remaining width. */
#pickedTable td, #pickedTable th { vertical-align: middle; }
#pickedTable .form-control,
#pickedTable .form-select { min-width: 4.5rem; }

@media (max-width: 575.98px) {
  #pickedTable { min-width: 30rem; }
}

/* ------------------------------------------------------------ gallery */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: .6rem;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--app-border);
  background: #eef1f6;
  cursor: zoom-in;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .photo-remove {
  position: absolute; top: 4px; right: 4px;
  border: 0; border-radius: 8px;
  background: rgba(17, 24, 39, .72);
  color: #fff; font-size: .72rem;
  padding: .18rem .4rem; line-height: 1;
}

/* ---------------------------------------------------------- tree view */
.tree-list { list-style: none; margin: 0; padding: 0; }
.tree-list .tree-list {
  margin-left: 1.1rem;
  padding-left: .85rem;
  border-left: 2px solid var(--app-border);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .25rem;
  border-radius: 10px;
  min-height: 48px;
}
.tree-row:hover { background: #f6f9ff; }

.tree-toggle {
  border: 0;
  background: transparent;
  color: var(--app-muted);
  width: 24px; height: 24px;
  border-radius: 6px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  padding: 0;
}
.tree-toggle:hover { background: var(--app-primary-soft); color: var(--app-primary); }
.tree-toggle[aria-expanded="false"] i { transform: rotate(-90deg); }
.tree-toggle i { transition: transform .15s ease; font-size: .85rem; }
.tree-toggle-empty { visibility: hidden; }

.tree-counts { display: flex; gap: .3rem; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 575.98px) {
  .tree-list .tree-list { margin-left: .5rem; padding-left: .5rem; }
  .tree-counts .badge { font-size: .68rem; }
}

/* ------------------------------------------------------------ timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1.1rem; border-left: 2px solid var(--app-border); }
.timeline-item { position: relative; padding: 0 0 1.1rem 1rem; }
.timeline-item::before {
  content: "";
  position: absolute; left: -1.42rem; top: .3rem;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--app-primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--app-primary-soft);
}
.timeline-item.muted::before { background: #aab3c4; box-shadow: 0 0 0 2px #eef1f6; }
.timeline-meta { font-size: .76rem; color: var(--app-muted); }

/* ------------------------------------------------------- empty states */
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--app-muted); }
.empty-state .bi { font-size: 2.1rem; opacity: .45; display: block; margin-bottom: .5rem; }

/* ----------------------------------------------------- loading states */
.is-loading { position: relative; pointer-events: none; opacity: .65; }
.btn.is-loading::after {
  content: "";
  width: 1rem; height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: app-spin .7s linear infinite;
}
@keyframes app-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- login page */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: linear-gradient(160deg, #1f2c4d 0%, #2f5bea 100%);
}
.login-card { width: 100%; max-width: 420px; border-radius: 18px; }

/* ------------------------------------------------------------- charts */
.chart-box { position: relative; height: 260px; }
@media (min-width: 768px) { .chart-box { height: 300px; } }
.chart-box canvas { max-width: 100%; }

/* ------------------------------------------------------------- print */
@media print {
  .app-topbar, .app-sidebar, .app-footer, .page-actions, .filter-card, .no-print, .pagination { display: none !important; }
  body { padding-top: 0; background: #fff; }
  .app-main { margin-left: 0; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
  a[href]::after { content: ""; }
}
