/*
  Member Portal design system.
  Deliberately not the LMS's AdminLTE/Bootstrap-3 skin - a distinct,
  modern "online banking" look. Colours are CSS custom properties so the
  real SACCO brand palette can be dropped in later by changing only the
  values below.
*/

:root {
  --brand-primary: #0b3d5c;      /* deep trust blue */
  --brand-primary-dark: #082b40;
  --brand-accent: #1a9e6b;       /* SACCO green - growth/money */
  --brand-accent-dark: #147a53;
  --bg-page: #f4f7fa;
  --bg-card: #ffffff;
  --text-primary: #1c2733;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #147a53;
  --success-bg: #ecfdf5;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(11, 61, 92, 0.08);
  --shadow-lg: 0 12px 40px rgba(11, 61, 92, 0.14);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth layout (login / forgot / reset / activate) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--brand-primary) 0%, var(--brand-primary-dark) 55%, #061c2b 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
  text-align: center;
}

.auth-brand img {
  height: 56px;
  margin-bottom: 12px;
}

.auth-brand h1 {
  font-size: 1.15rem;
  margin: 0;
  color: var(--text-primary);
}

.auth-brand p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-card h2 {
  font-size: 1.35rem;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.auth-card h2 > i.fa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(26, 158, 107, 0.12);
  color: var(--brand-accent);
  font-size: 0.95rem;
  flex-shrink: 0;
}

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 24px;
}

.form-group { margin-bottom: 18px; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(11, 61, 92, 0.12);
}

.form-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 0.88rem;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn-primary {
  background: var(--brand-accent);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-accent-dark); }
.btn-primary:active { transform: translateY(1px); }

.auth-footer-links {
  margin-top: 20px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.auth-footer-links a { font-weight: 600; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 20px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; word-break: break-all; }

.help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- Authenticated app shell ---------- */
/*
  Left sidebar navigation + slim top bar, replacing the earlier single
  horizontal nav row (which had grown to 13 links and no longer fit on
  one line). Sidebar is fixed-position and full height; content is
  offset by its width on desktop and the sidebar slides off-canvas
  behind a hamburger toggle below --mp-sidebar-breakpoint.
*/

:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

.app-shell { min-height: 100vh; display: flex; }

.brand-box {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: var(--topbar-height);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 14px;
  box-shadow: var(--shadow);
  z-index: 30;
}
.brand-box img { height: 30px; max-width: 40px; object-fit: contain; border-radius: 6px; flex-shrink: 0; }
.brand-box span {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--brand-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--brand-primary-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-nav { display: flex; flex-direction: column; padding: 10px 0; flex: 1; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: #cfe0ec;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.sidebar-nav a i { width: 18px; text-align: center; font-size: 0.95rem; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-left-color: var(--brand-accent);
  font-weight: 600;
}
.sidebar-nav a .nav-badge { margin-left: auto; }

.app-content-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.app-topbar {
  height: var(--topbar-height);
  background: var(--brand-primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-weight: 600; font-size: 1rem; color: #fff; margin-right: auto; }

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #fff;
  cursor: pointer;
  padding: 6px;
}

.nav-badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* ---------- User menu (topbar, top-right) ---------- */

.user-menu { position: relative; flex-shrink: 0; }

.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  cursor: pointer;
  color: #fff;
}
.user-menu-toggle:hover { background: rgba(255, 255, 255, 0.14); }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.user-menu-info { display: flex; flex-direction: column; text-align: left; line-height: 1.25; }
.topbar-user-name { font-weight: 600; font-size: 0.85rem; color: #fff; }
.topbar-user-sub { font-size: 0.7rem; color: #a9c2d4; }

.user-menu-toggle .fa-chevron-down { font-size: 0.7rem; transition: transform 0.15s ease; }
.user-menu.open .user-menu-toggle .fa-chevron-down { transform: rotate(180deg); }

.user-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 190px;
  padding: 6px;
  z-index: 40;
}
.user-menu.open .user-menu-dropdown { display: block; }
.user-menu-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.88rem;
}
.user-menu-dropdown a:hover { background: var(--bg-page); text-decoration: none; }
.user-menu-dropdown a i { width: 16px; text-align: center; color: var(--text-muted); }
.user-menu-dropdown-divider { height: 1px; background: var(--border-color); margin: 6px 4px; }

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .app-content-wrap { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .brand-box { width: 64px; padding: 0 8px; }
  .brand-box span { display: none; }
  .user-menu-info { display: none; }
  .app-topbar { padding-left: 76px; }
}

.notification-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}
.notification-item:last-child { border-bottom: none; }
.notification-item.unread { background: #eff6ff; margin: 0 -28px; padding: 16px 28px; }
.notification-item h3 { margin: 0 0 4px; font-size: 0.95rem; }
.notification-item p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }
.notification-item time { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }

.app-main {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

/*
  Every card's top-level heading gets an automatic icon badge just by
  adding an <i class="fa fa-..."> as its first child - no extra markup
  needed per page. Scoped to DIRECT children only (.card > h2/h3) so it
  never touches unrelated headings nested inside list items, e.g.
  .notification-item h3 (a person's name, not a section title).
*/
.card > h2, .card > h3, .card > form > h3, .card > .card-header-row > h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card > h2 > i.fa, .card > h3 > i.fa, .card > form > h3 > i.fa, .card > .card-header-row > h2 > i.fa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(26, 158, 107, 0.12);
  color: var(--brand-accent);
  font-size: 0.9rem;
  flex-shrink: 0;
}
.card > h3 > i.fa, .card > form > h3 > i.fa { width: 26px; height: 26px; font-size: 0.78rem; }

/*
  Card header with a trailing action button (e.g. "New Ticket", "Download
  Statement"). Replaces the old float:right buttons, which had no clearfix
  on .card and would visually overlap the card's own content below them
  (and collide with the heading on narrow screens). flex-wrap lets the
  button drop under the heading on mobile instead of overlapping it.
*/
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}
.card-header-row > h2 { margin: 0; }
.card-header-row > .btn, .card-header-row > form > .btn { width: auto; }
.card-header-row > form { margin: 0; }

/* Any wide table gets wrapped in this at runtime (see app-end.php) so it
   scrolls horizontally on narrow screens instead of forcing the whole
   page to scroll sideways or squeezing columns unreadably thin. */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
.table-responsive > table { min-width: 620px; }

/*
  Boxed label/value grid - replaces the old <dl class="kv-list"> definition
  list styling with a card of individually-boxed fields (label on top,
  value below), matching the reference design. Not used in PDF templates
  (Dompdf has no flexbox/grid support - those keep plain table markup).
*/
.kv-box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.kv-box {
  background: var(--bg-page);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kv-box-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.kv-box-value { font-size: 0.92rem; font-weight: 600; color: var(--text-primary); }
.kv-box-value:empty::before,
.kv-box-value.is-empty { color: var(--text-muted); font-weight: 400; font-style: italic; }

/* Row with a circular icon avatar - used for people (next of kin, nominees, guarantors). */
.person-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-color);
}
.person-row:last-child { border-bottom: none; }
.person-row-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-page);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.95rem;
}
.person-row-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.person-row-body strong { font-size: 0.92rem; }
.person-row-body span { font-size: 0.8rem; color: var(--text-muted); }
.person-row-body span i { margin-right: 4px; width: 12px; text-align: center; }

/* ---------- Profile page ---------- */

.profile-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .profile-grid { grid-template-columns: 1fr; } }

.profile-header-card { text-align: center; }
.profile-avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: var(--brand-primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 auto 14px;
  overflow: hidden;
}
.profile-avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.profile-header-card h2 { justify-content: center; margin-bottom: 2px; font-size: 1.1rem; }
.profile-header-card .member-code { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }

.info-row-list { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-color); text-align: left; }
.info-row { display: flex; align-items: flex-start; gap: 12px; }
.info-row > i.fa { color: var(--text-muted); width: 16px; margin-top: 3px; text-align: center; }
.info-row-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 600; }
.info-row-value { display: block; font-size: 0.88rem; font-weight: 600; color: var(--text-primary); word-break: break-word; }

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}

.card h2 { margin-top: 0; font-size: 1.2rem; }

.welcome-card { background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%); color: #fff; }
.welcome-card h2 { color: #fff; }
.welcome-card h2 > i.fa { background: rgba(255, 255, 255, 0.18); color: #fff; }
.welcome-card p { color: #cfe0ec !important; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.stat-sub { font-size: 0.82rem; color: var(--text-muted); }

.txn-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.txn-table th, .txn-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border-color); }
.txn-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.txn-table .align-right { text-align: right; }

.empty-state { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}
.doc-row:last-child { border-bottom: none; }

select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
}

input:disabled {
  background: var(--bg-page);
  color: var(--text-muted);
}

.card h3 { font-size: 1rem; margin: 24px 0 12px; color: var(--text-primary); }

.profile-photo-card { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }

.profile-photo img,
.profile-photo-placeholder {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-primary);
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
}

.profile-photo-form { flex: 1; min-width: 220px; }
.profile-photo-form input[type="file"] { font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-bg-green { background: var(--success-bg); color: var(--success); }
.badge-bg-yellow { background: #fffbeb; color: #b45309; }
.badge-bg-red { background: var(--danger-bg); color: var(--danger); }
.badge-bg-gray { background: #f1f5f9; color: #475569; }
.badge-bg-blue { background: #eff6ff; color: #1d4ed8; }
.badge-bg-orange { background: #fff7ed; color: #c2410c; }

.amount-positive { color: var(--success); font-weight: 600; }
.amount-negative { color: var(--danger); font-weight: 600; }

.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.filter-row .form-group { margin-bottom: 0; }
.filter-row input[type="date"] {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.9rem;
}

.mp-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}
.mp-pagination-label { color: var(--text-muted); font-size: 0.88rem; }
.mp-pagination-disabled {
  background: var(--bg-page);
  color: var(--text-muted);
  cursor: default;
  opacity: 0.6;
}

@media (max-width: 560px) {
  .auth-card { padding: 28px 22px; }
  .app-main { padding: 18px 14px; }
  .card { padding: 18px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.3rem; }
  .kv-box-grid { grid-template-columns: 1fr; }
  .profile-photo-card { flex-direction: column; align-items: flex-start; }
  .card-header-row > .btn,
  .card-header-row > form,
  .card-header-row > form > .btn { width: 100%; }
  .filter-row .btn,
  .filter-row a.btn { width: 100%; text-align: center; }
}
