/*
 * Widget styles.
 *
 * UX §12: logical properties only (inline-start/end, margin-inline, text-align:
 * start). No physical left/right anywhere — that is what makes RTL work rather
 * than "mostly work".
 *
 * UX §13: colours come from tokens shaped like monday's Vibe palette so the
 * widget reads as part of monday, and so all three themes (light/dark/black)
 * are a token swap rather than a restyle.
 */

.w-root {
  /* Vibe-shaped tokens. Values approximate monday's palette; in M3 these bind
     to context.themeConfig instead of being hard-coded. */
  --w-bg: #ffffff;
  --w-surface: #ffffff;
  --w-surface-2: #f5f6f8;
  --w-text: #323338;
  --w-muted: #676879;
  --w-border: #d0d4e4;
  --w-accent: #0073ea;
  --w-accent-soft: #cce5ff;
  --w-warn-bg: #fff4e4;
  --w-warn-border: #fdab3d;
  --w-warn-text: #7f4b0a;
  --w-danger: #d83a52;
  --w-ok: #00854d;
  --w-track: #e6e9ef;
  --w-blank: #c3c6d4;

  --w-c1: #0073ea; --w-c2: #00c875; --w-c3: #a25ddc; --w-c4: #fdab3d;
  --w-c5: #ff158a; --w-c6: #00d1d1; --w-c7: #7f5347; --w-c8: #579bfc;

  --w-radius: 8px;
  --w-gap: 12px;

  background: var(--w-bg);
  color: var(--w-text);
  font-family: Figtree, Roboto, "Noto Sans Hebrew", -apple-system, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding: 16px;
  min-block-size: 100%;
  box-sizing: border-box;
}

.w-root[data-theme="dark"] {
  --w-bg: #181b34; --w-surface: #30324e; --w-surface-2: #21243d;
  --w-text: #d5d8df; --w-muted: #9699a6; --w-border: #4b4e69;
  --w-track: #4b4e69; --w-blank: #6b6e85;
  --w-warn-bg: #3d2f14; --w-warn-text: #ffcc80;
}

.w-root[data-theme="black"] {
  --w-bg: #111111; --w-surface: #1c1c1c; --w-surface-2: #161616;
  --w-text: #e6e6e6; --w-muted: #9a9a9a; --w-border: #333333;
  --w-track: #333333; --w-blank: #555555;
  --w-warn-bg: #2e2410; --w-warn-text: #ffcc80;
}

/* Reduced motion is honoured rather than assumed away (UX §11). */
@media (prefers-reduced-motion: reduce) {
  .w-root *, .w-root *::before, .w-root *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

.w-root :focus-visible {
  outline: 2px solid var(--w-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- filter bar */

.w-filterbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
  margin-block-end: var(--w-gap);
}

.w-filterbar-end {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.w-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  min-block-size: 32px;
  border: 1px solid var(--w-border);
  border-radius: 16px;
  background: var(--w-surface);
  color: var(--w-text);
  font: inherit;
  cursor: pointer;
  text-align: start;
}
.w-chip:hover { background: var(--w-surface-2); }
.w-chip-active { background: var(--w-accent-soft); border-color: var(--w-accent); }
.w-chip-info { cursor: help; }
.w-chip-sub { color: var(--w-muted); font-size: 12px; }
.w-chip-x {
  border: 0; background: none; cursor: pointer; color: var(--w-muted);
  font-size: 16px; line-height: 1; padding: 0 2px; min-inline-size: 20px;
}

.w-btn {
  padding: 7px 14px; min-block-size: 32px;
  border: 1px solid var(--w-border); border-radius: var(--w-radius);
  background: var(--w-surface); color: var(--w-text);
  font: inherit; cursor: pointer; text-align: start;
}
.w-btn:hover { background: var(--w-surface-2); }
.w-btn-primary { background: var(--w-accent); border-color: var(--w-accent); color: #fff; }
.w-btn-sm { padding: 4px 10px; min-block-size: 28px; font-size: 13px; }
.w-btn-block { display: block; inline-size: 100%; margin-block-end: 6px; }
.w-icon-btn {
  min-inline-size: 32px; min-block-size: 32px;
  border: 1px solid transparent; border-radius: var(--w-radius);
  background: none; color: var(--w-muted); cursor: pointer; font: inherit;
}
.w-icon-btn:hover { background: var(--w-surface-2); }
.w-link { border: 0; background: none; color: var(--w-accent); cursor: pointer; font: inherit; padding: 4px; }

.w-input {
  inline-size: 100%; padding: 7px 10px; box-sizing: border-box;
  border: 1px solid var(--w-border); border-radius: var(--w-radius);
  background: var(--w-surface); color: var(--w-text); font: inherit;
  margin-block-end: 8px;
}

/* ------------------------------------------------------------------- KPIs */

.w-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--w-gap);
  margin-block-end: var(--w-gap);
}
.w-kpi {
  position: relative;
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius); padding: 14px 16px;
}
.w-kpi-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.w-kpi-label { color: var(--w-muted); font-size: 13px; margin-block-start: 2px; }
.w-kpi-sub { color: var(--w-muted); font-size: 12px; }
.w-kpi-note {
  position: absolute; inset-block-start: 8px; inset-inline-end: 10px;
  color: var(--w-muted); cursor: help;
}

/* ---------------------------------------------------------------- widgets */

.w-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--w-gap);
  align-items: start;
}
.w-widget {
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.w-widget-head { display: flex; align-items: flex-start; gap: 8px; }
.w-widget-title { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }

/*
 * The provenance line. It never collapses, never truncates away entirely, and
 * survives every widget size — AC12 is checked visually against this rule.
 */
.w-prov {
  font-size: 12px;
  color: var(--w-muted);
  border-block-end: 1px dashed var(--w-border);
  padding-block-end: 8px;
  overflow-wrap: anywhere;
}
.w-prov-warn { color: var(--w-warn-text); font-weight: 600; }

.w-widget-notes { display: flex; flex-direction: column; gap: 6px; }
.w-note {
  margin: 0; font-size: 12px; color: var(--w-muted);
  background: var(--w-surface-2); padding: 6px 8px; border-radius: 6px;
}
.w-override {
  font-size: 12px; color: var(--w-warn-text);
  background: var(--w-warn-bg); border-inline-start: 3px solid var(--w-warn-border);
  padding: 6px 8px; border-radius: 6px;
}
.w-add-widget {
  border: 1px dashed var(--w-border); border-radius: var(--w-radius);
  background: none; color: var(--w-muted); cursor: pointer;
  min-block-size: 120px; font: inherit;
}

.w-menu { position: relative; }
.w-menu-items {
  display: none; position: absolute; inset-inline-end: 0; inset-block-start: 100%;
  z-index: 10; min-inline-size: 220px;
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius); padding: 4px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 18%);
}
.w-menu.is-open .w-menu-items { display: block; }
.w-menu-item {
  display: block; inline-size: 100%; text-align: start;
  border: 0; background: none; color: var(--w-text);
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font: inherit;
}
.w-menu-item:hover { background: var(--w-surface-2); }
.w-menu-item.is-danger { color: var(--w-danger); }

/* ----------------------------------------------------------------- charts */

.w-bars { display: flex; flex-direction: column; gap: 8px; }
.w-bar-row {
  display: grid;
  grid-template-columns: minmax(80px, 130px) 1fr auto;
  align-items: center; gap: 10px;
  padding: 2px 4px; border-radius: 6px;
}
.w-bar-row.is-clickable { cursor: pointer; }
.w-bar-row.is-clickable:hover { background: var(--w-surface-2); }
.w-bar-label {
  font-size: 13px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; text-align: start;
}
.w-bar-track {
  background: var(--w-track); border-radius: 4px; block-size: 22px; overflow: hidden;
}
/* Logical inline-size means the fill grows from the inline start — which is the
   right edge under RTL, automatically. */
.w-bar-fill { block-size: 100%; border-radius: 4px; min-inline-size: 2px; }
.w-bar-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.w-bar-row.is-blank .w-bar-label { color: var(--w-muted); }

.w-donut { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.w-donut-chart { inline-size: 180px; flex: 0 0 auto; }
.w-donut-svg { inline-size: 100%; block-size: auto; }
.w-donut-total { font-size: 30px; font-weight: 700; fill: var(--w-text); }
.w-donut-unit { font-size: 11px; fill: var(--w-muted); }
.w-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-inline-size: 160px; }
.w-legend-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.w-swatch { inline-size: 12px; block-size: 12px; border-radius: 3px; flex: 0 0 auto; }
.w-legend-label { flex: 1; }
.w-legend-value { color: var(--w-muted); font-variant-numeric: tabular-nums; }

.w-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.w-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 8px; border: 1px solid var(--w-border);
  border-radius: var(--w-radius); background: var(--w-surface-2);
}
.w-card.is-clickable { cursor: pointer; }
.w-card.is-zero { opacity: 0.55; }
.w-avatar {
  inline-size: 40px; block-size: 40px; border-radius: 50%;
  object-fit: cover; background: var(--w-accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--w-accent);
}
.w-card-name { font-size: 13px; font-weight: 600; text-align: center; }
.w-gauge { inline-size: 74px; block-size: 74px; }
.w-gauge-value { font-size: 22px; font-weight: 700; fill: var(--w-text); }
.w-card-unit { font-size: 11px; color: var(--w-muted); }

/* ------------------------------------------------------------------ table */

.w-table-section {
  margin-block-start: var(--w-gap);
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius); padding: 10px 14px;
}
.w-table-section > summary { cursor: pointer; font-weight: 600; }
.w-table-controls {
  display: flex; align-items: center; gap: 8px;
  margin-block: 10px; flex-wrap: wrap;
}
.w-table-wrap { overflow-x: auto; }
.w-table { inline-size: 100%; border-collapse: collapse; font-size: 13px; }
.w-table th, .w-table td {
  text-align: start; padding: 7px 10px;
  border-block-end: 1px solid var(--w-border);
}
.w-table th { color: var(--w-muted); font-weight: 600; }

/* ----------------------------------------------------------------- states */

.w-banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; margin-block-end: var(--w-gap);
  border-radius: var(--w-radius);
  background: var(--w-surface-2); border: 1px solid var(--w-border);
}
.w-banner.is-warn {
  background: var(--w-warn-bg); border-color: var(--w-warn-border); color: var(--w-warn-text);
}
.w-banner.is-danger { background: var(--w-warn-bg); border-color: var(--w-danger); color: var(--w-danger); }
.w-banner-body { flex: 1; }
.w-banner-body p { margin: 2px 0; }
.w-banner-actions { display: flex; gap: 6px; }
.w-banner-icon { flex: 0 0 auto; }

.w-empty, .w-error {
  text-align: center; padding: 40px 20px;
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
}
.w-empty-msg { font-size: 15px; margin-block-end: 12px; }
.w-error h3 { margin: 0 0 6px; }
.w-details { margin-block-start: 10px; text-align: start; }
.w-pre {
  white-space: pre-wrap; font-size: 11px; color: var(--w-muted);
  background: var(--w-surface-2); padding: 8px; border-radius: 6px; direction: ltr;
}

.w-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / 45%);
}
.w-overlay-light { background: rgb(0 0 0 / 25%); }
.w-dialog, .w-popup {
  background: var(--w-surface); color: var(--w-text);
  border: 1px solid var(--w-border); border-radius: var(--w-radius);
  padding: 20px; max-inline-size: 460px; max-block-size: 80vh; overflow: auto;
  box-shadow: 0 12px 40px rgb(0 0 0 / 30%);
}
.w-dialog h3, .w-popup h4 { margin: 0 0 10px; }
.w-dialog-actions, .w-popup-actions { display: flex; gap: 8px; margin-block-start: 14px; }

.w-toast {
  position: fixed; inset-block-end: 16px; inset-inline-start: 50%;
  transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--w-text); color: var(--w-bg);
  padding: 10px 16px; border-radius: 20px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 30%);
}
.w-toast .w-btn { background: transparent; border-color: currentcolor; color: inherit; }
.w-readonly {
  display: flex; align-items: center; gap: 6px;
  inline-size: 100%; font-size: 12px; color: var(--w-muted);
}

.w-list { list-style: none; margin: 0 0 10px; padding: 0; }
.w-list li { padding: 5px 0; border-block-end: 1px solid var(--w-border); }
.w-check { display: flex; align-items: center; gap: 8px; padding: 6px 4px; cursor: pointer; }
.w-conflict-list { margin: 4px 0; padding-inline-start: 18px; font-size: 13px; }
.w-muted { color: var(--w-muted); }
.w-ok { color: var(--w-ok); }
.w-warn { color: var(--w-warn-border); }

.w-group { margin-block-end: 12px; }
.w-group-title {
  font-size: 12px; font-weight: 600; color: var(--w-muted);
  padding: 4px 0; border-block-end: 1px solid var(--w-border); margin-block-end: 4px;
}
.w-option {
  display: block; inline-size: 100%; text-align: start;
  border: 0; background: none; color: var(--w-text);
  padding: 7px 8px; border-radius: 6px; cursor: pointer; font: inherit;
}
.w-option:hover:not(.is-disabled) { background: var(--w-surface-2); }
.w-option[aria-current="true"] { background: var(--w-accent-soft); }
.w-option.is-disabled { cursor: not-allowed; opacity: 0.65; }
.w-option-title { font-weight: 600; }
.w-range-custom { display: flex; gap: 8px; align-items: center; margin-block: 10px; flex-wrap: wrap; }
.w-range-custom input { padding: 6px; border: 1px solid var(--w-border); border-radius: 6px;
  background: var(--w-surface); color: var(--w-text); font: inherit; }

/* Refresh keeps old data visible rather than blanking the screen (§6.2). */
.w-root.is-refreshing .w-grid, .w-root.is-refreshing .w-kpis { opacity: 0.6; }

/* --------------------------------------------------------------- skeleton */

.w-sk {
  background: linear-gradient(90deg, var(--w-track) 25%, var(--w-surface-2) 50%, var(--w-track) 75%);
  background-size: 200% 100%;
  animation: w-shimmer 1.2s infinite;
  border-radius: var(--w-radius);
}
@keyframes w-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.w-sk-bar { block-size: 52px; margin-block-end: var(--w-gap); }
.w-sk-kpi { block-size: 78px; }
.w-sk-widget { block-size: 260px; }

/* ------------------------------------------------- responsive widget sizes */
/*
 * UX §9: in a small dashboard tile the filter bar collapses, the KPI row
 * reduces, and a single widget is shown — but the provenance line NEVER
 * collapses. Container queries are used so the breakpoint follows the widget's
 * own width, not the browser viewport: a monday tile is small even on a large
 * screen.
 */
.w-root { container-type: inline-size; container-name: widget; }

@container widget (max-width: 520px) {
  /* Collapse the filter bar behind a single summary chip. */
  .w-filterbar { flex-wrap: nowrap; overflow: hidden; gap: 6px; padding: 8px; }
  .w-filterbar > .w-chip:not(.w-chip-summary) { display: none; }
  .w-filterbar.is-open > .w-chip { display: inline-flex; }
  .w-filterbar.is-open { flex-wrap: wrap; overflow: visible; }
  .w-chip-summary { display: inline-flex !important; }

  /* Two KPIs instead of four. */
  .w-kpi:nth-child(n + 3) { display: none; }
  .w-kpi-value { font-size: 22px; }

  /* One widget at a time. */
  .w-grid { grid-template-columns: 1fr; }
  .w-widget:nth-of-type(n + 2) { display: none; }
  .w-add-widget { display: none; }

  /* The provenance line stays — smaller, wrapped, never hidden. */
  .w-prov { font-size: 11px; }
  .w-widget-title { font-size: 15px; }
}

@container widget (min-width: 521px) {
  .w-chip-summary { display: none; }
}

/* -------------------------------------------------------- onboarding wizard */

.w-wizard {
  max-inline-size: 560px; margin-inline: auto; margin-block: 24px;
  background: var(--w-surface); border: 1px solid var(--w-border);
  border-radius: var(--w-radius); padding: 28px 32px;
}
.w-wizard-brand {
  font-size: 13px; color: var(--w-muted); letter-spacing: .04em;
  margin-block-end: 18px;
}
.w-wizard-head { margin-block-end: 10px; }
.w-wizard-step { font-size: 12px; color: var(--w-muted); }
.w-wizard-title { margin: 2px 0 0; font-size: 22px; font-weight: 700; }
.w-wizard-lede { color: var(--w-muted); margin-block: 8px 18px; }

/* Progress: back is allowed, skipping forward is not. */
.w-steps {
  display: flex; gap: 6px; list-style: none; margin: 0 0 20px; padding: 0;
  font-size: 12px; flex-wrap: wrap;
}
.w-step-dot {
  padding: 4px 12px; border-radius: 20px;
  background: var(--w-surface-2); color: var(--w-muted);
  border: 1px solid var(--w-border);
}
.w-step-dot.is-current {
  background: var(--w-accent); border-color: var(--w-accent); color: #fff; font-weight: 600;
}
.w-step-dot.is-done { background: var(--w-accent-soft); color: var(--w-accent); }

.w-secret-row { display: flex; gap: 6px; align-items: flex-start; }
.w-secret { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; direction: ltr; }
.w-wizard-secure {
  font-size: 12.5px; color: var(--w-muted); line-height: 1.5;
  background: var(--w-surface-2); padding: 10px 12px; border-radius: 8px;
  margin-block: 4px 14px;
}
.w-howto { margin: 8px 0 0; padding-inline-start: 20px; font-size: 13px; color: var(--w-muted); }
.w-howto li { margin-block-end: 4px; }

.w-wizard-actions { display: flex; gap: 8px; margin-block-start: 18px; flex-wrap: wrap; }
.w-wizard-busy { display: flex; align-items: center; gap: 10px; padding: 18px 0; color: var(--w-muted); }
.w-spinner {
  inline-size: 16px; block-size: 16px; border-radius: 50%;
  border: 2px solid var(--w-track); border-top-color: var(--w-accent);
  animation: w-spin .8s linear infinite;
}
@keyframes w-spin { to { transform: rotate(360deg); } }

.w-wizard-ok {
  background: var(--w-accent-soft); color: var(--w-accent);
  padding: 12px 14px; border-radius: 8px; font-weight: 600;
}
.w-root[data-theme="dark"] .w-wizard-ok,
.w-root[data-theme="black"] .w-wizard-ok { color: var(--w-text); }
.w-wizard-fail {
  background: var(--w-warn-bg); border: 1px solid var(--w-warn-border);
  color: var(--w-warn-text); padding: 14px 16px; border-radius: 8px;
  margin-block-start: 14px;
}
.w-wizard-fail p { margin: 6px 0 0; }

/* M2-only affordance: the fake takes sentinels, so no one pastes a real token. */
.w-fixture-hint {
  margin-block-start: 22px; padding-block-start: 16px;
  border-block-start: 1px dashed var(--w-border); font-size: 13px;
}
.w-fixture-row { display: flex; gap: 6px; flex-wrap: wrap; margin-block-start: 10px; }

@container widget (max-width: 520px) {
  .w-wizard { padding: 18px 16px; margin-block: 12px; }
  .w-wizard-title { font-size: 18px; }
}
