/* =========================================================================
   CPB HR Manager — Stylesheet v1.1 (mobile-first responsive)
   Counsellors and Psychologists Board
   ========================================================================= */

:root {
  --blue: #185FA5;
  --blue-dk: #0C447C;
  --blue-lt: #E6F1FB;
  --blue-bg: #F5F8FC;
  --red: #A32D2D;
  --red-lt: #FCE8E8;
  --green: #3B6D11;
  --green-lt: #EAF3DE;
  --amber: #854F0B;
  --amber-lt: #FEF3D7;
  --gray-bg: #F4F5F7;
  --border: #E0E0E0;
  --border-soft: #EEEEEE;
  --text: #1A1A1A;
  --text-soft: #444;
  --muted: #666;
  --muted-lt: #999;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --footer-h: 40px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ── Login pages ─────────────────────────────────────────────────────── */
.login-body {
  background: linear-gradient(135deg, #0C447C 0%, #185FA5 50%, #2E7BC0 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px 20px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.18);
}
.login-header {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.login-logo { max-width: 200px; max-height: 60px; height: auto; margin-bottom: 8px; }
.login-org { font-size: 13px; font-weight: 700; color: var(--blue-dk); line-height: 1.3; }
.login-tag { font-size: 10px; color: var(--muted); margin-top: 3px; font-style: italic; }
.login-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; text-align: center; }
.login-form { margin-top: 12px; }
.login-form .form-group { margin-bottom: 14px; }
.login-footer { text-align: center; margin-top: 18px; font-size: 12px; color: var(--muted); }
.login-footer a { color: var(--blue); text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }
.login-footer .dot { margin: 0 6px; color: #ccc; }
.login-foot { text-align: center; margin-top: 14px; color: rgba(255,255,255,0.7); font-size: 11px; }

@media (min-width: 480px) {
  .login-card { padding: 32px 28px; }
  .login-logo { max-width: 220px; max-height: 70px; }
  .login-org { font-size: 14px; }
  .login-tag { font-size: 11px; }
  .login-title { font-size: 17px; }
}

/* ── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  background: linear-gradient(to right, var(--blue-dk), var(--blue));
  color: #fff;
  padding: 8px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 3px solid var(--blue-dk);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1400px;
  margin: 0 auto;
}
.topbar-logo {
  height: 36px;
  background: #fff;
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.topbar-titles { flex: 1; min-width: 0; }
.topbar-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub { font-size: 10px; opacity: 0.85; font-style: italic; display: none; }
.topbar-user { text-align: right; flex-shrink: 0; }
.user-name {
  font-size: 12px;
  font-weight: 600;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role { font-size: 10px; margin-top: 2px; }

/* Hamburger toggle (mobile only) */
.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  flex-shrink: 0;
}
.menu-toggle:hover, .menu-toggle:active { background: rgba(255,255,255,0.15); }

@media (min-width: 768px) {
  .topbar { padding: 8px 20px; }
  .topbar-inner { gap: 14px; }
  .topbar-logo { height: 44px; padding: 4px 8px; }
  .topbar-title { font-size: 14px; }
  .topbar-sub { display: block; }
  .user-name { font-size: 13px; max-width: none; }
  .user-role { font-size: 11px; }
  .menu-toggle { display: none; }
}

/* ── Layout ───────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h) - var(--footer-h));
}
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  /* Mobile: off-canvas */
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  height: calc(100vh - var(--topbar-h));
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 99;
  box-shadow: 2px 0 12px rgba(0,0,0,0.1);
}
body.sidebar-open .sidebar { transform: translateX(0); }

/* Backdrop for mobile sidebar */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 98;
}
body.sidebar-open .sidebar-backdrop { display: block; }

.main {
  flex: 1;
  padding: 14px;
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}

@media (min-width: 768px) {
  .sidebar {
    position: static;
    transform: none;
    height: auto;
    box-shadow: none;
    top: auto;
  }
  .sidebar-backdrop { display: none !important; }
  .main { padding: 20px 24px; }
}

@media (min-width: 1024px) {
  .main { padding: 24px 28px; }
}

/* ── Navigation ───────────────────────────────────────────────────────── */
.nav { padding: 10px 0; }
.nav-section {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted-lt);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  text-decoration: none;
  color: var(--text-soft);
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: all 0.12s;
}
.nav-item:hover { background: #F0F4FA; color: var(--text); }
.nav-item.active { background: var(--blue-lt); color: var(--blue); border-left-color: var(--blue); font-weight: 600; }
.nav-ic { width: 18px; text-align: center; font-size: 14px; }
.nav-logout { color: var(--red); }
.nav-logout:hover { background: var(--red-lt); color: var(--red); }

@media (min-width: 768px) {
  .nav-item { padding: 9px 18px; font-size: 13px; }
}

/* ── Page header ──────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-title { font-size: 18px; font-weight: 600; color: var(--text); line-height: 1.2; }
.page-meta { font-size: 12px; color: var(--muted); }

@media (min-width: 768px) {
  .page-header { align-items: center; margin-bottom: 20px; gap: 12px; }
  .page-title { font-size: 22px; }
  .page-meta { font-size: 13px; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}
.card-tight { padding: 0; overflow: hidden; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.warning-card { background: var(--amber-lt); border-color: #F4D88B; }
.warning-card .card-title { color: var(--amber); }

@media (min-width: 768px) {
  .card { padding: 20px; margin-bottom: 16px; }
}

/* ── Metrics ──────────────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.metric-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.metric-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.metric-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  word-break: break-word;
}
.metric-value-sm { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.2; }
.metric-sub { font-size: 10px; color: var(--muted); margin-top: 3px; }

@media (min-width: 480px) {
  .metric-grid { gap: 12px; }
  .metric-value { font-size: 24px; }
}
@media (min-width: 768px) {
  .metric-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 22px;
  }
  .metric-card { padding: 16px 18px; }
  .metric-label { font-size: 12px; }
  .metric-value { font-size: 26px; }
  .metric-value-sm { font-size: 16px; }
  .metric-sub { font-size: 11px; }
}

/* ── Tables ───────────────────────────────────────────────────────────── */
.tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}
.card-tight .tbl-wrap { margin: 0; padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  background: #FAFBFC;
  white-space: nowrap;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #F8F9FC; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.td-name strong, .td-name { font-weight: 600; }
.td-name .td-sub { display: block; font-size: 11px; color: var(--muted); font-weight: normal; margin-top: 2px; }
.td-empty { text-align: center; padding: 24px !important; color: var(--muted); font-style: italic; white-space: normal; }
.td-actions { white-space: nowrap; }
.td-net { color: var(--blue); font-weight: 700; }
.row-total { background: #FAFBFC; }
.row-total td { border-top: 2px solid var(--blue-dk); }
.mono { font-family: 'Consolas', 'Courier New', monospace; font-size: 12px; }

@media (min-width: 768px) {
  .tbl-wrap { margin: 0; padding: 0; }
  table { font-size: 13px; }
  th { padding: 10px 12px; font-size: 12px; }
  td { padding: 10px 12px; }
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid #CCC;
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
  font-family: inherit;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { background: #F5F5F5; border-color: #999; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dk); border-color: var(--blue-dk); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #2A4F0B; }
.btn-amber { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-amber:hover { background: #633806; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #791F1F; }
.btn-sm { padding: 6px 12px; min-height: 32px; font-size: 12px; }
.btn-block { display: block; width: 100%; padding: 12px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  padding: 10px 12px;
  border: 1px solid #CCC;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  min-height: 40px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(24, 95, 165, 0.15);
}
input[readonly] { background: #F5F5F5; color: var(--muted); }
.divider { border: none; border-top: 1px solid var(--border-soft); margin: 16px 0; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
}

@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  input, select, textarea { padding: 8px 10px; font-size: 13px; min-height: 36px; }
  .divider { margin: 18px 0; }
  .section-label { margin-bottom: 12px; }
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  max-width: 600px;
  flex-wrap: wrap;
}
.search-bar input { flex: 1; min-width: 200px; }

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar select {
  width: auto;
  min-width: 130px;
  padding: 8px 10px;
}
@media (min-width: 640px) {
  .filter-bar select { min-width: 140px; padding: 6px 10px; }
}

/* Toggle switch */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 400;
  padding-top: 6px;
}
.switch input { width: auto; min-height: auto; }

/* ── Summary rows (preview) ──────────────────────────────────────────── */
.preview-card { background: #F8F9FC; }
.sum-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.sum-row:last-child { border-bottom: none; }
.sum-row span:last-child {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.sum-total {
  font-weight: 700;
  font-size: 14px;
  border-top: 2px solid #BBB;
  padding-top: 10px;
  margin-top: 4px;
}
.sum-total span:last-child { color: var(--blue); }
.negative { color: var(--red); }

@media (min-width: 640px) {
  .sum-total { font-size: 15px; }
}

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid;
}
.alert-success { background: var(--green-lt); color: #1F4708; border-color: #BCD9A1; }
.alert-info { background: var(--blue-lt); color: var(--blue-dk); border-color: #BFD8F0; }
.alert-danger { background: var(--red-lt); color: var(--red); border-color: #F0BFBF; }
.alert-warning { background: var(--amber-lt); color: var(--amber); border-color: #F0D688; }
.alert ul { margin: 6px 0 0 18px; }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-green { background: var(--green-lt); color: var(--green); }
.badge-gray { background: #F1F1F1; color: #555; }
.badge-red { background: var(--red-lt); color: var(--red); }

.role-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.role-admin { background: #FEE7E7; color: #8B1A1A; }
.role-hr { background: #DBEAFE; color: #1E40AF; }
.role-staff { background: #E5E7EB; color: #374151; }

/* ── Payslip / printable docs ────────────────────────────────────────── */
.payslip { max-width: 820px; }
.payslip-header-doc {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.payslip-logo { height: 50px; width: auto; align-self: flex-start; }
.payslip-org-block { flex: 1; }
.payslip-org { font-size: 15px; font-weight: 700; color: var(--blue-dk); line-height: 1.3; }
.payslip-tag { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 2px; }
.payslip-period {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #CCC;
}

@media (min-width: 640px) {
  .payslip-header-doc { flex-direction: row; align-items: center; gap: 16px; padding: 16px 20px; }
  .payslip-logo { height: 60px; align-self: auto; }
  .payslip-org { font-size: 16px; }
}

.payslip-meta-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 13px;
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 4px 0;
}
.meta-row > div { flex: 1 1 160px; min-width: 0; }
.meta-label { color: var(--muted); font-size: 11px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 768px) {
  .two-col { grid-template-columns: 1fr 1fr; gap: 14px; }
}

.pay-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.pay-row:last-of-type { border-bottom: none; }
.pay-row span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.pay-row.total {
  font-weight: 700;
  border-top: 2px solid var(--blue-dk);
  border-bottom: none;
  font-size: 14px;
  padding-top: 10px;
  margin-top: 4px;
}
.net-pay-banner {
  background: linear-gradient(to right, var(--blue), var(--blue-dk));
  color: #fff;
  padding: 16px 18px;
  border-radius: 10px;
  text-align: center;
  margin-top: 14px;
}
.net-pay-label { font-size: 11px; opacity: 0.9; }
.net-pay-amount {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.net-pay-sub { font-size: 11px; opacity: 0.85; margin-top: 3px; }

@media (min-width: 640px) {
  .net-pay-banner { padding: 18px 24px; }
  .net-pay-label { font-size: 12px; }
  .net-pay-amount { font-size: 30px; }
}

.payslip-footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 14px;
  padding: 10px 4px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border-soft);
}
@media (min-width: 640px) {
  .payslip-footer { flex-direction: row; justify-content: space-between; padding: 10px 16px; }
}

/* ── P9 ───────────────────────────────────────────────────────────────── */
.p9-card { max-width: 980px; }
.p9-table th, .p9-table td { font-size: 11px; padding: 6px 6px; }
@media (min-width: 768px) {
  .p9-table th, .p9-table td { font-size: 12px; padding: 7px 8px; }
}

/* Period banner (payroll) */
.period-banner {
  background: var(--blue-lt);
  color: var(--blue-dk);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Profile ─────────────────────────────────────────────────────────── */
.profile-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  flex-wrap: wrap;
}
.profile-row span:first-child { color: var(--muted); }
.profile-row:last-child { border-bottom: none; }

/* ── Actions menu (users page) ───────────────────────────────────────── */
.action-menu { display: inline-block; position: relative; }
.action-menu summary {
  list-style: none;
  cursor: pointer;
  display: inline-block;
}
.action-menu summary::-webkit-details-marker { display: none; }
.action-popup {
  position: absolute;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
  min-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  margin-top: 4px;
}
.action-popup form { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.action-popup input[type=password] { padding: 6px 8px; font-size: 12px; min-height: 32px; }

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin: 18px 0;
  flex-wrap: wrap;
}
.page-link {
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text-soft);
  font-size: 13px;
  min-width: 36px;
  text-align: center;
}
.page-link:hover { background: #F5F5F5; }
.page-link.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Footer ──────────────────────────────────────────────────────────── */
.footer {
  height: var(--footer-h);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 11px;
  color: var(--muted);
  gap: 10px;
  flex-wrap: wrap;
}
.footer > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 640px) {
  .footer { padding: 0 24px; }
}

/* ── Print ───────────────────────────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .sidebar-backdrop, .footer, .btn, .btn-row,
  .page-header > *:not(.page-title), .filter-bar, .alert-info { display: none !important; }
  .layout, .main { display: block; padding: 0; background: #fff; }
  .card { border: none; box-shadow: none; padding: 0; }
}
