:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef7f6;
  --text: #102a31;
  --muted: #6b7f86;
  --primary: #0f5966;
  --primary-2: #0a8f83;
  --accent: #2e9fd3;
  --danger: #d94b4b;
  --warning: #b67a13;
  --success: #11895d;
  --border: #d8e3e6;
  --shadow: 0 14px 35px rgba(15, 59, 74, .08);
  --radius: 18px;
  --font-ar: "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic" , sans-serif, Arial, Tahoma;
}

* {
  box-sizing: border-box
}

html {
  font-family: var(--font-ar);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  line-height: 1.55
}

.app-shell {
  display: grid;
  grid-template-columns: 285px 1fr;
  min-height: 100vh
}

.sidebar {
  background: linear-gradient(180deg, #0f3d4a, #0e5b67);
  color: #fff;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #19b38f, #39a2d4);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 24px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, .22)
}

.brand-title {
  font-weight: 800;
  font-size: 18px
}

.brand-subtitle {
  font-size: 12px;
  opacity: .78
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 34px
}

.nav-link {
  color: #d7f5f0;
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 700
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, .14);
  color: #fff
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, .18);
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px
}

.sidebar-footer a {
  color: #fff
}

.main {
  padding: 28px;
  overflow-x: hidden;
  min-width: 0
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 24px
}

.topbar h1 {
  margin: 0;
  font-size: 28px
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted)
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff
}

.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--border)
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 59, 74, .12)
}

.full {
  width: 100%
}

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 16px;
  margin-bottom: 20px
}

.cards.compact {
  grid-template-columns: repeat(3, minmax(130px, 1fr))
}

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0
}

.card {
  padding: 18px
}

.kpi span,
.card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700
}

.kpi strong,
.card strong {
  display: block;
  font-size: 28px;
  margin-top: 4px
}

.kpi small,
.card small {
  color: var(--muted)
}

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

.panel {
  padding: 20px;
  margin-bottom: 20px
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 19px
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px
}

.panel-head h2 {
  margin: 0
}

.link {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px
}

.bar-row {
  display: grid;
  grid-template-columns: 180px 70px 1fr;
  gap: 12px;
  align-items: center
}

.bar-row span {
  font-weight: 700
}

.bar-row b {
  font-variant-numeric: tabular-nums
}

.bar-row div {
  height: 12px;
  background: #edf2f4;
  border-radius: 999px;
  overflow: hidden
}

.bar-row i {
  height: 100%;
  display: block;
  background: linear-gradient(90deg, var(--danger), #f5a362);
  border-radius: 999px
}

.bar-list.accent .bar-row i {
  background: linear-gradient(90deg, var(--primary-2), var(--accent))
}

.insights {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px
}

.insights div {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 14px
}

.muted {
  color: var(--muted)
}

.muted-panel {
  background: #fbfdfd
}

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin: 0 0 16px;
  border: 1px solid var(--border);
  background: #eef6ff;
  color: #164364
}

.alert.success {
  background: #e9f9f2;
  color: #0c6847;
  border-color: #bde8d4
}

.alert.error {
  background: #fff0f0;
  color: #a83232;
  border-color: #f1c4c4
}

.alert.warning {
  background: #fff8e9;
  color: #8a5a00;
  border-color: #f1ddb0
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px
}

.form-stack label {
  font-weight: 800;
  color: var(--text)
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
  font: inherit;
  margin-top: 6px;
  color: var(--text)
}

.check {
  display: flex;
  align-items: center;
  gap: 8px
}

.check input {
  width: auto;
  margin: 0
}

.filters {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 16px
}

.filters input,
.filters select {
  min-width: 180px;
  margin-top: 0
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain
}

.table-wrap:focus-within {
  outline: 2px solid rgba(46, 159, 211, .25);
  outline-offset: 2px
}

table {
  width: max-content;
  min-width: max(100%, 920px);
  border-collapse: collapse;
  background: #fff
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: top
}

th {
  background: #f0f7f8;
  color: #163c45;
  font-weight: 900;
  position: sticky;
  top: 0
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 2px
}

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 12px
}

.badge-green {
  background: #dff7ed;
  color: #0a6d49
}

.badge-red {
  background: #ffe7e7;
  color: #a43030
}

.badge-blue {
  background: #e2f2ff;
  color: #176493
}

.badge-gray {
  background: #edf1f2;
  color: #607176
}

.steps {
  margin: 0;
  padding-right: 22px
}

.steps li {
  margin-bottom: 10px
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px
}

.report-card p {
  min-height: 54px;
  color: var(--muted)
}

.rule-list {
  display: grid;
  gap: 12px
}

.rule-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #f5fafb;
  border-radius: 14px;
  padding: 13px
}

.rule-list span {
  font-weight: 900;
  color: var(--primary)
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 10%, #dff8f1, transparent 30%), linear-gradient(135deg, #0f3d4a, #0e5b67)
}

.login-card {
  width: min(440px, 92vw);
  background: #fff;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .22)
}

.login-card h1 {
  margin: 24px 0 16px
}

.login-brand {
  color: var(--text)
}


/* Horizontal overflow handling for data-heavy pages */

.app-shell,
.main,
.topbar,
.panel,
.card,
.grid-2>*,
.cards>*,
.report-grid>* {
  min-width: 0
}

.table-wrap::-webkit-scrollbar,
.main-scroll-x::-webkit-scrollbar {
  height: 10px
}

.table-wrap::-webkit-scrollbar-thumb,
.main-scroll-x::-webkit-scrollbar-thumb {
  background: #b8cbd0;
  border-radius: 999px
}

.table-wrap::-webkit-scrollbar-track,
.main-scroll-x::-webkit-scrollbar-track {
  background: #eef4f5;
  border-radius: 999px
}

.table-wrap table th,
.table-wrap table td {
  white-space: nowrap
}

.table-wrap table td textarea {
  white-space: normal;
  min-width: 220px
}

.table-wrap table td input,
.table-wrap table td select {
  min-width: 120px
}

.table-wrap table td .check {
  white-space: nowrap;
  min-width: max-content
}

.small-table {
  max-width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch
}

.rule-form-grid,
.inline-form {
  min-width: 0
}

.rule-details {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch
}

.rules-page .panel {
  overflow: hidden
}

.rules-page .table-wrap table {
  min-width: max(100%, 1100px)
}

.rules-page #stage-update-form + .table-wrap table {
  min-width: max(100%, 1850px)
}

.rules-page .grid-2 .table-wrap table {
  min-width: max(100%, 900px)
}

@media (max-width:900px) {
  .table-wrap {
    border-radius: 12px
  }
  .table-wrap table {
    min-width: max(100%, 980px)
  }
  .rules-page #stage-update-form + .table-wrap table {
    min-width: 1700px
  }
}

@media print {
  .table-wrap {
    overflow: visible
  }
  .table-wrap table {
    width: 100%;
    min-width: 0
  }
  .table-wrap table th,
  .table-wrap table td {
    white-space: normal
  }
}

@media (max-width:1100px) {
  .app-shell {
    grid-template-columns: 1fr
  }
  .sidebar {
    position: static;
    height: auto
  }
  .nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr)
  }
  .cards {
    grid-template-columns: repeat(2, 1fr)
  }
  .grid-2,
  .insights,
  .report-grid {
    grid-template-columns: 1fr
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start
  }
  .bar-row {
    grid-template-columns: 1fr 60px
  }
  .bar-row div {
    grid-column: 1/-1
  }
  .main {
    padding: 18px
  }
}

@media print {
  .sidebar,
  .top-actions,
  .filters {
    display: none
  }
  .app-shell {
    display: block
  }
  .main {
    padding: 0
  }
  .panel,
  .card {
    box-shadow: none
  }
}

.btn-danger {
  background: linear-gradient(135deg, #9f2e2e, var(--danger));
  color: #fff
}

.danger-zone {
  border-color: #f1c4c4
}

.danger-zone h2 {
  color: #9f2e2e
}

code {
  direction: ltr;
  unicode-bidi: embed;
  background: #f2f6f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 6px;
  color: #17414b
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
  font: inherit;
  margin-top: 6px;
  color: var(--text);
  resize: vertical;
  min-width: 180px
}

.rule-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px
}

.inline-form .check {
  align-self: center
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap
}

.small-table {
  max-height: 440px;
  max-width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch
}

.small-table table {
  min-width: 720px
}

.rule-details {
  margin-top: 16px;
  background: #f8fbfb;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px
}

.rule-details summary {
  font-weight: 900;
  color: var(--primary);
  cursor: pointer;
  margin-bottom: 12px
}

@media (max-width:1100px) {
  .rule-form-grid,
  .inline-form {
    grid-template-columns: 1fr
  }
}


/* Users and account management */

.users-page .users-table-wrap table {
  min-width: max(100%, 1500px)
}

.users-page .mini-password-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: end;
  min-width: 430px
}

.users-page .mini-password-form input {
  margin-top: 0
}

.users-page .badge {
  margin-inline-start: 8px
}

@media (max-width:900px) {
  .users-page .mini-password-form {
    grid-template-columns: 1fr;
    min-width: 260px
  }
  .users-page .users-table-wrap table {
    min-width: 1350px
  }
}