/* ==========================================================================
   FES CLIENT PORTAL — COMPREHENSIVE STYLESHEET
   Security: Strict CSP compliant (Zero inline styles required)
   Accessibility: WCAG AA contrast, focus indicators, keyboard friendly
   Theme: FES Blue palette, Light/Dark mode, English/Urdu RTL
   ========================================================================== */

:root {
  /* FES Blue Theme */
  --primary-50: #EFF6FF;
  --primary-100: #DBEAFE;
  --primary-500: #3B82F6;
  --primary-600: #2563EB;
  --primary-700: #1D4ED8;
  --primary-900: #1E3A8A;
  
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --border-color: #E2E8F0;
  --border-focus: #2563EB;
  
  --text-main: #0F172A;
  --text-muted: #475569;
  --text-dim: #64748B;
  
  --green-bg: #DCFCE7;
  --green-text: #166534;
  --green-border: #86EFAC;
  
  --amber-bg: #FEF3C7;
  --amber-text: #92400E;
  --amber-border: #FCD34D;
  
  --red-bg: #FEE2E2;
  --red-text: #991B1B;
  --red-border: #FCA5A5;
  
  --blue-bg: #DBEAFE;
  --blue-text: #1E40AF;
  --blue-border: #93C5FD;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Space Grotesk', var(--font-sans);
}

[data-theme="dark"] {
  --bg-app: #090D16;
  --bg-card: #131B2E;
  --bg-subtle: #1E293B;
  --border-color: #2D3748;
  --border-focus: #60A5FA;
  
  --text-main: #F8FAFC;
  --text-muted: #CBD5E1;
  --text-dim: #94A3B8;
  
  --green-bg: #064E3B;
  --green-text: #A7F3D0;
  --green-border: #047857;
  
  --amber-bg: #78350F;
  --amber-text: #FDE68A;
  --amber-border: #B45309;
  
  --red-bg: #7F1D1D;
  --red-text: #FECACA;
  --red-border: #B91C1C;
  
  --blue-bg: #1E3A8A;
  --blue-text: #BFDBFE;
  --blue-border: #2563EB;
}

/* Base & Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Accessibility Focus */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Utilities */
.hide { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* RTL Layout Mode */
[dir="rtl"] {
  text-align: right;
}
[dir="rtl"] .topbar-actions {
  flex-direction: row-reverse;
}
[dir="rtl"] .nav-tabs {
  flex-direction: row-reverse;
}

/* ================= AUTHENTICATION VIEW ================= */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  padding: 36px 28px;
  text-align: center;
}

.auth-brand-logo {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  margin-bottom: 12px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 24px;
}

.form-field {
  text-align: left;
  margin-bottom: 18px;
}

[dir="rtl"] .form-field {
  text-align: right;
}

.form-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 14px;
  transition: border-color .2s;
}

.form-input:focus {
  border-color: var(--primary-600);
  background: var(--bg-card);
  outline: none;
}

.auth-error-box {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
  margin-bottom: 16px;
}

[dir="rtl"] .auth-error-box {
  text-align: right;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .2s;
}

.btn-primary {
  background: var(--primary-600);
  color: #FFFFFF;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-700);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-subtle);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.auth-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}

.auth-footer a {
  color: var(--primary-600);
  text-decoration: none;
  font-weight: 600;
}

/* ================= PORTAL MAIN SHELL ================= */
.app-container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand-names h1 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}

.brand-names span {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  display: block;
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-600);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.user-name-text {
  font-size: 13px;
  font-weight: 600;
}

/* Navigation Tabs */
.nav-tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 6px;
  padding: 8px 20px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar { display: none; }

.tab-button {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}

.tab-button.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-600);
}

.tab-button:hover:not(.active) {
  color: var(--text-main);
}

/* Main Content Area */
.portal-content {
  flex: 1;
  padding: 20px;
}

/* Alerts Strip */
.alert-banner {
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.alert-stale {
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1px solid var(--amber-border);
}

.alert-warning {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}

.alert-info {
  background: var(--blue-bg);
  color: var(--blue-text);
  border: 1px solid var(--blue-border);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.kpi-value-green { color: var(--green-text); }
.kpi-value-red { color: var(--red-text); }
.kpi-value-amber { color: var(--amber-text); }
.kpi-value-blue { color: var(--primary-600); }

/* Generic Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}

/* Status Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-operational, .badge-paid, .badge-resolved {
  background: var(--green-bg);
  color: var(--green-text);
  border: 1px solid var(--green-border);
}

.badge-under_repair, .badge-overdue {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}

.badge-stopped, .badge-new {
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1px solid var(--amber-border);
}

.badge-accepted, .badge-in_progress, .badge-partial, .badge-pending {
  background: var(--blue-bg);
  color: var(--blue-text);
  border: 1px solid var(--blue-border);
}

/* Sites & Lifts View */
.site-card {
  margin-bottom: 20px;
}

.site-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 2px;
}

.site-address {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

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

.lift-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.lift-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.lift-number {
  font-weight: 700;
  font-size: 15px;
}

.lift-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-color);
}

.lift-meta-row:last-child {
  border-bottom: none;
}

.lift-meta-label {
  color: var(--text-dim);
}

.lift-meta-val {
  font-weight: 600;
}

/* Service Reports List */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 13.5px;
}

.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 13.5px;
}

.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-color);
}

.report-item:last-child {
  border-bottom: none;
}

.report-code {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 3px;
}

.report-desc {
  font-size: 12px;
  color: var(--text-dim);
}

/* Visual Timeline for Complaints */
.timeline-card {
  margin-bottom: 14px;
}

.timeline-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  margin: 18px 0 12px;
  padding: 0 10px;
}

.timeline-line-bg {
  position: absolute;
  top: 12px;
  left: 30px;
  right: 30px;
  height: 3px;
  background: var(--border-color);
  z-index: 1;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  text-align: center;
  flex: 1;
}

.timeline-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 6px;
}

.timeline-step.complete .timeline-dot {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green-text);
}

.timeline-step.active .timeline-dot {
  background: var(--primary-600);
  border-color: var(--primary-700);
  color: #fff;
  box-shadow: 0 0 0 4px var(--primary-100);
}

.timeline-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.timeline-step.complete .timeline-label,
.timeline-step.active .timeline-label {
  color: var(--text-main);
  font-weight: 700;
}

/* Invoices & Table */
.data-table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

[dir="rtl"] .data-table {
  text-align: right;
}

.data-table th {
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-color);
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 11px;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

/* Charts */
.chart-scroll-wrap {
  overflow-x: auto;
  padding-bottom: 6px;
}

.chart-svg {
  width: 100%;
  height: auto;
  min-width: 320px;
}

.chart-grid-line {
  stroke: var(--border-color);
  stroke-width: 1;
  stroke-dasharray: 4,4;
}

.chart-bar-primary {
  fill: var(--primary-600);
}

.chart-bar-green {
  fill: var(--green-text);
}

.chart-val-text {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  fill: var(--text-main);
}

.chart-label-text {
  font-family: var(--font-sans);
  font-size: 10px;
  fill: var(--text-dim);
}

.chart-legend-text {
  font-family: var(--font-sans);
  font-size: 11px;
  fill: var(--text-main);
}

/* Contact FES View */
.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.contact-action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  text-decoration: none;
  color: var(--text-main);
  transition: all .2s;
}

.contact-action-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--primary-600);
}

.contact-action-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-50);
  color: var(--primary-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

/* Modal / Drawer */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  padding: 24px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
}
.btn-close:hover {
  color: var(--text-main);
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary-600);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
  margin-bottom: 12px;
}
.btn-link:hover {
  color: var(--primary-700);
}

.modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

.password-change-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

.password-feedback {
  font-size: 12px;
  margin: 6px 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.password-feedback.error {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}
.password-feedback.success {
  background: var(--green-bg);
  color: var(--green-text);
  border: 1px solid var(--green-border);
}

.contact-info-box {
  margin: 16px 0;
  text-align: left;
}
[dir="rtl"] .contact-info-box {
  text-align: right;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-dim);
  font-size: 13.5px;
}

/* Skeleton Loaders */
.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-color) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 80%;
}

.skeleton-title {
  height: 20px;
  margin-bottom: 12px;
  width: 50%;
}

.skeleton-card {
  height: 100px;
  margin-bottom: 14px;
  border-radius: var(--radius-md);
}

/* Toast */
.toast-msg {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0F172A;
  color: #FFFFFF;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
}

/* Print Styles */
@media print {
  body {
    background: #FFFFFF !important;
    color: #000000 !important;
  }
  .topbar, .nav-tabs, .filter-bar, .btn, .topbar-actions, .alert-banner {
    display: none !important;
  }
  .app-container {
    max-width: 100% !important;
    padding: 0 !important;
  }
  .card {
    border: 1px solid #000 !important;
    box-shadow: none !important;
    margin-bottom: 20px !important;
  }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .portal-content { padding: 14px 12px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-tabs { padding: 4px 12px 0; }
  .tab-button { padding: 8px 10px; font-size: 12.5px; }
}

/* Shown when the portal is not configured (fail-closed) */
.config-error { margin: 20vh auto 0; max-width: 480px; padding: 24px; text-align: center; font-family: system-ui, sans-serif; color: #7a1f1f; background: #fdecec; border: 1px solid #f5c2c2; border-radius: 12px; }
