/* Overlays: popovers, menus, modals, toasts, tooltips, editor pickers */

#overlay-root { position: relative; z-index: 2000; }
#toast-root { position: fixed; left: 20px; bottom: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }
#tooltip-root { position: fixed; z-index: 3500; top: 0; left: 0; }
body.modal-open { overflow: hidden; }

/* ================= popover ================= */
.popover {
  position: fixed;
  background: #fff;
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-pop);
  border: 1px solid rgba(0,0,0,0.05);
  z-index: 2100;
  opacity: 0;
  transform: scale(0.97) translateY(-2px);
  transform-origin: top center;
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
}
.popover.from-top { animation: pop-in 130ms cubic-bezier(0.2, 0.9, 0.35, 1.15) forwards; transform-origin: bottom center; }
.popover:not(.from-top) { animation: pop-in-below 130ms cubic-bezier(0.2, 0.9, 0.35, 1.15) forwards; }
.popover.open { opacity: 1; }
.popover.closing { opacity: 0; transition: opacity 100ms ease; }
.popover-body { overflow: auto; padding: 6px; min-width: 120px; }

/* ================= menu ================= */
.menu { min-width: 180px; padding: 5px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--t1);
  user-select: none;
  font-size: 13px;
  white-space: nowrap;
}
.menu-item:hover { background: #f0f0f2; }
.menu-item.active { background: #eef4ff; }
.menu-item.danger { color: #d02b20; }
.menu-item.danger:hover { background: #fdeceb; }
.menu-item.disabled { opacity: 0.42; pointer-events: none; }
.menu-icon { display: inline-flex; color: var(--t3); flex: 0 0 auto; }
.menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.menu-hint { font-size: 11px; color: var(--t4); }
.menu-check { display: inline-flex; color: var(--blue); }
.menu-sub-arrow { display: inline-flex; color: var(--t3); }
.menu-sep { height: 1px; background: var(--b3); margin: 5px 4px; }
.menu-header {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--t4);
  padding: 7px 9px 4px;
}

/* hide-fields rows */
.hide-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}
.hide-row:hover { background: #f0f0f2; }
.hide-row.primary { opacity: 0.55; cursor: default; }
.hide-row.primary:hover { background: none; }
.hide-name { flex: 1; min-width: 0; }
.hide-pin { font-size: 10.5px; color: var(--t4); text-transform: uppercase; letter-spacing: 0.4px; }

/* ================= select rows list ================= */
.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--t1);
}
.select-row:hover { background: #f0f0f2; }
.select-row.sel { background: #eef4ff; }

/* ================= editor popovers ================= */
.editor-pop .popover-body { padding: 0; }
.picker-search {
  width: 100%;
  height: 34px;
  border: none;
  border-bottom: 1px solid var(--b3);
  padding: 0 12px;
  outline: none;
  font-size: 13px;
  background: #fff;
}
.picker-search:focus { border-bottom-color: var(--blue); }
.picker-list { max-height: 264px; overflow-y: auto; padding: 5px; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--t1);
}
.picker-row:hover, .picker-row.active { background: #f0f0f2; }
.picker-row.chosen .picker-check { display: inline-flex; }
.picker-check { display: none; color: var(--blue); margin-left: auto; }
.picker-row .tag-chip { max-width: calc(100% - 24px); }
.picker-new { display: inline-flex; color: var(--blue); }
.create-row { color: var(--blue); font-weight: 500; }
.picker-empty { padding: 18px 12px; color: var(--t3); font-size: 12.5px; text-align: center; }
.picker-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--b3);
  font-size: 12.5px;
}
.picker-count { color: var(--t3); }

.editor-hint {
  padding: 6px 12px 8px;
  font-size: 11px;
  color: var(--t4);
  border-top: 1px solid var(--b3);
}
.longtext-input {
  display: block;
  width: 100%;
  min-height: 90px;
  border: none;
  outline: none;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 13px;
  resize: none;
  background: #fff;
}

/* date picker */
.date-pop .popover-body { padding: 0; }
.date-input { border-bottom: 1px solid var(--b3); }
.date-input:focus { border-bottom-color: var(--blue); }
.calendar-picker { padding: 10px 12px 6px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 12.5px; font-weight: 600; }
.cal-nav { width: 24px; height: 24px; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 2px; }
.cal-dow span { text-align: center; font-size: 10px; color: var(--t4); font-weight: 600; padding: 2px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-day {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--t1);
  border-radius: 50%;
  cursor: pointer;
  margin: 1px auto;
  width: 28px;
}
.cal-day:hover { background: #f0f0f2; }
.cal-day.other { color: #c3c3c8; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px #a9c7f5; color: var(--blue); font-weight: 600; }
.cal-day.sel { background: var(--blue); color: #fff; font-weight: 600; }

/* color palette */
.color-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 8px; }
.palette-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 90ms ease;
}
.palette-dot:hover { transform: scale(1.14); }
.palette-check { visibility: hidden; }
.palette-dot:hover .palette-check { visibility: visible; }

/* ================= config popovers (filter/sort/group/...) ================= */
.config-pop .popover-body { padding: 12px 14px; }
.pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pop-title { font-size: 13px; font-weight: 600; }
.pop-sub { font-size: 11.5px; color: var(--t3); margin-bottom: 10px; }
.pop-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }

.segmented { display: inline-flex; background: #f0f0f2; border-radius: var(--radius-m); padding: 2px; }
.segmented.small .seg-btn { height: 22px; padding: 0 9px; font-size: 11px; }
.seg-btn {
  height: 26px;
  padding: 0 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--t2);
  display: inline-flex;
  align-items: center;
  transition: background 90ms ease, color 90ms ease, box-shadow 90ms ease;
}
.seg-btn:hover { color: var(--t1); }
.seg-btn.on { background: #fff; color: var(--t1); box-shadow: 0 0 0 1px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.06); }
.icon-seg svg { display: block; }

.cond-list { display: flex; flex-direction: column; gap: 8px; }
.cond-row { display: flex; align-items: center; gap: 6px; }
.cond-field { flex: 1.2; min-width: 0; height: 28px; }
.cond-op { flex: 1; min-width: 0; height: 28px; }
.cond-value { flex: 1.3; min-width: 0; display: flex; align-items: center; }
.cond-novalue { padding: 0 4px; }
.cond-remove { width: 24px; height: 24px; flex: 0 0 24px; }
.cond-empty { padding: 14px 4px; color: var(--t3); font-size: 12.5px; text-align: center; }
.cond-choices { display: flex; flex-wrap: wrap; gap: 4px; max-height: 84px; overflow: auto; }
.cond-choice {
  border: 1px solid var(--b1);
  background: #fff;
  border-radius: 11px;
  height: 22px;
  padding: 0 9px;
  font-size: 11.5px;
  color: var(--t2);
}
.cond-choice.on { border-color: transparent; font-weight: 500; }

.text-input.sm { height: 28px; padding: 0 8px; }

.share-row { display: flex; gap: 8px; align-items: center; }
.share-row .text-input { flex: 1; }

/* ================= modals ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 26, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2200;
  opacity: 0;
  transition: opacity 130ms ease;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  background: #fff;
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-modal);
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  transform: translateY(8px) scale(0.985);
  opacity: 0;
  transition: transform 140ms cubic-bezier(0.2, 0.9, 0.35, 1.1), opacity 130ms ease;
  overflow: hidden;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); opacity: 1; }

.modal-head {
  display: flex;
  align-items: center;
  padding: 16px 20px 8px;
  gap: 8px;
}
.modal-title { font-size: 16px; font-weight: 600; flex: 1; }
.modal-close { margin-left: auto; }
.modal-body { padding: 10px 20px 18px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--b3);
  background: #fafafa;
}
.modal-foot .spacer { flex: 1; }
.btn.danger-btn { background: #d02b20; color: #fff; }
.btn.danger-btn:hover { background: #b3251c; }

.confirm-modal .confirm-msg { color: var(--t2); font-size: 13px; line-height: 1.5; margin-top: 2px; }

/* record modal */
.record-modal { width: 100%; }
.record-modal .modal-head { padding: 8px 10px 0; }
.record-modal .modal-title { display: none; }
.record-modal-main .block-input,
.record-modal-main .block-textarea {
  border-color: transparent;
  background: transparent;
  padding-left: 8px;
  margin-left: -8px;
}
.record-modal-main .block-input:hover,
.record-modal-main .block-textarea:hover { background: #f4f4f6; }
.record-modal-main .block-input:focus,
.record-modal-main .block-textarea:focus {
  background: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-ring);
}
.record-modal-main .block-textarea { min-height: 54px; }
.record-modal-body { display: flex; min-height: 340px; }
.record-modal-main { flex: 1.6; padding: 12px 18px 18px; min-width: 0; }
.record-modal-side {
  flex: 1;
  border-left: 1px solid var(--b3);
  background: #fafafa;
  padding: 16px;
  min-width: 200px;
}
.record-modal-primary {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  font-size: 17px;
  font-weight: 600;
  padding: 6px 8px;
  margin: 0 0 6px -8px;
  outline: none;
  background: transparent;
  color: var(--t1);
}
.record-modal-primary:hover { background: #f4f4f6; }
.record-modal-primary:focus { background: #fff; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-ring); }

.record-fields { margin-top: 8px; }
.record-field-row { display: flex; gap: 12px; padding: 7px 0; }
.record-field-label {
  width: 160px;
  flex: 0 0 160px;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding-top: 6px;
  color: var(--t2);
  font-size: 12.5px;
}
.record-field-label .head-icon { margin-top: 1px; }
.record-field-control { flex: 1; min-width: 0; }
.block-input { height: 30px; }
.block-textarea { min-height: 60px; }
.block-value { min-height: 30px; display: flex; align-items: center; padding: 3px 8px; margin: 0 -8px; border-radius: var(--radius-m); }
.block-value.clickable { cursor: pointer; }
.block-value.clickable:hover { background: #f4f4f6; }

.record-side-head { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--t3); margin-bottom: 12px; }
.record-activity { display: flex; flex-direction: column; gap: 12px; }
.record-activity-item { display: flex; gap: 8px; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-top: 4px; flex: 0 0 auto; }
.activity-dot.dim { background: #c5c5ca; }
.activity-title { font-size: 12.5px; font-weight: 500; }
.activity-sub { font-size: 11.5px; color: var(--t3); margin-top: 1px; }
.record-modal-foot { display: flex; align-items: center; gap: 8px; }
.record-count { color: var(--t3); font-size: 12px; }

/* field config modal */
.field-modal-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--t3); margin-bottom: 6px; }
.field-modal-note { font-size: 11.5px; color: var(--t3); margin-top: 10px; line-height: 1.5; }
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--b2);
  border-radius: var(--radius-m);
  font-size: 12.5px;
  color: var(--t2);
  text-align: left;
  transition: border-color 90ms ease, background 90ms ease, color 90ms ease;
}
.type-cell:hover { border-color: #b9d4fb; background: #f7faff; color: var(--t1); }
.type-cell.sel { border-color: var(--blue); background: #eef4ff; color: #1a5fd0; font-weight: 500; }
.type-cell.disabled { opacity: 0.4; pointer-events: none; }
.type-icon { display: inline-flex; color: var(--t3); }
.type-cell.sel .type-icon { color: var(--blue); }

.field-config { margin-top: 16px; }
.choices-list { display: flex; flex-direction: column; gap: 6px; }
.choice-row { display: flex; align-items: center; gap: 8px; }
.choice-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid;
  flex: 0 0 auto;
  transition: transform 90ms ease;
}
.choice-swatch:hover { transform: scale(1.12); }
.choice-row .text-input { flex: 1; }

.radio-row { display: flex; align-items: center; gap: 8px; padding: 5px 2px; cursor: pointer; font-size: 13px; }
.radio-row input { accent-color: var(--blue); }
.radio-label { min-width: 180px; }
.radio-example { color: var(--t3); font-size: 12px; }

/* shortcuts modal */
.shortcut-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px; border-bottom: 1px solid var(--b4); font-size: 13px; }
.shortcut-row:last-child { border-bottom: none; }
.shortcut-what { color: var(--t2); }

/* ================= toasts ================= */
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--b1);
  border-radius: var(--radius-m);
  box-shadow: 0 4px 16px rgba(0,0,0,0.16);
  padding: 10px 8px 10px 14px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  max-width: 380px;
  pointer-events: auto;
}
.toast.in { animation: toast-in 180ms cubic-bezier(0.2, 0.9, 0.35, 1.1) forwards; }
.toast.out { animation: toast-out 150ms ease forwards; }
.toast-icon { display: inline-flex; color: var(--t3); }
.toast-msg { flex: 1; }
.toast-action {
  color: var(--blue);
  font-weight: 600;
  font-size: 12.5px;
  padding: 4px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.toast-action:hover { background: #eef4ff; }
.toast-close { display: inline-flex; color: var(--t4); padding: 3px; border-radius: 4px; }
.toast-close:hover { color: var(--t2); background: #f0f0f2; }

/* ================= tooltip ================= */
.tooltip {
  position: fixed;
  transform: translateX(-50%) translateY(2px);
  background: #2c2c31;
  color: #fff;
  font-size: 11.5px;
  padding: 5px 9px;
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
  pointer-events: none;
  z-index: 3600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.tooltip.in { opacity: 1; transform: translateX(-50%) translateY(0); }

/* day popover in calendar */
.day-pop { padding: 5px; }
