/* ============================================================
   Aidacare MS-GP BAU Knowledge Portal — Admin / Edit Mode CSS
   ============================================================ */

/* ---- Edit Mode Body Class ---- */
body.edit-mode-active {
  --edit-border: #2563eb;
  --edit-bg: rgba(37, 99, 235, 0.04);
  --edit-hover-bg: rgba(37, 99, 235, 0.08);
}

/* ---- Edit Mode Topbar Indicator ---- */
.edit-mode-indicator {
  display: none;
  align-items: center;
  gap: .4rem;
  background: #f59e0b;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: .25rem .75rem;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
body.edit-mode-active .edit-mode-indicator { display: flex; }

/* ---- Edit Mode Toggle Button ---- */
#btn-edit-mode {
  position: relative;
  gap: .4rem;
  font-size: .82rem;
  font-weight: 600;
  padding: .35rem .85rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  display: none;
}
#btn-edit-mode:hover { background: rgba(255,255,255,.22); }
body.admin-logged-in #btn-edit-mode { display: flex; align-items: center; }
body.edit-mode-active #btn-edit-mode {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #fff;
}

/* ---- Editable Element Wrappers ---- */
body.edit-mode-active [data-cms-editable] {
  position: relative;
  cursor: pointer;
  transition: outline .15s, background .15s;
}
body.edit-mode-active [data-cms-editable]:hover {
  outline: 2px dashed var(--edit-border);
  outline-offset: 3px;
  background: var(--edit-hover-bg);
  border-radius: 4px;
}
body.edit-mode-active [data-cms-editable]:hover .cms-edit-btn {
  opacity: 1;
  pointer-events: all;
}

/* ---- Edit Button on Elements ---- */
.cms-edit-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  z-index: 150;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  font-size: 11px;
}
.cms-edit-btn:hover { transform: scale(1.1); background: #1d4ed8; }
.cms-edit-btn svg { pointer-events: none; }

/* ---- Image Edit Overlay ---- */
.cms-img-wrapper {
  position: relative;
  display: inline-block;
}
body.edit-mode-active .cms-img-wrapper:hover .cms-img-overlay {
  opacity: 1;
}
.cms-img-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 45, 82, 0.65);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  opacity: 0;
  transition: opacity .2s;
  cursor: pointer;
  border-radius: 6px;
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
}
.cms-img-overlay svg { opacity: .9; }

/* ---- Floating Edit Toolbar ---- */
#cms-edit-toolbar {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: none;
  flex-direction: column;
  gap: .5rem;
  align-items: flex-end;
}
body.edit-mode-active #cms-edit-toolbar { display: flex; }

.cms-toolbar-main {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: #0f2d52;
  border-radius: 12px;
  padding: .65rem 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.1);
}
.cms-toolbar-btn {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .9rem;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .18s;
  white-space: nowrap;
}
.cms-toolbar-btn.save {
  background: #10b981;
  color: #fff;
}
.cms-toolbar-btn.save:hover { background: #059669; }
.cms-toolbar-btn.exit {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.85);
}
.cms-toolbar-btn.exit:hover { background: rgba(255,255,255,.22); }
.cms-toolbar-btn.add-section {
  background: rgba(37,99,235,.9);
  color: #fff;
}
.cms-toolbar-btn.add-section:hover { background: #1d4ed8; }
.cms-toolbar-changes {
  font-size: .72rem;
  color: rgba(255,255,255,.6);
  padding: 0 .5rem;
}

/* ---- CMS Modal Dialog ---- */
.cms-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: cms-fade-in .15s ease;
}
.cms-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  animation: cms-slide-up .2s ease;
  display: flex;
  flex-direction: column;
}
.cms-modal.large { max-width: 900px; }
.cms-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.cms-modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #111827;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.cms-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f3f4f6;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  transition: all .15s;
}
.cms-modal-close:hover { background: #e5e7eb; color: #111827; }
.cms-modal-body {
  padding: 1.5rem;
  flex: 1;
}
.cms-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

/* ---- CMS Form Elements ---- */
.cms-form-group { margin-bottom: 1rem; }
.cms-form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: .35rem;
}
.cms-form-control {
  width: 100%;
  padding: .55rem .85rem;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  font-size: .85rem;
  color: #1f2937;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  background: #fff;
}
.cms-form-control:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.cms-form-control.mono { font-family: 'Courier New', monospace; font-size: .8rem; }
textarea.cms-form-control { min-height: 120px; resize: vertical; }
.cms-hint { font-size: .73rem; color: #6b7280; margin-top: .3rem; }
.cms-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---- CMS Buttons ---- */
.cms-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  font-size: .85rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}
.cms-btn-primary { background: #2563eb; color: #fff; }
.cms-btn-primary:hover { background: #1d4ed8; color: #fff; }
.cms-btn-success { background: #10b981; color: #fff; }
.cms-btn-success:hover { background: #059669; }
.cms-btn-danger { background: #ef4444; color: #fff; }
.cms-btn-danger:hover { background: #dc2626; }
.cms-btn-secondary { background: #f3f4f6; color: #374151; }
.cms-btn-secondary:hover { background: #e5e7eb; }
.cms-btn-sm { padding: .35rem .7rem; font-size: .78rem; }
.cms-btn-outline { background: none; border: 1.5px solid #2563eb; color: #2563eb; }
.cms-btn-outline:hover { background: #dbeafe; }

/* ---- Toast Notifications ---- */
#cms-toast-container {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: flex-end;
}
.cms-toast {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.1rem;
  border-radius: 10px;
  font-size: .83rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  animation: cms-slide-in .25s ease;
  max-width: 360px;
  min-width: 240px;
}
.cms-toast.success { background: #d1fae5; color: #065f46; border-left: 3px solid #10b981; }
.cms-toast.error { background: #fee2e2; color: #b91c1c; border-left: 3px solid #ef4444; }
.cms-toast.info { background: #dbeafe; color: #1e3a8a; border-left: 3px solid #2563eb; }
.cms-toast.warn { background: #fef3c7; color: #78350f; border-left: 3px solid #f59e0b; }
.cms-toast-close { margin-left: auto; cursor: pointer; opacity: .6; font-size: 1rem; line-height: 1; }
.cms-toast-close:hover { opacity: 1; }

/* ---- Admin Login Modal ---- */
#cms-admin-modal {
  /* Uses .cms-modal-backdrop styles */
}
.admin-login-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}

/* ---- Image Preview ---- */
.cms-img-preview-wrap {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1rem;
  background: #f9fafb;
}
.cms-img-preview-wrap img {
  max-height: 200px;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 6px;
}
.cms-img-preview-placeholder {
  color: #9ca3af;
  font-size: .82rem;
}

/* ---- Document Library Management ---- */
.cms-doc-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: box-shadow .15s;
}
.cms-doc-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.cms-doc-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .03em;
}
.cms-doc-icon.docx { background: #dbeafe; color: #1d4ed8; }
.cms-doc-icon.xlsx { background: #d1fae5; color: #065f46; }
.cms-doc-icon.pdf { background: #fee2e2; color: #b91c1c; }
.cms-doc-icon.png, .cms-doc-icon.jpg { background: #fef3c7; color: #92400e; }
.cms-doc-body { flex: 1; min-width: 0; }
.cms-doc-title { font-size: .88rem; font-weight: 600; color: #111827; margin-bottom: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cms-doc-meta { font-size: .72rem; color: #6b7280; }
.cms-doc-actions { display: flex; gap: .4rem; flex-shrink: 0; }

/* ---- Article List ---- */
.cms-article-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  transition: box-shadow .15s;
}
.cms-article-item:hover { box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.cms-article-body { flex: 1; }
.cms-article-title { font-size: .9rem; font-weight: 600; color: #111827; margin-bottom: .25rem; }
.cms-article-meta { font-size: .73rem; color: #6b7280; }

/* ---- Audit Log Table ---- */
.cms-audit-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.cms-audit-table th { background: #f3f4f6; padding: .6rem .85rem; text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; border-bottom: 1px solid #e5e7eb; }
.cms-audit-table td { padding: .65rem .85rem; border-bottom: 1px solid #f3f4f6; color: #374151; vertical-align: top; }
.cms-audit-table tr:last-child td { border-bottom: none; }
.cms-audit-table tr:hover td { background: #f9fafb; }

/* ---- Sidebar Admin Link ---- */
.sidebar-link.cms-admin-link {
  display: none;
}
body.admin-logged-in .sidebar-link.cms-admin-link {
  display: flex;
}

/* ---- Admin Panel Page Styles ---- */
.admin-page .topbar { background: #0f2d52; }
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.admin-stat {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.admin-stat-value { font-size: 1.8rem; font-weight: 800; color: #1f2937; line-height: 1; margin-bottom: .3rem; }
.admin-stat-label { font-size: .75rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Animations ---- */
@keyframes cms-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes cms-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cms-slide-in {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes cms-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .cms-modal { max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; }
  .cms-modal-backdrop { align-items: flex-end; padding: 0; }
  .cms-form-row { grid-template-columns: 1fr; }
  #cms-edit-toolbar { bottom: 16px; right: 16px; }
}

/* ---- Add Section Button (in Edit Mode) ---- */
.cms-add-section-marker {
  display: none;
  align-items: center;
  justify-content: center;
  height: 32px;
  margin: .5rem 0;
  border: 2px dashed #93c5fd;
  border-radius: 8px;
  cursor: pointer;
  color: #2563eb;
  font-size: .78rem;
  font-weight: 600;
  gap: .4rem;
  transition: background .15s;
}
body.edit-mode-active .cms-add-section-marker { display: flex; }
.cms-add-section-marker:hover { background: #dbeafe; }

/* ---- Tag Pills ---- */
.cms-tag-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }
.cms-tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: #f3f4f6;
  color: #374151;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
}
.cms-tag-remove { cursor: pointer; opacity: .6; font-size: .9rem; }
.cms-tag-remove:hover { opacity: 1; color: #ef4444; }

/* ---- Content Override Indicator ---- */
[data-cms-overridden]::after {
  content: ' ✎';
  font-size: .7em;
  color: #f59e0b;
  vertical-align: super;
  opacity: .7;
}
body:not(.edit-mode-active) [data-cms-overridden]::after { display: none; }

/* ---- Admin Page Layout ---- */
.admin-tabs { display: flex; gap: .25rem; border-bottom: 2px solid #e5e7eb; margin-bottom: 1.5rem; overflow-x: auto; }
.admin-tab-btn {
  padding: .7rem 1.2rem;
  font-size: .83rem;
  font-weight: 600;
  color: #6b7280;
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all .15s;
}
.admin-tab-btn:hover { color: #1f2937; }
.admin-tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; }
.admin-tab-panel { display: none; }
.admin-tab-panel.active { display: block; }
