/*
  PUC Self-Funded design system - shares the same visual identity as PUCSortingSystem's own
  puc-admin.css (same organization, meant to feel like one suite of tools), ported here as its
  own file so SelfFunded has no file/asset dependency on the sorting system's project.
*/

:root {
  --puc-navy: #244974;
  --puc-navy-dark: #16395f;
  --puc-navy-soft: #4d7099;
  --puc-navy-50: #eef2f7;
  --puc-gold: #c49a00;
  --puc-gold-dark: #8a6b00;
  --puc-gold-soft: #fbf1d1;
  --puc-bg: #f4f6f9;
  --puc-white: #ffffff;
  --puc-border: #e5e7eb;
  --puc-text: #1f2937;
  --puc-text-muted: #6b7280;
  --puc-danger: #dc3545;
  --puc-danger-soft: #fdecee;
  --puc-success: #198754;
  --puc-success-soft: #e8f5ee;
  --puc-warning: #ffc107;
  --puc-radius: 12px;
  --puc-radius-sm: 8px;
  --puc-shadow: 0 1px 2px rgba(22, 57, 95, .06), 0 4px 14px rgba(22, 57, 95, .07);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  background: var(--puc-bg);
  color: var(--puc-text);
  font-family: 'Cairo', 'Tajawal', 'Segoe UI', sans-serif;
}

body { min-height: 100vh; padding-bottom: 3rem; }

h1, h2, h3, h4, h5 { color: var(--puc-navy); font-weight: 700; margin: 0; }
h3 { font-size: 1.4rem; }

a { color: var(--puc-navy); }
a:hover { color: var(--puc-gold-dark); }

/* ---------- App shell (sidebar control panel) ---------- */
.puc-app { display: flex; min-height: 100vh; align-items: stretch; }

.puc-sidebar {
  width: 264px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--puc-navy) 0%, var(--puc-navy-dark) 100%);
  border-inline-start: 3px solid var(--puc-gold);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-inline-start: 0;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.puc-sidebar-brand { padding: 1.15rem 1.2rem 1rem; border-bottom: 1px solid rgba(255,255,255,.14); }
.puc-sidebar-logo {
    max-width: 100%;
    max-height: 64px;
    display: block;
    margin: 0 auto .55rem;
}
.puc-sidebar-brand-title {
  color: #fff;
  font-weight: 700;
  font-family: 'Amiri', 'Cairo', serif;
  font-size: 1.05rem;
  line-height: 1.35;
  display: block;
  text-align: center;
}
.puc-sidebar-brand-org { color: var(--puc-gold); font-size: .72rem; font-weight: 600; display: block; margin-top: .2rem; text-align: center; }

.puc-sidebar-nav { padding: .8rem .65rem 1.5rem; flex: 1; }

.puc-sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: #cfdcec;
  font-weight: 600;
  font-size: .88rem;
  padding: .65rem .8rem;
  border-radius: 8px;
  text-decoration: none;
  margin-bottom: .15rem;
  border-inline-start: 3px solid transparent;
  transition: background .15s ease, color .15s ease;
}
.puc-sidebar-link i { font-size: 1rem; width: 1.1rem; text-align: center; }
.puc-sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.puc-sidebar-link.active { background: rgba(255,255,255,.12); color: #fff; border-inline-start-color: var(--puc-gold); }

.puc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-inline-start: 264px; }

.puc-topbar-simple {
  background: #fff;
  border-bottom: 1px solid var(--puc-border);
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.puc-user-box { display: flex; align-items: center; gap: .6rem; color: var(--puc-text-muted); font-size: .85rem; }
.puc-user-box .btn { --bs-btn-padding-y: .25rem; --bs-btn-padding-x: .7rem; font-size: .8rem; }

/* ---------- Content container ---------- */
.puc-content { max-width: 1360px; margin: 0 auto; padding: 1.5rem 1.5rem 0; width: 100%; }

/* ---------- Guest (login) shell - no sidebar, same look as the sorting system's own login ---------- */
.puc-guest-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4rem;
}
.puc-guest-brand { text-align: center; margin-bottom: 1.5rem; }
.puc-guest-logo { max-height: 70px; margin-bottom: .5rem; }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--puc-border);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid var(--puc-border);
  border-top: 3px solid var(--puc-gold);
  border-radius: var(--puc-radius) var(--puc-radius) 0 0 !important;
  color: var(--puc-navy);
  font-weight: 700;
  padding: .85rem 1.1rem;
}

/* ---------- Buttons ---------- */
.btn { font-weight: 600; border-radius: var(--puc-radius-sm); }
.btn-primary { background: var(--puc-navy); border-color: var(--puc-navy); }
.btn-primary:hover, .btn-primary:focus { background: var(--puc-navy-dark); border-color: var(--puc-navy-dark); }
.btn-outline-primary { color: var(--puc-navy); border-color: var(--puc-navy); }
.btn-outline-primary:hover { background: var(--puc-navy); border-color: var(--puc-navy); }
.btn-gold { background: var(--puc-gold); border-color: var(--puc-gold-dark); color: #22160a; }
.btn-gold:hover { background: var(--puc-gold-dark); border-color: var(--puc-gold-dark); color: #fff; }
.btn-outline-light { border-color: rgba(255,255,255,.5); color: #fff; }
.btn-outline-light:hover { background: rgba(255,255,255,.15); border-color: #fff; color: #fff; }

/* ---------- Tables ---------- */
table.table thead th {
  background: var(--puc-navy);
  color: #fff;
  font-weight: 600;
  font-size: .82rem;
  white-space: nowrap;
  border: none;
}
table.table td, table.table th { vertical-align: middle; font-size: .88rem; }
table.table tbody tr:hover { background: var(--puc-navy-50); }
.table-responsive { background: #fff; }

/* ---------- Status badges ---------- */
.badge { font-weight: 600; font-size: .74rem; padding: .38rem .6rem; border-radius: 6px; }
/* inline-block matters: as a plain inline element the vertical padding paints outside the line
   box, so the pill bled over the rows above and below it. nowrap keeps it a pill instead of
   wrapping into a tall rounded blob when the column is narrow. */
.pa-badge-status {
  display: inline-block;
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}

/* Status titles come from the shared ApplicationStatus table and are full Arabic phrases —
   "مغلق — تم القبول في طلب آخر" is 27 characters. Without a reserved width the auto table layout
   squeezes this column to nothing and the badge has nowhere to go. */
th.col-status, td.col-status { min-width: 13rem; }

/* ---------- select2 ----------
   select2 ships its own sizing, which is shorter than Bootstrap's .form-select and sits on a
   different baseline — next to a normal input the two look broken. These rules make it match the
   controls beside it, so a row of fields lines up whether or not one of them is a select2. */
.select2-container { width: 100% !important; }

.select2-container--default .select2-selection--single {
  height: calc(1.5em + 0.75rem + 2px);   /* exactly Bootstrap's .form-select height */
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--puc-border, #ced4da);
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 1.5;
  padding: 0;
  color: var(--puc-text, #212529);
}

/* RTL: the arrow belongs on the left, and select2 places it right by default. */
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 100%;
  top: 0;
  inset-inline-end: auto;
  inset-inline-start: 0.5rem;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--puc-navy-soft, #86b7fe);
  box-shadow: 0 0 0 0.2rem rgba(36, 73, 116, .15);
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background: var(--puc-navy, #244974);
}

.select2-dropdown { border-color: var(--puc-border, #ced4da); border-radius: 6px; }
.select2-container--default .select2-search--dropdown .select2-search__field {
  border-radius: 4px; border: 1px solid var(--puc-border, #ced4da);
}

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--puc-text-muted); }
.empty-state i { font-size: 2rem; color: #c7d0da; display: block; margin-bottom: .6rem; }

/* ---------- DataTables polish (same fixes as the sorting system's own puc-admin.css) ---------- */
.dt-container { padding: .6rem .9rem 0; }
.dt-container > .row:first-child { margin: 0 0 .6rem; }
.dt-container .dt-length label,
.dt-container .dt-search label {
  display: flex; align-items: center; gap: .4rem; margin: 0; white-space: nowrap; font-size: .82rem;
}
.dt-container .dt-length select { width: auto; }
.dt-container .dt-search { text-align: start; }
.dt-container .dt-search input { width: auto; flex: 1 1 auto; max-width: 220px; }

table.dataTable thead th {
  background-color: var(--puc-navy) !important;
  color: #ffffff !important;
  border-color: var(--puc-navy-dark) !important;
  vertical-align: middle;
  position: relative;
  white-space: nowrap;
  padding-inline-end: 22px !important;
  padding-inline-start: 10px !important;
}
table.dataTable thead th a { color: #ffffff !important; }
table.dataTable thead th.sorting::before,
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::before,
table.dataTable thead th.sorting_asc::after,
table.dataTable thead th.sorting_desc::before,
table.dataTable thead th.sorting_desc::after {
  color: #ffffff !important;
  opacity: .85 !important;
  inset-inline-start: 6px;
  inset-inline-end: auto;
}
table.dataTable tbody td { vertical-align: middle; }

.dt-container .dt-search input,
.dt-container .dt-length select { border-radius: 6px; border: 1px solid var(--puc-border); }
.dt-container .dt-search input:focus { outline: 2px solid var(--puc-navy-soft); }
.dt-container .dt-paging { margin-top: .5rem; }
.dt-container .dt-paging .dt-paging-button { color: var(--puc-navy); }
.dt-container .dt-paging .dt-paging-button.current {
  background: var(--puc-navy);
  border-color: var(--puc-navy);
  color: #fff;
}
.dt-container .dt-info, .dt-container .dt-length label, .dt-container .dt-search label {
  color: var(--puc-text-muted);
  font-size: .84rem;
}

.table-card, .report-card { width: 100%; max-width: 100%; overflow: hidden; }
.table-card .table-responsive, .report-card .table-responsive { width: 100%; max-width: 100%; overflow-x: auto; }
table.dataTable { width: 100% !important; font-size: .85rem; margin-top: 0 !important; }
table.dataTable td, table.dataTable th { padding: .55rem .7rem; }

/* ---------- Plan cards (student: available appeal plans) ---------- */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}
.plan-card {
  background: #fff;
  border: 1px solid var(--puc-border);
  border-top: 4px solid var(--puc-gold);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
  padding: 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.plan-card-title {
  font-family: 'Amiri', 'Cairo', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--puc-navy);
  line-height: 1.4;
}
.plan-card-status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--puc-navy-50);
  color: var(--puc-navy);
  font-size: .82rem;
  font-weight: 600;
  padding: .45rem .7rem;
  border-radius: var(--puc-radius-sm);
  line-height: 1.4;
}
.plan-card-dates {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--puc-text-muted);
  font-size: .82rem;
}
.plan-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: auto;
  padding-top: .35rem;
}
.plan-card-actions .btn { flex: 1 1 auto; }

/* ---------- Centered form pages (student appeal submission) ---------- */
.form-page-center {
  display: flex;
  justify-content: center;
}
.form-page-card {
  width: 100%;
  max-width: 760px;
  background: #fff;
  border: 1px solid var(--puc-border);
  border-top: 4px solid var(--puc-gold);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
  padding: 2rem 2.25rem;
}
.form-page-card .form-label { font-weight: 600; color: var(--puc-navy); }
.form-page-card .form-control,
.form-page-card .form-select { border-radius: var(--puc-radius-sm); padding: .65rem .85rem; }
.form-page-card textarea.form-control { min-height: 140px; }
.form-page-card .btn { padding: .6rem 1.4rem; }

/* ---------- Footer ---------- */
.puc-footer { color: #8a97a6; font-size: .76rem; text-align: center; margin-top: 3rem; padding: 1rem 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .puc-app { flex-direction: column; }
  .puc-sidebar { width: 100%; height: auto; position: static; border-inline-start: none; border-bottom: 3px solid var(--puc-gold); }
  .puc-main { margin-inline-start: 0; }
  .puc-sidebar-nav { display: flex; flex-wrap: wrap; gap: .25rem; padding: .6rem; }
  .puc-topbar-simple { padding: .75rem 1rem; }
  .puc-content { padding: 1.25rem 1rem 0; }
}

/* ---------- Application wizard stepper ---------- */
.puc-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  background: #fff;
  border: 1px solid var(--puc-border);
  border-top: 3px solid var(--puc-gold);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
  padding: 1rem .75rem .85rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.puc-step {
  flex: 1 1 0;
  min-width: 84px;
  text-align: center;
  position: relative;
  padding: 0 .25rem;
}

/* The connector sits behind the bubbles and stops at the row's edges. */
.puc-step::before {
  content: "";
  position: absolute;
  top: 15px;
  inset-inline-start: -50%;
  width: 100%;
  height: 2px;
  background: var(--puc-border);
  z-index: 0;
}
.puc-step:first-child::before { display: none; }
.puc-step.done::before,
.puc-step.current::before { background: var(--puc-navy-soft); }

.puc-step-bubble {
  position: relative;
  z-index: 1;
  width: 32px;
  height: 32px;
  margin: 0 auto .4rem;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--puc-border);
  color: var(--puc-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.puc-step.done .puc-step-bubble {
  background: var(--puc-navy);
  border-color: var(--puc-navy);
  color: #fff;
}
.puc-step.current .puc-step-bubble {
  background: var(--puc-gold);
  border-color: var(--puc-gold-dark);
  color: #22160a;
  box-shadow: 0 0 0 4px var(--puc-gold-soft);
}

.puc-step-label {
  font-size: .74rem;
  font-weight: 600;
  color: var(--puc-text-muted);
  line-height: 1.3;
  display: block;
}
.puc-step.done .puc-step-label { color: var(--puc-navy); }
.puc-step.current .puc-step-label { color: var(--puc-gold-dark); font-weight: 700; }

/* ---------- Wizard card ---------- */
.wizard-card {
  background: #fff;
  border: 1px solid var(--puc-border);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
  padding: 1.5rem 1.75rem;
}
.wizard-card h4 {
  color: var(--puc-navy);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0 0 .25rem;
}
.wizard-card .wizard-hint {
  color: var(--puc-text-muted);
  font-size: .86rem;
  margin-bottom: 1.25rem;
}
.wizard-actions {
  display: flex;
  gap: .6rem;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--puc-border);
}
.wizard-actions .spacer { flex: 1 1 auto; }

/* Carried-over values the student only needs to confirm. */
.prefilled-note {
  background: var(--puc-navy-50);
  border-inline-start: 3px solid var(--puc-navy-soft);
  border-radius: var(--puc-radius-sm);
  padding: .6rem .85rem;
  font-size: .85rem;
  color: var(--puc-navy);
  margin-bottom: 1rem;
}

@media (max-width: 700px) {
  .puc-step-label { display: none; }
  .puc-step { min-width: 44px; }
  .wizard-card { padding: 1.15rem 1rem; }
}

/* ---------- Data table with visible cell separation ----------
   Dense rows of mixed Arabic text and Latin numerals run together without vertical rules; these
   are deliberately lighter than the row borders so the grid guides the eye without boxing it in. */
table.table-grid td,
table.table-grid th {
  border-inline-end: 1px solid var(--puc-border);
}
table.table-grid td:last-child,
table.table-grid th:last-child {
  border-inline-end: 0;
}
table.table-grid thead th {
  border-inline-end-color: rgba(255, 255, 255, .22);
}
table.table-grid tbody tr:hover td {
  background: var(--puc-navy-50);
}

/* The row awaiting a decision is the reviewer's actual work, so it carries a marker in the
   gutter rather than relying on the status pill alone. */
table.table-grid tbody tr.row-pending td:first-child {
  box-shadow: inset 3px 0 0 0 var(--puc-gold);
}

/* ---------- Filter bar ---------- */
.filter-bar {
  background: #fff;
  border: 1px solid var(--puc-border);
  border-radius: var(--puc-radius);
  box-shadow: var(--puc-shadow);
  padding: .85rem 1rem;
  margin-bottom: 1rem;
}

/* ---------------------------------------------------------------------------
   Statistics screen
   --------------------------------------------------------------------------- */

/* Charts need a fixed-height parent: a canvas with maintainAspectRatio off will
   otherwise grow on every resize event. */
.chart-box { position: relative; height: 260px; }
.chart-box-tall { height: 320px; }

.stat-card {
    background: #fff;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    padding: .85rem 1rem;
    height: 100%;
    border-top: 3px solid #244974;
}

.stat-label {
    font-size: .78rem;
    color: #6c757d;
    margin-bottom: .35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #244974;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-card.stat-gold  { border-top-color: #c49a00; }
.stat-card.stat-gold  .stat-value { color: #a8830a; }
.stat-card.stat-green { border-top-color: #14714a; }
.stat-card.stat-green .stat-value { color: #14714a; }
.stat-card.stat-red   { border-top-color: #a8321f; }
.stat-card.stat-red   .stat-value { color: #a8321f; }

.report-columns .form-check-label { font-size: .9rem; }
