:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee7;
  --primary: #008f7a;
  --primary-2: #2563eb;
  --accent: #f59e0b;
  --warning: #b7791f;
  --danger: #b42318;
  --success: #157347;
  --sidebar: #050b1f;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

a {
  text-decoration: none;
}

.erp-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.erp-sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(15, 23, 42, .18);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: #fff;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand:hover {
  color: #fff;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #b6c2d1;
}

.sidebar-nav {
  display: grid;
  gap: 2px;
  margin-top: 18px;
}

.nav-section {
  border-radius: 8px;
}

.nav-section[open] {
  background: rgba(255, 255, 255, .04);
  padding-bottom: 6px;
}

.nav-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: #e5e7eb;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

/* The default disclosure triangle sits on the wrong side in RTL and cannot be positioned, so it is
   removed and replaced by the caret drawn below. Safari needs the -webkit- pseudo-element too. */
.nav-section-head::-webkit-details-marker {
  display: none;
}

.nav-section-head:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.nav-section-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .10);
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 800;
}

.nav-section[open] .nav-section-icon {
  background: var(--primary);
  color: #fff;
}

.nav-section-title {
  flex: 1 1 auto;
  min-width: 0;
}

.nav-section-count {
  flex: 0 0 auto;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .10);
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* Caret, drawn last in the flex row so it lands on the left edge in RTL. */
.nav-section-head::after {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-left: 2px solid #94a3b8;
  border-bottom: 2px solid #94a3b8;
  transform: rotate(-45deg);
  transition: transform .15s ease;
}

.nav-section[open] > .nav-section-head::after {
  transform: rotate(135deg);
}

.nav-section-body {
  display: grid;
  gap: 2px;
  /* The rail ties the screens visually to the section they belong to. */
  margin: 2px 18px 0 8px;
  padding-right: 10px;
  border-right: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-nav a {
  color: #cbd5e1;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.sidebar-nav a.active {
  background: rgba(0, 143, 122, .18);
  color: #fff;
  box-shadow: inset -3px 0 0 var(--primary);
}

.erp-main {
  min-width: 0;
}

.erp-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 82px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-kicker {
  color: var(--muted);
  font-size: .82rem;
}

.erp-topbar h1 {
  margin: 2px 0 0;
  font-size: 1.45rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
}

.erp-content {
  padding: 26px 28px 48px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f5f7fa, #dfe7ef);
}

.login-panel {
  width: min(960px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(16, 24, 40, .15);
}

.login-intro {
  padding: 44px;
  background: var(--sidebar);
  color: #fff;
}

.login-intro h1 {
  margin: 22px 0 12px;
  font-size: 1.85rem;
}

.login-intro p {
  color: #cdd5df;
}

.login-hint {
  display: grid;
  gap: 6px;
  margin-top: 34px;
  background: rgba(255,255,255,.08);
  border-radius: 8px;
  padding: 16px;
}

.login-form {
  padding: 44px;
}

.filter-bar,
.search-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 10px;
  margin-bottom: 18px;
}

.dashboard-filter {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) auto;
}

.search-bar {
  grid-template-columns: minmax(220px, 1fr) auto auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.dashboard-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.quick-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .05);
}

.quick-actions a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.report-catalog {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.report-catalog a {
  display: grid;
  gap: 6px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .05);
}

.report-catalog a:hover {
  border-color: var(--primary);
}

.report-catalog strong {
  font-size: .98rem;
}

.report-catalog span {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.6;
}

.metric-card,
.panel,
.table-panel,
.form-panel,
.empty-state,
.details-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

.metric-card {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.metric-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric-card strong {
  font-size: 1.55rem;
}

.metric-card.warning strong {
  color: var(--warning);
}

.metric-card.success strong {
  color: var(--success);
}

.metric-card.danger strong {
  color: var(--danger);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header,
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-header h2,
.page-toolbar h2 {
  font-size: 1.15rem;
  margin: 0;
}

.page-toolbar p {
  color: var(--muted);
  margin: 4px 0 0;
}

.toolbar-actions,
.row-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: #007a69;
  --bs-btn-hover-border-color: #007a69;
}

.btn-warning {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
}

.row-actions {
  justify-content: flex-end;
}

.row-actions form {
  display: inline-flex;
}

.table-panel {
  overflow: hidden;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.progress-row {
  display: grid;
  grid-template-columns: 220px minmax(120px, 1fr) 52px;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.progress-row:first-of-type {
  border-top: 0;
}

.progress-row span {
  color: var(--muted);
  font-size: .9rem;
}

.progress-bar {
  background-color: var(--primary);
}

.summary-list {
  display: grid;
  gap: 10px;
}

.risk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.risk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #f8fafc;
}

.risk-item strong {
  font-size: 1.2rem;
}

.risk-item.warning strong {
  color: var(--warning);
}

.risk-item.danger strong {
  color: var(--danger);
}

.mini-chart {
  display: grid;
  gap: 12px;
}

.chart-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 110px;
  align-items: center;
  gap: 10px;
}

.chart-row span,
.chart-row small {
  color: var(--muted);
  font-size: .86rem;
}

.chart-bars {
  display: grid;
  gap: 4px;
}

.chart-bars i {
  display: block;
  height: 9px;
  min-width: 2px;
  border-radius: 999px;
}

.bar-primary {
  background: var(--primary);
}

.bar-secondary {
  background: var(--primary-2);
}

.bar-secondary.danger {
  background: var(--danger);
}

.compact-timeline {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-list span {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline div {
  display: grid;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.timeline span,
.timeline small {
  color: var(--muted);
}

.form-panel {
  padding: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-field.wide {
  grid-column: 1 / -1;
}

.form-actions {
  margin-top: 22px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
}

.details-grid div {
  padding: 16px;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.details-grid span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.empty-state {
  padding: 34px;
  text-align: center;
}

.empty-state h2 {
  margin: 10px 0;
  font-size: 1.25rem;
}

.empty-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
  font-weight: 800;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pass {
  background: #e8f7ef;
  color: var(--success);
}

.status-warning {
  background: #fff7e6;
  color: var(--warning);
}

.status-fail {
  background: #fff1f0;
  color: var(--danger);
}

.empty-state.compact {
  border: 0;
}

.empty-inline {
  color: var(--muted);
  padding: 18px 0;
}

.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.print-body {
  background: #fff;
  padding: 24px;
}

.print-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1rem;
  margin: 0 0 14px;
}

.checkbox-grid {
  display: grid;
  gap: 10px 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.permissions-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

@media (max-width: 1100px) {
  .erp-shell {
    grid-template-columns: 1fr;
  }

  .erp-sidebar {
    position: static;
    height: auto;
  }

  /* Sections stay stacked; it is the screens inside the open section that get the second column,
     so the collapsed headers remain a single readable list on a wide-but-short viewport. */
  .nav-section-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid,
  .dashboard-metrics,
  .quick-actions,
  .report-catalog,
  .dashboard-grid,
  .details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .erp-topbar,
  .page-toolbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-bar,
  .search-bar,
  .metric-grid,
  .dashboard-metrics,
  .quick-actions,
  .report-catalog,
  .dashboard-grid,
  .permissions-grid,
  .form-grid,
  .details-grid,
  .login-panel {
    grid-template-columns: 1fr;
  }

  .nav-section-body {
    grid-template-columns: 1fr;
  }

  .progress-row {
    grid-template-columns: 1fr;
  }

  .dashboard-filter,
  .risk-grid,
  .chart-row,
  .compact-timeline {
    grid-template-columns: 1fr;
  }

  .erp-content,
  .erp-topbar,
  .login-form,
  .login-intro {
    padding: 18px;
  }
}

@media print {
  .erp-sidebar,
  .erp-topbar,
  .page-toolbar,
  .search-bar,
  .pagination-wrap,
  .row-actions {
    display: none !important;
  }

  .erp-shell {
    display: block;
  }

  .erp-content {
    padding: 0;
  }
}
