/* @udf/ui styles — primitives only, all colours from @udf/tokens. */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--udf-font);
  background: var(--udf-color-bg);
  color: var(--udf-color-text);
}

/* ── table ─────────────────────────────────────────────────────────────── */
.udf-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--udf-color-surface);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-md);
  overflow: hidden;
  font-size: 14px;
}
.udf-table caption { text-align: left; padding: var(--udf-space-3); color: var(--udf-color-muted); }
.udf-table { table-layout: auto; }
.udf-table th, .udf-table td {
  padding: var(--udf-space-3);
  text-align: left;
  border-bottom: 1px solid var(--udf-color-border);
  /* A cell never overflows its column: it ellipsises, the row keeps its height. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.udf-table th { color: var(--udf-color-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.udf-table tbody tr:last-child td { border-bottom: none; }
.udf-row--clickable { cursor: pointer; }
.udf-row--clickable:hover, .udf-row--clickable:focus { background: var(--udf-color-surface-2); outline: none; }

/* ── form ──────────────────────────────────────────────────────────────── */
.udf-form { display: grid; gap: var(--udf-space-3); }
.udf-field { display: grid; gap: var(--udf-space-1); }
.udf-field label { font-size: 12px; color: var(--udf-color-muted); }
.udf-field input, .udf-field select {
  background: var(--udf-color-surface-2);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-sm);
  color: var(--udf-color-text);
  padding: var(--udf-space-2) var(--udf-space-3);
  font: inherit;
}
.udf-field input:focus, .udf-field select:focus { outline: 2px solid var(--udf-color-primary); outline-offset: 1px; }
.udf-form__actions { display: flex; gap: var(--udf-space-2); }
.udf-form__error { color: var(--udf-color-danger); font-size: 13px; min-height: 1em; }

/* ── buttons ───────────────────────────────────────────────────────────── */
.udf-btn {
  background: var(--udf-color-surface-2);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-sm);
  color: var(--udf-color-text);
  padding: var(--udf-space-2) var(--udf-space-3);
  font: inherit;
  cursor: pointer;
}
.udf-btn:hover { border-color: var(--udf-color-primary); }
.udf-btn--primary { background: var(--udf-color-primary); border-color: var(--udf-color-primary); color: var(--udf-color-primary-contrast); }
.udf-btn--ghost { background: transparent; border-color: transparent; color: var(--udf-color-muted); }

/* ── details ───────────────────────────────────────────────────────────── */
.udf-details { display: grid; grid-template-columns: 140px 1fr; gap: var(--udf-space-2) var(--udf-space-3); margin: 0; }
.udf-details dt { color: var(--udf-color-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.udf-details dd { margin: 0; }

/* ── states ────────────────────────────────────────────────────────────── */
.udf-state {
  display: grid; gap: var(--udf-space-1);
  padding: var(--udf-space-5);
  border: 1px dashed var(--udf-color-border);
  border-radius: var(--udf-radius-md);
  color: var(--udf-color-muted);
  text-align: center;
  font-size: 14px;
}
.udf-state--error { border-color: var(--udf-color-danger); color: var(--udf-color-danger); }
.udf-state--forbidden { border-color: var(--udf-color-warning); color: var(--udf-color-warning); }
.udf-state__detail { font-size: 12px; opacity: 0.8; }

/* ── dialog ────────────────────────────────────────────────────────────── */
.udf-dialog__overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: grid; place-items: center; padding: var(--udf-space-4); z-index: 40;
}
.udf-dialog {
  background: var(--udf-color-surface);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-lg);
  box-shadow: var(--udf-shadow);
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
}
.udf-dialog__header { display: flex; justify-content: space-between; align-items: center; padding: var(--udf-space-3) var(--udf-space-4); border-bottom: 1px solid var(--udf-color-border); }
.udf-dialog__header h2 { font-size: 15px; margin: 0; }
.udf-dialog__body { padding: var(--udf-space-4); }

/* ── window ────────────────────────────────────────────────────────────── */
.udf-window {
  background: var(--udf-color-surface);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-lg);
  box-shadow: var(--udf-shadow);
  min-width: 320px;
  max-width: 100%;
}
.udf-window__header { display: flex; justify-content: space-between; align-items: center; padding: var(--udf-space-2) var(--udf-space-3); border-bottom: 1px solid var(--udf-color-border); }
.udf-window__title { font-size: 14px; margin: 0; }
.udf-window__body { padding: var(--udf-space-4); display: grid; gap: var(--udf-space-3); }

/* ── search ────────────────────────────────────────────────────────────── */
.udf-search__input {
  width: 100%;
  background: var(--udf-color-surface-2);
  border: 1px solid var(--udf-color-border);
  border-radius: var(--udf-radius-sm);
  color: var(--udf-color-text);
  padding: var(--udf-space-2) var(--udf-space-3);
  font: inherit;
}

/* ── toast ─────────────────────────────────────────────────────────────── */
#toasts { position: fixed; right: var(--udf-space-4); bottom: var(--udf-space-4); display: grid; gap: var(--udf-space-2); z-index: 60; }
.udf-toast {
  background: var(--udf-color-surface);
  border: 1px solid var(--udf-color-border);
  border-left: 3px solid var(--udf-color-primary);
  border-radius: var(--udf-radius-sm);
  padding: var(--udf-space-2) var(--udf-space-3);
  font-size: 13px;
  box-shadow: var(--udf-shadow);
  max-width: 360px;
}
.udf-toast--error { border-left-color: var(--udf-color-danger); }
.udf-toast--success { border-left-color: var(--udf-color-success); }
