/* Topbar */
.topbar { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  gap: 10px;
  padding: 12px 16px; 
  background: var(--bg); 
  color: #e2e8f0; 
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.topbar .brand { 
  font-weight: 700; 
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  line-height: 1;
  height: 36px;
  min-width: 0;
  white-space: nowrap;
}

/* Mobile menu toggle button */
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-toggle:hover {
  background: #334155;
  border-color: #64748b;
}

.menu-toggle svg {
  display: block;
  width: 24px;
  height: 24px;
}

.user-area { 
  display: flex; 
  align-items: center; 
  gap: 8px;
  height: 36px;
  min-width: 0;
  flex: 1;
  justify-content: flex-end;
}
.user-area img { 
  width: 28px; 
  height: 28px; 
  border-radius: 50%; 
  flex-shrink: 0;
}
.user-area #user-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1;
}
.user-area .role { 
  background: #334155; 
  color: #e2e8f0; 
  padding: 2px 8px; 
  border-radius: 999px; 
  margin-left: 4px; 
  font-size: 12px;
  line-height: 1.4;
  flex-shrink: 0;
}

/* Mobile responsive for topbar */
@media (max-width: 768px) {
  .topbar {
    padding: 10px 12px;
  }
  
  .topbar .brand {
    font-size: 16px;
  }
  
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    order: -1;
    margin-right: 8px;
  }
  
  .user-area {
    gap: 6px;
    overflow: visible;
    height: auto;
    flex: 0 0 auto;
  }

  .user-area #btn-login {
    position: static;
  }

  .user-area #user-info {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: var(--mobile-userbar-height);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    z-index: 120;
  }
  
  .user-area #user-info #user-name,
  .user-area #user-info #user-photo,
  .user-area #user-info .role {
    display: none;
  }

  .user-area #user-info .icon-btn {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-color: #e2e8f0;
    color: #334155;
    background: #f8fafc;
    border-radius: 10px;
  }
  
  .user-area #user-info .icon-btn svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 8px 10px;
  }
  
  .topbar .brand {
    font-size: 14px;
    max-width: 36vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .user-area {
    gap: 4px;
  }

  .user-area #user-info {
    gap: 6px;
    min-height: var(--mobile-userbar-height);
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px));
  }

  .user-area #user-info .icon-btn {
    height: 40px;
    min-width: 0;
    min-height: 40px;
  }

  .user-area #user-info .icon-btn svg {
    width: 17px;
    height: 17px;
  }
  
  #btn-login {
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 430px) {
  .topbar {
    padding: 7px 8px;
    gap: 6px;
  }

  .menu-toggle {
    margin-right: 4px;
    padding: 6px;
  }

  .topbar .brand {
    font-size: 13px;
    max-width: 30vw;
  }

  .user-area {
    gap: 3px;
  }

  .user-area #user-info .icon-btn {
    height: 38px;
    min-width: 0;
    min-height: 38px;
  }

  .user-area #user-info .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  #btn-login {
    padding: 5px 8px;
    font-size: 12px;
  }
}

@media (max-width: 390px) {
  .topbar {
    padding: 6px 7px;
    gap: 5px;
  }

  .topbar .brand {
    font-size: 12px;
    max-width: 22vw;
  }

  .user-area {
    gap: 2px;
  }

  .user-area #user-info .icon-btn {
    height: 36px;
    min-width: 0;
    min-height: 36px;
  }

  .user-area #user-info .icon-btn svg {
    width: 15px;
    height: 15px;
  }

  #btn-login {
    padding: 4px 7px;
    font-size: 11px;
  }
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid #475569;
  border-radius: 8px;
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.icon-btn svg {
  display: block;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #334155;
  border-color: #64748b;
  color: #fff;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
  background: #1e293b;
}

.icon-btn svg {
  display: block;
}

/* Settings button specific styling */
#btn-settings {
  border-color: #3b82f6;
  color: #60a5fa;
}

#btn-settings:hover {
  background: #1e3a8a;
  border-color: #2563eb;
  color: #93c5fd;
}

/* Logout button specific styling */
#btn-logout {
  border-color: #dc2626;
  color: #ef4444;
}

#btn-logout:hover {
  background: #7f1d1d;
  border-color: #b91c1c;
  color: #fca5a5;
}

/* Navigation */
main { padding: 16px; max-width: 1100px; margin: 0 auto; }

nav.tabs { 
  display: flex; 
  gap: 8px; 
  margin-bottom: 16px;
  flex-wrap: wrap;
  position: relative;
}

nav.tabs .tab { 
  padding: 8px 12px; 
  border-radius: 8px; 
  background: white; 
  border: 1px solid #e2e8f0; 
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  font-size: 14px;
}

nav.tabs .tab:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

nav.tabs .tab.active { 
  background: #dbeafe; 
  border-color: #bfdbfe; 
  color: #1e40af;
  font-weight: 600;
}

nav.tabs .tab[style*="display: none"] { display: none !important; }

/* Mobile navigation - Sidebar style */
@media (max-width: 768px) {
  main {
    padding: 12px;
    padding-bottom: calc(var(--mobile-userbar-height) + env(safe-area-inset-bottom, 0px) + 12px);
  }
  
  nav.tabs {
    position: fixed;
    top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    left: -280px;
    width: 280px;
    height: calc(100vh - var(--topbar-height) - env(safe-area-inset-top, 0px));
    background: #ffffff;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    margin: 0;
    box-shadow: none;
    overflow-y: auto;
    transition: left 0.3s ease;
    z-index: 99;
  }
  
  nav.tabs.mobile-open {
    left: 0;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
  }
  
  nav.tabs .tab {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    text-align: left;
    justify-content: flex-start;
  }
  
  nav.tabs .tab.active {
    background: linear-gradient(135deg, #dbeafe, #e0e7ff);
    border-left: 4px solid #3b82f6;
    padding-left: 12px;
  }
}

@media (max-width: 480px) {
  main {
    padding: 8px;
    padding-bottom: calc(var(--mobile-userbar-height) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  nav.tabs {
    width: 260px;
    left: -260px;
    padding: 12px;
  }

  nav.tabs .tab {
    padding: 10px 14px;
    font-size: 14px;
  }
}

/* Mobile menu overlay */
.menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 98;
  backdrop-filter: blur(2px);
}

.menu-overlay.active {
  display: block;
}

@media (min-width: 769px) {
  .menu-overlay {
    display: none !important;
  }
}

/* Emphasize add-item tabs */
nav.tabs .tab[data-tab="attendance-new"],
nav.tabs .tab[data-tab="giving-new"] {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-weight: 600;
  border-color: #047857;
  position: relative;
}
nav.tabs .tab[data-tab="attendance-new"].active,
nav.tabs .tab[data-tab="giving-new"].active { 
  filter: brightness(1.05); 
}

/* Loading overlay */
.loading-overlay { 
  position: fixed; 
  inset: 0; 
  display: grid; 
  place-items: center; 
  background: rgba(15, 23, 42, 0.35); 
  z-index: 2000; 
  backdrop-filter: blur(1px); 
}

.spinner { 
  width: 48px; 
  height: 48px; 
  border: 4px solid #e2e8f0; 
  border-top-color: var(--primary); 
  border-radius: 50%; 
  animation: spin 1s linear infinite; 
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.03) inset; 
}

@keyframes spin { 
  to { transform: rotate(360deg); } 
}

/* Toast notifications */
#toast-container { 
  position: fixed; 
  right: 16px; 
  bottom: 16px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  z-index: 3000; 
}

@media (max-width: 768px) {
  #toast-container {
    bottom: calc(var(--mobile-userbar-height) + env(safe-area-inset-bottom, 8px) + 8px);
  }
}

.toast { 
  background: #111827; 
  color: #fff; 
  padding: 10px 12px; 
  border-radius: 8px; 
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18); 
  display: flex; 
  align-items: center; 
  gap: 10px; 
}

.toast.success { background: #065f46; }
.toast.error { background: #7f1d1d; }
.toast.info { background: #1f2937; }

.toast .close { 
  background: transparent; 
  color: #fff; 
  border: 0; 
  cursor: pointer; 
  opacity: .8; 
}
.toast .close:hover { opacity: 1; }

/* Enhanced toast notifications for mobile */
@media (max-width: 480px) {
  #toast-container {
    left: 16px;
    right: 16px;
    bottom: calc(var(--mobile-userbar-height) + env(safe-area-inset-bottom, 8px) + 8px);
  }
  
  .toast {
    width: 100%;
    justify-content: center;
    text-align: center;
    padding: 14px 16px;
    font-size: 15px;
  }
}

/* Modal */
.modal { 
  position: fixed; 
  inset: 0; 
  display: grid; 
  place-items: center; 
  background: rgba(0, 0, 0, 0.4); 
  z-index: 1000; 
}
.modal.hidden { display: none !important; }

/* Sermons move modal: visual destination picker */
#sermons-move-list {
  max-height: 320px;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
}

#sermons-move-list .sermons-move-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  background: transparent;
  cursor: pointer;
  text-align: left;
  color: inherit;
}

#sermons-move-list .sermons-move-option:last-child {
  border-bottom: 0;
}

#sermons-move-list .sermons-move-option:hover {
  background: #f8fafc;
}

#sermons-move-list .sermons-move-option[aria-selected="true"] {
  background: #f8fafc;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.modal-content { 
  width: min(640px, 96vw); 
  background: #fff; 
  border-radius: 12px; 
  overflow: hidden; 
  border: 1px solid #e2e8f0; 
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-header { 
  padding: 12px 16px; 
  border-bottom: 1px solid #e2e8f0; 
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.modal-body { 
  padding: 16px; 
  max-height: calc(90vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-footer { 
  padding: 12px 16px; 
  border-top: 1px solid #e2e8f0; 
  display: flex; 
  gap: 8px; 
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Email compose modal */
.email-modal .email-compose {
  max-width: none;
  margin: 0;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  gap: 16px 20px;
}

.email-modal .email-compose label {
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.email-modal .email-compose input,
.email-modal .email-compose select,
.email-modal .email-compose textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
  min-height: 46px;
  padding: 12px 14px;
  font-size: 15px;
}

.email-modal .email-compose textarea {
  width: 100%;
  min-height: 160px;
  max-height: 40vh;
  line-height: 1.6;
}

.email-modal .email-compose__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #475569;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.email-modal .email-compose__actions {
  display: flex;
  gap: 6px;
}

.email-modal .format-btn {
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #0f172a;
  font-weight: 700;
  font-size: 14px;
  min-width: 34px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.email-modal .format-btn:hover {
  background: #e2e8f0;
  border-color: #cbd5f5;
}

.email-modal .format-btn:active {
  transform: translateY(1px);
}

@media (max-width: 720px) {
  .email-modal .email-compose {
    gap: 14px;
  }

  .email-modal .email-compose textarea {
    min-height: 140px;
    max-height: 32vh;
  }
}

/* Sermons upload modal */
.upload-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  background: #f8fafc;
  color: #334155;
  user-select: none;
}

.upload-dropzone.dragover {
  border-color: #3b82f6;
  background: #eff6ff;
}

.upload-dropzone-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.upload-dropzone-sub {
  font-size: 13px;
  color: #64748b;
}

.upload-summary {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #ffffff;
  color: #0f172a;
  font-size: 14px;
}

/* Confirm overlay */
#confirm-overlay { 
  position: fixed; 
  inset: 0; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  background: rgba(0, 0, 0, .45); 
  z-index: 3500; 
}
#confirm-overlay.hidden { display: none; }

#confirm-overlay .confirm-dialog { 
  background: #fff; 
  color: #0f172a; 
  padding: 24px 28px; 
  border-radius: 10px; 
  width: 100%; 
  max-width: 420px; 
  box-shadow: 0 10px 32px -4px rgba(0, 0, 0, .35); 
  animation: scaleIn .18s ease; 
}

#confirm-overlay h3 { 
  margin: 0 0 8px; 
  font-size: 20px; 
  font-weight: 600; 
}

#confirm-overlay p { 
  margin: 0 0 16px; 
  font-size: 15px; 
  line-height: 1.4; 
}

#confirm-overlay .actions { 
  display: flex; 
  gap: 12px; 
  justify-content: flex-end; 
}

@keyframes scaleIn { 
  from { opacity: 0; transform: scale(.92); } 
  to { opacity: 1; transform: scale(1); } 
}

/* Success Modal Styling */
#success-modal { 
  z-index: 4000; 
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.5);
}

.success-modal-content {
  max-width: 480px;
  width: 90vw;
  animation: successModalIn 0.3s ease-out;
  border: none;
  overflow: hidden;
}

.success-header {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  text-align: center;
  padding: 20px;
  border-bottom: none;
}

.success-header h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.success-body {
  padding: 32px 24px;
  text-align: center;
  background: #f8fafc;
}

.success-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  color: #10b981;
}

.success-icon svg {
  width: 72px;
  height: 72px;
  stroke-width: 2.5;
  animation: successBounce 0.6s ease-out 0.2s both;
}

.success-message {
  font-size: 18px;
  font-weight: 600;
  color: #0f172a;
  margin: 0 0 16px;
  line-height: 1.4;
}

.success-details {
  background: white;
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
  border-left: 4px solid #10b981;
  text-align: left;
  font-size: 14px;
  color: #374151;
}

.success-details .detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid #f3f4f6;
}

.success-details .detail-row:last-child {
  border-bottom: none;
}

.success-details .detail-label {
  font-weight: 600;
  color: #6b7280;
}

.success-details .detail-value {
  font-weight: 500;
  color: #111827;
}

.success-footer {
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: 16px 24px;
  text-align: center;
}

.success-btn {
  min-width: 140px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
}

.success-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.success-btn:active {
  transform: translateY(0);
}

@keyframes successModalIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes successBounce {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-180deg);
  }
  50% {
    transform: scale(1.1) rotate(-90deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* Success modal responsive improvements */
@media (max-width: 480px) {
  #success-modal {
    padding: 16px;
  }
  
  .success-modal-content {
    width: 95vw;
    margin: 20px;
  }
  
  .success-header {
    padding: 16px;
  }
  
  .success-header h3 {
    font-size: 20px;
  }
  
  .success-body {
    padding: 24px 16px;
  }
  
  .success-icon svg {
    width: 56px;
    height: 56px;
  }
  
  .success-message {
    font-size: 16px;
  }
  
  .success-details {
    padding: 12px;
    font-size: 13px;
  }
  
  .success-details .detail-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .success-details .detail-value {
    font-size: 15px;
    font-weight: 600;
  }
}

/* Settings Tabs */
.tab-bar {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 24px;
}

.tab-link {
  padding: 10px 20px;
  cursor: pointer;
  border: none;
  background-color: transparent;
  font-size: 16px;
  font-weight: 500;
  color: #64748b;
  position: relative;
  transition: color 0.2s ease-in-out;
}

.tab-link:hover {
  color: #0f172a;
}

.tab-link.active {
  color: #1e40af;
  font-weight: 600;
}

.tab-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #3b82f6;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.5s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Override form-grid styles for settings form */
#settings-form {
  display: block; /* Override grid display */
  max-width: none; /* Remove max-width restriction */
  width: 100%; /* Make it take full width */
  padding: 0; /* Remove padding if any from form-grid */
  box-shadow: none; /* Remove box-shadow */
  border: none; /* Remove border */
  background: transparent; /* Remove background */
  gap: 0; /* Remove gap */
}

#settings-form .form-section {
  max-width: 760px; /* Re-apply max-width to sections for better readability */
  margin: 20px auto; /* Center the sections */
}

/* Ensure input groups still behave correctly within sections */
#settings-form .input-group {
  display: grid;
  grid-template-columns: 1fr; /* Default to single column for input groups */
  gap: 16px;
}

@media (min-width: 768px) {
  #settings-form .input-group {
    grid-template-columns: 1fr 1fr; /* Re-enable two columns for input groups on larger screens */
  }

  #settings-form .form-actions {
    grid-column: auto; /* Remove span 2 */
    max-width: none;
    margin-left: 0;
  }
}
