/* ===================================
   MAATI SPA - ADMIN THEME (density + standard components)
   Loaded after main/components/responsive so it can normalise sizes.
   - App top bar (desktop); bell + ticket popup live in ticket-alerts.css
   - Page header, KPI tiles, panels, standard tables, pills
   =================================== */

:root {
  --topbar-h: 56px;
  --std-radius: 8px;
  --std-border: #e5e7eb;
  --std-muted: #6b7280;
  --std-head-bg: #f9fafb;
}

/* ---------- Density: headings, cards, buttons ---------- */
.content-container h1 { font-size: 1.5rem; }
.content-container h2 { font-size: 1.25rem; }
.content-container h3 { font-size: 1.0625rem; }
.content-container h4 { font-size: 1rem; }
.content-container h5, .content-container h6 { font-size: .9375rem; }
.content-container h1, .content-container h2, .content-container h3 { margin-bottom: .75rem; }

.card { border-radius: var(--std-radius); border-color: var(--std-border); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card:hover { box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { padding: .875rem 1.25rem; background: #fff; }
.card-title { font-size: 1rem; }
.card-body { padding: 1.25rem; }
.card-footer { padding: .75rem 1.25rem; }

.btn { padding: .5rem 1rem; border-radius: 6px; font-size: .875rem; }
.btn-sm { padding: .3rem .65rem; font-size: .8125rem; }
.btn-lg { padding: .65rem 1.25rem; font-size: .9375rem; }

/* Touch-size minimums only on touch-sized screens (were global before) */
@media (min-width: 769px) {
  .btn, .nav-link, button, input[type="submit"], input[type="button"],
  input[type="reset"], .clickable { min-height: 0; min-width: 0; }
  .nav-link { min-height: 2.5rem; }
}

/* ---------- Standard tables (applies to every table in page content) ---------- */
.content-container table:not(.table-plain) {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
  color: var(--text-primary);
}
.content-container table:not(.table-plain) th {
  background: var(--std-head-bg);
  color: var(--std-muted);
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--std-border);
  white-space: nowrap;
}
.content-container table:not(.table-plain) td {
  padding: .55rem .75rem;
  border-bottom: 1px solid #f1f2f4;
  vertical-align: middle;
}
.content-container table:not(.table-plain) tbody tr:hover td { background: #f8fafc; }
.content-container table:not(.table-plain) tbody tr:last-child td { border-bottom: none; }
/* Opt out (layout tables, calendars): add class "table-plain" */

.table-wrap {
  background: #fff;
  border: 1px solid var(--std-border);
  border-radius: var(--std-radius);
  overflow-x: auto;
}
.table-wrap table { margin: 0; }
.cell-muted { color: var(--std-muted); }
.cell-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-nowrap { white-space: nowrap; }
.cell-strong { font-weight: 600; }
.cell-sub { display: block; font-size: .75rem; color: var(--std-muted); margin-top: 1px; }

/* ---------- Pills (status badges) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .125rem .5rem; border-radius: 999px;
  font-size: .6875rem; font-weight: 600; line-height: 1.5;
  white-space: nowrap; background: #f1f5f9; color: #475569;
}
.pill-green  { background: #dcfce7; color: #166534; }
.pill-amber  { background: #fef3c7; color: #92400e; }
.pill-red    { background: #fee2e2; color: #991b1b; }
.pill-blue   { background: #dbeafe; color: #1e40af; }
.pill-violet { background: #ede9fe; color: #5b21b6; }

/* ---------- Page header ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.375rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: .2rem 0 0; color: var(--std-muted); font-size: .8125rem; }
.page-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- KPI tiles ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.kpi {
  display: block;
  background: #fff;
  border: 1px solid var(--std-border);
  border-radius: var(--std-radius);
  padding: .8rem 1rem;
  color: inherit;
  text-decoration: none;
  transition: border-color .15s ease;
}
a.kpi:hover { border-color: var(--primary); text-decoration: none; color: inherit; }
.kpi-label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .75rem; color: var(--std-muted); font-weight: 500;
}
.kpi-label i { font-size: .75rem; color: #94a3b8; width: 14px; text-align: center; }
.kpi-value { font-size: 1.375rem; font-weight: 600; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: .6875rem; color: var(--std-muted); margin-top: .1rem; }
.kpi-alert { border-color: #fecaca; background: #fff7f7; }
.kpi-alert .kpi-value { color: #b91c1c; }
.kpi-alert .kpi-label i { color: #ef4444; }

/* ---------- Panels ---------- */
.panel {
  background: #fff;
  border: 1px solid var(--std-border);
  border-radius: var(--std-radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--std-border);
}
.panel-title { font-size: .875rem; font-weight: 600; margin: 0; display: flex; align-items: center; gap: .45rem; }
.panel-title i { color: #94a3b8; font-size: .8125rem; }
.panel-link { font-size: .75rem; font-weight: 500; }
.panel-body { padding: .9rem 1rem; }
.panel-flush table th:first-child, .panel-flush table td:first-child { padding-left: 1rem; }
.panel-flush table th:last-child, .panel-flush table td:last-child { padding-right: 1rem; }
.panel-empty { padding: 1.5rem 1rem; text-align: center; color: var(--std-muted); font-size: .8125rem; }

.list-rows { list-style: none; margin: 0; padding: 0; }
.list-rows li, .list-rows a.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .55rem 1rem; border-bottom: 1px solid #f1f2f4; font-size: .8125rem;
}
.list-rows li:last-child, .list-rows a.list-row:last-child { border-bottom: none; }
.list-rows a.list-row { color: inherit; text-decoration: none; }
.list-rows a.list-row:hover { background: #f8fafc; }
.list-row-main { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.list-row-main i { width: 16px; text-align: center; color: #94a3b8; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--std-border); background: #fff; color: #475569;
  font-size: .75rem; text-decoration: none; cursor: pointer;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

/* ---------- Desktop app top bar ---------- */
.app-topbar { display: none; }
@media (min-width: 768px) {
  .app-topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    position: sticky; top: 0; z-index: 900;
    height: var(--topbar-h);
    padding: 0 1.5rem;
    background: rgba(255,255,255,.96);
    backdrop-filter: saturate(180%) blur(6px);
    border-bottom: 1px solid var(--std-border);
  }
  body.sidebar-collapsed .app-topbar { padding-left: 4.25rem; }
  .flash-messages { top: calc(var(--topbar-h) + .75rem) !important; }
  .sidebar-expand-btn { top: 8px !important; }
}
.app-topbar-title { display: flex; flex-direction: column; min-width: 0; }
.app-topbar-title strong { font-size: .9375rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar-title span { font-size: .75rem; color: var(--std-muted); }
.app-topbar-right { display: flex; align-items: center; gap: .5rem; }
.app-topbar-user {
  display: flex; align-items: center; gap: .5rem;
  padding: .25rem .5rem .25rem .25rem; border-radius: 999px;
  border: 1px solid transparent; background: none; cursor: pointer; color: inherit;
}
.app-topbar-user:hover { border-color: var(--std-border); }
.app-topbar-user .avatar-circle {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 600; font-size: .8125rem;
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
}
.app-topbar-user .avatar-circle img { width: 100%; height: 100%; object-fit: cover; }
.app-topbar-user-name { font-size: .8125rem; font-weight: 500; line-height: 1.1; text-align: left; }
.app-topbar-user-name small { display: block; font-size: .6875rem; color: var(--std-muted); font-weight: 400; }
.app-menu { position: relative; }
.app-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 200px; background: #fff; border: 1px solid var(--std-border);
  border-radius: var(--std-radius); box-shadow: 0 12px 32px rgba(15,23,42,.14);
  z-index: 1100; overflow: hidden;
}
.app-dropdown.show { display: block; }
.app-dropdown a.app-dropdown-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem;
  font-size: .8125rem; color: var(--text-primary); text-decoration: none;
}
.app-dropdown a.app-dropdown-item:hover { background: #f8fafc; }
.app-dropdown a.app-dropdown-item i { width: 14px; color: #94a3b8; }
.app-dropdown-sep { height: 1px; background: var(--std-border); }


/* ---------- Specificity fixes: component titles beat the density headings ---------- */
.content-container .panel-title { font-size: .875rem; margin: 0; }
.content-container .page-head h1 { font-size: 1.375rem; margin: 0; }

/* ---------- Compact sidebar (desktop) ---------- */
@media (min-width: 768px) {
  .nav-menu { gap: 2px !important; }
  .nav-menu .nav-link {
    font-size: .8125rem;
    padding: .45rem .75rem;
    min-height: 2.125rem;
    border-radius: 6px;
    gap: .6rem;
  }
  .nav-menu .nav-link i { width: 16px; text-align: center; font-size: .8125rem; }
  .nav-user { padding: .75rem !important; gap: .5rem !important; }
  .nav-user .logout-btn { padding: .4rem .75rem; font-size: .8125rem; background: #fff;
                          color: #b91c1c; border: 1px solid #fecaca; }
  .nav-user .logout-btn:hover { background: #fef2f2; color: #991b1b; transform: none; box-shadow: none; }
}
@media (min-width: 768px) {
  .nav-menu .nav-link.nav-link-sub { font-size: .8125rem !important; padding-left: 2.1rem !important; color: var(--text-secondary); }
  .nav-menu .nav-link.nav-link-sub i { font-size: .75rem; }
  .nav-menu .nav-link.nav-link-sub:hover, .nav-menu .nav-link.nav-link-sub.active { color: #fff; }
}

/* KPI labels stay on one line */
.kpi-label span, .kpi-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Slim footer for signed-in staff ---------- */
.app-footer {
  margin-top: auto;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .9rem 1.5rem; border-top: 1px solid var(--std-border);
  font-size: .75rem; color: var(--std-muted); background: #fff;
}
.app-footer a { color: var(--std-muted); margin-left: 1rem; text-decoration: none; }
.app-footer a:hover { color: var(--primary); }
@media (min-width: 768px) {
  .app-footer { margin-left: 260px; transition: margin-left .2s ease; }
  body.sidebar-collapsed .app-footer { margin-left: 0; }
}
@media (max-width: 767.98px) { .app-footer { padding-bottom: 5rem; } }
.kpi { padding: .75rem .8rem; }
.kpi-label { font-size: .71875rem; gap: .35rem; }

/* ---------- Sidebar groups (collapsible) ---------- */
.nav-group { display: flex; flex-direction: column; }
.nav-group + .nav-group, .nav-link + .nav-group { margin-top: .35rem; }
.nav-group-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  width: 100%; min-height: 0 !important; min-width: 0 !important;
  padding: .5rem .75rem .3rem; background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: .6875rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: #94a3b8; text-align: left; border-radius: 6px;
}
.nav-group-toggle:hover { color: #475569; }
.nav-group-toggle i { font-size: .625rem; transition: transform .15s ease; }
.nav-group.collapsed .nav-group-toggle i { transform: rotate(-90deg); }
.nav-group-items { display: flex; flex-direction: column; gap: 2px; }
.nav-group.collapsed .nav-group-items { display: none; }
/* A collapsed group still signals waiting work (tickets, approvals, low stock) */
.nav-group.collapsed:has(.nav-badge[data-alert]:not([hidden])) .nav-group-toggle span::after {
  content: ''; display: inline-block; width: 7px; height: 7px; margin-left: .45rem;
  border-radius: 50%; background: #ef4444; vertical-align: middle;
}
.nav-link .nav-badge[hidden] { display: none; }
.nav-link .nav-badge { flex: 0 0 auto !important; margin-left: auto; text-align: center; }
