/* ════════════════════════════════════════════════════════════
   Flock Admin Component System — v1.0
   Requires: /flock-tokens.css  (must load first)
   Fonts:    Lora (serif) · DM Sans (sans-serif) via Google Fonts

   Contains all reusable admin interface styles.
   Page-specific panel overrides remain in admin.html.

   Variable convention: long-form names (--brown, --border, --white)
   resolved by flock-tokens.css dual-alias bridge.
   ════════════════════════════════════════════════════════════ */


/* ── 1. GLOBAL ADMIN SHELL ───────────────────────────────── */

html { scroll-behavior: smooth; }

body {
  font-family: "DM Sans", sans-serif;
  background: var(--sand-dark);
  color: var(--brown);
  display: flex;
  min-height: 100vh;
}


/* ── 2. SIDEBAR ──────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--brown);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(245,239,230,.03) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(245,239,230,.08);
  position: relative;
}

.logo-text {
  font-family: "Lora", serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--sand);
  letter-spacing: -.5px;
  display: block;
  text-decoration: none;
}

.logo-sub {
  font-size: 11px;
  color: rgba(245,239,230,.4);
  margin-top: 2px;
}

.org-switcher {
  margin: 16px 12px;
  background: rgba(245,239,230,.06);
  border: 1px solid rgba(245,239,230,.1);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}

.org-switcher-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sand);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-switcher-url { font-size: 11px; color: rgba(245,239,230,.4); }

.nav-section {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(245,239,230,.3);
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 1px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(245,239,230,.65);
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  min-height: 40px;
}
.nav-item:hover { background: rgba(245,239,230,.08); color: var(--sand); }
.nav-item.active { background: rgba(201,168,76,.15); color: var(--gold-light); }

.nav-icon { flex-shrink: 0; }

/* SVG icons inverted for the dark sidebar */
.nav-icon img { filter: brightness(0) invert(1); opacity: .6; vertical-align: middle; }
.nav-item:hover .nav-icon img { opacity: .85; }
.nav-item.active .nav-icon img { opacity: .9; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 12px;
  border-top: 1px solid rgba(245,239,230,.08);
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s;
}
.user-row:hover { background: rgba(245,239,230,.08); }

.user-avatar {
  width: 32px; height: 32px;
  background: var(--gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Lora", serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--brown);
  flex-shrink: 0;
}

.user-name  { font-size: 13px; font-weight: 600; color: var(--sand); }
.user-role  { font-size: 11px; color: rgba(245,239,230,.4); }


/* ── 3. MAIN AREA + TOPBAR ───────────────────────────────── */

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-family: "Lora", serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--brown);
  letter-spacing: -.3px;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.page-content { padding: 28px 32px; flex: 1; }

.panel { display: none; }
.panel.active { display: block; }

.mobile-signout { display: none; }


/* ── 4. ADMIN BUTTONS ────────────────────────────────────── */

.topbar-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  border: none;
  font-family: "DM Sans", sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}

.btn-primary { background: var(--brown); color: var(--sand); }
.btn-primary:hover { opacity: .88; }

.btn-outline { background: transparent; color: var(--brown-mid); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--brown); color: var(--brown); }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: var(--danger); color: white; }

.btn-success { background: var(--success-bg); color: var(--success); border: 1px solid #b7d9b7; }

/* Size + icon utility — applied to row action buttons */
.icon-action, .action-btn {
  min-width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 16px;
  justify-content: center;
  padding: 0 10px;
}

.action-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }


/* ── 5. DASHBOARD STAT CARDS ─────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border-radius: 14px;
  padding: 20px 22px;
  border: 1px solid var(--border);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--brown-mid);
  margin-bottom: 8px;
}

.stat-value {
  font-family: "Lora", serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--brown);
  letter-spacing: -1px;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-change { font-size: 12px; color: var(--success); font-weight: 500; }


/* ── 6. ADMIN CARDS ──────────────────────────────────────── */

.card {
  background: var(--white);
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-family: "Lora", serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--brown);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.module-help {
  font-size: 13px;
  color: var(--brown-mid);
  font-weight: 300;
  margin-top: 6px;
  line-height: 1.45;
}


/* ── 7. DATA TABLES ──────────────────────────────────────── */

.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--brown-mid);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--sand);
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--brown);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--cream); }

.td-name { font-weight: 600; }
.td-sub  { font-size: 11px; color: var(--brown-mid); margin-top: 1px; }

.table-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
}
.table-tools input, .table-tools select { max-width: 220px; padding: 8px 10px; font-size: 13px; }

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--white);
  font-size: 12px;
  font-weight: 700;
  color: var(--brown-mid);
}


/* ── 8. STATUS BADGES ────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}

.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-pending  { background: #fef3e2; color: #9a6b10; }
.badge-inactive { background: var(--sand); color: var(--brown-mid); }
.badge-taken    { background: var(--sand); color: var(--brown-mid); }


/* ── 9. FORMS ────────────────────────────────────────────── */

/* Admin forms use element selectors so every input is styled automatically.
   This is intentional for the dense admin interface. */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }

label { font-size: 13px; font-weight: 600; color: var(--brown); }

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
  color: var(--brown);
  background: var(--white);
  outline: none;
  transition: border-color .2s;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brown);
  box-shadow: 0 0 0 3px rgba(61,32,16,.06);
}

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

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b5e3c' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.field-hint { font-size: 11px; color: var(--brown-mid); }


/* ── 10. TOGGLE SWITCHES ─────────────────────────────────── */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }

.toggle-label { font-size: 14px; font-weight: 500; color: var(--brown); }
.toggle-sub   { font-size: 12px; color: var(--brown-mid); font-weight: 300; margin-top: 2px; }

.toggle {
  width: 44px; height: 24px;
  background: var(--border);
  border-radius: 100px;
  position: relative;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
  border: none;
}
.toggle.on { background: var(--success); }
.toggle::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  background: white;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: left .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle.on::after { left: 23px; }


/* ── 11. COLLAPSIBLE SECTIONS ────────────────────────────── */

.section-toggle {
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--brown-mid);
  cursor: pointer;
  padding: 0;
  margin-left: auto;
  flex-shrink: 0;
}
.section-toggle:hover { color: var(--brown); }

.collapsible-header { cursor: pointer; user-select: none; }
.collapsible-header:hover .card-title { color: var(--brown); }


/* ── 12. ANNOUNCEMENT ITEMS ──────────────────────────────── */

.announcement-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.announcement-item:last-child { border-bottom: none; }

.ann-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ann-icon img { width: 18px; height: 18px; display: block; filter: brightness(0) opacity(.65); }

.ann-icon-general { background: var(--sand); }
.ann-icon-janazah { background: var(--danger-bg); }
.ann-icon-janazah img {
  filter: brightness(0) saturate(100%) invert(20%) sepia(90%) saturate(1800%) hue-rotate(343deg) opacity(.9);
}

.ann-title  { font-family: "Lora", serif; font-size: 14px; font-weight: 700; color: var(--brown); margin-bottom: 3px; }
.ann-body   { font-size: 13px; color: var(--brown-mid); font-weight: 300; line-height: 1.4; }
.ann-meta   { font-size: 11px; color: var(--brown-light); margin-top: 5px; }
.ann-actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }


/* ── 13. ICON ACTION BUTTONS ─────────────────────────────── */

.icon-action {
  width: 30px; height: 30px;
  background: var(--sand);
  border: 1px solid var(--border);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  color: var(--brown-mid);
}
.icon-action:hover { background: var(--danger-bg); color: var(--danger); }


/* ── 14. EVENT ROWS ──────────────────────────────────────── */

.event-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.event-row:last-child { border-bottom: none; }

.event-date-box {
  width: 44px;
  background: var(--sand);
  border-radius: 8px;
  text-align: center;
  padding: 6px 4px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.event-day   { font-family: "Lora", serif; font-size: 18px; font-weight: 700; color: var(--brown); line-height: 1; }
.event-month { font-size: 9px; font-weight: 600; color: var(--brown-mid); text-transform: uppercase; }
.event-info  { flex: 1; }
.event-title { font-weight: 600; font-size: 14px; color: var(--brown); }
.event-meta  { font-size: 12px; color: var(--brown-mid); font-weight: 300; margin-top: 2px; }


/* ── 15. MODALS ──────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(61,32,16,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(61,32,16,.2);
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-family: "Lora", serif; font-size: 18px; font-weight: 700; color: var(--brown); }

.modal-close {
  width: 32px; height: 32px;
  background: var(--sand);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brown-mid);
  transition: background .15s;
}
.modal-close:hover { background: var(--border); }

.modal-body   { padding: 24px; overflow-y: auto; flex: 1; scrollbar-gutter: stable; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }


/* ── 16. LOADING + SPINNER ───────────────────────────────── */

.loading { text-align: center; padding: 40px; color: var(--brown-mid); }

.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--brown);
  border-radius: 50%;
  animation: adm-spin .7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes adm-spin { to { transform: rotate(360deg); } }


/* ── 17. TOAST (admin — bottom-right, opacity-based) ─────── */

/* Intentionally different from public fl-toast (centre, translate-based) */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--brown);
  color: var(--sand);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transform: translateY(20px);
  transition: all .3s;
  box-shadow: 0 8px 24px rgba(61,32,16,.3);
}
.toast.show { opacity: 1; transform: translateY(0); }


/* ── 18. PENDING APPROVAL SCREEN ─────────────────────────── */

.pending-approval-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sand-dark);
  padding: 32px;
  margin-left: 0;
  width: 100%;
}

.pending-approval-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 38px;
  max-width: 560px;
  text-align: center;
  box-shadow: 0 12px 36px rgba(61,32,16,.12);
}

.pending-approval-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #fef3e2;
  color: #9a6b10;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.pending-approval-card h1 {
  font-family: "Lora", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--brown);
  margin-bottom: 10px;
}

.pending-approval-card p {
  font-size: 14px;
  color: var(--brown-mid);
  line-height: 1.7;
  font-weight: 300;
  margin-bottom: 18px;
}

.pending-approval-details {
  background: var(--sand);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  color: var(--brown-mid);
  margin: 18px 0;
}

.pending-approval-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}


/* ── 19. RESPONSIVE ADMIN ────────────────────────────────── */

@media (max-width: 900px) {
  body         { display: block; }
  .sidebar     { position: relative; width: 100%; height: auto; bottom: auto; }
  .sidebar-footer { display: none; }
  .main        { margin-left: 0; }
  .topbar      { height: auto; min-height: 60px; padding: 12px 16px; gap: 12px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .mobile-signout { display: inline-flex; }
  .page-content { padding: 16px; }
  .stats-grid  { grid-template-columns: 1fr !important; }
  .two-col     { grid-template-columns: 1fr; }
  .form-grid   { grid-template-columns: 1fr !important; }
  .card-header { align-items: flex-start; gap: 12px; flex-direction: column; }
  .data-table th, .data-table td { padding: 10px 12px; }
  .icon-action, .action-btn { min-width: 44px; height: 44px; font-size: 17px; }
  .modal-overlay { align-items: flex-start; overflow: auto; padding: 12px; }
  .modal       { max-height: none; }
  .topbar-btn  { min-height: 40px; }
  .nav-item    { min-height: 42px; }
  .org-switcher { margin: 12px; }
  .sidebar-logo { padding: 18px 20px 12px; }
}

@media (max-width: 768px) {
  body         { display: block; overflow-x: hidden; }
  .sidebar     { display: none; }
  .main        { margin-left: 0; width: 100%; min-height: 100vh; }
  .topbar      { height: auto; min-height: 56px; padding: 10px 12px; gap: 10px; align-items: flex-start; position: sticky; top: 0; z-index: 80; flex-direction: column; }
  .topbar-title { font-size: 17px; }
  .topbar-actions { width: 100%; overflow-x: auto; padding-bottom: 2px; gap: 8px; }
  .topbar-btn  { white-space: nowrap; padding: 8px 12px; font-size: 12px; min-height: 44px; }
  .page-content { padding: 14px 12px 80px; }
  .stats-grid  { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card   { padding: 14px; }
  .stat-value  { font-size: 24px; }
  .two-col, .form-grid { grid-template-columns: 1fr; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .data-table  { display: block; overflow-x: auto; white-space: nowrap; }
  .modal       { width: calc(100vw - 20px); max-height: 90vh; overflow: auto; }

  /* iOS form zoom prevention — font-size < 16px triggers auto-zoom on focus */
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}


/* ── 20. ADMIN EMPTY STATE ───────────────────────────────── */

.adm-empty {
  text-align: center;
  padding: 40px 20px;
}

.adm-empty-icon {
  width: 48px; height: 48px;
  background: var(--sand);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}

.adm-empty-icon img {
  opacity: .35;
  filter: brightness(0);
}

.adm-empty-title {
  font-family: "Lora", serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--brown);
  margin-bottom: 5px;
}

.adm-empty-sub {
  font-size: 13px;
  color: var(--brown-mid);
  font-weight: 300;
  line-height: 1.6;
  margin-bottom: 18px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}
