/* Railway Contractor Portal — design tokens & UI */

:root {
  --portal-navy: #0a2540;
  --portal-navy-mid: #123b5c;
  --portal-navy-light: #1a4d75;
  --portal-accent: #e8a317;
  --portal-accent-soft: rgba(232, 163, 23, 0.15);
  --portal-success: #0d7a5c;
  --portal-danger: #c42b2b;
  --portal-surface: #ffffff;
  --portal-surface-2: #f4f7fb;
  --portal-border: rgba(10, 37, 64, 0.08);
  --portal-border-strong: rgba(10, 37, 64, 0.14);
  --portal-text: #0f2137;
  --portal-text-muted: #5c6d82;
  --portal-radius: 12px;
  --portal-radius-sm: 8px;
  --portal-shadow: 0 4px 24px rgba(10, 37, 64, 0.06);
  --portal-shadow-lg: 0 12px 40px rgba(10, 37, 64, 0.1);
  --portal-shadow-nav: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 20px rgba(0, 0, 0, 0.15);
  --portal-font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --portal-font-display: "Outfit", var(--portal-font);
  --portal-focus: 0 0 0 3px rgba(232, 163, 23, 0.45);
}

html {
  scroll-behavior: smooth;
}

body.portal-app {
  font-family: var(--portal-font);
  color: var(--portal-text);
  background: #e8ecf2;
  -webkit-font-smoothing: antialiased;
}

/* ——— App shell: fixed sidebar (always visible — no collapse / JS dependency) ——— */
.portal-shell {
  width: 100%;
}

.portal-sidebar {
  width: 260px;
  flex-shrink: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 55%, #0f172a 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem 1.5rem;
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-sidebar-brand {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.portal-sidebar-logo {
  font-family: var(--portal-font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  display: block;
  line-height: 1.2;
}

.portal-sidebar-logo::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.5rem;
  border-radius: 2px;
  background: var(--portal-accent);
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.portal-sidebar-tagline {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(226, 232, 240, 0.55);
  margin-top: 0.35rem;
}

.portal-sidebar-welcome {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: rgba(226, 232, 240, 0.88);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.75rem !important;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--portal-radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -0.25rem;
  padding-right: 0.25rem;
}

.portal-sidebar-nav > ul > li {
  margin-bottom: 0.2rem;
}

.portal-snav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--portal-radius-sm);
  color: rgba(248, 250, 252, 0.88) !important;
  text-decoration: none !important;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.portal-snav-link i {
  font-size: 1.1rem;
  opacity: 0.85;
  width: 1.35rem;
  text-align: center;
}

.portal-snav-link:hover,
.portal-snav-link:focus {
  background: rgba(255, 255, 255, 0.1);
  color: #fff !important;
}

.portal-sidebar-actions .btn-light {
  color: #0f172a;
  border: none;
}

.portal-sidebar-actions .btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.portal-body {
  background: #e8ecf2;
  min-width: 0;
}

/* Mobile: horizontal strip — menu always visible, scroll if needed */
@media (max-width: 991.98px) {
  .portal-shell {
    flex-direction: column !important;
  }

  .portal-sidebar {
    width: 100%;
    min-height: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.65rem 0.75rem;
    gap: 0.5rem;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
  }

  .portal-sidebar-brand {
    margin: 0;
    padding: 0;
    border: 0;
    flex: 1 1 auto;
    min-width: 140px;
  }

  .portal-sidebar-tagline {
    display: none;
  }

  .portal-sidebar-welcome {
    display: none !important;
  }

  .portal-sidebar-nav {
    flex: 1 1 100%;
    order: 3;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.25rem 0;
    margin: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .portal-sidebar-nav > ul {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.25rem;
    padding: 0.35rem 0;
  }

  .portal-sidebar-nav > ul > li {
    margin: 0;
    flex: 0 0 auto;
  }

  .portal-snav-link {
    white-space: nowrap;
    padding: 0.45rem 0.65rem;
    font-size: 0.8125rem;
  }

  .portal-snav-link span {
    display: inline;
  }

  .portal-sidebar-actions {
    display: flex;
    flex-direction: row !important;
    gap: 0.35rem;
    margin: 0 !important;
    padding: 0 !important;
    order: 2;
    width: auto;
  }

  .portal-sidebar-actions .btn {
    width: auto !important;
    padding: 0.35rem 0.75rem !important;
    margin: 0 !important;
    font-size: 0.8125rem;
  }
}

/* ——— Main & layout ——— */
.portal-main {
  flex: 1 0 auto;
}

.main-body {
  min-height: 50vh;
}

.portal-footer {
  background: var(--portal-surface);
  border-top: 1px solid var(--portal-border-strong);
  padding: 1rem 0;
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
}

.portal-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ——— Page chrome ——— */
.page-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--portal-border-strong);
}

.page-title {
  font-family: var(--portal-font-display);
  font-weight: 700;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  letter-spacing: -0.03em;
  color: var(--portal-navy);
  margin: 0 0 0.35rem;
  line-height: 1.2;
}

.page-lead,
.page-header .text-muted {
  font-size: 0.95rem;
  color: var(--portal-text-muted) !important;
  margin: 0;
  max-width: 52rem;
  line-height: 1.55;
}

/* ——— Alerts / flash ——— */
.portal-flash {
  border-radius: var(--portal-radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.9375rem;
  margin-bottom: 0.75rem;
}

.portal-flash.text-success {
  background: rgba(13, 122, 92, 0.1);
  color: var(--portal-success) !important;
  border: 1px solid rgba(13, 122, 92, 0.2);
}

.portal-flash.text-danger {
  background: rgba(196, 43, 43, 0.08);
  color: var(--portal-danger) !important;
  border: 1px solid rgba(196, 43, 43, 0.2);
}

p.portal-flash:has(> span:empty) {
  display: none;
  margin: 0;
  padding: 0;
  border: 0;
}

/* ——— Cards & forms ——— */
.form-section {
  background: var(--portal-surface);
  border-radius: var(--portal-radius);
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-shadow);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1rem;
}

.form-section h2.h5,
.form-section h2.h6 {
  font-family: var(--portal-font-display);
  font-weight: 600;
  color: var(--portal-navy);
  margin-bottom: 1rem;
}

.form-section .form-label,
.form-section label.form-label {
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--portal-text-muted);
  margin-bottom: 0.35rem;
}

.form-section label:not(.form-label) {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--portal-text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.form-section .form-control,
.form-section .form-select {
  border-radius: var(--portal-radius-sm);
  border-color: var(--portal-border-strong);
}

.form-section .form-control:focus,
.form-section .form-select:focus {
  border-color: var(--portal-navy-mid);
  box-shadow: var(--portal-focus);
}

.grid-wrap {
  background: var(--portal-surface);
  border-radius: var(--portal-radius);
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-shadow);
  padding: 0;
  overflow: hidden;
}

.grid-wrap .table {
  margin-bottom: 0;
}

/* ——— Tables ——— */
.table-responsive.grid-wrap {
  padding: 0;
}

.portal-table,
.grid-wrap .table {
  font-size: 0.9rem;
}

.portal-table thead th,
.grid-wrap .table thead th {
  font-family: var(--portal-font-display);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--portal-text-muted);
  background: var(--portal-surface-2);
  border-bottom: 2px solid var(--portal-border-strong);
  padding: 0.75rem 1rem;
  white-space: nowrap;
}

.portal-table tbody td,
.grid-wrap .table tbody td {
  padding: 0.7rem 1rem;
  vertical-align: middle;
  border-color: var(--portal-border);
}

.portal-table.table-hover tbody tr:hover,
.grid-wrap .table-hover tbody tr:hover {
  background: rgba(18, 59, 92, 0.04);
}

/* ——— Stat cards (dashboard) — gradient metric tiles ——— */
.stat-card {
  border-radius: 16px;
  border: none;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.15);
  padding: 1.15rem 1.25rem 1.25rem;
  height: 100%;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  color: #fff;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: -40%;
  right: -15%;
  width: 120px;
  height: 120px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  transform: rotate(25deg);
  pointer-events: none;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.22);
}

.portal-stats > div:nth-child(4n + 1) .stat-card {
  background: linear-gradient(135deg, #059669 0%, #34d399 100%);
}

.portal-stats > div:nth-child(4n + 2) .stat-card {
  background: linear-gradient(135deg, #6d28d9 0%, #a78bfa 100%);
}

.portal-stats > div:nth-child(4n + 3) .stat-card {
  background: linear-gradient(135deg, #db2777 0%, #fb923c 100%);
}

.portal-stats > div:nth-child(4n + 4) .stat-card {
  background: linear-gradient(135deg, #0284c7 0%, #38bdf8 100%);
}

.stat-card .stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 1;
}

.stat-card .stat-value {
  font-family: var(--portal-font-display);
  font-weight: 700;
  font-size: 1.65rem;
  color: #fff;
  line-height: 1.15;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* ——— Chart ——— */
.chart-box {
  min-height: 220px;
  border-radius: var(--portal-radius);
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-shadow);
  padding: 1.25rem;
  background: var(--portal-surface);
}

.chart-box h2.h6 {
  font-family: var(--portal-font-display);
  font-weight: 600;
  color: var(--portal-navy);
}

/* ——— Buttons ——— */
.btn {
  font-weight: 600;
  border-radius: var(--portal-radius-sm);
  padding: 0.45rem 1rem;
}

.btn-primary {
  background: linear-gradient(180deg, var(--portal-navy-mid) 0%, var(--portal-navy) 100%);
  border-color: var(--portal-navy);
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--portal-navy-light);
  border-color: var(--portal-navy-light);
}

.btn-success {
  background: linear-gradient(180deg, #159670 0%, var(--portal-success) 100%);
  border-color: var(--portal-success);
}

.btn-outline-primary {
  color: var(--portal-navy-mid);
  border-color: rgba(18, 59, 92, 0.35);
}

.btn-outline-primary:hover {
  background: var(--portal-navy);
  border-color: var(--portal-navy);
}

/* ——— Toolbar row (filters) ——— */
.portal-toolbar {
  background: var(--portal-surface);
  border-radius: var(--portal-radius);
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.portal-toolbar .form-label {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--portal-text-muted);
}

/* ——— Entry / readonly ——— */
.portal-readonly .form-label,
.readonly label {
  color: var(--portal-text-muted) !important;
}

/* ——— Validation ——— */
span[style*="color:Red"],
span[style*="color:red"] {
  font-size: 0.8125rem;
  font-weight: 500;
}

/* ——— Status chips (DPR) ——— */
.grid-wrap .table td:last-child .btn-sm {
  margin: 0.15rem 0.1rem;
}

/* ——— Login page — gold field + dark card (reference-inspired) ——— */
body.login-page {
  font-family: var(--portal-font);
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(160deg, #d4af37 0%, #c9a227 35%, #b8941f 100%);
}

.login-kbc-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.login-kbc-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, #252530 0%, #1a1a22 100%);
  border-radius: 18px;
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  padding: 2.25rem 2rem 1.75rem;
  color: #f8fafc;
}

.login-kbc-mark {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(212, 175, 55, 0.35), rgba(212, 175, 55, 0.08));
  border: 2px solid rgba(212, 175, 55, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: #f5e6a8;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.login-kbc-card .login-card-title {
  font-family: var(--portal-font-display);
  font-weight: 700;
  font-size: 1.5rem;
  text-align: center;
  color: #fff;
  margin-bottom: 0.35rem;
}

.login-kbc-card .login-card-sub {
  font-size: 0.9rem;
  text-align: center;
  color: rgba(248, 250, 252, 0.65);
  margin-bottom: 1.75rem;
}

.login-kbc-card .form-label {
  color: rgba(248, 250, 252, 0.75);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-kbc-card .form-control {
  background: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 1rem;
}

.login-kbc-card .form-control:focus {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

.login-kbc-card .btn-signin {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  padding: 0.7rem 1rem;
  margin-top: 0.25rem;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.login-kbc-card .btn-signin:hover {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
}

.login-kbc-card .text-danger {
  color: #fca5a5 !important;
  font-size: 0.875rem;
}

.login-hint {
  font-size: 0.78rem;
  color: rgba(248, 250, 252, 0.55);
  margin-top: 1.35rem;
  line-height: 1.55;
  padding-top: 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.login-hint strong {
  color: rgba(248, 250, 252, 0.85);
}

/* ——— Reduced motion ——— */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
