/* ==========================================================================
   MODULE PERSONAL NOTES - DESIGN SYSTEM 22X MISA
   Tối giản • Nền sáng • Xanh lá làm nhấn • Không gradient/shadow nặng
   ========================================================================== */

/* Topbar Quick Note Trigger */
.pn-topbar-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text);
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
  flex-shrink: 0;
}
.pn-topbar-btn:hover,
.pn-topbar-btn.active {
  background: var(--p-soft);
  border-color: var(--p);
  color: var(--p-dark);
}
.pn-topbar-dot {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #F59E0B;
  border: 1.5px solid #FFFFFF;
}
.pn-topbar-dot.on { display: block; }

.pn-nav-badge {
  display: none;
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: #FEF3C7;
  color: #B45309;
}
.pn-nav-badge.on { display: inline-block; }

/* Quick Note Floating Panel */
.pn-quick-panel {
  display: none;
  position: fixed;
  top: 54px;
  right: 16px;
  width: 390px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 76px);
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.10);
  z-index: 9500;
  flex-direction: column;
  overflow: hidden;
}
.pn-quick-panel.open {
  display: flex;
}
.pn-qp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: #FAFCFB;
}
.pn-qp-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.pn-qp-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pn-qp-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.pn-qp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.pn-qp-recent-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pn-qp-select {
  flex: 1;
  min-width: 0;
  height: 28px;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #FFFFFF;
  color: var(--text);
}
.pn-qp-title-inp {
  width: 100%;
  border: 1px solid transparent;
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  background: transparent;
}
.pn-qp-title-inp:focus {
  border-bottom-color: var(--p);
}
.pn-qp-editor {
  min-height: 150px;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #FFFFFF;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}
.pn-qp-editor:focus {
  border-color: var(--p);
  box-shadow: 0 0 0 2px var(--p-ring);
}
.pn-qp-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  border-top: 1px solid var(--border-subtle);
  background: #FAFCFB;
}

/* Full Notes Workspace (#pgNotes) */
#pgNotes {
  padding: 14px 18px;
  max-width: 100%;
}
.pn-workspace {
  display: flex;
  height: calc(100vh - 82px);
  min-height: 540px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

/* Left Sidebar Column */
.pn-list-col {
  width: 332px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: #FAFBF9;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pn-list-top {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #FFFFFF;
}
.pn-list-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pn-list-heading {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
}
.pn-private-pill {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--p-dark);
  background: var(--p-soft);
  border: 1px solid var(--p-line);
  padding: 1px 7px;
  border-radius: 10px;
}
.pn-search-box {
  position: relative;
}
.pn-search-box svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted-light);
  pointer-events: none;
}
.pn-search-inp {
  width: 100%;
  height: 32px;
  padding: 4px 28px 4px 29px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text);
  background: #F8FAF9;
  outline: none;
}
.pn-search-inp:focus {
  background: #FFFFFF;
  border-color: var(--p);
}
.pn-search-clear {
  display: none;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}
.pn-search-clear.on { display: inline-block; }

.pn-scope-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.pn-scope-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pn-scope-tab:hover {
  background: #F1F5F3;
  color: var(--text);
}
.pn-scope-tab.active {
  background: var(--p-soft);
  border-color: var(--p-line);
  color: var(--p-dark);
}
.pn-scope-cnt {
  font-size: 10.5px;
  opacity: 0.78;
}

.pn-tag-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.pn-tag-filter-chip {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--muted);
  cursor: pointer;
}
.pn-tag-filter-chip.active {
  background: var(--p);
  border-color: var(--p);
  color: #FFFFFF;
}

.pn-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.pn-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  padding: 6px 8px 4px;
}
.pn-note-item {
  padding: 10px 11px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 4px;
  background: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.pn-note-item:hover {
  background: #FFFFFF;
  border-color: var(--border);
}
.pn-note-item.active {
  background: #FFFFFF;
  border-color: var(--p);
  box-shadow: inset 3px 0 0 var(--p);
}
.pn-note-item-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.pn-note-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.pn-note-item-title.empty {
  color: var(--muted);
  font-style: italic;
}
.pn-note-item-time {
  font-size: 11px;
  color: var(--muted-light);
  white-space: nowrap;
  flex-shrink: 0;
}
.pn-note-item-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}
.pn-note-item-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.pn-mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: #F1F5F3;
  color: var(--muted);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pn-mini-pill.rem {
  background: #FFFBEB;
  color: #B45309;
}
.pn-mini-pill.rem.due {
  background: #FEF2F2;
  color: #DC2626;
}
.pn-mini-pill.chk {
  background: var(--p-soft);
  color: var(--p-dark);
}
.pn-mini-pill.erp {
  background: #EFF6FF;
  color: #1D4ED8;
}

/* Right Editor Column */
.pn-editor-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
}
.pn-editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  color: var(--muted);
}
.pn-editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.pn-editor-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pn-act-btn.pn-mobile-back-btn,
.pn-mobile-back-btn {
  display: none;
}
.pn-save-status {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pn-save-status.saving { color: #0284C7; }
.pn-save-status.saved { color: var(--p-dark); }
.pn-save-status.offline { color: #D97706; }
.pn-save-status.error { color: #DC2626; cursor: pointer; }

.pn-editor-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  position: relative;
}
.pn-act-btn {
  height: 29px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.pn-act-btn:hover {
  background: #F8FAF9;
  border-color: #CBD5CE;
}
.pn-act-btn.on {
  background: var(--p-soft);
  border-color: var(--p);
  color: var(--p-dark);
  font-weight: 600;
}
.pn-act-btn.danger {
  color: var(--danger);
}
.pn-act-btn.danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

/* Conflict Banner */
.pn-conflict-banner {
  display: none;
  padding: 9px 16px;
  background: #FFFBEB;
  border-bottom: 1px solid #FDE68A;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #92400E;
}
.pn-conflict-banner.on { display: flex; }

/* Format Toolbar */
.pn-format-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: #FCFCFB;
  flex-wrap: wrap;
}
.pn-fmt-btn {
  height: 26px;
  min-width: 26px;
  padding: 0 7px;
  border-radius: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.pn-fmt-btn:hover {
  background: #EEF2F0;
}
.pn-fmt-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}
.pn-chk-progress-wrap {
  margin-left: auto;
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--p-dark);
}
.pn-chk-progress-wrap.on { display: inline-flex; }
.pn-chk-track {
  width: 72px;
  height: 6px;
  border-radius: 99px;
  background: #E5EAE7;
  overflow: hidden;
}
.pn-chk-fill {
  height: 100%;
  background: var(--p);
  width: 0%;
  transition: width 0.2s ease;
}

/* Editor Body */
.pn-editor-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 26px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pn-title-inp {
  width: 100%;
  border: none;
  outline: none;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  background: transparent;
}
.pn-title-inp::placeholder {
  color: var(--muted-light);
}

.pn-meta-chips-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.pn-meta-chips-row:empty { display: none; }
.pn-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #F8FAF9;
  color: var(--text);
}
.pn-chip.rem {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #92400E;
}
.pn-chip.erp {
  background: #EFF6FF;
  border-color: #BFDBFE;
  color: #1E40AF;
  cursor: pointer;
}
.pn-chip.erp:hover {
  background: #DBEAFE;
}
.pn-chip-x {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
}
.pn-chip-x:hover { opacity: 1; }

/* Editable Rich + Checklist Surface */
.pn-editor-surface {
  flex: 1;
  min-height: 260px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  outline: none;
  word-break: break-word;
}
.pn-editor-surface:empty::before {
  content: attr(data-placeholder);
  color: var(--muted-light);
  pointer-events: none;
}
.pn-editor-surface p { margin: 0 0 6px; }
.pn-editor-surface ul,
.pn-editor-surface ol {
  margin: 4px 0 8px 22px;
}
.pn-editor-surface li {
  margin-bottom: 2px;
}
.pn-editor-surface a {
  color: var(--p-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Interactive Checklist Row */
.pn-chk-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 4px;
  margin: 2px 0;
  border-radius: 5px;
}
.pn-chk-row:hover {
  background: #F8FAF9;
}
.pn-chk-box {
  width: 16px;
  height: 16px;
  margin-top: 4px;
  border-radius: 4px;
  border: 1.5px solid #94A39D;
  background: #FFFFFF;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  display: inline-block;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.pn-chk-row[data-checked="1"] .pn-chk-box {
  background: var(--p);
  border-color: var(--p);
}
.pn-chk-row[data-checked="1"] .pn-chk-box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.pn-chk-text {
  flex: 1;
  min-width: 40px;
  outline: none;
}
.pn-chk-row[data-checked="1"] .pn-chk-text {
  color: var(--muted);
  text-decoration: line-through;
}

.pn-editor-foot {
  padding: 7px 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--muted-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #FAFCFB;
}

/* Reusable Minimalist Popovers */
.pn-popover {
  display: none;
  position: fixed;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.10);
  padding: 12px;
  z-index: 9800;
}
.pn-popover.open { display: block; }
.pn-pop-h {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pn-entity-results {
  max-height: 210px;
  overflow-y: auto;
  margin-top: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}
.pn-entity-opt {
  padding: 7px 9px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  font-size: 12px;
}
.pn-entity-opt:last-child { border-bottom: none; }
.pn-entity-opt:hover { background: var(--p-soft); }

/* ERP Entity Personal Notes Drawer */
.pn-entity-drawer-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.25);
  z-index: 9600;
}
.pn-entity-drawer-mask.open { display: block; }
.pn-entity-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 96vw;
  background: #FFFFFF;
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(16, 24, 40, 0.09);
  z-index: 9610;
  flex-direction: column;
}
.pn-entity-drawer.open { display: flex; }
.pn-ed-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: #FAFCFB;
}
.pn-ed-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pn-ed-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #FFFFFF;
}
.pn-ed-card:hover { border-color: var(--p); }

/* Embedded compact block inside Item Drawer & Outward Card */
.pn-inline-box {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--p-line);
  background: #FAFCFB;
  border-radius: 8px;
}
.pn-inline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.pn-inline-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--p-dark);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Reminder Toasts Stack */
.pn-reminder-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9700;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}
.pn-rem-toast {
  background: #FFFFFF;
  border: 1px solid #FDE68A;
  border-left: 4px solid #F59E0B;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.12);
  padding: 10px 12px;
  font-size: 12.5px;
}

/* Re-auth Modal for Legacy Session Upgrade */
.pn-reauth-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(24, 37, 34, 0.45);
  z-index: 9995;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.pn-reauth-mask.open { display: flex; }
.pn-reauth-card {
  width: 100%;
  max-width: 380px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.16);
  padding: 20px;
}

/* Responsive Tablet & Mobile */
@media (max-width: 900px) {
  #pgNotes {
    padding: 8px;
  }
  .pn-workspace {
    height: calc(100vh - 68px);
    min-height: 460px;
  }
  .pn-list-col {
    width: 100%;
    border-right: none;
  }
  .pn-workspace.pn-mobile-editing .pn-list-col {
    display: none;
  }
  .pn-workspace:not(.pn-mobile-editing) .pn-editor-col {
    display: none;
  }
  .pn-act-btn.pn-mobile-back-btn,
  .pn-mobile-back-btn {
    display: inline-flex;
  }
  .pn-editor-scroll {
    padding: 14px;
  }
  .pn-quick-panel {
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
  }
}
