/* ============================================================
   MDM SORP — UI v2 overrides (Stripe-like clarity)
   - Lighter, more confident table dividers
   - Smaller, quieter FieldBadge (dot + 2-letter src + hover tip)
   - Reworked .frow (drawer/card fields) with inline-edit affordance
   - Better visual hierarchy in column types
   - Consistent type scale, mono for codes/IDs, tabular for numbers
   ============================================================ */

/* ---------- Densities ---------- */
:root {
  --row-h:               40px;     /* default row height */
  --row-h-dense:         32px;
  --hairline:            #ECE7DD;  /* warmer than neutral-200 but lighter */
  --hairline-strong:     #DDD6C8;
  --cell-px:             16px;
  --cell-py:             0;
  --label-color:         #6E6859;
  --num-color:           #1E2128;
  --edit-bg-hover:       #FAF6EF;
  --edit-focus:          var(--sorp-red);
}

/* ============================================================
   DATA GRID (.dg) — premium, scannable, dense
   ============================================================ */
.dg {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: var(--w-regular);
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

/* HEADER */
.dg thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-surface);
  text-align: left;
  font-size: 10.5px;
  font-weight: var(--w-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8B8475;
  padding: 10px var(--cell-px) 9px;
  border-bottom: 1px solid var(--hairline-strong);
  white-space: nowrap;
  user-select: none;
  height: 36px;
  vertical-align: middle;
}
.dg thead th:hover { color: var(--fg-1); }
.dg thead th.checkbox { padding-left: 14px; padding-right: 0; width: 28px; }
.dg thead th.num { text-align: right; }
.dg thead th[data-sortable]::after {
  content: ""; display: inline-block; vertical-align: middle;
  width: 8px; height: 8px; margin-left: 4px; opacity: 0.4;
  background: linear-gradient(to bottom, currentColor 4px, transparent 4px);
}

/* BODY */
.dg tbody td {
  padding: 0 var(--cell-px);
  height: var(--row-h);
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
  color: var(--fg-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
  line-height: 1.35;
  font-size: 13px;
}
.dg.dense tbody td { height: var(--row-h-dense); padding-top: 0; padding-bottom: 0; font-size: 12.5px; }
.dg.dense thead th { padding-top: 8px; padding-bottom: 7px; height: 32px; }

.dg tbody td.checkbox { padding-left: 14px; padding-right: 0; width: 28px; }
.dg tbody td.checkbox input[type=checkbox] {
  width: 14px; height: 14px; accent-color: var(--sorp-red);
  margin: 0; cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--dur-fast);
}
.dg tbody tr:hover td.checkbox input[type=checkbox],
.dg tbody td.checkbox input[type=checkbox]:checked { opacity: 1; }

.dg tbody tr {
  cursor: pointer;
  position: relative;
}
.dg tbody tr:hover td { background: #FBF9F4; }
.dg tbody tr.selected td {
  background: rgba(214, 61, 74, 0.045);
}
.dg tbody tr.selected td:first-child {
  box-shadow: inset 3px 0 0 var(--sorp-red);
}
.dg tbody tr:last-child td { border-bottom: 0; }

/* CELL VARIANTS */
.dg .id, .dg .mono {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: -0.01em;
}
.dg .id a {
  color: var(--sorp-red-deep);
  font-weight: var(--w-semibold);
  text-decoration: none;
}
.dg .id a:hover { text-decoration: underline; text-decoration-thickness: 1px; }
.dg .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--num-color); font-weight: var(--w-medium); }
.dg td.num.muted { color: var(--fg-3); font-weight: var(--w-regular); }

.dg .cell-with-badge {
  display: inline-flex; align-items: center; gap: 8px;
  width: 100%; min-width: 0;
}
.dg .cell-with-badge .v {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dg .empty-cell {
  color: #B5AE9F;
  font-style: normal;
  font-size: 12px;
}

/* INLINE-EDITABLE CELL */
.dg td.editable {
  position: relative;
  cursor: text;
}
.dg td.editable:hover {
  background: var(--edit-bg-hover) !important;
  box-shadow: inset 0 0 0 1px rgba(214,61,74,0.18);
}
.dg td.editable::after {
  content: "";
  position: absolute; right: 8px; top: 50%;
  width: 11px; height: 11px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237A7468' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M12 20h9'/><path d='M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z'/></svg>") center/contain no-repeat;
  transform: translateY(-50%);
  opacity: 0; transition: opacity var(--dur-fast);
}
.dg td.editable:hover::after { opacity: 0.7; }

/* GRID WRAP */
.grid-wrap {
  flex: 1; min-height: 0;
  overflow: auto;
  background: var(--bg-surface);
  position: relative;
}
.grid-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.grid-wrap::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 5px; border: 2px solid var(--bg-surface); }
.grid-wrap::-webkit-scrollbar-track { background: transparent; }

/* GRID TOOLBAR */
.grid-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--hairline-strong);
  flex-shrink: 0;
}
.grid-toolbar h2 {
  font-size: 17px;
  font-weight: var(--w-semibold);
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--fg-1);
}
.grid-toolbar .count {
  color: var(--fg-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
  margin-right: 12px;
}

/* ============================================================
   FILTER PILLS — smaller, quieter
   ============================================================ */
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  background: transparent;
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  font-size: 12px;
  font-weight: var(--w-medium);
  color: var(--fg-2);
  line-height: 1.2;
  cursor: pointer;
  transition: all var(--dur-fast);
  height: 26px;
  white-space: nowrap;
}
.filter-pill:hover {
  background: var(--bg-page);
  border-color: var(--neutral-300);
  color: var(--fg-1);
}
.filter-pill.active {
  background: var(--sorp-red-wash);
  border-color: rgba(214, 61, 74, 0.30);
  color: var(--sorp-red-deep);
  font-weight: var(--w-semibold);
}
.filter-pill .x {
  color: rgba(214, 61, 74, 0.55);
  font-size: 14px; line-height: 1;
  margin-left: 2px;
}
.filter-pill .x:hover { color: var(--sorp-red); }
.filter-pill .tabular { color: inherit; opacity: 0.7; margin-left: 2px; }

/* ============================================================
   FieldBadge v2 — micro-marker; dot + 2-letter source
   Confidence shown as a tiny segmented arc (3 states: high/med/low)
   Full details (raw, when, applied) appear on hover only.
   ============================================================ */
.fbadge {
  display: inline-flex; align-items: center;
  gap: 4px;
  font-size: 10px;
  line-height: 1;
  font-weight: var(--w-semibold);
  letter-spacing: 0.02em;
  padding: 2px 5px 2px 4px;
  border-radius: 999px;
  background: rgba(20,23,28,0.04);
  border: 0;
  color: var(--fg-2);
  cursor: help;
  position: relative;
  height: 15px;
  text-transform: none;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.fbadge .src {
  font-size: 9.5px;
  font-weight: var(--w-bold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  display: inline-flex; align-items: center; gap: 3px;
}
.fbadge .src::before {
  content: ""; display: inline-block;
  width: 5px; height: 5px; border-radius: 999px;
  background: currentColor;
}
.fbadge .conf {
  display: inline-block;
  width: 12px; height: 4px; border-radius: 2px;
  background: rgba(0,0,0,0.10);
  position: relative;
  overflow: hidden;
}
.fbadge .conf::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--c, 0%);
  background: currentColor;
  border-radius: 2px;
  opacity: 0.85;
}
/* hide percent number — too noisy. Keep only the bar. */
.fbadge > span:not(.src):not(.conf):not(.fb-tip) { display: none; }

/* Source coloring — subtle */
.fbadge.amo    { color: #1F73C7; background: rgba(31, 115, 199, 0.08); }
.fbadge.asana  { color: #D14545; background: rgba(209, 69, 69, 0.08); }
.fbadge.drive  { color: #1A73E8; background: rgba(26, 115, 232, 0.08); }
.fbadge.ai     { color: var(--sorp-red-deep); background: rgba(214, 61, 74, 0.08); }
.fbadge.dadata { color: #6E45E2; background: rgba(110, 69, 226, 0.08); }
.fbadge.manual { color: #5A554A; background: rgba(90, 85, 74, 0.08); }

/* Confidence tone overrides the source bg subtly */
.fbadge.bad   { color: var(--sorp-red); background: rgba(214, 61, 74, 0.10); }
.fbadge.warn  { color: var(--status-warning); background: rgba(199, 122, 31, 0.10); }

/* TOOLTIP — premium */
.fbadge:hover { z-index: 50; }
.fbadge .fb-tip {
  display: none;
}
.fbadge:hover .fb-tip {
  display: block;
  position: absolute;
  left: 50%; top: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--sorp-ink);
  color: var(--fg-on-dark);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(20,23,28,0.18), 0 2px 6px rgba(20,23,28,0.12);
  min-width: 220px;
  font-family: var(--font-sans);
  text-transform: none;
  letter-spacing: 0;
  font-weight: var(--w-regular);
  pointer-events: none;
}
.fbadge .fb-tip::before {
  content: ""; position: absolute;
  top: -4px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 8px; height: 8px;
  background: var(--sorp-ink);
}
.fbadge .fb-tip .row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0;
}
.fbadge .fb-tip .k { color: rgba(255,255,255,0.55); font-size: 10.5px; }
.fbadge .fb-tip .v { font-weight: var(--w-semibold); color: #fff; }

/* ============================================================
   FROW v2 — drawer / card field rows, premium Stripe-like
   Two-column. Label muted ALL-CAPS micro. Value larger, editable on click.
   ============================================================ */
.frow {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 13.5px;
  min-height: 44px;
  position: relative;
}
.frow:last-child { border-bottom: 0; }
.frow .lbl {
  color: var(--label-color);
  font-size: 11px;
  font-weight: var(--w-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.3;
  padding-top: 1px;
  align-self: center;
}
.frow .val {
  color: var(--fg-1);
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  font-size: 14px;
  line-height: 1.4;
  font-weight: var(--w-regular);
  min-width: 0;
}
.frow .val .raw {
  color: var(--fg-3);
  font-size: 11.5px;
  text-decoration: line-through;
  text-decoration-color: rgba(214,61,74,0.4);
}
.frow .val.mono, .frow .val .mono { font-family: var(--font-mono); font-size: 13px; }

/* Inline-edit affordance */
.frow .val .text {
  cursor: text;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background var(--dur-fast), border-color var(--dur-fast);
  flex: 1; min-width: 0;
}
.frow:hover .val .text {
  background: var(--bg-page);
  border-color: var(--hairline);
}
.frow .val .text:focus {
  outline: none;
  background: var(--bg-surface);
  border-color: var(--sorp-red);
  box-shadow: 0 0 0 3px rgba(214,61,74,0.10);
}
.frow .val .text.empty { color: var(--fg-disabled); font-style: normal; }

/* Pencil icon — appears on hover */
.frow .actions {
  opacity: 0;
  display: flex; gap: 2px;
  transition: opacity var(--dur-fast);
}
.frow:hover .actions { opacity: 1; }
.frow .actions .icon-mini {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: transparent;
  border: 0;
  color: var(--fg-3);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.frow .actions .icon-mini:hover { background: var(--bg-page); color: var(--fg-1); }

/* compact variant — sidebar density */
.frow.compact { padding: 8px 0; min-height: 32px; font-size: 12.5px; }
.frow.compact .val { font-size: 13px; }
.frow.compact .lbl { font-size: 10.5px; }

/* Section header inside a card body */
.field-section {
  font-size: 11px;
  font-weight: var(--w-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8B8475;
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--hairline-strong);
  margin-bottom: 4px;
}

/* ============================================================
   CHIPS v2 — smaller, quieter
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: var(--w-semibold);
  background: rgba(20,23,28,0.05);
  color: var(--fg-2);
  border: 0;
  line-height: 1.5;
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.chip.success { background: rgba(47, 125, 91, 0.10); color: var(--status-success); }
.chip.warning { background: rgba(199, 122, 31, 0.12); color: #9E5F18; }
.chip.danger  { background: rgba(214, 61, 74, 0.10);  color: var(--sorp-red-deep); }
.chip.info    { background: rgba(44, 92, 140, 0.10);  color: var(--status-info); }
.chip.ink     { background: var(--sorp-ink); color: var(--fg-on-dark); }
.chip.role    { background: rgba(214, 61, 74, 0.08); color: var(--sorp-red-deep); }
.chip.outline {
  background: transparent;
  border: 1px solid var(--hairline-strong);
  color: var(--fg-2);
  font-weight: var(--w-medium);
}
.chip-dot {
  width: 5px; height: 5px; border-radius: 999px;
  background: currentColor;
  opacity: 0.9;
}

/* ============================================================
   CARDS — slightly lighter borders
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  box-shadow: none;
}
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; gap: 10px;
}
.card-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: var(--w-semibold);
  letter-spacing: -0.005em;
  color: var(--fg-1);
}
.card-head .sub {
  margin-left: auto;
  color: var(--fg-3);
  font-size: 11.5px;
}
.card-body { padding: 16px; }

/* ============================================================
   BUTTONS — tighter type
   ============================================================ */
.btn {
  font-size: 13px;
  font-weight: var(--w-semibold);
  padding: 6px 12px;
  height: 30px;
  letter-spacing: -0.005em;
  border-radius: 7px;
}
.btn.sm { padding: 4px 10px; font-size: 12px; height: 26px; }
.btn.lg { padding: 9px 18px; font-size: 14px; height: 38px; }

/* ============================================================
   QUEUE — list items + diff grid premium pass
   ============================================================ */
.queue-list .head { border-bottom: 1px solid var(--hairline-strong); }
.qitem {
  padding: 12px 16px 12px 14px;
  border-bottom: 1px solid var(--hairline);
  border-left: 2px solid transparent;
  gap: 5px;
}
.qitem:hover { background: #FBF9F4; }
.qitem.active {
  background: rgba(214, 61, 74, 0.045);
  border-left-color: var(--sorp-red);
}
.qitem .name { font-size: 13px; font-weight: var(--w-semibold); }
.qitem .meta { font-size: 11px; }
.qitem .diff { font-size: 11px; }
.qitem .diff .mono { font-size: 11px; color: var(--fg-3); }

.diff-grid {
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  background: var(--bg-surface);
  overflow: hidden;
}
.diff-grid > div { border-bottom: 1px solid var(--hairline); }
.diff-grid .hdr {
  background: #FBF9F4;
  font-size: 10.5px;
  letter-spacing: 0.07em;
  color: #8B8475;
  font-weight: var(--w-semibold);
  text-transform: uppercase;
  padding: 9px 16px;
  border-bottom: 1px solid var(--hairline-strong);
}
.diff-grid .field {
  color: var(--fg-1);
  font-size: 13px;
  font-weight: var(--w-medium);
  padding: 14px 16px;
}
.diff-grid .field > div:nth-child(2) {
  color: var(--fg-3); font-size: 11px; font-weight: 400; margin-top: 2px;
}
.diff-grid .raw {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-2);
  padding: 14px 16px;
}
.diff-grid .raw.bad {
  background: rgba(214,61,74,0.035);
  color: var(--sorp-red-deep);
  box-shadow: inset 2px 0 0 var(--sorp-red);
}
.diff-grid .sug {
  padding: 14px 16px;
  font-size: 13.5px;
  font-weight: var(--w-medium);
  display: flex; align-items: center; gap: 10px;
}
.diff-grid .sug.changed {
  background: rgba(47, 125, 91, 0.04);
  box-shadow: inset 2px 0 0 var(--status-success);
}
.diff-grid .sug.changed .v { font-weight: var(--w-semibold); color: var(--fg-1); }
.diff-grid > div:nth-last-child(-n+3) { border-bottom: 0; }

/* QAction buttons */
.qaction { border-radius: 8px; min-width: 96px; padding: 9px 14px; }
.qaction .lbl { font-size: 12px; font-weight: var(--w-semibold); }
.qaction .key {
  font-family: var(--font-mono); font-size: 10px;
  margin-top: 5px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0,0,0,0.05);
  border: 0;
  color: var(--fg-3);
}
.qaction.apply { background: #2F7D5B; }
.qaction.apply:hover { background: #266447; }
.qaction.apply .key { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.85); }

/* ============================================================
   DRAWER — premium
   ============================================================ */
.drawer { border-left: 1px solid var(--hairline-strong); box-shadow: -16px 0 40px rgba(20,23,28,0.10), -4px 0 10px rgba(20,23,28,0.04); }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--hairline); }
.drawer-head .title { font-size: 18px; font-weight: var(--w-semibold); letter-spacing: -0.01em; }
.drawer-head .sub { font-size: 12.5px; color: var(--fg-3); margin-top: 4px; }
.drawer-body { padding: 0 24px; }
.drawer-foot { padding: 14px 24px; border-top: 1px solid var(--hairline-strong); background: #FBF9F4; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { padding: 0 20px; border-bottom: 1px solid var(--hairline-strong); }
.tab {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: var(--w-medium);
  color: var(--fg-3);
  letter-spacing: -0.005em;
}
.tab .count {
  font-size: 10.5px;
  background: transparent;
  color: var(--fg-3);
  padding: 1px 6px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.tab.active { color: var(--fg-1); font-weight: var(--w-semibold); }
.tab.active .count { background: var(--sorp-red-wash); color: var(--sorp-red-deep); }

/* ============================================================
   TOP BAR / SIDEBAR — minor polish
   ============================================================ */
.topbar { border-bottom: 1px solid var(--hairline-strong); }
.crumbs { font-size: 12.5px; }
.omnibox input {
  height: 30px;
  border: 1px solid var(--hairline-strong);
  background: var(--bg-page);
  font-size: 13px;
}
.omnibox input:focus {
  border-color: var(--sorp-red);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px rgba(214,61,74,0.10);
}
.omnibox .hk { background: transparent; border-color: var(--hairline); color: var(--fg-3); }

/* ============================================================
   STATUS DOT (in row signals)
   ============================================================ */
.qdot { width: 6px; height: 6px; border-radius: 999px; flex-shrink: 0; }
.qdot.ok { background: var(--status-success); }
.qdot.warn { background: var(--status-warning); }
.qdot.bad { background: var(--sorp-red); }
.qdot.muted { background: var(--neutral-300); }

/* ============================================================
   SECONDARY UI: flag chips & avatars (smaller)
   ============================================================ */
.flag-ru, .flag-en, .flag-cn, .flag-ae, .flag-de, .flag-tr {
  display: inline-block;
  width: 14px; height: 10px;
  border-radius: 1.5px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.10);
}
