:root {
    --bg:          #eef2f7;
    --surface:     #f7f9fc;
    --white:       #ffffff;
    --navy:        #1a2e4a;
    --navy-mid:    #2a4570;
    --navy-light:  #3a5f96;
    --blue:        #2563a8;
    --blue-mid:    #3b7dd8;
    --blue-light:  #dbeafe;
    --blue-pale:   #eff6ff;
    --steel:       #6b8ab0;
    --steel-light: #c5d5e8;
    --charcoal:    #1e2d3d;
    --gray:        #7a8fa8;
    --gray-light:  #d0dce8;
    --green:       #1a6b45;
    --green-light: #dcf5e9;
    --red:         #7a1f1f;
    --red-light:   #fbe8e8;
    --amber:       #b45309;
    --amber-light: #fef3c7;
    --shadow:      0 2px 12px rgba(26,46,74,0.10);
    --shadow-lg:   0 8px 32px rgba(26,46,74,0.18);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'Lato', sans-serif; background: var(--bg); color: var(--charcoal); min-height: 100vh; }

  /* ══ LOGIN SCREEN ══════════════════════════════════════════════ */
  #loginScreen {
    display: none;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, var(--blue) 100%);
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  #loginScreen.visible { display: flex; }
  .login-card {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.30);
    overflow: hidden;
  }
  .login-header {
    background: var(--navy);
    padding: 32px 32px 24px;
    text-align: center;
  }
  .login-cross {
    width: 48px; height: 56px;
    margin: 0 auto 16px;
  }
  .login-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.6rem; color: #e8f0fa; letter-spacing: 0.02em;
  }
  .login-header h1 span { color: #7ab4e8; font-style: italic; }
  .login-header p { font-size: 0.82rem; color: var(--steel-light); margin-top: 6px; }
  .login-body { padding: 28px 32px 32px; }
  .login-error {
    background: var(--red-light); border: 1px solid #e8a0a0;
    color: var(--red); border-radius: 7px;
    padding: 10px 14px; font-size: 0.85rem; margin-bottom: 18px; display: none;
  }
  .login-error.show { display: block; }
  .login-btn {
    width: 100%; padding: 11px;
    background: var(--blue); color: #fff;
    border: none; border-radius: 8px;
    font-family: 'Lato', sans-serif; font-weight: 700;
    font-size: 0.9rem; letter-spacing: 0.05em; cursor: pointer;
    transition: background 0.2s; margin-top: 4px;
  }
  .login-btn:hover { background: var(--blue-mid); }
  .login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

  /* ══ APP SHELL ═════════════════════════════════════════════════ */
  #appShell { display: none; }
  #appShell.visible { display: block; }

  /* ── HEADER ── */
  header {
    background: var(--navy);
    padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    height: 60px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.30);
    position: sticky; top: 0; z-index: 100;
  }
  .header-brand { display: flex; align-items: center; gap: 12px; }
  .cross-icon { width: 20px; height: 24px; flex-shrink: 0; }
  header h1 { font-family: 'Playfair Display', serif; font-size: 1.25rem; color: #e8f0fa; letter-spacing: 0.02em; }
  header h1 span { color: #7ab4e8; font-style: italic; }

  .header-center { display: flex; gap: 4px; }
  .nav-btn {
    background: none; border: none; color: var(--steel-light);
    font-family: 'Lato', sans-serif; font-size: 0.8rem; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase;
    padding: 7px 14px; border-radius: 6px; cursor: pointer; transition: all 0.2s;
  }
  .nav-btn:hover { background: rgba(255,255,255,0.10); color: #fff; }
  .nav-btn.active { background: var(--blue-mid); color: #fff; }
  .nav-btn.admin-only { display: none; }

  .header-right { display: flex; align-items: center; gap: 8px; position: relative; }
  .user-pill {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px; padding: 5px 12px 5px 6px;
    cursor: pointer; transition: background 0.2s; user-select: none;
  }
  .user-pill:hover { background: rgba(255,255,255,0.14); }
  .user-avatar-sm {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--blue-mid); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
  }
  .user-pill-name { font-size: 0.8rem; color: #e8f0fa; font-weight: 700; }
  .user-pill-caret { font-size: 0.6rem; color: var(--steel-light); margin-left: 2px; }

  .user-dropdown {
    display: none;
    position: absolute; top: calc(100% + 10px); right: 0;
    background: var(--white); border: 1px solid var(--gray-light);
    border-radius: 10px; box-shadow: var(--shadow-lg);
    min-width: 200px; overflow: hidden; z-index: 200;
  }
  .user-dropdown.open { display: block; }
  .dropdown-header { padding: 12px 16px 10px; border-bottom: 1px solid var(--gray-light); }
  .dropdown-name { font-weight: 700; font-size: 0.9rem; color: var(--navy); }
  .dropdown-role { font-size: 0.75rem; color: var(--gray); text-transform: capitalize; }
  .dropdown-item {
    display: block; width: 100%; padding: 10px 16px;
    background: none; border: none; text-align: left;
    font-family: 'Lato', sans-serif; font-size: 0.85rem;
    color: var(--charcoal); cursor: pointer; transition: background 0.15s;
  }
  .dropdown-item:hover { background: var(--blue-pale); }
  .dropdown-item.danger { color: var(--red); }
  .dropdown-item.danger:hover { background: var(--red-light); }

  /* ── LAYOUT ── */
  .app { display: flex; min-height: calc(100vh - 60px); }

  /* ── SIDEBAR ── */
  .sidebar {
    width: 290px; min-width: 290px;
    background: var(--white); border-right: 1px solid var(--gray-light);
    display: flex; flex-direction: column; overflow: hidden;
  }
  .sidebar-header { padding: 16px 14px 10px; border-bottom: 1px solid var(--gray-light); }
  .sidebar-header h2 { font-family: 'Playfair Display', serif; font-size: 0.95rem; color: var(--navy); margin-bottom: 8px; }
  .search-box {
    width: 100%; padding: 7px 12px;
    border: 1px solid var(--gray-light); border-radius: 6px;
    font-family: 'Lato', sans-serif; font-size: 0.85rem;
    color: var(--charcoal); background: var(--bg); outline: none; transition: border-color 0.2s;
  }
  .search-box:focus { border-color: var(--blue-mid); }
  .sidebar-list { flex: 1; overflow-y: auto; padding: 6px; }
  .contact-item {
    padding: 9px 10px; border-radius: 8px; cursor: pointer;
    transition: all 0.15s; display: flex; align-items: center; gap: 10px; margin-bottom: 2px;
  }
  .contact-item:hover { background: var(--blue-pale); }
  .contact-item.selected { background: var(--blue-pale); border-left: 3px solid var(--blue-mid); padding-left: 7px; }
  .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--navy-mid); color: #e8f0fa;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Playfair Display', serif; font-size: 0.85rem; font-weight: 600; flex-shrink: 0;
  }
  .contact-info { flex: 1; min-width: 0; }
  .contact-name { font-weight: 700; font-size: 0.87rem; color: var(--charcoal); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .contact-meta { font-size: 0.73rem; color: var(--gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .req-badge { background: var(--blue-mid); color: #fff; font-size: 0.68rem; font-weight: 700; padding: 2px 7px; border-radius: 10px; flex-shrink: 0; }
  .add-contact-btn {
    margin: 10px;
    margin-bottom: max(10px, env(safe-area-inset-bottom));
    padding: 9px;
    background: var(--navy); color: #e8f0fa; border: none; border-radius: 8px;
    font-family: 'Lato', sans-serif; font-weight: 700; font-size: 0.82rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    gap: 8px; transition: background 0.2s; letter-spacing: 0.04em;
  }
  .add-contact-btn:hover { background: var(--navy-mid); }

  /* ── MAIN ── */
  .main { flex: 1; overflow-y: auto; padding: 28px 32px; }
  .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 400px; color: var(--gray); text-align: center; }
  .empty-cross { width: 56px; height: 66px; margin-bottom: 20px; opacity: 0.2; }
  .empty-state h3 { font-family: 'Playfair Display', serif; font-size: 1.3rem; color: var(--navy-light); margin-bottom: 8px; }
  .loading { display: flex; align-items: center; justify-content: center; min-height: 200px; }
  .spinner { width: 30px; height: 30px; border: 3px solid var(--gray-light); border-top-color: var(--blue-mid); border-radius: 50%; animation: spin 0.7s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── BUTTONS ── */
  .btn { padding: 7px 14px; border-radius: 6px; border: none; font-family: 'Lato', sans-serif; font-weight: 700; font-size: 0.78rem; letter-spacing: 0.05em; cursor: pointer; transition: all 0.2s; text-transform: uppercase; }
  .btn-primary { background: var(--blue); color: #fff; }
  .btn-primary:hover { background: var(--blue-mid); }
  .btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--steel-light); }
  .btn-outline:hover { background: var(--blue-pale); border-color: var(--blue-mid); }
  .btn-danger  { background: transparent; color: var(--red); border: 1.5px solid #e8a0a0; }
  .btn-danger:hover  { background: var(--red-light); }
  .btn-sm { padding: 4px 9px; font-size: 0.71rem; }

  /* ── DASHBOARD ── */
  .dashboard { max-width: 820px; }
  .dash-title { font-family: 'Playfair Display', serif; font-size: 1.5rem; color: var(--navy); margin-bottom: 20px; }
  .dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 28px; }
  .stat-card { background: var(--white); border: 1px solid var(--gray-light); border-radius: 12px; padding: 18px 20px; text-align: center; }
  .stat-num { font-family: 'Playfair Display', serif; font-size: 2.2rem; color: var(--blue-mid); line-height: 1; margin-bottom: 4px; }
  .stat-label { font-size: 0.72rem; color: var(--gray); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
  .section-title { font-family: 'Playfair Display', serif; font-size: 1.05rem; color: var(--navy); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--blue-light); }
  .recent-item { background: var(--white); border: 1px solid var(--gray-light); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: flex-start; gap: 12px; cursor: pointer; transition: box-shadow 0.15s; }
  .recent-item:hover { box-shadow: var(--shadow); }
  .recent-who { font-weight: 700; font-size: 0.83rem; color: var(--navy); margin-bottom: 2px; }
  .recent-req { font-size: 0.83rem; color: var(--charcoal); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .recent-date { font-size: 0.73rem; color: var(--gray); flex-shrink: 0; white-space: nowrap; }
  .today-list { display: grid; gap: 10px; margin-bottom: 28px; }
  .today-card { background: var(--white); border: 1px solid var(--gray-light); border-radius: 10px; padding: 14px 16px; box-shadow: 0 1px 0 rgba(10,22,40,0.02); }
  .today-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
  .today-who { font-weight: 700; font-size: 0.84rem; color: var(--navy); }
  .today-meta { font-size: 0.72rem; color: var(--gray); margin-top: 2px; }
  .today-text { font-size: 0.86rem; color: var(--charcoal); line-height: 1.55; margin-bottom: 10px; }
  .today-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--gray-light); }
  .today-stats { font-size: 0.74rem; color: var(--gray); display: flex; gap: 10px; flex-wrap: wrap; }
  .today-empty { color: var(--gray); font-style: italic; font-size: .87rem; background: var(--white); border: 1px solid var(--gray-light); border-radius: 10px; padding: 16px; }

  /* ── CONTACT DETAIL ── */
  .contact-detail { max-width: 820px; }
  .detail-header { display: flex; align-items: flex-start; gap: 18px; margin-bottom: 24px; }
  .avatar-lg { width: 60px; height: 60px; border-radius: 50%; background: var(--navy-mid); color: #e8f0fa; display: flex; align-items: center; justify-content: center; font-family: 'Playfair Display', serif; font-size: 1.5rem; flex-shrink: 0; }
  .detail-name { font-family: 'Playfair Display', serif; font-size: 1.7rem; color: var(--navy); line-height: 1.1; }
  .detail-sub { font-size: 0.83rem; color: var(--gray); margin-top: 4px; }
  .detail-actions { display: flex; gap: 7px; flex-shrink: 0; }
  .info-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 24px; }
  .info-card { background: var(--white); border: 1px solid var(--gray-light); border-radius: 9px; padding: 12px 14px; }
  .info-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gray); margin-bottom: 3px; }
  .info-value { font-size: 0.87rem; color: var(--charcoal); }
  .info-value a { color: var(--blue); text-decoration: none; }
  .info-value a:hover { text-decoration: underline; }
  .notes-section { margin-bottom: 24px; }
  .notes-text { background: var(--white); border: 1px solid var(--gray-light); border-radius: 9px; padding: 12px 14px; font-size: 0.87rem; color: var(--charcoal); white-space: pre-wrap; min-height: 54px; line-height: 1.6; }
  .requests-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
  .request-card { background: var(--white); border: 1px solid var(--gray-light); border-radius: 9px; padding: 14px 16px; margin-bottom: 9px; transition: box-shadow 0.2s; }
  .request-card:hover { box-shadow: var(--shadow); }
  .request-card.answered { border-left: 4px solid var(--green); background: var(--green-light); }
  .request-card.archived { opacity: 0.55; background: #f3f5f8; }
  .request-card.pending  { border-left: 4px solid #f59e0b; background: #fffbeb; }
  .request-card.pending  { border-left: 4px solid #f59e0b; background: #fffbeb; }
  .request-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
  .request-text { font-size: 0.88rem; color: var(--charcoal); line-height: 1.55; flex: 1; }
  .request-badges { display: flex; gap: 5px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
  .badge { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; }
  .badge-answered { background: var(--green-light); color: var(--green); border: 1px solid #5aaa7a; }
  .badge-active   { background: var(--blue-light);  color: var(--blue);  border: 1px solid var(--blue-mid); }
  .badge-archived { background: var(--gray-light);  color: var(--gray);  border: 1px solid var(--steel); }
  .badge-pending  { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
  .badge-pending  { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
  .request-footer { display: flex; align-items: flex-start; justify-content: space-between; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--gray-light); gap: 10px; flex-wrap: wrap; }
  .request-dates { font-size: 0.73rem; color: var(--gray); }
  .request-dates span { margin-right: 10px; }
  .request-dates strong { color: var(--charcoal); }
  .prayer-log-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gray); margin: 5px 0 3px; }
  .prayer-entries { display: flex; flex-wrap: wrap; gap: 4px; }
  .prayer-entry { font-size: 0.71rem; background: var(--blue-light); color: var(--navy); padding: 2px 7px; border-radius: 12px; display: flex; align-items: center; gap: 3px; cursor: pointer; transition: background 0.15s; }
  .prayer-entry:hover { background: #bdd7f8; }
  .request-actions { display: flex; gap: 5px; align-items: flex-start; flex-shrink: 0; }

  /* ══ USER MANAGER ══════════════════════════════════════════════ */
  .user-manager { max-width: 820px; }
  .um-title { font-family: 'Playfair Display', serif; font-size: 1.5rem; color: var(--navy); margin-bottom: 6px; }
  .um-subtitle { font-size: 0.85rem; color: var(--gray); margin-bottom: 24px; }
  .user-table-wrap { background: var(--white); border: 1px solid var(--gray-light); border-radius: 12px; overflow: hidden; }
  table { width: 100%; border-collapse: collapse; }
  thead { background: var(--navy); }
  thead th { color: #c5d5e8; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; padding: 11px 16px; text-align: left; }
  tbody tr { border-bottom: 1px solid var(--gray-light); transition: background 0.1s; }
  tbody tr:last-child { border-bottom: none; }
  tbody tr:hover { background: var(--blue-pale); }
  tbody td { padding: 12px 16px; font-size: 0.85rem; color: var(--charcoal); vertical-align: middle; }
  .role-badge { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 4px; }
  .role-admin     { background: var(--blue-light); color: var(--blue); border: 1px solid var(--blue-mid); }
  .role-superuser { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
  .role-user      { background: var(--gray-light);  color: var(--gray);  border: 1px solid var(--steel); }
  .status-active   { color: var(--green); font-weight: 700; font-size: 0.8rem; }
  .status-disabled { color: var(--gray);  font-weight: 700; font-size: 0.8rem; }
  .td-actions { display: flex; gap: 5px; }
  .um-add-row { padding: 14px 16px; border-top: 1px solid var(--gray-light); background: var(--bg); display: flex; justify-content: flex-end; }

  /* ══ MODALS ════════════════════════════════════════════════════ */
  .modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(10,22,40,0.60); z-index: 200; align-items: center; justify-content: center; padding: 24px; overflow: visible; }
  .modal-backdrop.open { display: flex; }
  .modal { background: var(--white); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); overflow: visible; animation: modalIn 0.2s ease; }
  .modal-header { background: var(--navy); padding: 16px 22px; display: flex; align-items: center; justify-content: space-between; border-radius: 14px 14px 0 0; }
  .modal-body { padding: 22px; overflow: visible; }
  @keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
  .modal-header { background: var(--navy); padding: 16px 22px; display: flex; align-items: center; justify-content: space-between; }
  .modal-header h3 { font-family: 'Playfair Display', serif; color: #e8f0fa; font-size: 1.05rem; }
  .modal-close { background: none; border: none; color: var(--steel-light); font-size: 1.4rem; cursor: pointer; line-height: 1; padding: 2px 5px; border-radius: 4px; transition: color 0.15s; }
  .modal-close:hover { color: #fff; }
  .modal-body { padding: 22px; }
  .modal-footer { padding: 0 22px 18px; display: flex; gap: 8px; justify-content: flex-end; }
  .form-group { margin-bottom: 14px; }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  label { display: block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--navy-light); margin-bottom: 4px; }
  input[type=text], input[type=email], input[type=tel], input[type=password], textarea, select {
    width: 100%; padding: 8px 11px; border: 1px solid var(--gray-light); border-radius: 7px;
    font-family: 'Lato', sans-serif; font-size: 0.87rem; color: var(--charcoal);
    background: var(--bg); outline: none; transition: border-color 0.2s, box-shadow 0.2s; resize: vertical;
  }
  input:focus, textarea:focus, select:focus { border-color: var(--blue-mid); box-shadow: 0 0 0 3px rgba(59,125,216,0.14); }
  textarea { min-height: 78px; }
  .modal-err { background: var(--red-light); border: 1px solid #e8a0a0; color: var(--red); border-radius: 6px; padding: 8px 12px; font-size: 0.83rem; margin-bottom: 14px; display: none; }
  .modal-err.show { display: block; }

  /* TOAST */
  .toast { position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #e8f0fa; padding: 10px 18px; border-radius: 8px; font-size: 0.83rem; font-weight: 700; box-shadow: var(--shadow-lg); z-index: 999; transform: translateY(70px); opacity: 0; transition: all 0.3s ease; pointer-events: none; }
  .toast.show { transform: translateY(0); opacity: 1; }

  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--gray-light); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--steel); }

  /* ── PWA & MOBILE ── */
  /* Prevent tap highlight flicker on mobile */
  * { -webkit-tap-highlight-color: transparent; }
  /* Prevent text size adjust on rotate */
  body { -webkit-text-size-adjust: 100%; }
  /* Make inputs look native on iOS */
  input, textarea, select { -webkit-appearance: none; appearance: none; border-radius: 7px; }

  /* ── MOBILE (iPhone / small screens) ── */
  @media (max-width: 700px) {

    /* Header: move nav to its own row so mobile tabs do not get clipped */
    header {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas:
        "brand right"
        "nav nav";
      align-items: center;
      padding: calc(env(safe-area-inset-top) + 8px) 12px 10px;
      height: auto;
      gap: 10px;
    }
    .header-brand { grid-area: brand; min-width: 0; gap: 10px; }
    .header-right { grid-area: right; justify-self: end; }
    .header-center {
      grid-area: nav;
      display: flex;
      gap: 6px;
      width: 100%;
      overflow-x: auto;
      overflow-y: hidden;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
      padding-bottom: 2px;
    }
    .header-center::-webkit-scrollbar { display: none; }
    header h1 { font-size: 0.98rem; line-height: 1.05; }
    .cross-icon { width: 16px; height: 19px; }
    .nav-btn {
      flex: 0 0 auto;
      white-space: nowrap;
      padding: 7px 10px;
      font-size: 0.72rem;
      letter-spacing: 0.04em;
    }
    .user-pill-name, .user-pill-caret { display: none; }
    .user-pill { padding: 4px 6px; }

    /* App: switch to mobile view — hide sidebar, show panel full width */
    .app { flex-direction: column; position: relative; }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
      position: fixed;
      top: calc(env(safe-area-inset-top) + 104px);
      left: 0; right: 0; bottom: 0;
      width: 100%;
      min-width: unset;
      border-right: none;
      z-index: 50;
      transform: translateX(-100%);
      transition: transform 0.25s ease;
      box-shadow: 4px 0 20px rgba(0,0,0,0.15);
      padding-bottom: env(safe-area-inset-bottom);
    }
    .sidebar.mobile-open {
      transform: translateX(0);
    }
    /* Backdrop when drawer is open */
    .sidebar-backdrop {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(10,22,40,0.45);
      z-index: 49;
    }
    .sidebar-backdrop.show { display: block; }

    /* Main panel fills full screen */
    .main {
      width: 100%;
      padding: 14px 14px max(14px, env(safe-area-inset-bottom));
      min-height: calc(100vh - env(safe-area-inset-top) - 104px);
    }

    /* Floating people button */
    .mobile-people-btn {
      display: flex !important;
    }

    /* Content adjustments */
    .info-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .dash-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat-card { padding: 12px 8px; }
    .stat-num { font-size: 1.6rem; }
    .stat-label { font-size: 0.65rem; }
    .detail-name { font-size: 1.35rem; }
    .detail-header { gap: 12px; }
    .avatar-lg { width: 48px; height: 48px; font-size: 1.2rem; }
    .form-row { grid-template-columns: 1fr; }
    .request-footer { flex-direction: column; gap: 8px; }
    .request-actions { width: 100%; justify-content: flex-end; }

    /* User table scrollable */
    .user-table-wrap { overflow-x: auto; }
    table { font-size: 0.78rem; min-width: 500px; }
    thead th, tbody td { padding: 8px 10px; }
    .um-title { font-size: 1.2rem; }

    /* Modal full-width on mobile */
    .modal { max-width: 100% !important; margin: 0 8px; border-radius: 12px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 0 16px 16px; }
  }

  /* Floating "People" button — hidden on desktop, shown on mobile */
  .mobile-people-btn {
    display: none;
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: 20px;
    background: var(--navy);
    color: #e8f0fa;
    border: none;
    border-radius: 28px;
    padding: 12px 20px;
    font-family: 'Lato', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 20px rgba(26,46,74,0.35);
    cursor: pointer;
    z-index: 48;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
  }
  .mobile-people-btn:hover { background: var(--navy-mid); }

  .add-contact-btn {
    position: fixed;
    bottom: 24px;
    z-index: 47;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    background: var(--navy);
    color: #e8f0fa;
    border: none;
    border-radius: 8px;
    font-family: 'Lato', sans-serif;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    box-shadow: 0 4px 20px rgba(26,46,74,0.24);
    transition: background 0.2s, box-shadow 0.2s;
  }
  .add-contact-btn.fab-right { right: 24px; left: auto; }
  .add-contact-btn.fab-left  { left: 24px; right: auto; }
  .add-contact-btn:hover {
    background: var(--navy-mid);
    box-shadow: 0 6px 22px rgba(26,46,74,0.28);
  }

  @media (max-width: 900px) {
    .add-contact-btn {
      bottom: calc(max(88px, env(safe-area-inset-bottom) + 72px));
      padding: 9px 14px;
    }
    .add-contact-btn.fab-right { right: 16px; }
    .add-contact-btn.fab-left { left: 16px; }
  }

  /* ── REPORTS ── */
  .report-wrap { max-width: 860px; }
  .report-controls {
    background: var(--white); border: 1px solid var(--gray-light);
    border-radius: 12px; padding: 18px 20px; margin-bottom: 24px;
    display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  }
  .report-controls .form-group { margin-bottom: 0; min-width: 180px; }
  .report-output { background: var(--white); border: 1px solid var(--gray-light); border-radius: 12px; padding: 28px 32px; }
  .report-title { font-family: 'Playfair Display', serif; font-size: 1.4rem; color: var(--navy); margin-bottom: 4px; }
  .report-subtitle { font-size: 0.82rem; color: var(--gray); margin-bottom: 24px; }
  .report-section { margin-bottom: 28px; }
  .report-section-title { font-family: 'Playfair Display', serif; font-size: 1rem; color: var(--navy); padding-bottom: 6px; border-bottom: 1px solid var(--blue-light); margin-bottom: 14px; }
  .report-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--bg); }
  .report-row:last-child { border-bottom: none; }
  .report-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--navy-mid); color: #e8f0fa; display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; flex-shrink: 0; }
  .report-name { font-weight: 700; font-size: 0.88rem; color: var(--navy); margin-bottom: 2px; }
  .report-meta { font-size: 0.78rem; color: var(--gray); }
  .report-text { font-size: 0.85rem; color: var(--charcoal); line-height: 1.5; margin-top: 3px; }
  .report-praise { background: #fffbeb; border-left: 3px solid #f59e0b; border-radius: 0 6px 6px 0; padding: 8px 12px; margin-top: 6px; font-size: 0.82rem; color: var(--charcoal); }
  .report-praise-date { font-size: 0.72rem; font-weight: 700; color: #b45309; margin-bottom: 2px; }
  .report-empty { color: var(--gray); font-style: italic; font-size: 0.88rem; padding: 12px 0; }
  .report-stat { display: inline-flex; align-items: center; gap: 5px; background: var(--blue-pale); color: var(--blue); font-size: 0.75rem; font-weight: 700; padding: 2px 9px; border-radius: 10px; margin-left: 8px; }
  .report-stat.amber { background: #fef3c7; color: #92400e; }
  .report-stat.green { background: var(--green-light); color: var(--green); }
  .report-stat.red   { background: var(--red-light); color: var(--red); }

  @media print {
    header, .sidebar, .mobile-people-btn, .report-controls, #mobilePeopleBtn, #sidebarBackdrop { display: none !important; }
    .app { display: block; }
    .main { padding: 0; }
    .report-output { border: none; padding: 0; box-shadow: none; }
    body { background: white; }
  }
  .dp-wrap { position: relative; display: inline-flex; width: 100%; }
  .dp-input-row { display: flex; align-items: center; width: 100%; }
  .dp-input-row input { border-radius: 7px 0 0 7px !important; border-right: none !important; flex: 1; cursor: pointer; }
  .dp-cal-btn {
    height: 36px; padding: 0 10px;
    border: 1px solid var(--gray-light); border-left: none;
    border-radius: 0 7px 7px 0;
    background: var(--bg); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--gray); transition: background 0.15s; flex-shrink: 0;
  }
  .dp-cal-btn:hover { background: var(--blue-pale); color: var(--blue); }
  .dp-popup {
    display: none; position: absolute; top: calc(100% + 6px); left: 0;
    z-index: 600; background: var(--white);
    border: 1px solid var(--gray-light); border-radius: 12px;
    padding: 14px 12px 10px; width: 280px;
    box-shadow: 0 8px 24px rgba(26,46,74,0.15);
  }
  .dp-popup.open { display: block; }
  .dp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
  .dp-month-lbl { font-size: 14px; font-weight: 700; color: var(--charcoal); }
  .dp-month-lbl span { font-weight: 400; color: var(--gray); font-size: 13px; margin-left: 3px; }
  .dp-nav-btn { background: none; border: none; cursor: pointer; color: var(--charcoal); font-size: 14px; padding: 3px 8px; border-radius: 6px; line-height: 1; }
  .dp-nav-btn:hover { background: var(--blue-pale); }
  .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
  .dp-dow { font-size: 11px; font-weight: 700; text-align: center; color: var(--gray); padding: 3px 0 6px; }
  .dp-day { font-size: 12px; text-align: center; padding: 6px 2px; border-radius: 6px; cursor: pointer; border: none; background: none; color: var(--charcoal); width: 100%; }
  .dp-day:hover { background: var(--blue-pale); }
  .dp-day.dp-other { color: var(--gray-light); }
  .dp-day.dp-sel { background: var(--blue-mid); color: #fff; font-weight: 700; }
  .dp-day.dp-sel:hover { background: var(--blue); }
  .dp-footer { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--gray-light); margin-top: 8px; padding-top: 8px; }
  .dp-foot-btn { background: none; border: none; cursor: pointer; font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px; font-family: 'Lato', sans-serif; }
  .dp-foot-btn:hover { background: var(--bg); }
  .dp-foot-today { color: var(--blue); }
  .dp-foot-clear { color: var(--red); }
  .dp-foot-close { color: var(--gray); }
