/* ══════════════════════════════════════════════════════
   KCSC Client Portal — Design System
   Stage 2 Professional UI
   ══════════════════════════════════════════════════════ */

/* ── CSS Variables ───────────────────────────────────── */
:root {
  --portal-primary:       #1B4F8A;
  --portal-primary-dark:  #153D6B;
  --portal-primary-light: #E8F0FB;
  --portal-accent:        #2E86C1;
  --portal-success:       #1E8449;
  --portal-success-light: #D5F5E3;
  --portal-warning:       #D35400;
  --portal-warning-light: #FDEBD0;
  --portal-danger:        #C0392B;
  --portal-danger-light:  #FADBD8;
  --portal-gray:          #5D6D7E;
  --portal-light:         #F8F9FA;
  --portal-white:         #FFFFFF;
  --portal-border:        #E0E6ED;
  --portal-shadow:        0 2px 8px rgba(0,0,0,0.08);
  --portal-radius:        10px;
}

/* ── Typography ──────────────────────────────────────── */
body {
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  background: #F4F6F9;
  margin: 0;
}
html[dir="rtl"] body {
  font-family: 'Cairo', 'Tajawal', Arial, sans-serif;
}

/* ── Full-height layout ──────────────────────────────── */
.portal-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
.portal-sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--portal-white);
  border-right: 1px solid var(--portal-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
html[dir="rtl"] .portal-sidebar {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--portal-border);
}

/* Sidebar — brand/logo block */
.portal-sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--portal-border);
  min-height: 64px;
  display: flex;
  align-items: center;
}
.portal-sidebar-brand img {
  max-height: 36px;
  max-width: 160px;
  object-fit: contain;
}
.portal-sidebar-brand .brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--portal-primary);
  line-height: 1.3;
}

/* Sidebar — nav section */
.portal-sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.portal-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #3D4F60;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
html[dir="rtl"] .portal-nav-link {
  border-left: none;
  border-right: 3px solid transparent;
  flex-direction: row-reverse;
}
.nav-icon {
  width: 18px;
  height: 18px;
  margin-right: 10px;
  flex-shrink: 0;
  opacity: 0.85;
  vertical-align: middle;
}
html[dir="rtl"] .nav-icon {
  margin-right: 0;
  margin-left: 10px;
}
.portal-nav-link.active .nav-icon {
  opacity: 1;
}
.portal-nav-link:hover .nav-icon {
  opacity: 1;
}
.portal-nav-link:hover {
  background: #F0F4F8;
  color: var(--portal-primary);
  text-decoration: none;
}
.portal-nav-link.active {
  background: var(--portal-primary-light);
  color: var(--portal-primary);
  border-left-color: var(--portal-primary);
  border-radius: 0 8px 8px 0;
  font-weight: 600;
}
html[dir="rtl"] .portal-nav-link.active {
  border-left-color: transparent;
  border-right-color: var(--portal-primary);
  border-radius: 8px 0 0 8px;
}

/* Sidebar — user footer */
.portal-sidebar-user {
  padding: 14px 20px;
  border-top: 1px solid var(--portal-border);
  font-size: 13px;
  color: var(--portal-gray);
}
.portal-sidebar-user .user-email {
  font-weight: 500;
  color: #2C3E50;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  display: block;
  margin-bottom: 6px;
}
.portal-sidebar-user .user-links {
  display: flex;
  gap: 12px;
}
.portal-sidebar-user a {
  color: var(--portal-gray);
  text-decoration: none;
  font-size: 12px;
}
.portal-sidebar-user a:hover {
  color: var(--portal-primary);
}

/* ── Main content area ───────────────────────────────── */
.portal-main {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
html[dir="rtl"] .portal-main {
  margin-left: 0;
  margin-right: 240px;
}

/* ── Top header bar ──────────────────────────────────── */
.portal-topbar {
  height: 60px;
  background: var(--portal-white);
  border-bottom: 1px solid var(--portal-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.portal-topbar .topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--portal-primary);
}
.portal-topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--portal-gray);
}

/* ── Page body ───────────────────────────────────────── */
.portal-body {
  padding: 28px 32px;
  max-width: 1200px;
  width: 100%;
}

/* ── Page header ─────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--portal-primary);
  margin: 0 0 4px 0;
}
.page-header p {
  font-size: 13px;
  color: var(--portal-gray);
  margin: 0;
}

/* ── Stat cards ──────────────────────────────────────── */
.stat-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
  border: 1px solid #E8EDF2;
  border-left: 4px solid #1B4F8A;
  text-decoration: none !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: 140px;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}
.stat-top-row {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  align-items: center !important;
  width: 100%;
  margin-bottom: 12px;
}
.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #7F8C9A;
  display: block;
  max-width: 70%;
  line-height: 1.4;
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: #1A2B4B;
  line-height: 1;
}
.stat-desc {
  font-size: 12px;
  color: #95A5A6;
  margin: 0;
}
.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card-outstanding { border-left-color: #E67E22; }
.stat-card-outstanding .stat-icon { background-color: #FEF0E6 !important; color: #E67E22 !important; }
.stat-card-outstanding .stat-icon svg { fill: #E67E22 !important; }

.stat-card-orders { border-left-color: #2E86C1; }
.stat-card-orders .stat-icon { background-color: #EBF5FB !important; color: #2E86C1 !important; }
.stat-card-orders .stat-icon svg { fill: #2E86C1 !important; }

.stat-card-quotations { border-left-color: #1B4F8A; }
.stat-card-quotations .stat-icon { background-color: #E8F0FB !important; color: #1B4F8A !important; }
.stat-card-quotations .stat-icon svg { fill: #1B4F8A !important; }

.stat-card-tickets { border-left-color: #1E8449; }
.stat-card-tickets .stat-icon { background-color: #E9F7EF !important; color: #1E8449 !important; }
.stat-card-tickets .stat-icon svg { fill: #1E8449 !important; }

/* ── Portal card wrapper ─────────────────────────────── */
.portal-card {
  background: var(--portal-white);
  border-radius: var(--portal-radius);
  box-shadow: var(--portal-shadow);
  border: 1px solid var(--portal-border);
  overflow: hidden;
  margin-bottom: 24px;
}
.portal-card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--portal-border);
  font-weight: 600;
  font-size: 14px;
  color: var(--portal-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.portal-card-body {
  padding: 20px;
}

/* ── Tables ──────────────────────────────────────────── */
.portal-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--portal-white);
}
.portal-table thead th {
  background: var(--portal-primary);
  color: var(--portal-white);
  padding: 13px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}
.portal-table tbody tr {
  border-bottom: 1px solid var(--portal-border);
  transition: background 0.12s;
}
.portal-table tbody tr:last-child {
  border-bottom: none;
}
.portal-table tbody tr:hover {
  background: var(--portal-primary-light);
}
.portal-table tbody td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: #2C3E50;
  vertical-align: middle;
}
.portal-table .empty-row td {
  text-align: center;
  padding: 52px 20px;
  color: var(--portal-gray);
  font-size: 14px;
}
.portal-table .ref-link {
  color: var(--portal-primary);
  font-weight: 600;
  text-decoration: none;
}
.portal-table .ref-link:hover {
  text-decoration: underline;
}
.portal-table .sub-text {
  font-size: 11px;
  color: var(--portal-gray);
  margin-top: 2px;
}

/* ── Status badges ───────────────────────────────────── */
.badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-block;
  white-space: nowrap;
}
.badge-paid,
.badge-completed,
.badge-ordered {
  background: var(--portal-success-light);
  color: var(--portal-success);
}
.badge-unpaid,
.badge-cancelled,
.badge-overdue {
  background: var(--portal-danger-light);
  color: var(--portal-danger);
}
.badge-partial,
.badge-pending,
.badge-to-bill {
  background: var(--portal-warning-light);
  color: var(--portal-warning);
}
.badge-open,
.badge-to-deliver {
  background: #EBF5FB;
  color: var(--portal-accent);
}
.badge-draft {
  background: #EAECEE;
  color: #566573;
}
.badge-expired {
  background: #EAECEE;
  color: #566573;
}

/* ── Buttons ─────────────────────────────────────────── */

/* Shared base — guarantees identical height/font on all button variants */
.btn-portal,
.btn-portal-outline,
.btn-portal-success,
.btn-portal-secondary {
  height: 40px;
  font-size: 14px;
  padding: 0 20px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  box-sizing: border-box;
}

.btn-portal-sm {
  height: 34px;
  font-size: 13px;
  padding: 0 14px;
}

.btn-portal {
  background: var(--portal-primary);
  color: var(--portal-white);
  border: 1.5px solid var(--portal-primary);
}
.btn-portal:hover {
  background: var(--portal-primary-dark);
  border-color: var(--portal-primary-dark);
  color: var(--portal-white);
}
.btn-portal-outline {
  background: transparent;
  color: var(--portal-primary);
  border: 1.5px solid var(--portal-primary);
}
.btn-portal-outline:hover {
  background: var(--portal-primary);
  color: var(--portal-white);
}
.btn-portal-success {
  background: var(--portal-success);
  color: var(--portal-white);
  border: 1.5px solid var(--portal-success);
}
.btn-portal-success:hover {
  background: #166638;
  border-color: #166638;
  color: var(--portal-white);
}
.btn-portal-secondary {
  background: #6c757d;
  color: var(--portal-white);
  border: 1.5px solid #6c757d;
}
.btn-portal-secondary:hover {
  background: #545b62;
  border-color: #545b62;
  color: var(--portal-white);
}

/* ── Filter bar ──────────────────────────────────────── */
.filter-bar {
  background: var(--portal-white);
  border-radius: var(--portal-radius);
  padding: 16px 20px;
  box-shadow: var(--portal-shadow);
  border: 1px solid var(--portal-border);
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--portal-gray);
}
.filter-bar input,
.filter-bar select {
  border: 1.5px solid var(--portal-border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13.5px;
  color: #2C3E50;
  background: var(--portal-white);
  height: 36px;
}
.filter-bar input:focus,
.filter-bar select:focus {
  outline: none;
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px rgba(46,134,193,0.12);
}
.filter-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-bottom: 0;
}

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--portal-gray);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}
.empty-state h3 {
  font-size: 17px;
  font-weight: 600;
  color: #3D4F60;
  margin-bottom: 8px;
}
.empty-state p {
  font-size: 13px;
  margin: 0;
}

/* ── Modal ───────────────────────────────────────────── */
.portal-modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 9999;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
  backdrop-filter: blur(2px);
}
.portal-modal.active {
  display: flex;
}
.modal-box {
  background: var(--portal-white);
  border-radius: 12px;
  max-width: 820px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}
.modal-header {
  background: var(--portal-primary);
  color: var(--portal-white);
  padding: 18px 24px;
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1;
}
.modal-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  color: var(--portal-white);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
  padding: 0;
}
.modal-close:hover { opacity: 1; }
.modal-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--portal-border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--portal-white);
  border-radius: 0 0 12px 12px;
  position: sticky;
  bottom: 0;
}
html[dir="rtl"] .modal-footer {
  justify-content: flex-start;
}

/* ── Overdue highlight ───────────────────────────────── */
.text-overdue {
  color: var(--portal-danger);
  font-weight: 600;
}

/* ── View-all link ───────────────────────────────────── */
.view-all-link {
  font-size: 12.5px;
  color: var(--portal-primary);
  text-decoration: none;
  font-weight: 500;
}
.view-all-link:hover {
  text-decoration: underline;
}

/* ── RTL table alignment ─────────────────────────────── */
html[dir="rtl"] .portal-table thead th,
html[dir="rtl"] .portal-table tbody td {
  text-align: right;
}
html[dir="rtl"] .text-end {
  text-align: left !important;
}
html[dir="rtl"] .text-start {
  text-align: right !important;
}

/* ── Mobile responsive ───────────────────────────────── */
@media (max-width: 1024px) {
  .stat-cards-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 576px) {
  .stat-cards-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .portal-sidebar {
    width: 100%;
    min-height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .portal-sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
  }
  .portal-nav-link {
    border-left: none;
    border-bottom: 3px solid transparent;
    border-radius: 6px;
    padding: 8px 12px;
  }
  .portal-nav-link.active {
    border-left-color: transparent;
    border-bottom-color: var(--portal-primary);
    border-radius: 6px;
  }
  .portal-sidebar-user { display: none; }
  .portal-main { margin-left: 0; }
  html[dir="rtl"] .portal-main { margin-right: 0; }
  .portal-layout { flex-direction: column; }
  .stat-cards-grid { grid-template-columns: repeat(2, 1fr); }
  .portal-body { padding: 16px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}
@media (max-width: 480px) {
  .stat-cards-grid { grid-template-columns: 1fr; }
}
