/* ContractsHub — neutral executive UI with Saudi accent touches (not all-green) */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Tajawal:wght@400;500;700;800&display=swap');

:root {
  /* Neutrals (dominant) */
  --ch-ink: #1a2332;
  --ch-ink-soft: #2d3a4d;
  --ch-muted: #64748b;
  --ch-line: #e2e8f0;
  --ch-bg: #f1f4f8;
  --ch-surface: #ffffff;
  --ch-sidebar-bg: #1a2332;
  --ch-sidebar-hover: #243044;
  --ch-sidebar-text: #94a3b8;
  --ch-sidebar-text-active: #f8fafc;

  /* Accent touches only */
  --ch-accent: #127a44;
  --ch-accent-soft: #e8f4ee;
  --ch-gold: #b8943a;
  --ch-gold-soft: #f6f0dd;
  --ch-brand: #1e3a5f;
  --ch-brand-hover: #152a45;

  --ch-sidebar-width: 252px;
  --ch-radius: 12px;
  --ch-shadow: 0 8px 28px rgba(18, 36, 52, 0.08);
  --ch-font: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  --ch-font-ar: "Tajawal", "Segoe UI", "Tahoma", sans-serif;

  --bs-primary: #1e3a5f;
  --bs-primary-rgb: 30, 58, 95;
  --bs-link-color: #1e3a5f;
  --bs-link-hover-color: #127a44;
}

html[dir="rtl"] body {
  font-family: var(--ch-font-ar);
}

body {
  font-family: var(--ch-font);
  background: var(--ch-bg);
  color: var(--ch-ink);
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  background: var(--ch-bg);
}

.main-area {
  background: linear-gradient(180deg, #fafbfc 0%, var(--ch-bg) 140px);
}

/* ── Sidebar (slate — not green) ─────────────────────────────────────────── */
.sidebar {
  width: var(--ch-sidebar-width);
  min-height: 100vh;
  background: var(--ch-sidebar-bg);
  border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: 4px 0 20px rgba(15, 23, 42, 0.15);
}

[dir="rtl"] .sidebar {
  box-shadow: -4px 0 20px rgba(15, 23, 42, 0.15);
}

.sidebar-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  color: var(--ch-sidebar-text-active) !important;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-brand i {
  color: var(--ch-gold) !important;
}

.sidebar .nav-link {
  color: var(--ch-sidebar-text);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 4px;
  transition: background 0.18s, color 0.18s;
}

.sidebar .nav-link i {
  opacity: 0.9;
}

.sidebar .nav-link:hover {
  background: var(--ch-sidebar-hover);
  color: var(--ch-sidebar-text-active);
}

.sidebar .nav-link.active {
  background: var(--ch-sidebar-hover);
  color: var(--ch-sidebar-text-active);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--ch-gold);
}

[dir="rtl"] .sidebar .nav-link.active {
  box-shadow: inset -3px 0 0 var(--ch-gold);
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  min-height: 58px;
  background: var(--ch-surface) !important;
  border-bottom: 1px solid var(--ch-line) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.topbar .badge {
  background: #eef2f7 !important;
  color: var(--ch-ink-soft) !important;
  border-color: var(--ch-line) !important;
  font-weight: 600;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
main h4, main .page-title {
  color: var(--ch-ink);
  letter-spacing: -0.02em;
}

.text-muted {
  color: var(--ch-muted) !important;
}

.text-primary {
  color: var(--ch-brand) !important;
}

.sidebar .text-primary {
  color: var(--ch-gold) !important;
}

.bg-primary-subtle {
  background: #eef2f7 !important;
}

.text-primary.badge,
.badge.text-primary {
  color: var(--ch-brand) !important;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  background: var(--ch-surface);
}

.card.shadow-sm {
  box-shadow: var(--ch-shadow) !important;
}

.card-header {
  background: var(--ch-surface) !important;
  border-bottom: 1px solid var(--ch-line) !important;
  color: var(--ch-ink);
  font-weight: 600;
}

.stat-card {
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  background: var(--ch-surface);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--ch-shadow);
}

.stat-card .stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--ch-brand);
  line-height: 1.1;
}

.stat-card .stat-icon {
  color: var(--ch-gold);
}

.stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--ch-muted);
  font-weight: 500;
}

.stat-card .stat-sub {
  font-size: 0.75rem;
  color: var(--ch-muted);
  margin-top: 0.15rem;
}

.stat-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.stat-card--users .stat-icon-wrap {
  background: #eef2f7;
  color: var(--ch-brand);
}

.stat-card--companies .stat-icon-wrap {
  background: var(--ch-gold-soft);
  color: var(--ch-gold);
}

.stat-card--contracts .stat-icon-wrap {
  background: #f1f5f9;
  color: var(--ch-muted);
}

.stat-card--value .stat-icon-wrap {
  background: var(--ch-accent-soft);
  color: var(--ch-accent);
}

.stat-card--warn {
  border-inline-start: 3px solid #dc3545;
}

.stat-card--due {
  border-inline-start: 3px solid var(--ch-gold);
}

/* ── Tables ────────────────────────────────────────────────────────────── */
.table thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ch-muted);
  font-weight: 700;
  border-bottom-width: 1px;
}

.table-hover tbody tr:hover {
  background: #f8fafc;
}

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.nav-tabs {
  border-bottom: 2px solid var(--ch-line);
  gap: 4px;
}

.nav-tabs .nav-link {
  border: none;
  color: var(--ch-muted);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.65rem 1rem;
  border-radius: 10px 10px 0 0;
}

.nav-tabs .nav-link:hover {
  color: var(--ch-brand);
  background: #f1f5f9;
}

.nav-tabs .nav-link.active {
  color: var(--ch-brand);
  background: var(--ch-surface);
  border: 1px solid var(--ch-line);
  border-bottom-color: var(--ch-surface);
  margin-bottom: -2px;
  box-shadow: inset 0 -2px 0 var(--ch-gold);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--ch-brand);
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.2);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--ch-brand-hover);
  box-shadow: 0 6px 16px rgba(30, 58, 95, 0.28);
}

.btn-outline-primary {
  color: var(--ch-brand);
  border-color: #b8c5d6;
  font-weight: 600;
}

.btn-outline-primary:hover {
  background: #f1f5f9;
  border-color: var(--ch-brand);
  color: var(--ch-brand);
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--ch-muted);
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--ch-ink);
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-control:focus,
.form-select:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 0.2rem rgba(30, 58, 95, 0.12);
}

.filter-bar {
  background: var(--ch-surface);
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  padding: 0.85rem 1rem;
}

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge.bg-secondary-subtle {
  background: #eef1f5 !important;
  color: var(--ch-muted) !important;
}

.badge.bg-info-subtle {
  background: #eef2f7 !important;
  color: var(--ch-ink-soft) !important;
}

/* ── Contract workspace (detail) ───────────────────────────────────────── */
.contract-workspace-hero {
  background: var(--ch-surface);
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--ch-shadow);
  border-inline-start: 4px solid var(--ch-gold);
}

.contract-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.contract-kpi {
  background: #f8fafc;
  border: 1px solid var(--ch-line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
}

.contract-kpi-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ch-muted);
  font-weight: 600;
}

.contract-kpi-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ch-ink);
  line-height: 1.2;
}

.contract-mini-progress {
  height: 4px;
  background: #e8edf2;
}

.contract-mini-progress .progress-bar {
  background: var(--ch-brand);
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}

.status-pill--draft { background: #f1f5f9; color: #475569; }
.status-pill--active { background: var(--ch-accent-soft); color: var(--ch-accent); }
.status-pill--expired { background: #fde8e8; color: #b42318; }
.status-pill--neutral { background: #eef2f7; color: var(--ch-muted); }

.contract-workspace-tabs .tab-count {
  display: inline-block;
  min-width: 1.25rem;
  padding: 0 0.35rem;
  margin-inline-start: 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  background: #eef2f7;
  color: var(--ch-muted);
  border-radius: 999px;
}

.contract-workspace-tabs .nav-link.active .tab-count {
  background: var(--ch-brand);
  color: #fff;
}

.contract-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem 1.5rem;
}

.contract-meta-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ch-muted);
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.contract-meta-value {
  font-weight: 600;
  color: var(--ch-ink);
}

.party-chip {
  border: 1px solid var(--ch-line);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  background: #fafbfc;
}

.party-role {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--ch-muted);
  font-weight: 600;
}

.party-name {
  font-weight: 700;
  color: var(--ch-ink);
}

/* ── Contract detail (legacy) ──────────────────────────────────────────── */
.contract-hero {
  background: linear-gradient(135deg, var(--ch-surface) 0%, #f8fafc 100%);
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  border-inline-start: 4px solid var(--ch-gold);
}

.avatar-initials {
  background: #eef2f7;
  color: var(--ch-brand);
  font-weight: 700;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination .page-item.active .page-link {
  background: var(--ch-brand);
  border-color: var(--ch-brand);
}

.pagination .page-link {
  color: var(--ch-brand);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert-success {
  background: var(--ch-accent-soft);
  border-color: #c5e6d4;
  color: #0d4d2c;
}

.alert-info {
  background: #f0f4f8;
  border-color: var(--ch-line);
  color: var(--ch-ink-soft);
}

/* ── Portal ──────────────────────────────────────────────────────────────── */
.portal-content .portal-page-header h4,
.portal-page-header h4 {
  color: var(--ch-ink);
  letter-spacing: -0.02em;
}

.portal-hub-card {
  background: var(--ch-surface);
  border: 1px solid var(--ch-line);
  border-radius: var(--ch-radius);
  padding: 1.5rem;
  box-shadow: var(--ch-shadow);
  transition: border-color 0.18s, transform 0.18s;
  color: inherit;
}

.portal-hub-card:hover {
  border-color: #cbd5e1;
  transform: translateY(-2px);
}

.portal-hub-card i.text-primary {
  color: var(--ch-gold) !important;
}

.portal-content .card {
  border-radius: var(--ch-radius);
}

/* ── Auth ────────────────────────────────────────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  background: var(--ch-bg);
}

.auth-layout {
  min-height: 100vh;
  display: flex;
  flex-wrap: wrap;
}

.auth-brand-panel {
  flex: 1 1 320px;
  min-height: 280px;
  background: linear-gradient(145deg, var(--ch-sidebar-bg) 0%, #243044 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.5rem 2rem;
  position: relative;
  overflow: hidden;
}

.auth-brand-panel::after {
  content: "";
  position: absolute;
  inset: auto -40% -30% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(184, 148, 58, 0.25) 0%, transparent 70%);
  pointer-events: none;
}

.auth-brand-panel .brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(184, 148, 58, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--ch-gold);
  margin-bottom: 1.25rem;
}

.auth-brand-panel h1 {
  font-size: 1.65rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}

.auth-brand-panel p {
  color: #94a3b8;
  font-size: 0.95rem;
  max-width: 320px;
  margin: 0;
}

.auth-form-panel {
  flex: 1 1 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  border-radius: var(--ch-radius) !important;
  border: 1px solid var(--ch-line) !important;
  box-shadow: var(--ch-shadow) !important;
  background: var(--ch-surface);
}

.auth-card .auth-accent-link {
  color: var(--ch-brand);
  font-weight: 600;
}

.auth-card .auth-accent-link:hover {
  color: var(--ch-accent);
}

/* Legacy centered auth (Forgot password etc.) */
.auth-shell-centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #f8fafc 0%, var(--ch-bg) 50%);
}

/* ── Public legal pages ──────────────────────────────────────────────────── */
.public-shell header {
  background: var(--ch-surface) !important;
  border-bottom: 1px solid var(--ch-line);
}

.public-shell header .text-primary,
.public-shell .bi-file-earmark-text-fill {
  color: var(--ch-brand) !important;
}

.public-shell main .rounded {
  border-radius: var(--ch-radius) !important;
  border: 1px solid var(--ch-line);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: #c5d0db; border-radius: 4px; }

/* ── Portal mobile shell (≤1023px) ─────────────────────────────────────── */
.d-portal-mobile {
  display: none !important;
}

.portal-content {
  overflow-x: hidden;
  max-width: 100%;
}

.portal-touch-btn {
  min-height: 44px;
  padding: 0.5rem 1rem;
}

.portal-touch-btn-sm {
  min-height: 40px;
  padding: 0.4rem 0.75rem;
}

.portal-welcome-card {
  border-inline-start: 4px solid var(--ch-gold) !important;
  background: linear-gradient(135deg, #fff 0%, #f8fafc 100%);
}

.filter-bar .form-control,
.filter-bar .form-select,
.portal-filter-field {
  max-width: 100% !important;
  width: 100%;
}

@media (min-width: 768px) {
  .portal-filter-field {
    width: auto;
    max-width: 250px !important;
  }

  .portal-filter-field[name="statusId"] {
    max-width: 160px !important;
  }

  .portal-filter-field[name="companyId"] {
    max-width: 220px !important;
  }
}

@media (max-width: 1023px) {
  .d-portal-mobile {
    display: inline-flex !important;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(15, 23, 42, 0.45);
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    z-index: 1040;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  html[dir="rtl"] .sidebar {
    transform: translateX(100%);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .main-area {
    width: 100%;
    min-width: 0;
  }

  .portal-content {
    padding-inline: 0.75rem !important;
  }

  .filter-bar form {
    flex-direction: column;
    align-items: stretch !important;
  }

  .filter-bar form > * {
    width: 100% !important;
    max-width: 100% !important;
  }

  .contract-workspace-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .contract-workspace-tabs .nav-item {
    flex-shrink: 0;
  }

  .calendar-grid-view {
    display: none !important;
  }

  .calendar-agenda-view {
    display: block !important;
  }

  .calendar-day-cell {
    min-height: 56px;
  }
}

@media (min-width: 1024px) {
  .calendar-agenda-view {
    display: none !important;
  }
}

/* Responsive stacked tables */
@media (max-width: 767px) {
  .portal-r-table thead {
    display: none;
  }

  .portal-r-table tbody tr {
    display: block;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--ch-line);
    border-radius: var(--ch-radius);
    background: var(--ch-surface);
  }

  .portal-r-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.35rem 0;
    border: none;
    text-align: end;
  }

  .portal-r-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--ch-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: start;
    flex-shrink: 0;
  }

  .portal-r-table tbody td.portal-r-actions {
    flex-direction: column;
    align-items: stretch;
    padding-top: 0.5rem;
  }

  .portal-r-table tbody td.portal-r-actions::before {
    display: none;
  }

  .portal-r-table tbody td.portal-r-actions .btn {
    width: 100%;
    margin-bottom: 0.35rem;
  }

  .portal-r-table tbody tr:only-child td[colspan] {
    display: block;
    text-align: center;
  }

  .portal-r-table tbody tr:only-child td[colspan]::before {
    display: none;
  }
}

@media (max-width: 767px) {
  .auth-brand-panel {
    min-height: 200px;
    padding: 1.75rem 1.25rem;
  }

  .public-shell .container {
    padding-inline: 1rem;
    max-width: 100%;
  }

  .public-shell main .rounded {
    padding: 1.25rem !important;
  }
}
