/* ============================================================
   RMS — Risk Management System  |  Custom Design System
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --rms-primary:       #1a3c6e;
  --rms-primary-light: #2a5298;
  --rms-accent:        #e8a020;
  --rms-accent-light:  #f5c842;
  --rms-success:       #1a9e5c;
  --rms-danger:        #c0392b;
  --rms-warning:       #e67e22;
  --rms-info:          #2980b9;
  --rms-sidebar-bg:    #0f2444;
  --rms-sidebar-w:     270px;
  --rms-header-h:      64px;
  --rms-radius:        10px;
  --rms-shadow:        0 2px 16px rgba(15,36,68,.10);
  --rms-shadow-md:     0 4px 24px rgba(15,36,68,.14);
  --rms-font:          'Inter', 'Nunito', 'Open Sans', sans-serif;
}

/* ── Reset / Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--rms-font);
  background: #f0f4f8;
  color: #2d3748;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--rms-primary-light); text-decoration: none; }
a:hover { color: var(--rms-accent); }

h1,h2,h3,h4,h5,h6 { font-family: var(--rms-font); font-weight: 700; color: var(--rms-primary); }

/* ── Header ─────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0;
  left: var(--rms-sidebar-w);   /* starts after sidebar */
  right: 0;
  height: var(--rms-header-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 8px rgba(15,36,68,.08);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  transition: left .3s ease;
}

.header .toggle-sidebar-btn {
  font-size: 22px;
  color: var(--rms-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background .2s;
  line-height: 1;
}
.header .toggle-sidebar-btn:hover { background: #f0f4f8; }

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.header-brand img { height: 32px; width: auto; }
.header-brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--rms-primary);
  letter-spacing: .3px;
  white-space: nowrap;
}

.header-nav { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.header-register-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--rms-primary);
  color: #fff !important;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background .2s, transform .15s;
  white-space: nowrap;
}
.header-register-btn:hover {
  background: var(--rms-primary-light);
  color: #fff !important;
  transform: translateY(-1px);
}

/* Profile dropdown */
.nav-profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s;
  color: var(--rms-primary);
  font-weight: 600;
  font-size: 13px;
}
.nav-profile-btn:hover { background: #f0f4f8; }
.nav-profile-btn .avatar {
  width: 34px; height: 34px;
  background: var(--rms-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--rms-sidebar-w);
  background: var(--rms-sidebar-bg);
  z-index: 1001;          /* above header so brand block is never cut */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .3s ease;
  transform: translateX(0);
}

/* Sidebar brand block — same height as header so they align */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--rms-header-h);
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
  text-decoration: none;
  background: rgba(0,0,0,.15);   /* slightly darker so it reads as a header */
}
.sidebar-brand-logo {
  width: 42px; height: 42px;
  background: rgba(255,255,255,.95);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  padding: 3px;
}
.sidebar-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand-logo .logo-icon {
  font-size: 20px;
  color: var(--rms-accent);
}
.sidebar-brand-info { overflow: hidden; }
.sidebar-brand-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .4px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand-subtitle {
  font-size: 10px;
  color: rgba(255,255,255,.45);
  letter-spacing: .8px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Sidebar scroll area */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

/* Nav sections */
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  padding: 16px 12px 6px;
  margin: 0;
}

.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li { margin-bottom: 2px; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.65);
  font-size: 13.5px;
  font-weight: 500;
  transition: all .2s;
  text-decoration: none;
  position: relative;
}
.sidebar-nav .nav-link i {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  color: rgba(255,255,255,.45);
  transition: color .2s;
}
.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.sidebar-nav .nav-link:hover i { color: var(--rms-accent); }

/* Active state */
.sidebar-nav .nav-link.active,
.sidebar-nav .nav-link:not(.collapsed) {
  background: rgba(232,160,32,.15);
  color: var(--rms-accent-light);
  font-weight: 600;
}
.sidebar-nav .nav-link.active i,
.sidebar-nav .nav-link:not(.collapsed) i {
  color: var(--rms-accent);
}
.sidebar-nav .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--rms-accent);
  border-radius: 0 3px 3px 0;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-footer .lang-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.65);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.sidebar-footer .lang-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-footer .lang-btn i { font-size: 14px; color: var(--rms-accent); }

/* ── Main content area ──────────────────────────────────────── */
#main {
  margin-left: var(--rms-sidebar-w);
  margin-top: var(--rms-header-h);
  padding: 28px 32px;
  min-height: calc(100vh - var(--rms-header-h));
  transition: margin-left .3s ease;
}

/* ── Sidebar collapsed (desktop: slide sidebar out, expand main) */
body.sidebar-collapsed .sidebar {
  transform: translateX(calc(-1 * var(--rms-sidebar-w)));
}
body.sidebar-collapsed .header {
  left: 0;
}
body.sidebar-collapsed #main {
  margin-left: 0;
}

/* ── Mobile: sidebar hidden by default, shown on toggle ── */
@media (max-width: 1199px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--rms-sidebar-w)));
    z-index: 1050;
  }
  .header {
    left: 0;
  }
  #main {
    margin-left: 0;
    padding: 20px 16px;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  /* Overlay behind sidebar on mobile */
  body.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1049;
  }
}

/* ── Page Title ─────────────────────────────────────────────── */
.pagetitle { margin-bottom: 20px; }
.pagetitle h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--rms-primary);
  margin-bottom: 4px;
}
.breadcrumb {
  font-size: 12.5px;
  color: #718096;
  font-weight: 500;
  margin: 0;
  padding: 0;
  background: none;
}
.breadcrumb-item + .breadcrumb-item::before { color: #a0aec0; }
.breadcrumb a { color: #718096; }
.breadcrumb a:hover { color: var(--rms-primary-light); }
.breadcrumb .active { color: var(--rms-primary); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  border: none;
  border-radius: var(--rms-radius);
  box-shadow: var(--rms-shadow);
  background: #fff;
  margin-bottom: 24px;
  overflow: hidden;
}
.card-header {
  background: #fff;
  border-bottom: 1px solid #edf2f7;
  padding: 16px 20px;
  font-weight: 600;
  color: var(--rms-primary);
}
.card-body { padding: 20px; }
.card-footer {
  background: #f8fafc;
  border-top: 1px solid #edf2f7;
  padding: 12px 20px;
}

/* Stat cards */
.stat-card {
  border-radius: var(--rms-radius);
  padding: 20px 22px;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--rms-shadow-md);
  transition: transform .2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon {
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: 52px;
  opacity: .15;
}
.stat-card .stat-label { font-size: 12px; font-weight: 600; opacity: .85; letter-spacing: .5px; text-transform: uppercase; }
.stat-card .stat-value { font-size: 36px; font-weight: 800; line-height: 1.1; margin: 4px 0; }
.stat-card .stat-sub { font-size: 11.5px; opacity: .75; }

.stat-critical { background: linear-gradient(135deg, #c0392b, #e74c3c); }
.stat-high     { background: linear-gradient(135deg, #d35400, #e67e22); }
.stat-medium   { background: linear-gradient(135deg, #b7950b, #f1c40f); color: #2d3748; }
.stat-medium .stat-label, .stat-medium .stat-sub { color: #2d3748; opacity: .7; }
.stat-low      { background: linear-gradient(135deg, #1a7a4a, #27ae60); }
.stat-primary  { background: linear-gradient(135deg, var(--rms-primary), var(--rms-primary-light)); }
.stat-accent   { background: linear-gradient(135deg, #b7770d, var(--rms-accent)); color: #2d3748; }

/* ── Tables ─────────────────────────────────────────────────── */
.table { font-size: 13.5px; color: #2d3748; }
.table thead th {
  background: #f7fafc;
  color: #4a5568;
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 2px solid #e2e8f0;
  padding: 12px 14px;
  white-space: nowrap;
}
.table tbody td { padding: 11px 14px; border-bottom: 1px solid #f0f4f8; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr:hover { background: #f7fafc; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: .3px;
}
.badge-status-draft     { background: #edf2f7; color: #4a5568; }
.badge-status-submitted { background: #fef3c7; color: #92400e; }
.badge-status-approved  { background: #d1fae5; color: #065f46; }
.badge-status-rejected  { background: #fee2e2; color: #991b1b; }

/* Risk score badges */
.risk-critical { background: #fee2e2; color: #991b1b; }
.risk-high      { background: #ffedd5; color: #9a3412; }
.risk-medium    { background: #fef9c3; color: #713f12; }
.risk-low       { background: #dcfce7; color: #14532d; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 16px;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 11px 24px; font-size: 14px; }

.btn-primary {
  background: var(--rms-primary);
  border-color: var(--rms-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--rms-primary-light);
  border-color: var(--rms-primary-light);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(26,60,110,.25);
}
.btn-success { background: var(--rms-success); border-color: var(--rms-success); }
.btn-success:hover { background: #158a4e; border-color: #158a4e; transform: translateY(-1px); }
.btn-danger  { background: var(--rms-danger);  border-color: var(--rms-danger); }
.btn-warning { background: var(--rms-warning); border-color: var(--rms-warning); color: #fff; }
.btn-warning:hover { color: #fff; }

.btn-outline-primary { border-color: var(--rms-primary); color: var(--rms-primary); }
.btn-outline-primary:hover { background: var(--rms-primary); color: #fff; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-label { font-size: 12.5px; font-weight: 600; color: #4a5568; margin-bottom: 5px; }
.form-control, .form-select {
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13.5px;
  padding: 8px 12px;
  color: #2d3748;
  transition: border-color .2s, box-shadow .2s;
  background: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: var(--rms-primary-light);
  box-shadow: 0 0 0 3px rgba(42,82,152,.12);
  outline: none;
}
.form-control-sm, .form-select-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
textarea.form-control { resize: vertical; min-height: 70px; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  border: none;
  border-radius: var(--rms-radius);
  font-size: 13.5px;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger   { background: #fee2e2; color: #991b1b; }
.alert-warning  { background: #fef3c7; color: #92400e; }
.alert-info     { background: #dbeafe; color: #1e40af; }

/* ── Progress bars ──────────────────────────────────────────── */
.progress {
  background: #edf2f7;
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  border-radius: 99px;
  transition: width .6s ease;
}

/* ── Approval workflow status strip ────────────────────────── */
.workflow-strip {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 20px;
  background: #f7fafc;
  border-bottom: 1px solid #edf2f7;
  flex-wrap: wrap;
  gap: 8px;
}
.workflow-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #a0aec0;
}
.workflow-step.done   { color: var(--rms-success); }
.workflow-step.active { color: var(--rms-primary); }
.workflow-step .step-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.workflow-step.done   .step-dot { background: var(--rms-success); color: #fff; }
.workflow-step.active .step-dot { background: var(--rms-primary); color: #fff; }
.workflow-connector { width: 24px; height: 2px; background: #e2e8f0; flex-shrink: 0; }
.workflow-connector.done { background: var(--rms-success); }

/* ── Month target grid ──────────────────────────────────────── */
.month-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}
.month-cell {
  text-align: center;
  font-size: 11px;
}
.month-cell .month-label {
  font-weight: 700;
  color: #718096;
  font-size: 10px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.month-cell input {
  width: 100%;
  text-align: center;
  padding: 4px 2px;
  font-size: 12px;
}

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: #dde3ea;
  background-image:
    radial-gradient(circle at 15% 15%, rgba(26,60,110,.06) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(232,160,32,.05) 0%, transparent 45%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 6px 32px rgba(15,36,68,.13), 0 1px 3px rgba(15,36,68,.06);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}
.login-card-header {
  background: var(--rms-primary);
  padding: 36px 32px 28px;
  text-align: center;
}
.login-card-header .login-logo {
  width: 200px;
  height: 72px;
  background: rgba(255,255,255,.12);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
  overflow: hidden;
  padding: 8px 16px;
}
.login-card-header .login-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.95;
}
.login-card-header h1 {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}
.login-card-header p { color: rgba(255,255,255,.65); font-size: 12.5px; margin: 0; }
.login-card-body { padding: 28px 32px 32px; }

/* ── Pending approval banners ───────────────────────────────── */
.approval-banner {
  border-radius: var(--rms-radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  transition: transform .2s, box-shadow .2s;
  margin-bottom: 16px;
}
.approval-banner:hover { transform: translateY(-2px); box-shadow: var(--rms-shadow-md); }
.approval-banner-plans   { background: linear-gradient(135deg, #fef3c7, #fde68a); }
.approval-banner-reports { background: linear-gradient(135deg, #dbeafe, #bfdbfe); }
.approval-banner .banner-icon { font-size: 28px; flex-shrink: 0; }
.approval-banner .banner-count {
  margin-left: auto;
  font-size: 28px;
  font-weight: 800;
  flex-shrink: 0;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  #main { padding: 16px 12px; }
  .stat-card .stat-value { font-size: 28px; }
  .month-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ── Utility ─────────────────────────────────────────────────── */
.text-primary-rms { color: var(--rms-primary) !important; }
.text-accent      { color: var(--rms-accent) !important; }
.bg-primary-rms   { background: var(--rms-primary) !important; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.rounded-rms { border-radius: var(--rms-radius); }
.shadow-rms  { box-shadow: var(--rms-shadow); }
.shadow-rms-md { box-shadow: var(--rms-shadow-md); }
.divider { border: none; border-top: 1px solid #edf2f7; margin: 16px 0; }

/* ── Language dropdown (sidebar footer) ────────────────────── */
.sidebar-footer .dropdown-menu {
  background: #1e3a5f;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 6px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.sidebar-footer .dropdown-menu .dropdown-item {
  color: rgba(255,255,255,.85) !important;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s;
}
.sidebar-footer .dropdown-menu .dropdown-item:hover,
.sidebar-footer .dropdown-menu .dropdown-item:focus {
  background: rgba(255,255,255,.12) !important;
  color: #fff !important;
}
.sidebar-footer .dropdown-menu .dropdown-item.active,
.sidebar-footer .dropdown-menu .dropdown-item:active {
  background: rgba(232,160,32,.25) !important;
  color: var(--rms-accent-light) !important;
}

/* ── Active sidebar nav link — definitive rules ─────────────── */
.sidebar-nav .nav-link.active {
  background: rgba(232,160,32,.18) !important;
  color: #fff !important;
  font-weight: 600;
}
.sidebar-nav .nav-link.active i {
  color: var(--rms-accent) !important;
}
.sidebar-nav .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--rms-accent);
  border-radius: 0 3px 3px 0;
}
/* Remove the old :not(.collapsed) rule that was causing false positives */
.sidebar-nav .nav-link:not(.active) {
  background: transparent;
  color: rgba(255,255,255,.65);
}
.sidebar-nav .nav-link:not(.active) i {
  color: rgba(255,255,255,.45);
}
.sidebar-nav .nav-link:not(.active):hover {
  background: rgba(255,255,255,.08) !important;
  color: #fff !important;
}
.sidebar-nav .nav-link:not(.active):hover i {
  color: var(--rms-accent) !important;
}

/* ── Hamburger button visible on all sizes ──────────────────── */
.toggle-sidebar-btn {
  font-size: 24px;
  color: var(--rms-primary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background .2s;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}
.toggle-sidebar-btn:hover { background: #f0f4f8; }
