/* Modal stack, generic dialog, toast, anchored popovers, and the
   list-style bodies shared by the calendar / archive / share / trash / admin
   / history sheets. */

.overlay-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.overlay-layer > * { pointer-events: auto; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 42, 77, 0.44);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 16px 16px;
  overflow-y: auto;
  animation: overlay-in var(--t-fast);
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(620px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  position: relative;
}
.modal.narrow { width: min(430px, 100%); }
.modal.wide { width: min(900px, 100%); }
.modal.modal-xl { width: min(1040px, 100%); }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: var(--surface-alt); color: var(--ink); }

.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; padding-right: 28px; }
.modal-lead { color: var(--ink-soft); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.modal-actions .push-right { margin-left: auto; }

/* ---------- Generic dialog ---------- */
.dialog-input { margin-top: 4px; }
.dialog-message { white-space: pre-wrap; }
.dialog-members { margin-top: 12px; }
.dialog-members-head { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.dialog-members .dialog-members-list { max-height: 220px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: toast-in 0.16s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast button {
  border: none;
  background: none;
  color: #8fc3ff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.toast button:hover { text-decoration: underline; }

/* ---------- Anchored popover (recolour, ⋯ menu, filter panel) ---------- */
.popover {
  position: fixed;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 180px;
  animation: overlay-in var(--t-fast);
}
.popover.pad { padding: 14px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-alt); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-tint); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.menu-head {
  padding: 8px 10px 6px;
  line-height: 1.35;
}
.menu-head strong { display: block; font-size: 13px; }
.menu-head span { font-size: 12px; color: var(--ink-soft); }

/* Swatch grid (board colour / label colour). */
.swatch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatch-grid.pad { padding: 4px; }
.swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--ink); }

/* ---------- Filter panel ---------- */
.filter-panel { width: 288px; display: flex; flex-direction: column; gap: 14px; }
.filter-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.filter-opts { display: flex; flex-direction: column; gap: 5px; }
.filter-opt { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.filter-opt .swatch-mini { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }

/* ---------- Shared list body (archive / share / trash / admin / history) ---------- */
.sheet-list { list-style: none; display: flex; flex-direction: column; gap: 7px; max-height: 58vh; overflow-y: auto; }
.sheet-list > li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 11px;
}
.sheet-list .row-main { flex: 1; min-width: 0; }
.sheet-list .row-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-list .row-sub { font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-empty { color: var(--ink-soft); font-size: 13px; padding: 10px 2px; }
.sheet-list select { min-height: 30px; padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); font-size: 12px; }
/* ---------- Google Sheet pull/push preview ---------- */
.sheet-preview-list > li { align-items: flex-start; }
.sheet-preview-list .row-title { white-space: normal; }
.sheet-diff { margin-top: 7px; font-size: 12px; }
.sheet-diff-field { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink-soft); }
.sheet-diff-values { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; margin-top: 3px; }
.sheet-diff-from, .sheet-diff-to { white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet-diff-from { color: var(--ink-soft); text-decoration: line-through; }
.sheet-diff-arrow { color: var(--ink-faint); }
.sheet-diff.skip { opacity: 0.75; }
.sheet-diff.skip .sheet-diff-from { text-decoration: none; }
.sheet-diff.skip .sheet-diff-to { text-decoration: line-through; }
.badge.sheet-badge-new { background: var(--ok-tint); color: var(--ok-ink); font-weight: 600; }
.badge.sheet-badge-warn { background: var(--warn-tint); color: var(--warn-ink); font-weight: 600; }

.row-x {
  border: none; background: none; color: var(--ink-faint); cursor: pointer;
  display: inline-flex; align-items: center;
  font-size: 13px; padding: 4px 6px; border-radius: 5px;
}
.row-x:hover { background: var(--danger-tint); color: var(--danger); }
.row-star { border: none; background: none; color: var(--warn-ink); cursor: pointer; display: inline-flex; align-items: center; font-size: 14px; padding: 4px 6px; border-radius: 5px; }
.row-star:hover { background: var(--surface-alt); }

/* ---------- Notifications bell dropdown ---------- */
.notif-panel { width: 340px; }
.notif-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.notif-list { max-height: 360px; }
.notif-row { cursor: pointer; align-items: flex-start; }
.notif-row .row-title { white-space: normal; font-weight: 500; }
.notif-row.unread { border-color: var(--brand); background: var(--brand-tint); }
.notif-row.unread .row-title { font-weight: 700; }

/* ---------- Share add form ---------- */
.share-add { display: flex; gap: 7px; margin-bottom: 12px; }
.share-add .input { min-height: 34px; }
.share-add select { flex-shrink: 0; width: auto; }
.share-link {
  display: flex; flex-direction: column; gap: 7px;
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; margin-bottom: 12px;
}
.share-link-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.share-link-note { font-size: 12px; color: var(--ink-soft); }
.share-link-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.share-link-row .input { min-height: 32px; }
.share-link-row input.input { flex: 1; min-width: 0; font-size: 12px; }
.share-link-row select { flex-shrink: 0; width: auto; }
.share-link-label { font-size: 12px; color: var(--ink-soft); }
.share-link-spacer { flex: 1; }
.form-error { background: var(--danger-tint); color: var(--danger); border-radius: var(--r-sm); padding: 7px 10px; font-size: 12px; margin-bottom: 10px; }

/* ---------- Automation ---------- */
.automation-body .sheet-list .row-main { display: flex; align-items: center; }
.automation-body .sheet-list li { align-items: flex-start; }
.rule-form { display: flex; flex-direction: column; gap: 10px; }
.rule-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); flex-shrink: 0; padding-top: 7px;
}
.rule-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rule-row .input, .rule-row select { min-height: 34px; width: auto; }
.rule-actions { display: flex; flex-direction: column; gap: 8px; }
.rule-param { display: inline-flex; align-items: center; gap: 6px; }
.rule-days { width: 70px !important; }
.rule-lists { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rule-list-opt {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-xs); font-size: 13px; cursor: pointer;
}
.rule-list-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
.rule-scope-hint { font-size: 12px; color: var(--ink-soft); }

/* ---------- Calendar ---------- */
.cal-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-month { font-weight: 700; font-size: 13px; margin-left: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); text-align: center; padding: 3px 0;
}
.cal-cell {
  min-height: 92px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.cal-cell.outside { opacity: 0.45; }
.cal-cell.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.cal-daynum { font-size: 11px; font-weight: 600; color: var(--ink-soft); padding: 1px 3px; }
.cal-cell.today .cal-daynum { color: var(--brand); }
.cal-card {
  text-align: left;
  border: none;
  border-left: 3px solid var(--brand);
  background: var(--surface-alt);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-card:hover { background: var(--line); }
.cal-card.due-overdue { border-left-color: var(--danger); }
.cal-card.due-today, .cal-card.due-soon { border-left-color: var(--warn-ink); }
.cal-card.due-done { border-left-color: var(--ok-ink); text-decoration: line-through; color: var(--ink-soft); }
.cal-card.due-start { border-left-style: dashed; border-left-color: var(--ink-faint); }

@media (max-width: 720px) {
  .cal-cell { min-height: 58px; }
  .cal-card { font-size: 10px; }
}

/* ---------- Keyboard shortcuts sheet ---------- */
.shortcuts { display: flex; flex-direction: column; gap: 8px; }
.shortcuts > div { display: flex; align-items: baseline; gap: 12px; }
.shortcuts dt { flex-shrink: 0; width: 132px; }
.shortcuts dd { font-size: 13px; color: var(--ink-soft); }

/* Custom field manager */
.fields-list li { align-items: flex-start; }
.field-def-head { width: 100%; }
.field-def-head .field-def-name { flex: 1; min-width: 140px; }
.field-def-show { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-soft); }
.field-def-spacer { flex: 1; }
.field-options { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 2px 4px; padding-left: 10px; border-left: 2px solid var(--line); }

/* Google Sheet column-mapping editor */
.mapping-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.mapping-tab { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.mapping-tab select, .mapping-controls select, .share-add > select {
  min-height: 32px; padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); font-size: 12px;
}
.mapping-list > li { align-items: center; }
.mapping-controls { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.mapping-controls .mapping-target { width: 190px; }
.mapping-summary { max-height: 30vh; margin-top: 8px; }
.mapping-adds-head { margin: 14px 0 6px; }
.mapping-subhead { font-size: 13px; font-weight: 600; }
.mapping-add { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.mapping-add input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--brand); }
.mapping-add-text { display: flex; flex-direction: column; min-width: 0; }
.mapping-controls .mapping-col-name { width: 190px; min-height: 32px; padding: 4px 8px; font-size: 12px; }

/* Google Sheet column-order editor (Trellite format) */
.mapping-list.column-order > li { flex-direction: row; align-items: center; cursor: grab; padding-top: 5px; padding-bottom: 5px; }
.column-order > li.moved { border-color: var(--brand); }
.column-order > li.dragging { opacity: .5; }
.column-order > li.drop-before { box-shadow: 0 -2px 0 var(--brand); }
.column-order > li.drop-after { box-shadow: 0 2px 0 var(--brand); }
.column-order .column-grip { display: inline-flex; color: var(--ink-soft); }
.column-order .column-letter {
  flex-shrink: 0; min-width: 26px; text-align: center; font-size: 11px; font-weight: 600;
  color: var(--ink-soft); font-variant-numeric: tabular-nums;
}
.column-order .mapping-controls { flex-wrap: nowrap; gap: 2px; }
@media (max-width: 560px) {
  .mapping-list > li { flex-direction: column; align-items: stretch; }
  .mapping-controls { justify-content: flex-start; }
  .mapping-controls .mapping-target, .mapping-controls .mapping-col-name { width: 100%; }
}

/* Board flow: list roles + Statistik panel */
.flow-list > li { align-items: center; }
.flow-role { width: auto; min-width: 140px; flex-shrink: 0; }
.flow-hint { font-size: 12px; color: var(--ink-soft); margin-top: 10px; }
.stats-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; font-size: 13px; }
.stats-error { font-size: 12px; color: var(--danger); background: var(--danger-tint); border-radius: var(--r-sm); padding: 8px 10px; margin-bottom: 12px; }
.stats-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 6px 0 18px; }
.stats-tile { background: var(--surface-sunk); border: 1px solid var(--line); border-radius: var(--r-md); padding: 11px 12px; min-width: 0; }
.stats-tile-label { font-size: 11px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.stats-tile-value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stats-tile-value.trend-up { color: var(--ok-ink); }
.stats-tile-value.trend-down { color: var(--warn-ink); }
.stats-tile-sub { font-size: 12px; color: var(--ink-soft); }
.stats-section-title { font-size: 12px; font-weight: 700; color: var(--ink-soft); margin: 14px 0 8px; }
.stats-chart { display: flex; align-items: stretch; gap: 6px; height: 150px; padding: 6px 2px 0; border-bottom: 1px solid var(--line-strong); }
.stats-bar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; padding-bottom: 18px; }
.stats-bar { width: 100%; max-width: 34px; background: var(--brand-tint); border: 1px solid var(--brand); border-bottom: none; border-radius: var(--r-xs) var(--r-xs) 0 0; }
.stats-bar.current { background: var(--brand); }
.stats-bar-value { font-size: 11px; font-weight: 600; color: var(--ink-soft); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.stats-bar-label { position: absolute; bottom: 0; font-size: 10px; color: var(--ink-faint); white-space: nowrap; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stats-list { max-height: none; }
.stats-count { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.stats-link { cursor: pointer; }
.stats-link:hover, .stats-link:focus-visible { border-color: var(--brand); }

@media (max-width: 720px) {
  .stats-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
  .stats-bar-label { display: none; }
}
