* { box-sizing: border-box; }

body {
  font-family: "Nirmala UI", "Segoe UI", Arial, sans-serif;
  margin: 0;
  background: #f5f6f8;
  color: #1f2430;
}

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #111827;
  color: #d1d5db;
  padding: 18px 0;
}

.sidebar-title {
  font-weight: 700;
  color: white;
  padding: 0 18px 16px;
  font-size: 1rem;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 8px;
}

.sidebar nav { display: flex; flex-direction: column; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #d1d5db;
  padding: 11px 18px;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
}

.nav-item:hover { background: #1f2937; color: white; }
.nav-item.active { background: #2563eb; color: white; font-weight: 600; }

.nav-submenu {
  display: flex;
  flex-direction: column;
  border-left: 2px solid #1f2937;
  margin: 4px 0 4px 18px;
}

.nav-submenu .nav-item { padding-left: 14px; font-size: 0.85rem; }

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px;
  background: #1f2937;
  color: white;
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
}

main { padding: 20px 24px; flex: 1; min-width: 0; }

.app-section.hidden { display: none; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  max-width: 760px;
}

.stat-card {
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px 20px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

.stat-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
  border-color: #93c5fd;
}

.stat-label { font-size: 0.9rem; color: #6b7280; }
.stat-value { font-size: 2rem; font-weight: 700; color: #1f2430; }

.stat-card-donation {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.stat-card-donation:hover { border-color: #6ee7b7; }

.stat-card-donation .stat-value { color: #047857; }

.hidden { display: none !important; }

.btn {
  padding: 8px 14px;
  border: 1px solid #cbd2d9;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn:hover { background: #f0f1f3; }
.btn-primary { background: #2563eb; color: white; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar input, .toolbar select {
  padding: 7px 10px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 0.9rem;
}

#search-box { flex: 1; min-width: 220px; }

.result-count { align-self: center; color: #6b7280; font-size: 0.85rem; }

.table-wrap {
  overflow-x: auto;
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid #eef0f2;
  white-space: nowrap;
}

thead th { background: #f9fafb; position: sticky; top: 0; }

tbody tr { cursor: pointer; }
tbody tr:hover { background: #f3f6ff; }
tbody tr.own-row { background: #ecfdf5; }
tbody tr.own-row:hover { background: #d1fae5; }

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.form-header-actions { display: flex; gap: 8px; }

.form-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
}

.form-success {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px 16px;
  margin-bottom: 14px;
  background: white;
}

legend { font-weight: 600; color: #374151; padding: 0 6px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: #4b5563;
}

label.full { grid-column: 1 / -1; }

input, select, textarea {
  padding: 7px 9px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

textarea { min-height: 56px; resize: vertical; }

.form-actions { margin: 8px 0 30px; }

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fbdfe9;
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px 36px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

.login-icon {
  width: 54px;
  height: 54px;
  color: #6b7280;
  margin: 0 auto 4px;
}

.login-card h1 {
  font-size: 1.2rem;
  line-height: 1.4;
  margin: 0;
  text-align: center;
  color: #0d9488;
  font-weight: 700;
}

.login-divider {
  width: 100%;
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 0 0 4px;
}

.login-sub { margin: 0; color: #6b7280; font-size: 0.85rem; text-align: center; }

.login-btn-row { display: flex; justify-content: flex-end; }

.login-btn {
  padding: 9px 26px;
  background: #e5e1b0;
  border: 1px solid #333;
  border-radius: 4px;
  color: #1f2430;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.login-btn:hover { background: #d9d59a; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user .who { font-size: 0.85rem; color: #d1d5db; }

.readonly-banner {
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #713f12;
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: white;
  border-radius: 10px;
  padding: 24px 26px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-card h2 { margin: 0 0 4px; font-size: 1rem; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: #4b5563; }
.modal-card p.modal-sub { margin: 0; color: #6b7280; font-size: 0.82rem; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}

.record-modal-card { width: 420px; }

#record-modal-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}

#record-modal-fields textarea { min-height: 60px; }

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
}

.doc-date { color: #6b7280; font-size: 0.8rem; margin-left: 10px; }
.doc-actions { display: flex; gap: 8px; align-items: center; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.photo-card {
  position: relative;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.photo-card img { width: 100%; height: 150px; object-fit: cover; display: block; }
.photo-caption { padding: 8px 10px; font-size: 0.8rem; color: #4b5563; }

.photo-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(220, 38, 38, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 130px);
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
}

.chat-call-bar {
  display: flex;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-message {
  max-width: 65%;
  background: #f3f4f6;
  border-radius: 10px;
  padding: 8px 12px;
  align-self: flex-start;
}

.chat-message.own {
  align-self: flex-end;
  background: #dbeafe;
}

.chat-message .chat-sender { font-size: 0.75rem; font-weight: 600; color: #2563eb; margin-bottom: 2px; }
.chat-message .chat-body { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }
.chat-message .chat-time { font-size: 0.68rem; color: #9ca3af; margin-top: 4px; }
.chat-message .chat-attachment { display: inline-block; margin-top: 6px; font-size: 0.82rem; }
.chat-message .chat-attachment img { max-width: 220px; border-radius: 6px; display: block; margin-top: 4px; }
.chat-message .chat-delete { background: none; border: none; color: #dc2626; font-size: 0.7rem; cursor: pointer; margin-top: 4px; padding: 0; }

.chat-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.chat-composer input[type="text"] { flex: 1; }

.chat-attach-btn {
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  background: white;
}

.chat-file-name { font-size: 0.78rem; color: #6b7280; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- chat header extras ---- */
.chat-header-spacer { flex: 1; }
.chat-disappearing-note { font-size: 0.72rem; color: #92400e; background: #fef3c7; padding: 4px 8px; border-radius: 6px; align-self: center; }

.chat-menu-wrap { position: relative; }
.chat-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  min-width: 220px;
  padding: 6px;
  z-index: 30;
}
.chat-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
}
.chat-menu button:hover { background: #f3f4f6; }
.chat-menu-section { border-top: 1px solid #e5e7eb; margin-top: 6px; padding: 8px 10px 4px; }
.chat-menu-label { font-size: 0.72rem; color: #6b7280; margin-bottom: 4px; }
.chat-menu-section select { width: 100%; }

/* ---- pinned bar ---- */
.chat-pinned-bar {
  padding: 6px 16px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-pinned-item { font-size: 0.78rem; color: #78350f; cursor: pointer; }
.chat-pinned-item:hover { text-decoration: underline; }

/* ---- search ---- */
.chat-search-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}
.chat-search-bar input { flex: 1; }
.chat-search-empty { color: #9ca3af; font-size: 0.85rem; padding: 16px; text-align: center; }

/* ---- select mode ---- */
.chat-select-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  font-size: 0.82rem;
}
.chat-select-checkbox { position: absolute; left: -22px; top: 8px; }
.chat-select-checkbox.hidden { display: none; }

/* ---- message bubble extras ---- */
.chat-message { position: relative; }
.chat-message.pinned { border: 1px solid #fbbf24; }
.chat-message-actions {
  position: absolute;
  top: -14px;
  right: 4px;
  display: none;
  gap: 2px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 2px;
}
.chat-message:hover .chat-message-actions { display: flex; }
.chat-message-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
}
.chat-more-menu {
  position: absolute;
  top: -14px;
  right: 4px;
  transform: translateY(-100%);
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 20;
  min-width: 140px;
}
.chat-more-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}
.chat-more-menu button:hover { background: #f3f4f6; }

.chat-reply-quote {
  border-left: 3px solid #2563eb;
  padding: 3px 8px;
  margin-bottom: 4px;
  font-size: 0.78rem;
  color: #4b5563;
  background: rgba(37, 99, 235, 0.06);
  border-radius: 4px;
  cursor: pointer;
}

.chat-reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chat-reaction-pill {
  font-size: 0.75rem;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 999px;
  padding: 1px 8px;
  cursor: pointer;
}
.chat-reaction-pill.mine { background: #dbeafe; border-color: #93c5fd; }

.chat-reaction-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  right: 4px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 4px 6px;
  display: flex;
  gap: 4px;
  z-index: 25;
}
.chat-reaction-picker button { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 2px; }
.chat-reaction-picker button:hover { transform: scale(1.2); }

.chat-message .chat-attachment video,
.chat-message .chat-attachment audio { max-width: 260px; display: block; margin-top: 4px; }

/* ---- reply preview / composer extras ---- */
.chat-reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  background: #f0f9ff;
  border-top: 1px solid #bae6fd;
  font-size: 0.8rem;
}
.chat-reply-preview-sender { font-weight: 600; color: #2563eb; }
.chat-reply-preview button { background: none; border: none; cursor: pointer; font-size: 1rem; }

.chat-attach-wrap { position: relative; }
.chat-attach-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 25;
}
.chat-attach-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}
.chat-attach-menu button:hover { background: #f3f4f6; }

.chat-recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fef2f2;
}
.chat-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #dc2626;
  animation: chat-rec-pulse 1.2s infinite;
}
.chat-rec-hint { font-size: 0.8rem; color: #6b7280; flex: 1; }
@keyframes chat-rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Responsive: tablet & mobile (sidebar becomes an off-canvas drawer) ===== */
@media (max-width: 900px) {
  .hamburger-btn { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.25);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  main { padding: 14px; }

  .dashboard-grid { grid-template-columns: repeat(2, 1fr); max-width: 100%; }

  .table-wrap { max-width: 100%; }

  .modal-card, .record-modal-card, .login-card {
    width: min(92vw, 380px);
  }

  #record-modal-fields { max-height: 50vh; }

  .chat-panel { height: calc(100vh - 150px); }
  .chat-message { max-width: 82%; }

  .toolbar { gap: 8px; }
  #search-box { flex-basis: 100%; min-width: 0; }

  fieldset { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 1rem; max-width: 55vw; }
  .topbar-user { gap: 6px; }
  .topbar-user .who { display: none; }
  .btn { padding: 6px 10px; font-size: 0.82rem; }

  .dashboard-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.5rem; }
  .stat-card { padding: 14px 16px; }

  .sidebar { width: 250px; }

  .chat-message { max-width: 90%; }
  .chat-composer { padding: 10px; gap: 6px; }
  .chat-file-name { display: none; }

  .login-card { padding: 28px 20px; }
}
